From 564985e46e8ef7149ab206f1937a05397fadb5e3 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Thu, 11 Nov 2021 17:20:10 +0530 Subject: [PATCH 1/8] FEATURE: allow 'New Topic' button to redirect to a wizard --- .../create-topic-wizard.hbs | 16 +++++++++++++ .../create-topic-wizard.js.es6 | 24 +++++++++++++++++++ .../initializers/custom-wizard-edits.js.es6 | 18 ++++++++++++++ config/locales/client.en.yml | 3 +++ plugin.rb | 1 + 5 files changed, 62 insertions(+) create mode 100644 assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.hbs create mode 100644 assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.hbs b/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.hbs new file mode 100644 index 00000000..027296f0 --- /dev/null +++ b/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.hbs @@ -0,0 +1,16 @@ +

{{i18n "admin.wizard.category_settings.create_topic_wizard"}}

+ +
+ +
+ {{combo-box + value=wizardListVal + content=wizardList + onChange=(action "changeWizard") + options=(hash + none="admin.wizard.select" + )}} +
+
diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 b/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 new file mode 100644 index 00000000..0ff16c29 --- /dev/null +++ b/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 @@ -0,0 +1,24 @@ +import { ajax } from "discourse/lib/ajax"; +import CustomWizard from "../../models/custom-wizard"; +import { popupAjaxError } from "discourse/lib/ajax-error"; + +export default { + setupComponent(attrs, component) { + CustomWizard.all() + .then(result => { + component.set('wizardList', result); + }) + .catch(popupAjaxError); + component.set( + 'wizardListVal', + attrs.category.custom_fields.create_topic_wizard + ); + }, + + actions: { + changeWizard(wizard){ + this.set('wizardListVal', wizard); + this.set('category.custom_fields.create_topic_wizard', wizard); + } + } +} diff --git a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 index 63ddd5e8..d615e5bf 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 @@ -1,4 +1,6 @@ import DiscourseURL from "discourse/lib/url"; +import { withPluginApi } from "discourse/lib/plugin-api"; +import getUrl from "discourse-common/lib/get-url"; export default { name: "custom-wizard-edits", @@ -16,5 +18,21 @@ export default { } return existing.apply(this, [path, opts]); }; + + withPluginApi("0.8.7", (api) => { + api.modifyClass("component:d-navigation", { + pluginId: 'custom-wizard', + actions: { + clickCreateTopicButton(){ + let createTopicWizard = this.get('category.custom_fields.create_topic_wizard'); + if (createTopicWizard) { + window.location.href = getUrl(`/w/${createTopicWizard}`); + } else { + this._super(); + } + } + } + }) + }); }, }; diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index b07fd84a..cbcf6e5a 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -60,6 +60,9 @@ en: select_type: "Select a type" condition: "Condition" index: "Index" + category_settings: + create_topic_wizard: "Create Topic Wizard" + select_wizard: "Select a wizard you want to use for creating topics in this category" message: wizard: diff --git a/plugin.rb b/plugin.rb index b4d09421..356650f2 100644 --- a/plugin.rb +++ b/plugin.rb @@ -117,6 +117,7 @@ after_initialize do end Liquid::Template.register_filter(::CustomWizard::LiquidFilter::FirstNonEmpty) + Site.preloaded_category_custom_fields << "create_topic_wizard" add_class_method(:wizard, :user_requires_completion?) do |user| wizard_result = self.new(user).requires_completion? From f044ad6101187c19bce8046762ffe7d2cf3d5517 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Thu, 11 Nov 2021 17:22:54 +0530 Subject: [PATCH 2/8] bump version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 356650f2..e68f88d8 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Create custom wizards -# version: 1.15.3 +# version: 1.16.0 # authors: Angus McLeod # url: https://github.com/paviliondev/discourse-custom-wizard # contact emails: angus@thepavilion.io From 892914d649542b9047308afb555e48f464fc5cf9 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Thu, 11 Nov 2021 17:38:53 +0530 Subject: [PATCH 3/8] fixed formatting --- .../create-topic-wizard.js.es6 | 25 +++++++++---------- .../initializers/custom-wizard-edits.js.es6 | 14 ++++++----- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 b/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 index 0ff16c29..3abfd4e7 100644 --- a/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 +++ b/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 @@ -1,24 +1,23 @@ -import { ajax } from "discourse/lib/ajax"; import CustomWizard from "../../models/custom-wizard"; import { popupAjaxError } from "discourse/lib/ajax-error"; export default { setupComponent(attrs, component) { CustomWizard.all() - .then(result => { - component.set('wizardList', result); + .then((result) => { + component.set("wizardList", result); }) .catch(popupAjaxError); - component.set( - 'wizardListVal', - attrs.category.custom_fields.create_topic_wizard - ); + component.set( + "wizardListVal", + attrs.category.custom_fields.create_topic_wizard + ); }, actions: { - changeWizard(wizard){ - this.set('wizardListVal', wizard); - this.set('category.custom_fields.create_topic_wizard', wizard); - } - } -} + changeWizard(wizard) { + this.set("wizardListVal", wizard); + this.set("category.custom_fields.create_topic_wizard", wizard); + }, + }, +}; diff --git a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 index d615e5bf..20787b4e 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 @@ -21,18 +21,20 @@ export default { withPluginApi("0.8.7", (api) => { api.modifyClass("component:d-navigation", { - pluginId: 'custom-wizard', + pluginId: "custom-wizard", actions: { - clickCreateTopicButton(){ - let createTopicWizard = this.get('category.custom_fields.create_topic_wizard'); + clickCreateTopicButton() { + let createTopicWizard = this.get( + "category.custom_fields.create_topic_wizard" + ); if (createTopicWizard) { window.location.href = getUrl(`/w/${createTopicWizard}`); } else { this._super(); } - } - } - }) + }, + }, + }); }); }, }; From cdafffea2b8ed71f69826d76db2720e23e19bc4e Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Wed, 17 Nov 2021 20:15:48 +0530 Subject: [PATCH 4/8] use proper structure for preloading category custom fields --- plugin.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index e68f88d8..ce0d7b6f 100644 --- a/plugin.rb +++ b/plugin.rb @@ -116,8 +116,15 @@ after_initialize do load File.expand_path(path, __FILE__) end + # preloaded category custom fields + %w[ + create_topic_wizard + ] + .each do |custom_field| + Site.preloaded_category_custom_fields << custom_field + end + Liquid::Template.register_filter(::CustomWizard::LiquidFilter::FirstNonEmpty) - Site.preloaded_category_custom_fields << "create_topic_wizard" add_class_method(:wizard, :user_requires_completion?) do |user| wizard_result = self.new(user).requires_completion? From 460d4e397aeb60c57c9aa4592ec30570a152232a Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Tue, 7 Dec 2021 14:01:39 +0530 Subject: [PATCH 5/8] fixed linting --- plugin.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin.rb b/plugin.rb index ce0d7b6f..bf43de25 100644 --- a/plugin.rb +++ b/plugin.rb @@ -119,8 +119,7 @@ after_initialize do # preloaded category custom fields %w[ create_topic_wizard - ] - .each do |custom_field| + ].each do |custom_field| Site.preloaded_category_custom_fields << custom_field end From 9c98887437a6f1d4c05699ae687a075096765888 Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Wed, 8 Dec 2021 12:50:57 +0530 Subject: [PATCH 6/8] optional chaining to prevent errors --- .../category-custom-settings/create-topic-wizard.js.es6 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 b/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 index 3abfd4e7..3026e729 100644 --- a/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 +++ b/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 @@ -8,9 +8,10 @@ export default { component.set("wizardList", result); }) .catch(popupAjaxError); + attrs component.set( "wizardListVal", - attrs.category.custom_fields.create_topic_wizard + attrs?.category?.custom_fields?.create_topic_wizard ); }, From 21b0d52b1b26cddb4fb5d228c677ed17b71b40ef Mon Sep 17 00:00:00 2001 From: Faizaan Gagan Date: Wed, 8 Dec 2021 12:56:14 +0530 Subject: [PATCH 7/8] cleanup --- .../category-custom-settings/create-topic-wizard.js.es6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 b/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 index 3026e729..16352f95 100644 --- a/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 +++ b/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 @@ -8,7 +8,7 @@ export default { component.set("wizardList", result); }) .catch(popupAjaxError); - attrs + component.set( "wizardListVal", attrs?.category?.custom_fields?.create_topic_wizard From 70c3f19334293a46821cbabab696735ca58aba0c Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Thu, 9 Dec 2021 09:53:10 +0800 Subject: [PATCH 8/8] Update settings text and file naming --- ...opic-wizard.hbs => custom-wizard-category-settings.hbs} | 4 ++-- ...izard.js.es6 => custom-wizard-category-settings.js.es6} | 0 config/locales/client.en.yml | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) rename assets/javascripts/discourse/connectors/category-custom-settings/{create-topic-wizard.hbs => custom-wizard-category-settings.hbs} (67%) rename assets/javascripts/discourse/connectors/category-custom-settings/{create-topic-wizard.js.es6 => custom-wizard-category-settings.js.es6} (100%) diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.hbs b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs similarity index 67% rename from assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.hbs rename to assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs index 027296f0..4b5d673d 100644 --- a/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.hbs +++ b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.hbs @@ -1,8 +1,8 @@ -

{{i18n "admin.wizard.category_settings.create_topic_wizard"}}

+

{{i18n "admin.wizard.category_settings.custom_wizard.title"}}

{{combo-box diff --git a/assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 b/assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.js.es6 similarity index 100% rename from assets/javascripts/discourse/connectors/category-custom-settings/create-topic-wizard.js.es6 rename to assets/javascripts/discourse/connectors/category-custom-settings/custom-wizard-category-settings.js.es6 diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index cbcf6e5a..40e103c8 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -61,9 +61,10 @@ en: condition: "Condition" index: "Index" category_settings: - create_topic_wizard: "Create Topic Wizard" - select_wizard: "Select a wizard you want to use for creating topics in this category" - + custom_wizard: + title: "Custom Wizard" + create_topic_wizard: "Select a wizard to replace the new topic composer in this category." + message: wizard: select: "Select a wizard, or create a new one"