2019-01-24 22:34:32 +03:00
|
|
|
import Controller from '@ember/controller';
|
|
|
|
import {alias} from '@ember/object/computed';
|
2019-04-16 18:02:43 +03:00
|
|
|
import {computed} from '@ember/object';
|
2019-02-22 14:31:45 +03:00
|
|
|
import {inject as controller} from '@ember/controller';
|
|
|
|
import {inject as service} from '@ember/service';
|
2019-04-16 18:02:43 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2019-01-24 22:34:32 +03:00
|
|
|
|
|
|
|
export default Controller.extend({
|
2019-02-22 14:31:45 +03:00
|
|
|
members: controller(),
|
2019-04-16 18:02:43 +03:00
|
|
|
store: service(),
|
|
|
|
|
2019-02-22 14:31:45 +03:00
|
|
|
router: service(),
|
|
|
|
|
|
|
|
member: alias('model'),
|
|
|
|
|
2019-04-16 18:02:43 +03:00
|
|
|
subscription: computed('member.subscriptions', function () {
|
2019-04-16 20:29:52 +03:00
|
|
|
let subscriptions = this.member.get('subscriptions');
|
|
|
|
if (!subscriptions) {
|
|
|
|
return {
|
|
|
|
amount: '...',
|
|
|
|
status: '...',
|
|
|
|
plan: '...'
|
|
|
|
};
|
|
|
|
}
|
2019-04-16 18:02:43 +03:00
|
|
|
let subscription = subscriptions[0] || {};
|
|
|
|
return {
|
2019-04-16 20:29:52 +03:00
|
|
|
amount: subscription.amount ? (subscription.amount / 100) : 0,
|
|
|
|
status: subscription.status || '-',
|
2019-04-16 19:07:02 +03:00
|
|
|
plan: subscription.plan || 'Free'
|
2019-04-16 18:02:43 +03:00
|
|
|
};
|
|
|
|
}),
|
|
|
|
|
2019-02-22 14:31:45 +03:00
|
|
|
actions: {
|
|
|
|
finaliseDeletion() {
|
|
|
|
// decrememnt the total member count manually so there's no flash
|
|
|
|
// when transitioning back to the members list
|
|
|
|
if (this.members.meta) {
|
|
|
|
this.members.decrementProperty('meta.pagination.total');
|
|
|
|
}
|
|
|
|
this.router.transitionTo('members');
|
|
|
|
}
|
2019-04-16 18:02:43 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
fetchMember: task(function* (memberId) {
|
|
|
|
yield this.store.findRecord('member', memberId, {
|
|
|
|
reload: true
|
|
|
|
}).then((data) => {
|
|
|
|
this.set('member', data);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
|
2019-01-24 22:34:32 +03:00
|
|
|
});
|