Ghost/ghost/admin/app/controllers/settings/apps/slack.js
Kevin Ansfield 983110d931 Switched from ember-cli-shims to new module imports (#779)
no issue

- add eslint-plugin-ember, configure no-old-shims rule
- run `eslint --fix` on `app`, `lib`, `mirage`, and `tests` to move imports to the new module imports
- further cleanup of Ember globals usage
- remove event-dispatcher initializer now that `canDispatchToEventManager` is deprecated
2017-08-22 14:53:26 +07:00

64 lines
1.8 KiB
JavaScript

import Controller from '@ember/controller';
import {alias} from '@ember/object/computed';
import {empty} from '@ember/object/computed';
import {inject as injectService} from '@ember/service';
import {isInvalidError} from 'ember-ajax/errors';
import {task} from 'ember-concurrency';
export default Controller.extend({
ghostPaths: injectService(),
ajax: injectService(),
notifications: injectService(),
settings: injectService(),
model: alias('settings.slack.firstObject'),
testNotificationDisabled: empty('model.url'),
save: task(function* () {
let slack = this.get('model');
let settings = this.get('settings');
try {
yield slack.validate();
settings.get('slack').clear().pushObject(slack);
return yield settings.save();
} catch (error) {
if (error) {
this.get('notifications').showAPIError(error);
throw error;
}
}
}).drop(),
sendTestNotification: task(function* () {
let notifications = this.get('notifications');
let slackApi = this.get('ghostPaths.url').api('slack', 'test');
try {
yield this.get('save').perform();
yield this.get('ajax').post(slackApi);
notifications.showNotification('Check your Slack channel for the test message!', {type: 'info', key: 'slack-test.send.success'});
return true;
} catch (error) {
notifications.showAPIError(error, {key: 'slack-test:send'});
if (!isInvalidError(error)) {
throw error;
}
}
}).drop(),
actions: {
save() {
this.get('save').perform();
},
updateURL(value) {
this.set('model.url', value);
this.get('model.errors').clear();
}
}
});