2018-10-18 02:18:29 +03:00
|
|
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
|
|
|
import CurrentUserSettings from 'ghost-admin/mixins/current-user-settings';
|
2019-05-07 16:04:16 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2018-10-18 02:18:29 +03:00
|
|
|
|
2019-05-20 16:15:46 +03:00
|
|
|
export default AuthenticatedRoute.extend(CurrentUserSettings, {
|
2019-05-07 16:04:16 +03:00
|
|
|
router: service(),
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.router.on('routeWillChange', (transition) => {
|
|
|
|
this.showUnsavedChangesModal(transition);
|
2020-05-05 21:14:45 +03:00
|
|
|
if (this.controller) {
|
|
|
|
this.controller.set('selectedApiKey', null);
|
|
|
|
this.controller.set('isApiKeyRegenerated', false);
|
|
|
|
}
|
2019-05-07 16:04:16 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-10-18 02:18:29 +03:00
|
|
|
beforeModel() {
|
|
|
|
this._super(...arguments);
|
|
|
|
return this.get('session.user')
|
|
|
|
.then(this.transitionAuthor())
|
|
|
|
.then(this.transitionEditor());
|
|
|
|
},
|
|
|
|
|
|
|
|
model(params, transition) {
|
2019-04-04 14:25:16 +03:00
|
|
|
// use the integrations controller to fetch all integrations and pick
|
|
|
|
// out the one we want. Allows navigation back to integrations screen
|
|
|
|
// without a loading state
|
|
|
|
return this
|
2021-01-28 18:25:21 +03:00
|
|
|
.controllerFor('integrations')
|
2019-04-04 14:25:16 +03:00
|
|
|
.integrationModelHook('id', params.integration_id, this, transition);
|
2018-10-18 02:18:29 +03:00
|
|
|
},
|
|
|
|
|
2019-12-13 20:09:06 +03:00
|
|
|
deactivate() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.controller.set('leaveScreenTransition', null);
|
|
|
|
this.controller.set('showUnsavedChangesModal', false);
|
|
|
|
},
|
|
|
|
|
2018-10-18 02:18:29 +03:00
|
|
|
actions: {
|
|
|
|
save() {
|
|
|
|
this.controller.send('save');
|
2019-05-07 16:04:16 +03:00
|
|
|
}
|
|
|
|
},
|
2018-10-18 02:18:29 +03:00
|
|
|
|
2019-05-07 16:04:16 +03:00
|
|
|
showUnsavedChangesModal(transition) {
|
|
|
|
if (transition.from && transition.from.name.match(/^settings\.integration\./) && transition.targetName) {
|
2018-10-18 02:18:29 +03:00
|
|
|
let {controller} = this;
|
|
|
|
|
2018-11-06 13:59:47 +03:00
|
|
|
// check to see if we're navigating away from the custom integration
|
|
|
|
// route - we want to allow editing webhooks without showing the
|
|
|
|
// "unsaved changes" confirmation modal
|
|
|
|
let isExternalRoute =
|
2021-01-28 18:25:21 +03:00
|
|
|
// allow sub-routes of integration
|
|
|
|
!(transition.targetName || '').match(/^integration\./)
|
2018-11-06 13:59:47 +03:00
|
|
|
// do not allow changes in integration
|
2019-05-07 16:04:16 +03:00
|
|
|
// .to will be the index, so use .to.parent to get the route with the params
|
|
|
|
|| transition.to.parent.params.integration_id !== controller.integration.id;
|
2018-11-06 13:59:47 +03:00
|
|
|
|
|
|
|
if (isExternalRoute && !controller.integration.isDeleted && controller.integration.hasDirtyAttributes) {
|
2018-10-18 02:18:29 +03:00
|
|
|
transition.abort();
|
|
|
|
controller.send('toggleUnsavedChangesModal', transition);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-05-20 18:16:19 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
buildRouteInfoMetadata() {
|
|
|
|
return {
|
|
|
|
titleToken: 'Settings - Integrations'
|
|
|
|
};
|
2018-10-18 02:18:29 +03:00
|
|
|
}
|
|
|
|
});
|