mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 01:42:29 +03:00
ee5aae8a90
refs https://github.com/TryGhost/Team/issues/1277 - removed inclusion of `email_recipients` in member query when fetching member for display on the member details screen as it was only used for the activity feed - added `<Member::ActivityFeed>` template-only component as a replacement for `<GhMemberActivityFeed>` - uses `members-event-fetcher` resource for consistency with main activity feed and dashboard widget. Allows for a template-only component because data fetching behaviour can be managed directly from the template rather than requiring a backing component
72 lines
2.3 KiB
JavaScript
72 lines
2.3 KiB
JavaScript
import AdminRoute from 'ghost-admin/routes/admin';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default class MembersRoute extends AdminRoute {
|
|
@service feature;
|
|
@service router;
|
|
|
|
_requiresBackgroundRefresh = true;
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
this.router.on('routeWillChange', (transition) => {
|
|
this.showUnsavedChangesModal(transition);
|
|
});
|
|
}
|
|
|
|
model(params) {
|
|
this._requiresBackgroundRefresh = false;
|
|
|
|
if (params.member_id) {
|
|
if (this.feature.membersActivityFeed) {
|
|
return this.store.queryRecord('member', {id: params.member_id, include: 'products'});
|
|
} else {
|
|
return this.store.queryRecord('member', {id: params.member_id, include: 'email_recipients,products'});
|
|
}
|
|
} else {
|
|
return this.store.createRecord('member');
|
|
}
|
|
}
|
|
|
|
setupController(controller, member) {
|
|
super.setupController(...arguments);
|
|
if (this._requiresBackgroundRefresh) {
|
|
// `member` is passed directly in `<LinkTo>` so it can be a proxy
|
|
// object used by the sparse list requiring the use of .get()
|
|
controller.fetchMemberTask.perform(member.get('id'));
|
|
}
|
|
}
|
|
|
|
deactivate() {
|
|
super.deactivate(...arguments);
|
|
// clean up newly created records and revert unsaved changes to existing
|
|
this.controller.member.rollbackAttributes();
|
|
this._requiresBackgroundRefresh = true;
|
|
}
|
|
|
|
@action
|
|
save() {
|
|
this.controller.save();
|
|
}
|
|
|
|
titleToken() {
|
|
return this.controller.member.name;
|
|
}
|
|
|
|
showUnsavedChangesModal(transition) {
|
|
if (transition.from && transition.from.name === this.routeName && transition.targetName) {
|
|
let {controller} = this;
|
|
|
|
// member.changedAttributes is always true for new members but number of changed attrs is reliable
|
|
let isChanged = Object.keys(controller.member.changedAttributes()).length > 0;
|
|
|
|
if (!controller.member.isDeleted && isChanged) {
|
|
transition.abort();
|
|
controller.toggleUnsavedChangesModal(transition);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|