Ghost/ghost/admin/app/controllers/settings/apps/slack.js
Kevin Ansfield cb59388c5b 💄🐷 sort-imports eslint rule (#712)
no issue

- adds `eslint-plugin-sort-imports-es6-autofix` dependency
  - implements ESLint's base `sort-imports` rule but has a distinction in that `import {foo} from 'bar';` is considered `multiple` rather than `single`
  - fixes ESLint's autofix behaviour so `eslint --fix` will actually fix the sort order
- updates all unordered import rules by using `eslint --fix`

With the increased number of `import` statements since Ember+ecosystem started moving towards es6 modules I've found it frustrating at times trying to search through randomly ordered import statements. Recently I've been sorting imports manually when I've added new code or touched old code so I thought I'd add an ESLint rule to codify it.
2017-05-29 20:50:03 +02:00

64 lines
1.8 KiB
JavaScript

import Controller from 'ember-controller';
import injectService from 'ember-service/inject';
import {alias} from 'ember-computed';
import {empty} from 'ember-computed';
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.showAlert('Check your slack channel 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();
}
}
});