diff --git a/app/controllers/settings/apps/index.js b/app/controllers/settings/apps/index.js new file mode 100644 index 000000000..5017fbc1d --- /dev/null +++ b/app/controllers/settings/apps/index.js @@ -0,0 +1,14 @@ +import Ember from 'ember'; + +const { + computed, + inject: {controller} +} = Ember; + +const {alias} = computed; + +export default Ember.Controller.extend({ + appsController: controller('settings.apps'), + + slack: alias('appsController.model.slack.firstObject') +}); diff --git a/app/controllers/settings/apps/slack.js b/app/controllers/settings/apps/slack.js new file mode 100644 index 000000000..26877cd8a --- /dev/null +++ b/app/controllers/settings/apps/slack.js @@ -0,0 +1,75 @@ +import Ember from 'ember'; +import { invoke } from 'ember-invoke-action'; + +const { + Controller, + computed: {empty}, + inject: {service} +} = Ember; + +export default Controller.extend({ + ghostPaths: service(), + ajax: service(), + notifications: service(), + + // will be set by route + settings: null, + + isSaving: false, + savePromise: null, + isSendingTest: false, + + testNotificationDisabled: empty('model.url'), + + actions: { + sendTestNotification() { + let notifications = this.get('notifications'); + let slackApi = this.get('ghostPaths.url').api('slack', 'test'); + + if (this.get('isSendingTest')) { + return; + } + + this.set('isSendingTest', true); + + invoke(this, 'save').then(() => { + this.get('ajax').post(slackApi).then(() => { + notifications.showAlert('Check your slack channel test message.', {type: 'info', key: 'slack-test.send.success'}); + }).catch((error) => { + notifications.showAPIError(error, {key: 'slack-test:send'}); + }); + }).catch(() => { + // noop - error already handled in .save + }).finally(() => { + this.set('isSendingTest', false); + }); + }, + + updateURL(value) { + this.set('model.url', value); + this.get('model.errors').clear(); + }, + + save() { + let slack = this.get('model'); + let settings = this.get('settings'); + + if (this.get('isSaving')) { + return; + } + + return slack.validate().then(() => { + settings.get('slack').clear().pushObject(slack); + + this.set('isSaving', true); + + return settings.save().catch((err) => { + this.get('notifications').showErrors(err); + throw err; + }).finally(() => { + this.set('isSaving', false); + }); + }); + } + } +}); diff --git a/app/html/apps.html b/app/html/apps.html index ba3a41e0e..ec8783bdd 100644 --- a/app/html/apps.html +++ b/app/html/apps.html @@ -47,8 +47,8 @@
  • Navigation
  • Tags
  • Code Injection
  • -
  • Labs
  • -
  • Apps
  • +
  • Labs
  • +
  • Apps