2018-01-11 01:57:43 +03:00
|
|
|
/* eslint-disable ghost/ember/alias-model-in-controller */
|
2018-01-09 13:36:41 +03:00
|
|
|
import Controller from '@ember/controller';
|
2018-10-04 14:16:41 +03:00
|
|
|
import config from 'ghost-admin/config/environment';
|
2019-04-04 14:25:16 +03:00
|
|
|
import copyTextToClipboard from 'ghost-admin/utils/copy-text-to-clipboard';
|
|
|
|
import {alias} from '@ember/object/computed';
|
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
import {task, timeout} from 'ember-concurrency';
|
2018-01-09 13:36:41 +03:00
|
|
|
|
|
|
|
export default Controller.extend({
|
2019-04-04 14:25:16 +03:00
|
|
|
ghostPaths: service(),
|
|
|
|
|
2020-05-05 21:14:45 +03:00
|
|
|
selectedApiKey: null,
|
|
|
|
isApiKeyRegenerated: false,
|
2018-10-04 14:16:41 +03:00
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
if (this.isTesting === undefined) {
|
|
|
|
this.isTesting = config.environment === 'test';
|
|
|
|
}
|
2019-04-04 14:25:16 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
integration: alias('model'),
|
|
|
|
|
|
|
|
apiUrl: computed(function () {
|
|
|
|
let origin = window.location.origin;
|
|
|
|
let subdir = this.ghostPaths.subdir;
|
|
|
|
let url = this.ghostPaths.url.join(origin, subdir);
|
|
|
|
|
|
|
|
return url.replace(/\/$/, '');
|
|
|
|
}),
|
|
|
|
|
2020-05-05 21:14:45 +03:00
|
|
|
regeneratedKeyType: computed('isApiKeyRegenerated', 'selectedApiKey', function () {
|
|
|
|
if (this.isApiKeyRegenerated) {
|
|
|
|
return this.get('selectedApiKey.type');
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}),
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
confirmRegenerateKeyModal(apiKey) {
|
|
|
|
this.set('showRegenerateKeyModal', true);
|
|
|
|
this.set('isApiKeyRegenerated', false);
|
|
|
|
this.set('selectedApiKey', apiKey);
|
|
|
|
},
|
|
|
|
|
|
|
|
cancelRegenerateKeyModal() {
|
|
|
|
this.set('showRegenerateKeyModal', false);
|
|
|
|
},
|
|
|
|
|
|
|
|
regenerateKey() {
|
|
|
|
this.set('isApiKeyRegenerated', true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-04-04 14:25:16 +03:00
|
|
|
copyAdminKey: task(function* () {
|
|
|
|
copyTextToClipboard(this.integration.adminKey.secret);
|
2020-05-11 13:37:35 +03:00
|
|
|
yield timeout(this.isTesting ? 50 : 3000);
|
2019-04-04 14:25:16 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
copyApiUrl: task(function* () {
|
|
|
|
copyTextToClipboard(this.apiUrl);
|
2020-05-11 13:37:35 +03:00
|
|
|
yield timeout(this.isTesting ? 50 : 3000);
|
2019-04-04 14:25:16 +03:00
|
|
|
})
|
2018-01-09 13:36:41 +03:00
|
|
|
});
|