From c260a4e34d8df1a6f8263ca0d3b5c3a6a8a8bb29 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Mon, 9 Jan 2017 11:22:35 +0800 Subject: [PATCH] FIX: Can't add categories when creating a new web hook. --- .../admin/controllers/admin-web-hooks-show.js.es6 | 6 ++++++ app/assets/javascripts/admin/models/web-hook.js.es6 | 13 +++++++------ .../javascripts/admin/templates/web-hooks-show.hbs | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/admin/controllers/admin-web-hooks-show.js.es6 b/app/assets/javascripts/admin/controllers/admin-web-hooks-show.js.es6 index 53d8370403b..28f93925127 100644 --- a/app/assets/javascripts/admin/controllers/admin-web-hooks-show.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-web-hooks-show.js.es6 @@ -65,10 +65,16 @@ export default Ember.Controller.extend({ this.set('saved', false); const url = extractDomainFromUrl(this.get('model.payload_url')); const model = this.get('model'); + const isNew = model.get('isNew'); + const saveWebHook = () => { return model.save().then(() => { this.set('saved', true); this.get('adminWebHooks').get('model').addObject(model); + + if (isNew) { + this.transitionToRoute('adminWebHooks.show', model.get('id')); + } }).catch(popupAjaxError); }; diff --git a/app/assets/javascripts/admin/models/web-hook.js.es6 b/app/assets/javascripts/admin/models/web-hook.js.es6 index e688a4dd0a1..1ed76970efc 100644 --- a/app/assets/javascripts/admin/models/web-hook.js.es6 +++ b/app/assets/javascripts/admin/models/web-hook.js.es6 @@ -10,7 +10,6 @@ export default RestModel.extend({ verify_certificate: true, active: false, web_hook_event_types: null, - categoriesFilter: null, groupsFilterInName: null, @computed('wildcard_web_hook') @@ -23,9 +22,9 @@ export default RestModel.extend({ } }, - @observes('category_ids') - updateCategoriesFilter() { - this.set('categoriesFilter', Category.findByIds(this.get('category_ids'))); + @computed('category_ids') + categories(categoryIds) { + return Category.findByIds(categoryIds); }, @observes('group_ids') @@ -55,7 +54,9 @@ export default RestModel.extend({ createProperties() { const types = this.get('web_hook_event_types'); - const categories = this.get('categoriesFilter'); + const categories = this.get('categories'); + const categoryIds = this.get('categories').map(c => c.id); + // Hack as {{group-selector}} accepts a comma-separated string as data source, but // we use an array to populate the datasource above. const groupsFilter = this.get('groupsFilterInName'); @@ -69,7 +70,7 @@ export default RestModel.extend({ verify_certificate: this.get('verify_certificate'), active: this.get('active'), web_hook_event_type_ids: Ember.isEmpty(types) ? [null] : types.map(type => type.id), - category_ids: Ember.isEmpty(categories) ? [null] : categories.map(c => c.id), + category_ids: Ember.isEmpty(categoryIds) ? [null] : categoryIds, group_ids: Ember.isEmpty(groupNames) || Ember.isEmpty(groupNames[0]) ? [null] : Discourse.Site.currentProp('groups') .reduce((groupIds, g) => { if (groupNames.includes(g.name)) { groupIds.push(g.id); } diff --git a/app/assets/javascripts/admin/templates/web-hooks-show.hbs b/app/assets/javascripts/admin/templates/web-hooks-show.hbs index b0e0c0c0bfb..458a18c1e22 100644 --- a/app/assets/javascripts/admin/templates/web-hooks-show.hbs +++ b/app/assets/javascripts/admin/templates/web-hooks-show.hbs @@ -50,7 +50,7 @@
- {{category-selector categories=model.categoriesFilter blacklist=model.categoriesFilter}} + {{category-selector categories=model.categories blacklist=model.categories}}
{{i18n 'admin.web_hooks.categories_filter_instructions'}}