mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03: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
@ -1,17 +1,12 @@
|
||||
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 feature;
|
||||
@service modals;
|
||||
@service settings;
|
||||
@service ui;
|
||||
|
||||
confirmModal = null;
|
||||
hasConfirmed = false;
|
||||
|
||||
beforeModel() {
|
||||
super.beforeModel(...arguments);
|
||||
|
||||
@ -32,27 +27,8 @@ export default class SettingsDesignRoute extends AuthenticatedRoute {
|
||||
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() {
|
||||
this.ui.contextualNavMenu = null;
|
||||
this.confirmModal = null;
|
||||
this.hasConfirmed = false;
|
||||
}
|
||||
|
||||
buildRouteInfoMetadata() {
|
||||
@ -60,25 +36,3 @@ export default class SettingsDesignRoute extends AuthenticatedRoute {
|
||||
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() {
|
||||
run(() => this.store.unloadAll('custom-theme-setting'));
|
||||
|
||||
this.settings = [];
|
||||
this.settingGroups = [];
|
||||
this.settings.forEach(setting => setting.rollbackAttributes());
|
||||
}
|
||||
|
||||
_buildSettingGroups(settings) {
|
||||
|
Loading…
Reference in New Issue
Block a user