From 3090c016d08f0c21a48772e8a35a6a6a345afbf0 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Thu, 14 Dec 2017 14:40:08 +0100 Subject: [PATCH] FIX: do not display used categories as selectable in categories notifications preferences --- .../discourse/controllers/preferences/categories.js.es6 | 6 ++++++ .../discourse/controllers/preferences/notifications.js.es6 | 6 ------ .../discourse/templates/preferences/categories.hbs | 3 +-- .../select-kit/components/category-selector.js.es6 | 5 ++++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6 b/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6 index 58103411a81..f394acd3e1e 100644 --- a/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6 +++ b/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6 @@ -1,5 +1,6 @@ import PreferencesTabController from "discourse/mixins/preferences-tab-controller"; import { popupAjaxError } from 'discourse/lib/ajax-error'; +import { default as computed } from "ember-addons/ember-computed-decorators"; export default Ember.Controller.extend(PreferencesTabController, { saveAttrNames: [ @@ -9,6 +10,11 @@ export default Ember.Controller.extend(PreferencesTabController, { 'watched_first_post_category_ids' ], + @computed("model.watchedCategories", "model.watchedFirstPostCategories", "model.trackedCategories", "model.mutedCategories") + selectedCategories(watched, watchedFirst, tracked, muted) { + return [].concat(watched, watchedFirst, tracked, muted); + }, + canSave: function() { return this.get('currentUser.id') === this.get('model.id') || this.get('currentUser.admin'); diff --git a/app/assets/javascripts/discourse/controllers/preferences/notifications.js.es6 b/app/assets/javascripts/discourse/controllers/preferences/notifications.js.es6 index bd9609b09a9..dbc8a4aa2f5 100644 --- a/app/assets/javascripts/discourse/controllers/preferences/notifications.js.es6 +++ b/app/assets/javascripts/discourse/controllers/preferences/notifications.js.es6 @@ -1,5 +1,4 @@ import PreferencesTabController from "discourse/mixins/preferences-tab-controller"; -import { default as computed } from "ember-addons/ember-computed-decorators"; import { NotificationLevels } from 'discourse/lib/notification-levels'; import { popupAjaxError } from 'discourse/lib/ajax-error'; @@ -14,11 +13,6 @@ export default Ember.Controller.extend(PreferencesTabController, { 'allow_private_messages', ], - @computed("model.watchedCategories", "model.trackedCategories", "model.mutedCategories") - selectedCategories(watched, tracked, muted) { - return [].concat(watched, tracked, muted); - }, - likeNotificationFrequencies: [{ name: I18n.t('user.like_notification_frequency.always'), value: 0 }, { name: I18n.t('user.like_notification_frequency.first_time_and_daily'), value: 1 }, { name: I18n.t('user.like_notification_frequency.first_time'), value: 2 }, diff --git a/app/assets/javascripts/discourse/templates/preferences/categories.hbs b/app/assets/javascripts/discourse/templates/preferences/categories.hbs index d4f4bf67a7b..ee57fea81e4 100644 --- a/app/assets/javascripts/discourse/templates/preferences/categories.hbs +++ b/app/assets/javascripts/discourse/templates/preferences/categories.hbs @@ -1,5 +1,4 @@
-
@@ -22,7 +21,7 @@
- {{category-selector categories=model.watchedFirstPostCategories}} + {{category-selector categories=model.watchedFirstPostCategories blacklist=selectedCategories}}
{{i18n 'user.watched_first_post_categories_instructions'}}
diff --git a/app/assets/javascripts/select-kit/components/category-selector.js.es6 b/app/assets/javascripts/select-kit/components/category-selector.js.es6 index 63e58e3d308..c3d729087bc 100644 --- a/app/assets/javascripts/select-kit/components/category-selector.js.es6 +++ b/app/assets/javascripts/select-kit/components/category-selector.js.es6 @@ -35,6 +35,9 @@ export default MultiSelectComponent.extend({ computeContent() { const blacklist = Ember.makeArray(this.get("blacklist")); - return Category.list().filter(category => !blacklist.includes(category)); + return Category.list().filter(category => { + return this.get("computedValues").includes(category.id) || + !blacklist.includes(category); + }); } });