From f4a9cf86f2156df9215bda5635a2daf9ebc60238 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Fri, 22 May 2020 23:42:26 +0100 Subject: [PATCH 01/15] FEATURE: added ability for user to selected watched categories in wizard --- .../components/wizard-custom-action.js.es6 | 1 + .../discourse/lib/wizard-schema.js.es6 | 5 ++ .../components/wizard-custom-action.hbs | 63 +++++++++++++------ config/locales/client.en.yml | 3 + controllers/custom_wizard/admin/wizard.rb | 1 + lib/custom_wizard/action.rb | 12 ++++ lib/custom_wizard/mapper.rb | 5 +- 7 files changed, 68 insertions(+), 22 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 95ac4dd7..23cd5d27 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -12,6 +12,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'), diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index bd99ba7b..c18913c0 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -141,6 +141,10 @@ const action = { profile_updates: null, custom_fields: null }, + watch_categories: { + category: null, + mute_remainder: null + }, add_to_group: { group: null }, @@ -158,6 +162,7 @@ const action = { 'recipient', 'profile_updates', 'group', + 'mute_remainder', 'url' ], advanced: [ diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index c27e56cd..7b9eeb2f 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -10,7 +10,7 @@
- +
{{combo-box value=action.type @@ -26,7 +26,7 @@
- +
{{combo-box value=action.run_after @@ -45,7 +45,7 @@
- +
{{wizard-mapper inputs=action.title @@ -102,7 +102,7 @@
- +
{{wizard-mapper inputs=action.category @@ -123,7 +123,7 @@
- +
{{wizard-mapper inputs=action.tags @@ -146,7 +146,7 @@
- +
{{wizard-mapper inputs=action.recipient @@ -170,7 +170,7 @@
- + {{wizard-mapper inputs=action.profile_updates property='profile_updates' @@ -191,7 +191,7 @@
- +
{{combo-box value=action.api @@ -208,7 +208,7 @@
- +
{{combo-box value=action.api_endpoint @@ -225,7 +225,7 @@
- +
{{wizard-text-editor value=action.api_body @@ -242,7 +242,7 @@
- +
{{wizard-mapper inputs=action.group @@ -265,7 +265,7 @@
- +
{{wizard-mapper inputs=action.url @@ -283,18 +283,41 @@
{{/if}} +{{#if watchCategories}} +
+
+ +
+ +
+ {{wizard-mapper + inputs=action.mute_remainder + property='mute_remainder' + onUpdate=(action 'mappedFieldUpdated') + options=(hash + context='action' + wizardFieldSelection=true + userFieldSelection='key,value' + groupSelection='key,value' + categorySelection='key,value' + userSelection='key,value' + )}} +
+
+{{/if}} + {{#if showAdvanced}} {{wizard-advanced-toggle showAdvanced=action.showAdvanced}} {{#if action.showAdvanced}}
- + {{#if hasCustomFields}}
- +
{{wizard-mapper inputs=action.custom_fields @@ -310,13 +333,13 @@
{{/if}} - + {{#if sendMessage}}
- +
{{wizard-mapper inputs=action.required @@ -332,23 +355,23 @@
{{/if}} - + {{#if showSkipRedirect}}
- +
{{input type='checkbox' checked=action.skip_redirect}} - + {{i18n 'admin.wizard.action.skip_redirect.description' type='topic'}}
{{/if}} - + {{#if routeTo}}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 0a79915d..f47d7e95 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -208,6 +208,9 @@ en: label: "Update Profile" setting: "Fields" key: "field" + watch_categories: + label: "Watch Categories" + mute_remainder: "Mute Remainder" 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..b15dcf65 100644 --- a/controllers/custom_wizard/admin/wizard.rb +++ b/controllers/custom_wizard/admin/wizard.rb @@ -122,6 +122,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController custom_fields: mapped_params, required: mapped_params, recipient: 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..e0b84257 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -133,6 +133,18 @@ class CustomWizard::Action end end + def watch_categories + key, watched_categories = data.first + mute_remainder = data.values[1] + Category.all.each do |category| + if watched_categories.include?(category.id.to_s) + CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], 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 diff --git a/lib/custom_wizard/mapper.rb b/lib/custom_wizard/mapper.rb index 19b40e6b..aafc317f 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -3,6 +3,7 @@ class CustomWizard::Mapper USER_FIELDS = ['name', 'username', 'email', 'date_of_birth', 'title', 'locale', 'trust_level'] PROFILE_FIELDS = ['location', 'website', 'bio_raw'] + CATEGORY_NOTIFICATION_LEVELS = ['regular','watching', 'tracking', 'watching_first_post','muted'] def self.user_fields USER_FIELDS + PROFILE_FIELDS @@ -115,10 +116,10 @@ class CustomWizard::Mapper end end end - + def validation_result(key, value, operator) result = nil - + if operator.is_a?(Hash) && (operator = operator[value.to_sym]).present? if value == "present" result = key.public_send(operator) From ca3bad6664e19a7dd6a09ffd5ad770f29a3c87a0 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 08:35:17 +0100 Subject: [PATCH 02/15] revert deletions of redundant spaces to improve clarity of PR --- .../components/wizard-custom-action.hbs | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 7b9eeb2f..5b520eea 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -10,7 +10,7 @@
- +
{{combo-box value=action.type @@ -26,7 +26,7 @@
- +
{{combo-box value=action.run_after @@ -45,7 +45,7 @@
- +
{{wizard-mapper inputs=action.title @@ -102,7 +102,7 @@
- +
{{wizard-mapper inputs=action.category @@ -123,7 +123,7 @@
- +
{{wizard-mapper inputs=action.tags @@ -146,7 +146,7 @@
- +
{{wizard-mapper inputs=action.recipient @@ -170,7 +170,7 @@
- + {{wizard-mapper inputs=action.profile_updates property='profile_updates' @@ -191,7 +191,7 @@
- +
{{combo-box value=action.api @@ -208,7 +208,7 @@
- +
{{combo-box value=action.api_endpoint @@ -225,7 +225,7 @@
- +
{{wizard-text-editor value=action.api_body @@ -242,7 +242,7 @@
- +
{{wizard-mapper inputs=action.group @@ -265,7 +265,7 @@
- +
{{wizard-mapper inputs=action.url @@ -311,13 +311,13 @@ {{#if action.showAdvanced}}
- + {{#if hasCustomFields}}
- +
{{wizard-mapper inputs=action.custom_fields @@ -333,13 +333,13 @@
{{/if}} - + {{#if sendMessage}}
- +
{{wizard-mapper inputs=action.required @@ -355,23 +355,23 @@
{{/if}} - + {{#if showSkipRedirect}}
- +
{{input type='checkbox' checked=action.skip_redirect}} - + {{i18n 'admin.wizard.action.skip_redirect.description' type='topic'}}
{{/if}} - + {{#if routeTo}}
From d3e7fceb56d7f7103a80b88bf3e49abf12ee59df Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 08:36:56 +0100 Subject: [PATCH 03/15] revert deletions of redundant spaces continued --- .../discourse/templates/components/wizard-custom-action.hbs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 5b520eea..98b508a2 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -45,7 +45,7 @@
- +
{{wizard-mapper inputs=action.title @@ -311,7 +311,7 @@ {{#if action.showAdvanced}}
- + {{#if hasCustomFields}}
From beed6a93fc63da2a30473ce31d691cc5fbc9463f Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 08:38:54 +0100 Subject: [PATCH 04/15] revert deletions of redundant spaces continued#3 --- lib/custom_wizard/mapper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/custom_wizard/mapper.rb b/lib/custom_wizard/mapper.rb index aafc317f..1b1f8101 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -116,10 +116,10 @@ class CustomWizard::Mapper end end end - + def validation_result(key, value, operator) result = nil - + if operator.is_a?(Hash) && (operator = operator[value.to_sym]).present? if value == "present" result = key.public_send(operator) From 5fc5ce113e0377cd06e16a045894ce27a40b3c56 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 08:56:27 +0100 Subject: [PATCH 05/15] Update schema against PR feedback --- assets/javascripts/discourse/lib/wizard-schema.js.es6 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index c18913c0..f3c61cd8 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -142,7 +142,7 @@ const action = { custom_fields: null }, watch_categories: { - category: null, + categories: null, mute_remainder: null }, add_to_group: { @@ -162,8 +162,9 @@ const action = { 'recipient', 'profile_updates', 'group', - 'mute_remainder', - 'url' + 'url', + 'categories', + 'mute_remainder' ], advanced: [ 'code', From 9097e3cad253c3f5c144249a6b35695e84662c52 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 09:03:34 +0100 Subject: [PATCH 06/15] Remove unnecessary selection options --- .../discourse/templates/components/wizard-custom-action.hbs | 3 --- 1 file changed, 3 deletions(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 98b508a2..208007d7 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -298,9 +298,6 @@ context='action' wizardFieldSelection=true userFieldSelection='key,value' - groupSelection='key,value' - categorySelection='key,value' - userSelection='key,value' )}}
From f13c04043b877a42f0319d56462cc960e937b17c Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 09:07:47 +0100 Subject: [PATCH 07/15] remove unused constant --- lib/custom_wizard/mapper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/custom_wizard/mapper.rb b/lib/custom_wizard/mapper.rb index 1b1f8101..19b40e6b 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -3,7 +3,6 @@ class CustomWizard::Mapper USER_FIELDS = ['name', 'username', 'email', 'date_of_birth', 'title', 'locale', 'trust_level'] PROFILE_FIELDS = ['location', 'website', 'bio_raw'] - CATEGORY_NOTIFICATION_LEVELS = ['regular','watching', 'tracking', 'watching_first_post','muted'] def self.user_fields USER_FIELDS + PROFILE_FIELDS From 24585252060f78b0e3a8def709ba5ff734810a7c Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 11:20:15 +0100 Subject: [PATCH 08/15] utilise wizard mapper to retrieve values --- .../components/wizard-custom-action.hbs | 19 +++++++++++++++++++ config/locales/client.en.yml | 1 + controllers/custom_wizard/admin/wizard.rb | 1 + lib/custom_wizard/action.rb | 17 ++++++++++++++--- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 208007d7..40d6b31a 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -284,6 +284,25 @@ {{/if}} {{#if watchCategories}} +
+
+ +
+ +
+ {{wizard-mapper + inputs=action.categories + property='categories' + onUpdate=(action 'mappedFieldUpdated') + options=(hash + textSelection='key,value' + wizardFieldSelection=true + userFieldSelection='key,value' + context='action' + )}} +
+
+
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index f47d7e95..a601fbe5 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -211,6 +211,7 @@ en: watch_categories: label: "Watch Categories" mute_remainder: "Mute Remainder" + categories: "Categories" post_builder: checkbox: "Post Builder" label: "Builder" diff --git a/controllers/custom_wizard/admin/wizard.rb b/controllers/custom_wizard/admin/wizard.rb index b15dcf65..0f155fbe 100644 --- a/controllers/custom_wizard/admin/wizard.rb +++ b/controllers/custom_wizard/admin/wizard.rb @@ -122,6 +122,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController custom_fields: mapped_params, required: mapped_params, recipient: mapped_params, + categories: mapped_params, mute_remainder: mapped_params, profile_updates: mapped_params, group: mapped_params, diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index e0b84257..c3c6fbe5 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -134,10 +134,21 @@ class CustomWizard::Action end def watch_categories - key, watched_categories = data.first - mute_remainder = data.values[1] + + watched_categories_map = CustomWizard::Mapper.new( + inputs: action['categories'], + data: data, + user: user + ).perform + + mute_remainder = CustomWizard::Mapper.new( + inputs: action['mute_remainder'], + data: data, + user: user + ).perform + Category.all.each do |category| - if watched_categories.include?(category.id.to_s) + if watched_categories_map.include?(category.id.to_s) CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], category.id) elsif mute_remainder CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id) From 355d1abc544f3335bb4715126209af4e25c04092 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 11:23:17 +0100 Subject: [PATCH 09/15] simplify naming --- lib/custom_wizard/action.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index c3c6fbe5..e78353d9 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -135,7 +135,7 @@ class CustomWizard::Action def watch_categories - watched_categories_map = CustomWizard::Mapper.new( + watched_categories = CustomWizard::Mapper.new( inputs: action['categories'], data: data, user: user @@ -148,7 +148,7 @@ class CustomWizard::Action ).perform Category.all.each do |category| - if watched_categories_map.include?(category.id.to_s) + if watched_categories.include?(category.id.to_s) CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], category.id) elsif mute_remainder CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id) From c4471fa15f8832fdfbc68169d97ad8ddb2b85124 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Mon, 25 May 2020 14:59:31 +0100 Subject: [PATCH 10/15] Added notification level dropdown to allow admin to specify which level of tracking will be chosen during action --- .../components/wizard-custom-action.js.es6 | 7 +++++++ .../discourse/lib/wizard-schema.js.es6 | 5 ++++- assets/javascripts/discourse/lib/wizard.js.es6 | 9 +++++++++ .../components/wizard-custom-action.hbs | 17 +++++++++++++++++ config/locales/client.en.yml | 10 +++++++++- controllers/custom_wizard/admin/wizard.rb | 1 + lib/custom_wizard/action.rb | 4 +++- 7 files changed, 50 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 23cd5d27..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', @@ -32,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 f3c61cd8..599f4708 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -143,6 +143,7 @@ const action = { }, watch_categories: { categories: null, + notification_level: null, mute_remainder: null }, add_to_group: { @@ -164,6 +165,7 @@ const action = { 'group', 'url', 'categories', + // 'notification_level', 'mute_remainder' ], advanced: [ @@ -186,7 +188,8 @@ const wizardSchema = { wizard, step, field, - action + action, + } export function buildFieldTypes(types) { 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 40d6b31a..fa119d14 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -303,6 +303,23 @@
+
+
+ +
+ +
+ {{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' + )}} +
+
+
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index a601fbe5..b7c3d73f 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -210,8 +210,16 @@ en: key: "field" watch_categories: label: "Watch Categories" - mute_remainder: "Mute Remainder" 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 0f155fbe..5c3ade4e 100644 --- a/controllers/custom_wizard/admin/wizard.rb +++ b/controllers/custom_wizard/admin/wizard.rb @@ -116,6 +116,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController :post, :post_builder, :post_template, + :notification_level, title: mapped_params, category: mapped_params, tags: mapped_params, diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index e78353d9..2d539287 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -141,6 +141,8 @@ class CustomWizard::Action user: user ).perform + notification_level = action['notification_level'] + mute_remainder = CustomWizard::Mapper.new( inputs: action['mute_remainder'], data: data, @@ -149,7 +151,7 @@ class CustomWizard::Action Category.all.each do |category| if watched_categories.include?(category.id.to_s) - CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], category.id) + 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 From 92f626196d9e2652b4b255c09cb06b8472d46c67 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 26 May 2020 09:53:01 +0100 Subject: [PATCH 11/15] remove commented out code --- assets/javascripts/discourse/lib/wizard-schema.js.es6 | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 599f4708..06fd6b50 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -165,7 +165,6 @@ const action = { 'group', 'url', 'categories', - // 'notification_level', 'mute_remainder' ], advanced: [ From 518a4f3dce4f783ff96ab6a23d4f370b86de8eaf Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 26 May 2020 10:59:11 +0100 Subject: [PATCH 12/15] added some checks on data in action to reduce runtime issues --- lib/custom_wizard/action.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index 2d539287..e45dab3a 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -143,6 +143,11 @@ class CustomWizard::Action 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, @@ -150,7 +155,7 @@ class CustomWizard::Action ).perform Category.all.each do |category| - if watched_categories.include?(category.id.to_s) + 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) From 1f0f7ff5f9252f3100bbb223d2e2efb4a91aa470 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 26 May 2020 11:16:06 +0100 Subject: [PATCH 13/15] Added categorySelection on the output --- .../discourse/templates/components/wizard-custom-action.hbs | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index fa119d14..fabc4b36 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -298,6 +298,7 @@ textSelection='key,value' wizardFieldSelection=true userFieldSelection='key,value' + categorySelection='output' context='action' )}}
From 33b20038270a1b97797e5414652e037e97e375e3 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 26 May 2020 11:47:15 +0100 Subject: [PATCH 14/15] improved layout so that mapped field settings have more room --- .../components/wizard-custom-action.hbs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index fabc4b36..c52f6cd1 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -304,24 +304,7 @@
-
-
- -
- -
- {{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' - )}} -
-
- -
+
@@ -338,6 +321,23 @@ )}}
+ +
+
+ +
+ +
+ {{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}} From 99f9907b1be1daaed6ffffca000b75a41e106280 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 26 May 2020 11:52:25 +0100 Subject: [PATCH 15/15] fixed spurious line --- assets/javascripts/discourse/lib/wizard-schema.js.es6 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 06fd6b50..268306d3 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -187,8 +187,7 @@ const wizardSchema = { wizard, step, field, - action, - + action } export function buildFieldTypes(types) {