From 345bb310e8e174251d769b0749342179bdbc65a4 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 26 Oct 2022 10:04:50 +0200 Subject: [PATCH 1/2] FEATURE: add can_create_tag --- app/controllers/custom_wizard/admin/wizard.rb | 1 + .../custom_wizard/wizard_field_serializer.rb | 5 +++++ .../templates/components/custom-wizard-field-tag.hbs | 1 + .../templates/components/wizard-custom-field.hbs | 12 ++++++++++++ config/locales/client.en.yml | 1 + lefthook.yml | 6 ------ lib/custom_wizard/builder.rb | 4 ++++ lib/custom_wizard/field.rb | 5 ++++- 8 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/controllers/custom_wizard/admin/wizard.rb b/app/controllers/custom_wizard/admin/wizard.rb index c778bc7e..08e7b6d0 100644 --- a/app/controllers/custom_wizard/admin/wizard.rb +++ b/app/controllers/custom_wizard/admin/wizard.rb @@ -114,6 +114,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController :property, :preview_template, :placeholder, + :can_create_tag, prefill: mapped_params, content: mapped_params, condition: mapped_params, diff --git a/app/serializers/custom_wizard/wizard_field_serializer.rb b/app/serializers/custom_wizard/wizard_field_serializer.rb index d5f57060..56e86cc8 100644 --- a/app/serializers/custom_wizard/wizard_field_serializer.rb +++ b/app/serializers/custom_wizard/wizard_field_serializer.rb @@ -17,6 +17,7 @@ class CustomWizard::FieldSerializer < ::ApplicationSerializer :property, :content, :tag_groups, + :can_create_tag, :validations, :max_length, :char_counter, @@ -98,6 +99,10 @@ class CustomWizard::FieldSerializer < ::ApplicationSerializer object.tag_groups end + def can_create_tag + object.can_create_tag + end + def validations validations = {} object.validations&.each do |type, props| diff --git a/assets/javascripts/discourse/templates/components/custom-wizard-field-tag.hbs b/assets/javascripts/discourse/templates/components/custom-wizard-field-tag.hbs index fb45db4e..90679ae7 100644 --- a/assets/javascripts/discourse/templates/components/custom-wizard-field-tag.hbs +++ b/assets/javascripts/discourse/templates/components/custom-wizard-field-tag.hbs @@ -5,4 +5,5 @@ everyTag=true options=(hash maximum=field.limit + allowAny=field.can_create_tag )}} diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index 6e524fe3..6273f9a9 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -222,6 +222,18 @@ }} + +
+
+ +
+ +
+ {{input + type="checkbox" + checked=field.can_create_tag}} +
+
{{/if}} {{#wizard-subscription-container}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 267f099f..e5954a22 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -277,6 +277,7 @@ en: prefill: "Prefill" content: "Content" tag_groups: "Tag Groups" + can_create_tag: "Can Create Tag" date_time_format: label: "Format" instructions: "Moment.js format" diff --git a/lefthook.yml b/lefthook.yml index 995d1f2a..91d2ad53 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -20,9 +20,6 @@ pre-commit: glob: "*.js" include: "app/assets/javascripts|plugins/.+?/assets/javascripts" run: yarn eslint -f compact --quiet {staged_files} - i18n-lint: - glob: "**/{client,server}.en.yml" - run: bundle exec ruby script/i18n_lint.rb {staged_files} lints: parallel: true @@ -36,6 +33,3 @@ lints: run: yarn prettier --list-different **/*.scss eslint: run: yarn eslint -f compact --quiet --ext .js . - i18n-lint: - glob: "**/{client,server}.en.yml" - run: bundle exec ruby script/i18n_lint.rb {all_files} diff --git a/lib/custom_wizard/builder.rb b/lib/custom_wizard/builder.rb index 251ec1e5..3b12ad27 100644 --- a/lib/custom_wizard/builder.rb +++ b/lib/custom_wizard/builder.rb @@ -135,6 +135,10 @@ class CustomWizard::Builder params[:limit] = field_template['limit'] end + if field_template['type'] === 'tag' + params[:can_create_tag] = standardise_boolean(field_template['can_create_tag']) + end + if field_template['type'] === 'category' params[:property] = field_template['property'] end diff --git a/lib/custom_wizard/field.rb b/lib/custom_wizard/field.rb index 600f685e..6215fc8c 100644 --- a/lib/custom_wizard/field.rb +++ b/lib/custom_wizard/field.rb @@ -22,6 +22,7 @@ class CustomWizard::Field :property, :content, :tag_groups, + :can_create_tag, :preview_template, :placeholder @@ -47,6 +48,7 @@ class CustomWizard::Field @property = attrs[:property] @content = attrs[:content] @tag_groups = attrs[:tag_groups] + @can_create_tag = attrs[:can_create_tag] @preview_template = attrs[:preview_template] @placeholder = attrs[:placeholder] end @@ -113,7 +115,8 @@ class CustomWizard::Field limit: nil, prefill: nil, content: nil, - tag_groups: nil + tag_groups: nil, + can_create_tag: false }, category: { limit: 1, From f76ae370b0a7451d88ffc73a4b20c0a4dd39f273 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 26 Oct 2022 10:08:14 +0200 Subject: [PATCH 2/2] Update plugin version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 6837e83b..8d23068d 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.0.6 +# version: 2.1.0 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech