2022-01-17 13:05:27 +03:00
|
|
|
import AdminRoute from 'ghost-admin/routes/admin';
|
2022-09-09 17:51:48 +03:00
|
|
|
import ConfirmUnsavedChangesModal from '../../components/modals/confirm-unsaved-changes';
|
|
|
|
import {action} from '@ember/object';
|
2021-10-18 15:46:29 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
2022-09-09 17:51:48 +03:00
|
|
|
export default class IntegrationRoute extends AdminRoute {
|
|
|
|
@service modals;
|
|
|
|
@service router;
|
2021-10-18 15:46:29 +03:00
|
|
|
|
|
|
|
model(params, transition) {
|
|
|
|
// 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
|
|
|
|
.controllerFor('settings.integrations')
|
|
|
|
.integrationModelHook('id', params.integration_id, this, transition);
|
2022-09-09 17:51:48 +03:00
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-11-14 12:41:09 +03:00
|
|
|
resetController(controller) {
|
|
|
|
controller.regeneratedApiKey = null;
|
|
|
|
}
|
|
|
|
|
2021-10-18 15:46:29 +03:00
|
|
|
deactivate() {
|
2022-09-09 17:51:48 +03:00
|
|
|
this.confirmModal = null;
|
|
|
|
this.hasConfirmed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async willTransition(transition) {
|
|
|
|
if (this.hasConfirmed) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
transition.abort();
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-09-09 17:51:48 +03:00
|
|
|
// wait for any existing confirm modal to be closed before allowing transition
|
|
|
|
if (this.confirmModal) {
|
|
|
|
return;
|
2021-10-18 15:46:29 +03:00
|
|
|
}
|
|
|
|
|
2022-09-09 17:51:48 +03:00
|
|
|
if (this.controller.saveTask?.isRunning) {
|
|
|
|
await this.controller.saveTask.last;
|
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-09-09 17:51:48 +03:00
|
|
|
const shouldLeave = await this.confirmUnsavedChanges();
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-09-09 17:51:48 +03:00
|
|
|
if (shouldLeave) {
|
|
|
|
this.controller.model.rollbackAttributes();
|
|
|
|
this.hasConfirmed = true;
|
|
|
|
return transition.retry();
|
2021-10-18 15:46:29 +03:00
|
|
|
}
|
2022-09-09 17:51:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
async confirmUnsavedChanges() {
|
|
|
|
if (this.controller.model?.hasDirtyAttributes) {
|
|
|
|
this.confirmModal = this.modals
|
|
|
|
.open(ConfirmUnsavedChangesModal)
|
|
|
|
.finally(() => {
|
|
|
|
this.confirmModal = null;
|
|
|
|
});
|
|
|
|
|
|
|
|
return this.confirmModal;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
save() {
|
|
|
|
this.controller.send('save');
|
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
|
|
|
buildRouteInfoMetadata() {
|
|
|
|
return {
|
|
|
|
titleToken: 'Settings - Integrations'
|
|
|
|
};
|
|
|
|
}
|
2022-09-09 17:51:48 +03:00
|
|
|
}
|