mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 02:41:50 +03:00
07f24e69f6
no issue - fixed `<GhTaskButton>` not resetting after an externally triggered task run such as when pressing Cmd+S - cleaned up manual timeouts/resets where button reset is now fully handled by `<GhTaskButton>` (these were causing 2.5s waits each time a save occurred in acceptance tests) - where manual timeouts were required, reduce testing time from >2.5s to 50ms
78 lines
2.2 KiB
JavaScript
78 lines
2.2 KiB
JavaScript
/* eslint-disable ghost/ember/alias-model-in-controller */
|
|
import Controller from '@ember/controller';
|
|
import {alias} from '@ember/object/computed';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default Controller.extend({
|
|
notifications: service(),
|
|
settings: service(),
|
|
|
|
leaveSettingsTransition: null,
|
|
|
|
ampSettings: alias('settings.amp'),
|
|
|
|
actions: {
|
|
update(value) {
|
|
this.set('ampSettings', value);
|
|
},
|
|
|
|
save() {
|
|
this.save.perform();
|
|
},
|
|
|
|
toggleLeaveSettingsModal(transition) {
|
|
let leaveTransition = this.leaveSettingsTransition;
|
|
|
|
if (!transition && this.showLeaveSettingsModal) {
|
|
this.set('leaveSettingsTransition', null);
|
|
this.set('showLeaveSettingsModal', false);
|
|
return;
|
|
}
|
|
|
|
if (!leaveTransition || transition.targetName === leaveTransition.targetName) {
|
|
this.set('leaveSettingsTransition', transition);
|
|
|
|
// if a save is running, wait for it to finish then transition
|
|
if (this.save.isRunning) {
|
|
return this.save.last.then(() => {
|
|
transition.retry();
|
|
});
|
|
}
|
|
|
|
// we genuinely have unsaved data, show the modal
|
|
this.set('showLeaveSettingsModal', true);
|
|
}
|
|
},
|
|
|
|
leaveSettings() {
|
|
let transition = this.leaveSettingsTransition;
|
|
let settings = this.settings;
|
|
|
|
if (!transition) {
|
|
this.notifications.showAlert('Sorry, there was an error in the application. Please let the Ghost team know what happened.', {type: 'error'});
|
|
return;
|
|
}
|
|
|
|
// roll back changes on settings model
|
|
settings.rollbackAttributes();
|
|
|
|
return transition.retry();
|
|
}
|
|
},
|
|
|
|
save: task(function* () {
|
|
let amp = this.ampSettings;
|
|
let settings = this.settings;
|
|
|
|
settings.set('amp', amp);
|
|
|
|
try {
|
|
return yield settings.save();
|
|
} catch (error) {
|
|
this.notifications.showAPIError(error);
|
|
throw error;
|
|
}
|
|
}).drop()
|
|
});
|