From 947a42cf0f5f9219789cde1fc9bb273c792c0f1f Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 31 Mar 2020 17:29:59 +1100 Subject: [PATCH] wip --- .../components/wizard-custom-action.hbs | 168 ++++++------------ .../components/wizard-custom-input-pair.hbs | 2 +- .../components/wizard-custom-input.hbs | 1 + assets/stylesheets/wizard_custom_admin.scss | 4 +- config/locales/client.en.yml | 8 +- lib/custom_wizard/actions.rb | 20 +-- 6 files changed, 73 insertions(+), 130 deletions(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 8c31baa8..8185f936 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -15,29 +15,20 @@ {{#if basicTopicFields}} -
+
- {{combo-box - value=action.title - content=wizardFields - nameProperty="label" - onChange=(action (mut action.title)) + {{wizard-field-mapper + inputs=action.title + wizardFields=wizardFields options=(hash - none='admin.wizard.select_field' - isDisabled=action.custom_title_enabled + hasOutput=true + wizardFieldSelection=true + userFieldSelection='key,value' )}} - -
- {{input type='checkbox' checked=action.custom_title_enabled}} - {{i18n 'admin.wizard.action.custom_title'}} - {{#if action.custom_title_enabled}} - {{input value=action.custom_title}} - {{/if}} -
@@ -80,85 +71,45 @@ {{/if}} {{#if publicTopicFields}} -
+
- {{category-chooser - value=action.category_id - isDisabled=action.custom_category_enabled}} - -
- {{input type='checkbox' checked=action.custom_category_enabled}} - {{i18n 'admin.wizard.action.custom_category.label'}} - - {{#if action.custom_category_enabled}} -
-
- {{input type='checkbox' checked=action.custom_category_wizard_field}} - {{i18n 'admin.wizard.wizard_field'}} - {{#if action.custom_category_wizard_field}} - {{combo-box - value=action.category_id - content=categoryFields - nameProperty="label" - onChange=(action (mut action.category_id)) - options=(hash - none='admin.wizard.select_field' - )}} - {{/if}} -
- -
- {{input type='checkbox' checked=action.custom_category_user_field}} - {{i18n 'admin.wizard.action.custom_category.user_field'}} - {{#if action.custom_category_user_field}} - {{input value=action.custom_category_user_field_key}} - {{/if}} -
-
- {{/if}} -
+ {{wizard-field-mapper + inputs=action.category + wizardFields=wizardFields + options=(hash + hasOutput=true + categorySelection='output' + wizardFieldSelection=true + userFieldSelection='key,value' + )}}
-
+
- {{tag-chooser - tags=action.tags - filterable=true - allowCreate=true - isDisabled=action.custom_tag_enabled}} - -
- {{input type='checkbox' checked=action.custom_tag_enabled}} - {{i18n 'admin.wizard.action.custom_tag.label'}} - - {{#if action.custom_tag_enabled}} -
- {{combo-box - value=action.custom_tag_field - content=tagFields - nameProperty="label" - onChange=(action (mut action.custom_tag_field)) - options=(hash - none='admin.wizard.select_field' - )}} -
- {{/if}} -
+ {{wizard-field-mapper + inputs=action.tags + wizardFields=wizardFields + options=(hash + hasOutput=true + tagSelection='output' + wizardFieldSelection=true + userFieldSelection='key,value' + )}}
{{/if}} {{#if newTopicFields}} -
+
@@ -173,75 +124,70 @@
{{/if}} -{{#if createTopic}} +{{#if basicTopicFields}}
- +
-
- {{wizard-field-mapper - inputs=action.add_fields - wizardFields=wizardFields - options=(hash - wizardFieldSelection=true - )}} -
+ {{wizard-field-mapper + inputs=action.add_fields + wizardFields=wizardFields + connectorKey='admin.wizard.action.add_fields.connector' + options=(hash + wizardFieldSelection=true + )}}
{{/if}} {{#if sendMessage}} -
+
- {{combo-box - value=action.required - content=wizardFields - nameProperty='label' - onChange=(action (mut action.required)) + {{wizard-field-mapper + inputs=action.required + wizardFields=wizardFields options=(hash - none='admin.wizard.select_field' + enableConnectors=true + wizardFieldSelection=true + userFieldSelection=true + groupSelection=true )}}
-
+
- {{user-selector - single="true" - includeMentionableGroups="true" - usernames=action.username - allowedUsers="true"}} + {{wizard-field-mapper + inputs=action.recipient + wizardFields=wizardFields + options=(hash + hasOutput=true + wizardFieldSelection=true + userFieldSelection=true + groupSelection='key,value' + )}}
- -
-
- -
- - {{wizard-field-mapper - inputs=action.add_fields - wizardFields=wizardFields}} -
{{/if}} {{#if updateProfile}}
- +
{{wizard-field-mapper inputs=action.profile_updates wizardFields=wizardFields + connectorKey='admin.wizard.action.add_fields.connector' options=(hash wizardFieldSelection=true userFieldSelection=true diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-input-pair.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-input-pair.hbs index 06974074..6a4b128b 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-input-pair.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-input-pair.hbs @@ -38,7 +38,7 @@
{{#if showJoin}} -
&
+ & {{/if}} {{#if showRemove}} diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-input.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-input.hbs index 1ef4517b..d1c463b5 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-input.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-input.hbs @@ -16,6 +16,7 @@ inputType=inputType keyPlaceholder=keyPlaceholder valuePlaceholder=valuePlaceholder + connectorKey=connectorKey wizardFields=wizardFields options=options removePair=(action 'removePair')}} diff --git a/assets/stylesheets/wizard_custom_admin.scss b/assets/stylesheets/wizard_custom_admin.scss index 4bc608ff..3f5bd0b9 100644 --- a/assets/stylesheets/wizard_custom_admin.scss +++ b/assets/stylesheets/wizard_custom_admin.scss @@ -361,7 +361,7 @@ $setting-background: dark-light-diff($primary, $secondary, 96%, -65%); .remove-pair { position: absolute; top: 25px; - right: -30px; + right: -25px; } .join-pair { @@ -378,7 +378,7 @@ $setting-background: dark-light-diff($primary, $secondary, 96%, -65%); position: relative; &:not(:first-of-type) { - margin-top: 10px; + margin-top: 20px; } &.no-connector div.input-block:not(:last-of-type) { diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 2cc266f6..bdd49e97 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -131,12 +131,14 @@ en: include: "Include Fields" title: "Title" post: "Post" - add_fields: "Fields" topic_attr: "Topic Attribute" interpolate_fields: "Insert wizard fields using the field_id in w{}. Insert user fields using field key in u{}." - + + add_fields: + label: "Fields" + connector: "set" skip_redirect: - label: "No Redirect" + label: "Redirect" description: "Don't redirect the user to this {{type}} after the wizard completes" send_message: label: "Send Message" diff --git a/lib/custom_wizard/actions.rb b/lib/custom_wizard/actions.rb index 995281c7..5afb582b 100644 --- a/lib/custom_wizard/actions.rb +++ b/lib/custom_wizard/actions.rb @@ -19,7 +19,7 @@ class CustomWizard::Action @mapper ||= CustomWizard::Mapper.new(user: user, data: data) end - def create_topic + def create_topic if action['custom_title_enabled'] title = mapper.interpolate(action['custom_title']) else @@ -43,8 +43,6 @@ class CustomWizard::Action tags = action_tags(action, data) params[:tags] = tags - topic_custom_fields = {} - if action['add_fields'] action['add_fields'].each do |field| value = field['value_custom'].present? ? field['value_custom'] : data[field['value']] @@ -59,14 +57,16 @@ class CustomWizard::Action type = keyArr.first if type === 'topic' - topic_custom_fields[custom_key] = value + params[:topic_opts] ||= {} + params[:topic_opts][:custom_fields] ||= {} + params[:topic_opts][:custom_fields][custom_key] = value elsif type === 'post' params[:custom_fields] ||= {} params[:custom_fields][custom_key.to_sym] = value end end else - value = [*value] + tags if key === 'tags' + value = [*value] + [*tags] if key === 'tags' params[key.to_sym] = value end end @@ -79,12 +79,6 @@ class CustomWizard::Action if creator.errors.present? updater.errors.add(:create_topic, creator.errors.full_messages.join(" ")) else - if topic_custom_fields.present? - topic_custom_fields.each do |k, v| - post.topic.custom_fields[k] = v - end - post.topic.save_custom_fields(true) - end unless action['skip_redirect'] data['redirect_on_complete'] = post.topic.url @@ -211,13 +205,13 @@ class CustomWizard::Action url += "&body=#{post}" - if category_id = action_category_id(action, data) + if category_id = action_category_id if category = Category.find(category_id) url += "&category=#{category.full_slug('/')}" end end - if tags = action_tags(action, data) + if tags = action_tags url += "&tags=#{tags.join(',')}" end