From 8aafb257fd20aa40aada891e2a6713a551a3099a Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Thu, 29 Apr 2021 11:02:51 +0530 Subject: [PATCH 1/6] DEV: checkbox value should default to false --- .../wizard/initializers/custom-wizard-field.js.es6 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 b/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 index 3ede2b05..0ccb227a 100644 --- a/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 +++ b/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 @@ -57,6 +57,12 @@ export default { ]; FieldModel.reopen({ + init() { + this._super(...arguments); + if (this.type === "checkbox") { + this.set("value", this.value || false); + } + }, check() { if (this.customCheck) { return this.customCheck(); From c463e8b5419b0888d80d547c1e74d22ddbb9ab0e Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Thu, 29 Apr 2021 12:18:09 +0530 Subject: [PATCH 2/6] fix formatting --- .../javascripts/wizard/initializers/custom-wizard-field.js.es6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 b/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 index 0ccb227a..89f9d16a 100644 --- a/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 +++ b/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 @@ -59,7 +59,7 @@ export default { FieldModel.reopen({ init() { this._super(...arguments); - if (this.type === "checkbox") { + if (this.type === "checkbox") { this.set("value", this.value || false); } }, From 848874ea1feff72dfd51a2e7faecb13282832f5f Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Fri, 30 Apr 2021 21:56:00 +0530 Subject: [PATCH 3/6] FIX: clicking Maybe Later was causing 500 error (#105) --- controllers/custom_wizard/wizard.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/controllers/custom_wizard/wizard.rb b/controllers/custom_wizard/wizard.rb index 73c1f592..37728ecb 100644 --- a/controllers/custom_wizard/wizard.rb +++ b/controllers/custom_wizard/wizard.rb @@ -11,7 +11,9 @@ class CustomWizard::WizardController < ::ApplicationController helper_method :wizard_theme_translations_lookup def wizard - CustomWizard::Wizard.create(params[:wizard_id].underscore, current_user) + @builder = CustomWizard::Builder.new(params[:wizard_id].underscore, current_user) + @wizard ||= @builder.build + @wizard end def wizard_page_title From 887de2583351d6a3399f313fbae17492bf319924 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Fri, 30 Apr 2021 22:59:06 +0530 Subject: [PATCH 4/6] FIX: set checkbox field default value as false --- lib/custom_wizard/field.rb | 8 +++++++- serializers/custom_wizard/wizard_field_serializer.rb | 4 ---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/custom_wizard/field.rb b/lib/custom_wizard/field.rb index 51e3d4de..a8160b4c 100644 --- a/lib/custom_wizard/field.rb +++ b/lib/custom_wizard/field.rb @@ -31,7 +31,7 @@ class CustomWizard::Field @index = attrs[:index] @type = attrs[:type] @required = !!attrs[:required] - @value = attrs[:value] + @value = attrs[:value] || default_value @description = attrs[:description] @image = attrs[:image] @key = attrs[:key] @@ -50,6 +50,12 @@ class CustomWizard::Field @label ||= PrettyText.cook(@raw[:label]) end + def default_value + if @type == 'checkbox' + false + end + end + def self.types @types ||= { text: { diff --git a/serializers/custom_wizard/wizard_field_serializer.rb b/serializers/custom_wizard/wizard_field_serializer.rb index 19025dff..42d5eba0 100644 --- a/serializers/custom_wizard/wizard_field_serializer.rb +++ b/serializers/custom_wizard/wizard_field_serializer.rb @@ -40,10 +40,6 @@ class CustomWizard::FieldSerializer < ::ApplicationSerializer object.value end - def include_value? - object.value.present? - end - def i18n_key @i18n_key ||= "wizard.step.#{object.step.id}.fields.#{object.id}".underscore end From 4a4c1934a00cbdc1d288fb978e8f48ea24b2dcdd Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Fri, 30 Apr 2021 23:02:13 +0530 Subject: [PATCH 5/6] revert client side change --- .../wizard/initializers/custom-wizard-field.js.es6 | 6 ------ 1 file changed, 6 deletions(-) diff --git a/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 b/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 index 89f9d16a..3ede2b05 100644 --- a/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 +++ b/assets/javascripts/wizard/initializers/custom-wizard-field.js.es6 @@ -57,12 +57,6 @@ export default { ]; FieldModel.reopen({ - init() { - this._super(...arguments); - if (this.type === "checkbox") { - this.set("value", this.value || false); - } - }, check() { if (this.customCheck) { return this.customCheck(); From 743af8edc522748d34aa6fd6704537005ae077df Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Wed, 5 May 2021 11:35:53 +0530 Subject: [PATCH 6/6] FIX: breakage due to core changes (#107) --- .../discourse/initializers/custom-wizard-redirect.js.es6 | 2 +- assets/javascripts/discourse/lib/wizard-schema.js.es6 | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 index 21dd0e81..e413cd17 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-redirect.js.es6 @@ -21,7 +21,7 @@ export default { actions: { willTransition(transition) { const redirectToWizard = this.get("currentUser.redirect_to_wizard"); - const excludedPaths = Discourse.SiteSettings.wizard_redirect_exclude_paths + const excludedPaths = this.siteSettings.wizard_redirect_exclude_paths .split("|") .concat(["loading"]); diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index d196f387..8b8200b0 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -1,4 +1,5 @@ import { get, set } from "@ember/object"; +import { getOwner } from "discourse-common/lib/get-owner"; const wizard = { basic: { @@ -222,7 +223,8 @@ export function buildFieldValidations(validations) { wizardSchema.field.validations = validations; } -if (Discourse.SiteSettings.wizard_apis_enabled) { +const siteSettings = getOwner(this).lookup("site-settings:main"); +if (siteSettings.wizard_apis_enabled) { wizardSchema.action.types.send_to_api = { api: null, api_endpoint: null,