diff --git a/ghost/admin/app/controllers/member.js b/ghost/admin/app/controllers/member.js index dc0b12c5e7..e0e4a7afee 100644 --- a/ghost/admin/app/controllers/member.js +++ b/ghost/admin/app/controllers/member.js @@ -1,14 +1,29 @@ import Controller from '@ember/controller'; import {alias} from '@ember/object/computed'; +import {computed} from '@ember/object'; import {inject as controller} from '@ember/controller'; import {inject as service} from '@ember/service'; +import {task} from 'ember-concurrency'; export default Controller.extend({ members: controller(), + store: service(), + router: service(), member: alias('model'), + subscription: computed('member.subscriptions', function () { + let subscriptions = this.member.get('subscriptions') || []; + let subscription = subscriptions[0] || {}; + return { + amount: subscription.amount ? (subscription.amount / 100) : '-', + status: subscription.status || '-', + plan: subscription.plan || '-' + + }; + }), + actions: { finaliseDeletion() { // decrememnt the total member count manually so there's no flash @@ -18,5 +33,14 @@ export default Controller.extend({ } this.router.transitionTo('members'); } - } + }, + + fetchMember: task(function* (memberId) { + yield this.store.findRecord('member', memberId, { + reload: true + }).then((data) => { + this.set('member', data); + }); + }) + }); diff --git a/ghost/admin/app/models/member-subscription.js b/ghost/admin/app/models/member-subscription.js new file mode 100644 index 0000000000..4b83d59b72 --- /dev/null +++ b/ghost/admin/app/models/member-subscription.js @@ -0,0 +1,9 @@ +import EmberObject from '@ember/object'; + +export default EmberObject.extend({ + adapter: '', + amount: 0, + plan: '', + status: '', + validUntil: 0 +}); diff --git a/ghost/admin/app/models/member.js b/ghost/admin/app/models/member.js index 6ba5795b0c..e92f537fa1 100644 --- a/ghost/admin/app/models/member.js +++ b/ghost/admin/app/models/member.js @@ -4,5 +4,6 @@ import attr from 'ember-data/attr'; export default DS.Model.extend({ name: attr('string'), email: attr('string'), - createdAt: attr('moment-utc') + createdAt: attr('moment-utc'), + subscriptions: attr('member-subscription') }); diff --git a/ghost/admin/app/routes/member.js b/ghost/admin/app/routes/member.js index 5880e6ac3c..028bf8b66a 100644 --- a/ghost/admin/app/routes/member.js +++ b/ghost/admin/app/routes/member.js @@ -1,7 +1,26 @@ import AuthenticatedRoute from 'ghost-admin/routes/authenticated'; export default AuthenticatedRoute.extend({ - // TODO: add model method to load member if not passed in + model(params) { + this._isMemberUpdated = true; + return this.store.findRecord('member', params.member_id, { + reload: true + }); + }, + + setupController(controller, model) { + this._super(...arguments); + if (!this._isMemberUpdated) { + controller.fetchMember.perform(model.get('id')); + } + }, + + deactivate() { + this._super(...arguments); + + // clear the properties + this._isMemberUpdated = false; + }, titleToken() { return this.controller.get('member.name'); diff --git a/ghost/admin/app/templates/member.hbs b/ghost/admin/app/templates/member.hbs index 4010e49e2e..0b8ddf5a20 100644 --- a/ghost/admin/app/templates/member.hbs +++ b/ghost/admin/app/templates/member.hbs @@ -32,8 +32,8 @@