2022-02-01 12:34:03 +03:00
|
|
|
import Controller from '@ember/controller';
|
2022-11-03 14:14:36 +03:00
|
|
|
import {inject} from 'ghost-admin/decorators/inject';
|
2022-09-08 11:18:51 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2021-10-18 15:46:29 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
export default class IntegrationsController extends Controller {
|
2022-02-01 20:03:45 +03:00
|
|
|
@service settings;
|
|
|
|
@service store;
|
2022-11-03 14:14:36 +03:00
|
|
|
|
|
|
|
@inject config;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
2022-09-08 11:18:51 +03:00
|
|
|
_allIntegrations = this.store.peekAll('integration');
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
get zapierDisabled() {
|
2022-10-07 17:24:03 +03:00
|
|
|
return this.config.hostSettings?.limits?.customIntegrations?.disabled;
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
|
|
|
// filter over the live query so that the list is automatically updated
|
|
|
|
// as integrations are added/removed
|
2022-02-01 12:34:03 +03:00
|
|
|
get integrations() {
|
2021-10-18 15:46:29 +03:00
|
|
|
return this._allIntegrations.reject((integration) => {
|
|
|
|
return integration.isNew || integration.type !== 'custom';
|
|
|
|
});
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
|
|
|
// use ember-concurrency so that we can use the derived state to show
|
|
|
|
// a spinner only in the integrations list and avoid delaying the whole
|
|
|
|
// screen display
|
2022-09-08 11:18:51 +03:00
|
|
|
@task
|
|
|
|
*fetchIntegrations() {
|
2021-10-18 15:46:29 +03:00
|
|
|
return yield this.store.findAll('integration');
|
2022-09-08 11:18:51 +03:00
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
|
|
|
// used by individual integration routes' `model` hooks
|
|
|
|
integrationModelHook(prop, value, route, transition) {
|
|
|
|
let preloadedIntegration = this.store.peekAll('integration').findBy(prop, value);
|
|
|
|
|
|
|
|
if (preloadedIntegration) {
|
|
|
|
return preloadedIntegration;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.fetchIntegrations.perform().then((integrations) => {
|
|
|
|
let integration = integrations.findBy(prop, value);
|
|
|
|
|
|
|
|
if (!integration) {
|
|
|
|
let path = transition.intent.url.replace(/^\//, '');
|
|
|
|
return route.replaceWith('error404', {path, status: 404});
|
|
|
|
}
|
|
|
|
|
|
|
|
return integration;
|
|
|
|
});
|
|
|
|
}
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|