mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-18 16:01:40 +03:00
17a6217cc7
fixes https://github.com/TryGhost/Team/issues/2404 This change introduces a new 'post' query parameter to the members and member routes. Previously, the members route would check if the previous route was the analytics page, and then show the breadcrumbs to go back to the analytics page. But when navigating to the members page from the menu, we don't want to show the breadcrumbs. To accomplish this, the routes that point to the members page from the analytics page now specifically pass on the post id in the query parameters. The query parameter is then passed on from the members page to the member page. `directlyFromAnalytics` is still used in the member route, to know wheter we came from the members page or from the analytics page (changes the breadcrumbs). This doesn't need to go via a query parameter (figured that would make the url too long/complex). The resetController method is now implemented and resets the filter and/or fromAnalytics post id if required (when going from members to member, we don't want to reset it because the we would lose the filter going back).
122 lines
3.3 KiB
JavaScript
122 lines
3.3 KiB
JavaScript
import AdminRoute from 'ghost-admin/routes/admin';
|
|
import ConfirmUnsavedChangesModal from '../components/modals/confirm-unsaved-changes';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default class MembersRoute extends AdminRoute {
|
|
@service feature;
|
|
@service modals;
|
|
@service router;
|
|
|
|
queryParams = {
|
|
postAnalytics: {refreshModel: false}
|
|
};
|
|
|
|
_requiresBackgroundRefresh = true;
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
this.router.on('routeWillChange', (transition) => {
|
|
this.closeImpersonateModal(transition);
|
|
});
|
|
}
|
|
|
|
model(params) {
|
|
this._requiresBackgroundRefresh = false;
|
|
|
|
if (params.member_id) {
|
|
return this.store.queryRecord('member', {id: params.member_id, include: 'tiers'});
|
|
} else {
|
|
return this.store.createRecord('member');
|
|
}
|
|
}
|
|
|
|
setupController(controller, member, transition) {
|
|
super.setupController(...arguments);
|
|
|
|
controller.setInitialRelationshipValues();
|
|
|
|
if (this._requiresBackgroundRefresh) {
|
|
controller.fetchMemberTask.perform(member.id);
|
|
}
|
|
|
|
controller.directlyFromAnalytics = false;
|
|
if (transition.from?.name === 'posts.analytics') {
|
|
controller.directlyFromAnalytics = true;
|
|
}
|
|
}
|
|
|
|
resetController(controller, isExiting) {
|
|
super.resetController(...arguments);
|
|
|
|
// Make sure we clear
|
|
if (isExiting && controller.postAnalytics) {
|
|
controller.set('postAnalytics', null);
|
|
controller.set('directlyFromAnalytics', false);
|
|
}
|
|
}
|
|
|
|
deactivate() {
|
|
this._requiresBackgroundRefresh = true;
|
|
|
|
this.confirmModal = null;
|
|
this.hasConfirmed = false;
|
|
}
|
|
|
|
@action
|
|
save() {
|
|
this.controller.save();
|
|
}
|
|
|
|
@action
|
|
async willTransition(transition) {
|
|
let hasDirtyAttributes = this.controller.dirtyAttributes;
|
|
|
|
// wait for any existing confirm modal to be closed before allowing transition
|
|
if (this.confirmModal) {
|
|
return;
|
|
}
|
|
|
|
if (!this.hasConfirmed && hasDirtyAttributes) {
|
|
transition.abort();
|
|
|
|
if (this.controller.saveTask?.isRunning) {
|
|
await this.controller.saveTask.last;
|
|
transition.retry();
|
|
}
|
|
|
|
const shouldLeave = await this.confirmUnsavedChanges();
|
|
|
|
if (shouldLeave) {
|
|
this.controller.model.rollbackAttributes();
|
|
this.hasConfirmed = true;
|
|
return transition.retry();
|
|
}
|
|
}
|
|
}
|
|
|
|
async confirmUnsavedChanges() {
|
|
this.confirmModal = this.modals
|
|
.open(ConfirmUnsavedChangesModal)
|
|
.finally(() => {
|
|
this.confirmModal = null;
|
|
});
|
|
|
|
return this.confirmModal;
|
|
}
|
|
|
|
closeImpersonateModal(transition) {
|
|
// If user navigates away with forward or back button, ensure returning to page
|
|
// hides modal
|
|
if (transition.from && transition.from.name === this.routeName && transition.targetName) {
|
|
let {controller} = this;
|
|
|
|
controller.closeImpersonateMemberModal(transition);
|
|
}
|
|
}
|
|
|
|
titleToken() {
|
|
return this.controller.member.name;
|
|
}
|
|
}
|