2022-02-01 12:34:03 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
2021-10-18 15:46:29 +03:00
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
2022-02-01 12:34:03 +03:00
|
|
|
/* eslint-disable ghost/ember/alias-model-in-controller */
|
|
|
|
import Controller from '@ember/controller';
|
2021-10-18 15:46:29 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@classic
|
|
|
|
export default class IntegrationsController extends Controller {
|
2022-02-01 20:03:45 +03:00
|
|
|
@service settings;
|
|
|
|
@service store;
|
|
|
|
@service config;
|
2022-02-01 12:34:03 +03:00
|
|
|
|
|
|
|
_allIntegrations = null;
|
2021-10-18 15:46:29 +03:00
|
|
|
|
|
|
|
init() {
|
2022-02-01 12:34:03 +03:00
|
|
|
super.init(...arguments);
|
2021-10-18 15:46:29 +03:00
|
|
|
this._allIntegrations = this.store.peekAll('integration');
|
2022-02-01 12:34:03 +03:00
|
|
|
}
|
2021-10-18 15:46:29 +03:00
|
|
|
|
2022-02-01 12:34:03 +03:00
|
|
|
@computed('config.hostSettings.limits')
|
|
|
|
get zapierDisabled() {
|
2021-10-18 15:46:29 +03:00
|
|
|
return this.config.get('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
|
|
|
@computed('_allIntegrations.@each.{isNew,type}')
|
|
|
|
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-02-01 12:34:03 +03:00
|
|
|
@task(function* () {
|
2021-10-18 15:46:29 +03:00
|
|
|
return yield this.store.findAll('integration');
|
2022-02-01 12:34:03 +03:00
|
|
|
})
|
2022-02-10 13:41:36 +03:00
|
|
|
fetchIntegrations;
|
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
|
|
|
}
|