From a0f2d85eff5d34c8c4601c94012e866e19c33728 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 20 Jul 2020 14:26:11 +1000 Subject: [PATCH] Add visible to create_topic action --- .../discourse/lib/wizard-schema.js.es6 | 2 ++ .../components/wizard-custom-action.hbs | 18 ++++++++++ config/locales/client.en.yml | 1 + controllers/custom_wizard/admin/wizard.rb | 1 + lib/custom_wizard/action.rb | 35 ++++++++++++++++--- 5 files changed, 53 insertions(+), 4 deletions(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index e75339bd..840b84a5 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -115,6 +115,7 @@ const action = { post_template: null, category: null, tags: null, + visible: null, custom_fields: null, skip_redirect: null }, @@ -188,6 +189,7 @@ const action = { 'title', 'category', 'tags', + 'visible', 'custom_fields', 'required', 'recipient', diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index f46be9ad..272c3155 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -139,6 +139,24 @@ )}} + +
+
+ +
+ +
+ {{wizard-mapper + inputs=action.visible + property='visible' + onUpdate=(action 'mappedFieldUpdated') + options=(hash + wizardFieldSelection=true + userFieldSelection=true + context='action' + )}} +
+
{{/if}} {{#if sendMessage}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 0b9587ea..ca231362 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -205,6 +205,7 @@ en: label: "Create Topic" category: "Category" tags: "Tags" + visible: "Visible" open_composer: label: "Open Composer" update_profile: diff --git a/controllers/custom_wizard/admin/wizard.rb b/controllers/custom_wizard/admin/wizard.rb index c17de1cb..bf62d1a4 100644 --- a/controllers/custom_wizard/admin/wizard.rb +++ b/controllers/custom_wizard/admin/wizard.rb @@ -125,6 +125,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController category: mapped_params, tags: mapped_params, custom_fields: mapped_params, + visible: mapped_params, required: mapped_params, recipient: mapped_params, categories: mapped_params, diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index ec54e110..a916d847 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -36,12 +36,9 @@ class CustomWizard::Action end def create_topic - params = basic_topic_params + params = basic_topic_params.merge(public_topic_params) if params[:title].present? && params[:raw].present? - params[:category] = action_category - params[:tags] = action_tags - creator = PostCreator.new(user, params) post = creator.create @@ -437,6 +434,32 @@ class CustomWizard::Action add_custom_fields(params) end + def public_topic_params + params = {} + + if (category = action_category) + params[:category] = category + end + + if (tags = action_tags) + params[:tags] = tags + end + + if public_topic_fields.any? + public_topic_fields.each do |field| + unless action[field].nil? || action[field] == "" + params[field.to_sym] = CustomWizard::Mapper.new( + inputs: action[field], + data: data, + user: user + ).perform + end + end + end + + params + end + def new_group_params params = {} @@ -532,6 +555,10 @@ class CustomWizard::Action [:create_topic, :send_message].include?(action['type'].to_sym) end + def public_topic_fields + ['visible'] + end + def profile_url_fields ['profile_background', 'card_background'] end