diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 95ac4dd7..205e3580 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -5,6 +5,7 @@ import { computed } from "@ember/object"; import wizardSchema from '../lib/wizard-schema'; import UndoChanges from '../mixins/undo-changes'; import Component from "@ember/component"; +import { notificationLevels } from '../lib/wizard'; export default Component.extend(UndoChanges, { componentType: 'action', @@ -12,6 +13,7 @@ export default Component.extend(UndoChanges, { visible: computed('currentActionId', function() { return this.action.id === this.currentActionId }), createTopic: equal('action.type', 'create_topic'), updateProfile: equal('action.type', 'update_profile'), + watchCategories: equal('action.type', 'watch_categories'), sendMessage: equal('action.type', 'send_message'), openComposer: equal('action.type', 'open_composer'), sendToApi: equal('action.type', 'send_to_api'), @@ -31,6 +33,12 @@ export default Component.extend(UndoChanges, { name: I18n.t(`admin.wizard.action.${type}.label`) }; }), + availableNotificationLevels: notificationLevels.map((type, index) => { + return { + id: type, + name: I18n.t(`admin.wizard.action.watch_categories.notification_level.${type}`) + }; + }), messageUrl: 'https://thepavilion.io/t/2810', diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index bd99ba7b..268306d3 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -141,6 +141,11 @@ const action = { profile_updates: null, custom_fields: null }, + watch_categories: { + categories: null, + notification_level: null, + mute_remainder: null + }, add_to_group: { group: null }, @@ -158,7 +163,9 @@ const action = { 'recipient', 'profile_updates', 'group', - 'url' + 'url', + 'categories', + 'mute_remainder' ], advanced: [ 'code', diff --git a/assets/javascripts/discourse/lib/wizard.js.es6 b/assets/javascripts/discourse/lib/wizard.js.es6 index 668ebe6a..4351367d 100644 --- a/assets/javascripts/discourse/lib/wizard.js.es6 +++ b/assets/javascripts/discourse/lib/wizard.js.es6 @@ -49,6 +49,14 @@ const userProperties = [ 'trust_level' ]; +const notificationLevels = [ + 'regular', + 'watching', + 'tracking', + 'watching_first_post', + 'muted' +]; + function listProperties(type, opts={}) { let properties = Object.keys(wizardSchema[type].basic); @@ -106,5 +114,6 @@ export { snakeCase, userProperties, listProperties, + notificationLevels, wizardFieldList }; \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index c27e56cd..c52f6cd1 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -283,6 +283,63 @@ {{/if}} +{{#if watchCategories}} +
+
+ +
+ +
+ {{wizard-mapper + inputs=action.categories + property='categories' + onUpdate=(action 'mappedFieldUpdated') + options=(hash + textSelection='key,value' + wizardFieldSelection=true + userFieldSelection='key,value' + categorySelection='output' + context='action' + )}} +
+
+ +
+
+ +
+ +
+ {{wizard-mapper + inputs=action.mute_remainder + property='mute_remainder' + onUpdate=(action 'mappedFieldUpdated') + options=(hash + context='action' + wizardFieldSelection=true + userFieldSelection='key,value' + )}} +
+
+ +
+
+ +
+ +
+ {{combo-box + value=action.notification_level + content=availableNotificationLevels + onChange=(action (mut action.notification_level)) + options=(hash + isDisabled=action.custom_title_enabled + none='admin.wizard.action.watch_categories.select_a_notification_level' + )}} +
+
+{{/if}} + {{#if showAdvanced}} {{wizard-advanced-toggle showAdvanced=action.showAdvanced}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 0a79915d..b7c3d73f 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -208,6 +208,18 @@ en: label: "Update Profile" setting: "Fields" key: "field" + watch_categories: + label: "Watch Categories" + categories: "Categories" + mute_remainder: "Mute Remainder" + notification_level: + label: "Notification Level" + regular: "Normal" + watching: "Watching" + tracking: "Tracking" + watching_first_post: "Watching First Post" + muted: "Muted" + select_a_notification_level: "Select level" post_builder: checkbox: "Post Builder" label: "Builder" diff --git a/controllers/custom_wizard/admin/wizard.rb b/controllers/custom_wizard/admin/wizard.rb index d7f87f9a..5c3ade4e 100644 --- a/controllers/custom_wizard/admin/wizard.rb +++ b/controllers/custom_wizard/admin/wizard.rb @@ -116,12 +116,15 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController :post, :post_builder, :post_template, + :notification_level, title: mapped_params, category: mapped_params, tags: mapped_params, custom_fields: mapped_params, required: mapped_params, recipient: mapped_params, + categories: mapped_params, + mute_remainder: mapped_params, profile_updates: mapped_params, group: mapped_params, url: mapped_params diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index d85067bb..e45dab3a 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -133,6 +133,36 @@ class CustomWizard::Action end end + def watch_categories + + watched_categories = CustomWizard::Mapper.new( + inputs: action['categories'], + data: data, + user: user + ).perform + + notification_level = action['notification_level'] + + if notification_level.blank? + log_error("Notifcation Level was not set! Exiting wizard action") + return + end + + mute_remainder = CustomWizard::Mapper.new( + inputs: action['mute_remainder'], + data: data, + user: user + ).perform + + Category.all.each do |category| + if watched_categories.present? && watched_categories.include?(category.id.to_s) + CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[notification_level.to_sym], category.id) + elsif mute_remainder + CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id) + end + end + end + def send_to_api api_body = nil