From 83d3ca8eb36dfa79cfb00e7707e2350cee161697 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 21 Mar 2023 15:34:07 +0100 Subject: [PATCH 01/18] Add output text selection to category name --- .../discourse/templates/components/wizard-custom-action.hbs | 2 +- plugin.rb | 2 +- 2 files 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 106c61ee..8763d3a5 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -716,7 +716,7 @@ property="name" onUpdate=(action "mappedFieldUpdated") options=(hash - textSelection="key,value" + textSelection="key,value,output" wizardFieldSelection=true userFieldSelection="key,value" context="action" diff --git a/plugin.rb b/plugin.rb index 5b5c7980..3ba2d9c2 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.2.12 +# version: 2.2.13 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From a146d57f0e77704bbb20e89a31f45ea0b8818fba Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 21 Mar 2023 17:20:58 +0100 Subject: [PATCH 02/18] Ensure we're not interpolating an object --- lib/custom_wizard/mapper.rb | 9 ++++- spec/components/custom_wizard/mapper_spec.rb | 39 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/custom_wizard/mapper.rb b/lib/custom_wizard/mapper.rb index 9d26c82e..41519b07 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -44,7 +44,7 @@ class CustomWizard::Mapper def initialize(params) @inputs = params[:inputs] || {} - @data = params[:data] || {} + @data = params[:data].with_indifferent_access || {} @user = params[:user] @opts = params[:opts] || {} end @@ -267,7 +267,12 @@ class CustomWizard::Mapper return nil if data.nil? k = keys.shift result = data[k] - keys.empty? ? result : self.recurse(result, keys) + + if keys.empty? + result.is_a?(Object) ? "" : result + else + self.recurse(result, keys) + end end def bool(value) diff --git a/spec/components/custom_wizard/mapper_spec.rb b/spec/components/custom_wizard/mapper_spec.rb index f460cc01..510632a9 100644 --- a/spec/components/custom_wizard/mapper_spec.rb +++ b/spec/components/custom_wizard/mapper_spec.rb @@ -58,6 +58,11 @@ describe CustomWizard::Mapper do "step_1_field_3" => "Value" } } + let(:template_params_object) { + { + "step_1_field_1": get_wizard_fixture("field/upload") + } + } def create_template_mapper(data, user) CustomWizard::Mapper.new( @@ -448,6 +453,40 @@ describe CustomWizard::Mapper do expect(result).to eq(template) end + it "handles correct object variable references" do + template = <<-LIQUID.strip + {%- if "w{step_1_field_1.id}" == "step_2_field_7" -%} + Correct + {%- else -%} + Incorrect + {%-endif-%} + LIQUID + mapper = create_template_mapper(template_params_object, user1) + result = mapper.interpolate( + template.dup, + template: true, + wizard: true + ) + expect(result).to eq("Correct") + end + + it "handles incorrect object variable references" do + template = <<-LIQUID.strip + {%- if "w{step_1_field_1}" == "step_2_field_7" -%} + Correct + {%- else -%} + Incorrect + {%-endif-%} + LIQUID + mapper = create_template_mapper(template_params_object, user1) + result = mapper.interpolate( + template.dup, + template: true, + wizard: true + ) + expect(result).to eq("Incorrect") + end + context "custom filter: 'first_non_empty'" do it "gives first non empty element from list" do template = <<-LIQUID.strip From 076e1f4966ece5e36d7844cc9748bad89feb75fb Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 21 Mar 2023 17:22:15 +0100 Subject: [PATCH 03/18] Bump version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 3ba2d9c2..c9cb9201 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.2.13 +# version: 2.2.14 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From 8fdd21601bf9621eadad32d27f5b643ac9d80283 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 21 Mar 2023 17:38:53 +0100 Subject: [PATCH 04/18] Strings are Objects in ruby --- 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 41519b07..4e18ad01 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -44,7 +44,7 @@ class CustomWizard::Mapper def initialize(params) @inputs = params[:inputs] || {} - @data = params[:data].with_indifferent_access || {} + @data = params[:data] ? params[:data].with_indifferent_access : {} @user = params[:user] @opts = params[:opts] || {} end @@ -269,7 +269,7 @@ class CustomWizard::Mapper result = data[k] if keys.empty? - result.is_a?(Object) ? "" : result + result.is_a?(Hash) ? "" : result else self.recurse(result, keys) end From e2797ced64e0559f47fae1fb8411b43bbce7f465 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 21 Mar 2023 17:41:49 +0100 Subject: [PATCH 05/18] Bump version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index c9cb9201..788ba1da 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.2.14 +# version: 2.2.15 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From 392b6f3d58506106ce5c5df7942f047569411515 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 22 Mar 2023 10:11:48 +0100 Subject: [PATCH 06/18] Fix deprecations && invalid field handling --- .../custom-wizard-date-input.js.es6 | 1 + .../custom-wizard-date-time-input.js.es6 | 2 ++ .../custom-wizard-field-time.js.es6 | 2 ++ .../custom-wizard-field-upload.js.es6 | 2 +- .../custom-wizard-field-user-selector.js.es6 | 4 ++- .../components/custom-wizard-step.js.es6 | 28 ++++++++----------- .../models/custom-wizard-field.js.es6 | 2 +- .../components/custom-wizard-date-input.hbs | 14 +++++----- .../custom-wizard-field-category.hbs | 1 + .../custom-wizard-field-checkbox.hbs | 8 +++++- .../custom-wizard-field-composer.hbs | 1 + .../components/custom-wizard-field-group.hbs | 1 + .../components/custom-wizard-field-number.hbs | 10 ++++++- .../components/custom-wizard-field-tag.hbs | 1 + .../components/custom-wizard-field-text.hbs | 9 +++++- .../custom-wizard-field-textarea.hbs | 8 +++++- .../components/custom-wizard-field-url.hbs | 7 ++++- assets/stylesheets/common/wizard/field.scss | 9 ++---- 18 files changed, 72 insertions(+), 38 deletions(-) diff --git a/assets/javascripts/discourse/components/custom-wizard-date-input.js.es6 b/assets/javascripts/discourse/components/custom-wizard-date-input.js.es6 index 9c8e4bff..2805c370 100644 --- a/assets/javascripts/discourse/components/custom-wizard-date-input.js.es6 +++ b/assets/javascripts/discourse/components/custom-wizard-date-input.js.es6 @@ -3,6 +3,7 @@ import discourseComputed from "discourse-common/utils/decorators"; export default DateInput.extend({ useNativePicker: false, + classNameBindings: ["fieldClass"], @discourseComputed() placeholder() { diff --git a/assets/javascripts/discourse/components/custom-wizard-date-time-input.js.es6 b/assets/javascripts/discourse/components/custom-wizard-date-time-input.js.es6 index 44b675b0..1fcb62f5 100644 --- a/assets/javascripts/discourse/components/custom-wizard-date-time-input.js.es6 +++ b/assets/javascripts/discourse/components/custom-wizard-date-time-input.js.es6 @@ -2,6 +2,8 @@ import DateTimeInput from "discourse/components/date-time-input"; import discourseComputed from "discourse-common/utils/decorators"; export default DateTimeInput.extend({ + classNameBindings: ["fieldClass"], + @discourseComputed("timeFirst", "tabindex") timeTabindex(timeFirst, tabindex) { return timeFirst ? tabindex : tabindex + 1; diff --git a/assets/javascripts/discourse/components/custom-wizard-field-time.js.es6 b/assets/javascripts/discourse/components/custom-wizard-field-time.js.es6 index 82f9c68b..ead5e94f 100644 --- a/assets/javascripts/discourse/components/custom-wizard-field-time.js.es6 +++ b/assets/javascripts/discourse/components/custom-wizard-field-time.js.es6 @@ -2,6 +2,8 @@ import Component from "@ember/component"; import { observes } from "discourse-common/utils/decorators"; export default Component.extend({ + classNameBindings: ['fieldClass'], + @observes("time") setValue() { this.set("field.value", this.time.format(this.field.format)); diff --git a/assets/javascripts/discourse/components/custom-wizard-field-upload.js.es6 b/assets/javascripts/discourse/components/custom-wizard-field-upload.js.es6 index eb5d318b..990d7daa 100644 --- a/assets/javascripts/discourse/components/custom-wizard-field-upload.js.es6 +++ b/assets/javascripts/discourse/components/custom-wizard-field-upload.js.es6 @@ -4,7 +4,7 @@ import { computed } from "@ember/object"; export default Component.extend(UppyUploadMixin, { classNames: ["wizard-field-upload"], - classNameBindings: ["isImage"], + classNameBindings: ["isImage", "fieldClass"], uploading: false, type: computed(function () { return `wizard_${this.field.id}`; diff --git a/assets/javascripts/discourse/components/custom-wizard-field-user-selector.js.es6 b/assets/javascripts/discourse/components/custom-wizard-field-user-selector.js.es6 index 87d5ddb0..7ffb6dff 100644 --- a/assets/javascripts/discourse/components/custom-wizard-field-user-selector.js.es6 +++ b/assets/javascripts/discourse/components/custom-wizard-field-user-selector.js.es6 @@ -1,3 +1,5 @@ import Component from "@ember/component"; -export default Component.extend({}); +export default Component.extend({ + classNameBindings: ['fieldClass'] +}); diff --git a/assets/javascripts/discourse/components/custom-wizard-step.js.es6 b/assets/javascripts/discourse/components/custom-wizard-step.js.es6 index b98db1ab..ee318b60 100644 --- a/assets/javascripts/discourse/components/custom-wizard-step.js.es6 +++ b/assets/javascripts/discourse/components/custom-wizard-step.js.es6 @@ -9,6 +9,7 @@ import CustomWizard, { updateCachedWizard, } from "discourse/plugins/discourse-custom-wizard/discourse/models/custom-wizard"; import { alias, not } from "@ember/object/computed"; +import discourseLater from "discourse-common/lib/later"; const alreadyWarned = {}; @@ -110,29 +111,24 @@ export default Component.extend({ }, autoFocus() { - schedule("afterRender", () => { - const $invalid = $( - ".wizard-field.invalid:nth-of-type(1) .wizard-focusable" - ); - - if ($invalid.length) { - return $invalid.focus(); - } - - $(".wizard-focusable:first").focus(); + discourseLater(() => { + schedule("afterRender", () => { + if ($(".invalid .wizard-focusable").length) { + this.animateInvalidFields(); + } else { + $(".wizard-focusable:first").focus(); + } + }); }); }, animateInvalidFields() { schedule("afterRender", () => { - let $element = $( - ".invalid input[type=text],.invalid textarea,.invalid input[type=checkbox],.invalid .select-kit" - ); - - if ($element.length) { + let $invalid = $(".invalid .wizard-focusable"); + if ($invalid.length) { $([document.documentElement, document.body]).animate( { - scrollTop: $element.offset().top - 200, + scrollTop: $invalid.offset().top - 200, }, 400 ); diff --git a/assets/javascripts/discourse/models/custom-wizard-field.js.es6 b/assets/javascripts/discourse/models/custom-wizard-field.js.es6 index a03c7c9e..2afe79d9 100644 --- a/assets/javascripts/discourse/models/custom-wizard-field.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard-field.js.es6 @@ -72,7 +72,7 @@ export default EmberObject.extend(ValidState, { valid = true; } - this.setValid(valid); + this.setValid(Boolean(valid)); return valid; }, diff --git a/assets/javascripts/discourse/templates/components/custom-wizard-date-input.hbs b/assets/javascripts/discourse/templates/components/custom-wizard-date-input.hbs index 3b776215..0f798714 100644 --- a/assets/javascripts/discourse/templates/components/custom-wizard-date-input.hbs +++ b/assets/javascripts/discourse/templates/components/custom-wizard-date-input.hbs @@ -1,11 +1,11 @@ -{{input - type=inputType +
diff --git a/assets/javascripts/discourse/templates/components/custom-wizard-field-category.hbs b/assets/javascripts/discourse/templates/components/custom-wizard-field-category.hbs index 9cce87bc..79180dc4 100644 --- a/assets/javascripts/discourse/templates/components/custom-wizard-field-category.hbs +++ b/assets/javascripts/discourse/templates/components/custom-wizard-field-category.hbs @@ -1,5 +1,6 @@ {{custom-wizard-category-selector categories=categories + class=fieldClass whitelist=field.content onChange=(action (mut categories)) tabindex=field.tabindex diff --git a/assets/javascripts/discourse/templates/components/custom-wizard-field-checkbox.hbs b/assets/javascripts/discourse/templates/components/custom-wizard-field-checkbox.hbs index 053e0218..0ceeb11b 100644 --- a/assets/javascripts/discourse/templates/components/custom-wizard-field-checkbox.hbs +++ b/assets/javascripts/discourse/templates/components/custom-wizard-field-checkbox.hbs @@ -1 +1,7 @@ -{{input type="checkbox" id=field.id checked=field.value tabindex=field.tabindex}} + diff --git a/assets/javascripts/discourse/templates/components/custom-wizard-field-composer.hbs b/assets/javascripts/discourse/templates/components/custom-wizard-field-composer.hbs index 51964a1b..2c966d24 100644 --- a/assets/javascripts/discourse/templates/components/custom-wizard-field-composer.hbs +++ b/assets/javascripts/discourse/templates/components/custom-wizard-field-composer.hbs @@ -2,6 +2,7 @@ field=field composer=composer wizard=wizard + fieldClass=fieldClass groupsMentioned=(action "groupsMentioned") cannotSeeMention=(action "cannotSeeMention") importQuote=(action "importQuote") diff --git a/assets/javascripts/discourse/templates/components/custom-wizard-field-group.hbs b/assets/javascripts/discourse/templates/components/custom-wizard-field-group.hbs index 6873f9bd..75a5b2b1 100644 --- a/assets/javascripts/discourse/templates/components/custom-wizard-field-group.hbs +++ b/assets/javascripts/discourse/templates/components/custom-wizard-field-group.hbs @@ -1,5 +1,6 @@ {{custom-wizard-group-selector groups=site.groups + class=fieldClass field=field whitelist=field.content value=field.value diff --git a/assets/javascripts/discourse/templates/components/custom-wizard-field-number.hbs b/assets/javascripts/discourse/templates/components/custom-wizard-field-number.hbs index f5d6543c..3049ab08 100644 --- a/assets/javascripts/discourse/templates/components/custom-wizard-field-number.hbs +++ b/assets/javascripts/discourse/templates/components/custom-wizard-field-number.hbs @@ -1 +1,9 @@ -{{input type="number" step="0.01" id=field.id value=field.value tabindex=field.tabindex}} + + 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 90679ae7..17f68b92 100644 --- a/assets/javascripts/discourse/templates/components/custom-wizard-field-tag.hbs +++ b/assets/javascripts/discourse/templates/components/custom-wizard-field-tag.hbs @@ -1,5 +1,6 @@ {{custom-wizard-tag-chooser tags=field.value + class=fieldClass tabindex=field.tabindex tagGroups=field.tag_groups everyTag=true diff --git a/assets/javascripts/discourse/templates/components/custom-wizard-field-text.hbs b/assets/javascripts/discourse/templates/components/custom-wizard-field-text.hbs index 08733d3f..76dbee2a 100644 --- a/assets/javascripts/discourse/templates/components/custom-wizard-field-text.hbs +++ b/assets/javascripts/discourse/templates/components/custom-wizard-field-text.hbs @@ -1 +1,8 @@ -{{input id=field.id value=field.value class=fieldClass placeholder=field.translatedPlaceholder tabindex=field.tabindex autocomplete=autocomplete}} + \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/components/custom-wizard-field-textarea.hbs b/assets/javascripts/discourse/templates/components/custom-wizard-field-textarea.hbs index dda299bc..5431538c 100644 --- a/assets/javascripts/discourse/templates/components/custom-wizard-field-textarea.hbs +++ b/assets/javascripts/discourse/templates/components/custom-wizard-field-textarea.hbs @@ -1 +1,7 @@ -{{textarea id=field.id value=field.value class=fieldClass placeholder=field.translatedPlaceholder tabindex=field.tabindex}} +