mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 07:09:48 +03:00
5047b9f3d7
refs https://github.com/TryGhost/Ghost/issues/9865, https://github.com/TryGhost/Ghost/issues/9942 - `integration`, `api-key`, and `webhook` models and respective mirage mocks - moves integration routes around to match ember's concept of nested routes (nested routes reflect nested UI not nested URLs) - adds custom integrations list to integrations screen - adds custom integration screen - allow editing of integration details - show list of webhooks - webhook creation modal NB: the `enableDeveloperExperiments` flag needs to be enabled in the `config.development.json` file for the custom integrations UI to be displayed until it's out of development.
88 lines
2.6 KiB
JavaScript
88 lines
2.6 KiB
JavaScript
import Controller from '@ember/controller';
|
|
import {alias} from '@ember/object/computed';
|
|
import {computed} from '@ember/object';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default Controller.extend({
|
|
integration: alias('model'),
|
|
|
|
allWebhooks: computed(function () {
|
|
return this.store.peekAll('webhook');
|
|
}),
|
|
|
|
filteredWebhooks: computed('allWebhooks.@each.{isNew,isDeleted}', function () {
|
|
return this.allWebhooks.filter((webhook) => {
|
|
let matchesIntegration = webhook.belongsTo('integration').id() === this.integration.id;
|
|
|
|
return matchesIntegration
|
|
&& !webhook.isNew
|
|
&& !webhook.isDeleted;
|
|
});
|
|
}),
|
|
|
|
actions: {
|
|
save() {
|
|
return this.save.perform();
|
|
},
|
|
|
|
copyContentKey() {
|
|
this._copyInputTextToClipboard('input#content_key');
|
|
},
|
|
|
|
copyAdminKey() {
|
|
this._copyInputTextToClipboard('input#admin_key');
|
|
},
|
|
|
|
toggleUnsavedChangesModal(transition) {
|
|
let leaveTransition = this.leaveScreenTransition;
|
|
|
|
if (!transition && this.showUnsavedChangesModal) {
|
|
this.set('leaveScreenTransition', null);
|
|
this.set('showUnsavedChangesModal', false);
|
|
return;
|
|
}
|
|
|
|
if (!leaveTransition || transition.targetName === leaveTransition.targetName) {
|
|
this.set('leaveScreenTransition', 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('showUnsavedChangesModal', true);
|
|
}
|
|
},
|
|
|
|
leaveScreen() {
|
|
let transition = this.leaveScreenTransition;
|
|
|
|
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 model props
|
|
this.integration.rollbackAttributes();
|
|
|
|
return transition.retry();
|
|
}
|
|
},
|
|
|
|
save: task(function* () {
|
|
return yield this.integration.save();
|
|
}),
|
|
|
|
_copyInputTextToClipboard(selector) {
|
|
let input = document.querySelector(selector);
|
|
input.disabled = false;
|
|
input.focus();
|
|
input.select();
|
|
document.execCommand('copy');
|
|
input.disabled = true;
|
|
}
|
|
});
|