From 24585252060f78b0e3a8def709ba5ff734810a7c Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 11:20:15 +0100 Subject: [PATCH] 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)