mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Fixed custom theme settings disappearing when confirming leave-without-save
refs https://github.com/TryGhost/Team/issues/1149 - `customThemeSettings.rollback()` was not performing the correct job, changed to rollback attributes on each model rather than resetting everything to empty - moved leave confirmation handling to the `settings.design.index` route so that it's always called when moving to the change-theme route, previously with the behaviour on the main `settings.design` route the willtransition/deactivate was not called when expected because that route is still active when on `settings.design.change-theme`
This commit is contained in:
parent
7534dbc7a6
commit
d9c9818c73
3 changed files with 56 additions and 50 deletions
|
@ -1,17 +1,12 @@
|
||||||
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
||||||
import {action} from '@ember/object';
|
|
||||||
import {inject as service} from '@ember/service';
|
import {inject as service} from '@ember/service';
|
||||||
|
|
||||||
export default class SettingsDesignRoute extends AuthenticatedRoute {
|
export default class SettingsDesignRoute extends AuthenticatedRoute {
|
||||||
@service customThemeSettings;
|
|
||||||
@service feature;
|
@service feature;
|
||||||
@service modals;
|
@service modals;
|
||||||
@service settings;
|
@service settings;
|
||||||
@service ui;
|
@service ui;
|
||||||
|
|
||||||
confirmModal = null;
|
|
||||||
hasConfirmed = false;
|
|
||||||
|
|
||||||
beforeModel() {
|
beforeModel() {
|
||||||
super.beforeModel(...arguments);
|
super.beforeModel(...arguments);
|
||||||
|
|
||||||
|
@ -32,27 +27,8 @@ export default class SettingsDesignRoute extends AuthenticatedRoute {
|
||||||
this.ui.contextualNavMenu = 'design';
|
this.ui.contextualNavMenu = 'design';
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
|
||||||
willTransition(transition) {
|
|
||||||
if (this.hasConfirmed) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// always abort when not confirmed because Ember's router doesn't automatically wait on promises
|
|
||||||
transition.abort();
|
|
||||||
|
|
||||||
this.confirmUnsavedChanges().then((shouldLeave) => {
|
|
||||||
if (shouldLeave) {
|
|
||||||
this.hasConfirmed = true;
|
|
||||||
return transition.retry();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
deactivate() {
|
deactivate() {
|
||||||
this.ui.contextualNavMenu = null;
|
this.ui.contextualNavMenu = null;
|
||||||
this.confirmModal = null;
|
|
||||||
this.hasConfirmed = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buildRouteInfoMetadata() {
|
buildRouteInfoMetadata() {
|
||||||
|
@ -60,25 +36,3 @@ export default class SettingsDesignRoute extends AuthenticatedRoute {
|
||||||
mainClasses: ['gh-main-fullwidth']
|
mainClasses: ['gh-main-fullwidth']
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
confirmUnsavedChanges() {
|
|
||||||
if (!this.settings.get('hasDirtyAttributes') && !this.customThemeSettings.isDirty) {
|
|
||||||
return Promise.resolve(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.confirmModal) {
|
|
||||||
this.confirmModal = this.modals.open('modals/confirm-unsaved-changes')
|
|
||||||
.then((discardChanges) => {
|
|
||||||
if (discardChanges === true) {
|
|
||||||
this.settings.rollbackAttributes();
|
|
||||||
this.customThemeSettings.rollback();
|
|
||||||
}
|
|
||||||
return discardChanges;
|
|
||||||
}).finally(() => {
|
|
||||||
this.confirmModal = null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.confirmModal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
55
ghost/admin/app/routes/settings/design/index.js
Normal file
55
ghost/admin/app/routes/settings/design/index.js
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
||||||
|
import {action} from '@ember/object';
|
||||||
|
import {inject as service} from '@ember/service';
|
||||||
|
|
||||||
|
export default class SettingsDesignRoute extends AuthenticatedRoute {
|
||||||
|
@service customThemeSettings;
|
||||||
|
@service modals;
|
||||||
|
@service settings;
|
||||||
|
|
||||||
|
confirmModal = null;
|
||||||
|
hasConfirmed = false;
|
||||||
|
|
||||||
|
@action
|
||||||
|
willTransition(transition) {
|
||||||
|
if (this.hasConfirmed) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// always abort when not confirmed because Ember's router doesn't automatically wait on promises
|
||||||
|
transition.abort();
|
||||||
|
|
||||||
|
this.confirmUnsavedChanges().then((shouldLeave) => {
|
||||||
|
if (shouldLeave) {
|
||||||
|
this.hasConfirmed = true;
|
||||||
|
return transition.retry();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
deactivate() {
|
||||||
|
this.confirmModal = null;
|
||||||
|
this.hasConfirmed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
confirmUnsavedChanges() {
|
||||||
|
if (!this.settings.get('hasDirtyAttributes') && !this.customThemeSettings.isDirty) {
|
||||||
|
return Promise.resolve(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.confirmModal) {
|
||||||
|
this.confirmModal = this.modals.open('modals/confirm-unsaved-changes')
|
||||||
|
.then((discardChanges) => {
|
||||||
|
if (discardChanges === true) {
|
||||||
|
this.settings.rollbackAttributes();
|
||||||
|
this.customThemeSettings.rollback();
|
||||||
|
}
|
||||||
|
return discardChanges;
|
||||||
|
}).finally(() => {
|
||||||
|
this.confirmModal = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.confirmModal;
|
||||||
|
}
|
||||||
|
}
|
|
@ -79,10 +79,7 @@ export default class CustomThemeSettingsServices extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
rollback() {
|
rollback() {
|
||||||
run(() => this.store.unloadAll('custom-theme-setting'));
|
this.settings.forEach(setting => setting.rollbackAttributes());
|
||||||
|
|
||||||
this.settings = [];
|
|
||||||
this.settingGroups = [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_buildSettingGroups(settings) {
|
_buildSettingGroups(settings) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue