From 155493ce3b15743cc60ac8a9eab5426864451d9b Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 12 May 2020 14:01:26 -0400 Subject: [PATCH 01/33] DEV: Discourse.Route has been deprecated --- .../javascripts/discourse/routes/admin-wizards-logs.js.es6 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/routes/admin-wizards-logs.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-logs.js.es6 index 1c1de391..a7e62ad6 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-logs.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-logs.js.es6 @@ -1,11 +1,12 @@ import CustomWizardLogs from '../models/custom-wizard-logs'; +import DiscourseRoute from "discourse/routes/discourse"; -export default Discourse.Route.extend({ +export default DiscourseRoute.extend({ model() { return CustomWizardLogs.list(); }, - + setupController(controller, model) { controller.set('logs', model); } -}) \ No newline at end of file +}) From f28bde520699b0ad2ea0f2c40aa0b8dff9e3814c Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 14 May 2020 13:42:11 +1000 Subject: [PATCH 02/33] I18n is now imported --- assets/javascripts/wizard-preload.js.es6 | 2 ++ .../javascripts/wizard/components/custom-user-selector.js.es6 | 1 + .../javascripts/wizard/components/wizard-field-upload.js.es6 | 1 + assets/javascripts/wizard/components/wizard-text-field.js.es6 | 1 + assets/javascripts/wizard/routes/custom-step.js.es6 | 2 ++ views/layouts/wizard.html.erb | 3 ++- 6 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 assets/javascripts/wizard-preload.js.es6 diff --git a/assets/javascripts/wizard-preload.js.es6 b/assets/javascripts/wizard-preload.js.es6 new file mode 100644 index 00000000..0cf785fa --- /dev/null +++ b/assets/javascripts/wizard-preload.js.es6 @@ -0,0 +1,2 @@ +//= require discourse-loader +//= require locales/i18n \ No newline at end of file diff --git a/assets/javascripts/wizard/components/custom-user-selector.js.es6 b/assets/javascripts/wizard/components/custom-user-selector.js.es6 index 143b340c..dfc45604 100644 --- a/assets/javascripts/wizard/components/custom-user-selector.js.es6 +++ b/assets/javascripts/wizard/components/custom-user-selector.js.es6 @@ -1,6 +1,7 @@ import { default as computed, observes } from 'discourse-common/utils/decorators'; import { renderAvatar } from 'discourse/helpers/user-avatar'; import userSearch from '../lib/user-search'; +import I18n from "I18n"; const template = function(params) { const options = params.options; diff --git a/assets/javascripts/wizard/components/wizard-field-upload.js.es6 b/assets/javascripts/wizard/components/wizard-field-upload.js.es6 index 58faff14..2241c940 100644 --- a/assets/javascripts/wizard/components/wizard-field-upload.js.es6 +++ b/assets/javascripts/wizard/components/wizard-field-upload.js.es6 @@ -1,5 +1,6 @@ import getUrl from "discourse-common/lib/get-url"; import { getToken } from "wizard/lib/ajax"; +import I18n from "I18n"; export default Ember.Component.extend({ classNames: ["wizard-field-upload"], diff --git a/assets/javascripts/wizard/components/wizard-text-field.js.es6 b/assets/javascripts/wizard/components/wizard-text-field.js.es6 index 5c62abc8..8e4570a7 100644 --- a/assets/javascripts/wizard/components/wizard-text-field.js.es6 +++ b/assets/javascripts/wizard/components/wizard-text-field.js.es6 @@ -2,6 +2,7 @@ import computed from "discourse-common/utils/decorators"; import { siteDir, isRTL, isLTR } from "discourse/lib/text-direction"; +import I18n from "I18n"; export default Ember.TextField.extend({ attributeBindings: ['autocorrect', 'autocapitalize', 'autofocus', 'maxLength', 'dir'], diff --git a/assets/javascripts/wizard/routes/custom-step.js.es6 b/assets/javascripts/wizard/routes/custom-step.js.es6 index bba4b49f..72dd5263 100644 --- a/assets/javascripts/wizard/routes/custom-step.js.es6 +++ b/assets/javascripts/wizard/routes/custom-step.js.es6 @@ -1,3 +1,5 @@ +import I18n from "I18n"; + export default Ember.Route.extend({ model(params) { const appModel = this.modelFor('custom'); diff --git a/views/layouts/wizard.html.erb b/views/layouts/wizard.html.erb index 47d54309..2f94a767 100644 --- a/views/layouts/wizard.html.erb +++ b/views/layouts/wizard.html.erb @@ -11,7 +11,8 @@ <%- if theme_ids.present? %> <%= discourse_stylesheet_link_tag (mobile_view? ? :mobile_theme : :desktop_theme) %> <%- end %> - + + <%= preload_script "wizard-preload" %> <%= preload_script "ember_jquery" %> <%= preload_script "wizard-vendor" %> <%= preload_script "wizard-application" %> From 14bb8be66e45ee804397a8a9f7a17004aacbca5c Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 14 May 2020 13:42:38 +1000 Subject: [PATCH 03/33] Update after_time feature to new wizard api --- jobs/set_after_time_wizard.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jobs/set_after_time_wizard.rb b/jobs/set_after_time_wizard.rb index 7aa528ba..80f8f5e5 100644 --- a/jobs/set_after_time_wizard.rb +++ b/jobs/set_after_time_wizard.rb @@ -2,7 +2,7 @@ module Jobs class SetAfterTimeWizard < ::Jobs::Base def execute(args) if SiteSetting.custom_wizard_enabled - wizard = CustomWizard::Wizard.find(args[:wizard_id]) + wizard = CustomWizard::Wizard.create(args[:wizard_id]) if wizard && wizard.after_time user_ids = [] From e28576ba5b8a78f34b857aca3a0c33d5bd98edb2 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 14 May 2020 14:46:41 +1000 Subject: [PATCH 04/33] Update wizard-preload.js.es6 --- assets/javascripts/wizard-preload.js.es6 | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/javascripts/wizard-preload.js.es6 b/assets/javascripts/wizard-preload.js.es6 index 0cf785fa..278cc686 100644 --- a/assets/javascripts/wizard-preload.js.es6 +++ b/assets/javascripts/wizard-preload.js.es6 @@ -1,2 +1 @@ -//= require discourse-loader //= require locales/i18n \ No newline at end of file From f19cc33af46d380ddf80f1b7f147775fb1578155 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 14 May 2020 15:00:23 +1000 Subject: [PATCH 05/33] Precompile wizard-preload --- plugin.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin.rb b/plugin.rb index d4c04a99..6e26bcee 100644 --- a/plugin.rb +++ b/plugin.rb @@ -18,6 +18,7 @@ config.assets.paths << "#{plugin_asset_path}/stylesheets/wizard" if Rails.env.production? config.assets.precompile += %w{ + wizard-preload.js wizard-custom-guest.js wizard-custom-lib.js wizard-custom.js From b9ad37c38f19a5b0cfdc23ef6c5b2d9cc4e9fd16 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 15 May 2020 09:31:39 +1000 Subject: [PATCH 06/33] Locale loading update --- assets/javascripts/wizard-preload.js.es6 | 1 - views/layouts/wizard.html.erb | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) delete mode 100644 assets/javascripts/wizard-preload.js.es6 diff --git a/assets/javascripts/wizard-preload.js.es6 b/assets/javascripts/wizard-preload.js.es6 deleted file mode 100644 index 278cc686..00000000 --- a/assets/javascripts/wizard-preload.js.es6 +++ /dev/null @@ -1 +0,0 @@ -//= require locales/i18n \ No newline at end of file diff --git a/views/layouts/wizard.html.erb b/views/layouts/wizard.html.erb index 2f94a767..0deb4c71 100644 --- a/views/layouts/wizard.html.erb +++ b/views/layouts/wizard.html.erb @@ -12,7 +12,7 @@ <%= discourse_stylesheet_link_tag (mobile_view? ? :mobile_theme : :desktop_theme) %> <%- end %> - <%= preload_script "wizard-preload" %> + <%= preload_script "locales/#{I18n.locale}" %> <%= preload_script "ember_jquery" %> <%= preload_script "wizard-vendor" %> <%= preload_script "wizard-application" %> @@ -20,7 +20,6 @@ <%= preload_script "wizard-custom" %> <%= preload_script "wizard-plugin" %> <%= preload_script "pretty-text-bundle" %> - <%= preload_script "locales/#{I18n.locale}" %> <%= csrf_meta_tags %> From b196acf15145f6f337c89b7c9f91687fca1bef5c Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 15 May 2020 12:06:21 +1000 Subject: [PATCH 07/33] Update after-time modal to use new date time inputs --- .../controllers/next-session-scheduled.js.es6 | 47 +++------------- .../modal/next-session-scheduled.hbs | 30 ++++------- assets/stylesheets/common/wizard-admin.scss | 54 +++---------------- 3 files changed, 25 insertions(+), 106 deletions(-) diff --git a/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 b/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 index cb7650e7..4cfd4883 100644 --- a/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 +++ b/assets/javascripts/discourse/controllers/next-session-scheduled.js.es6 @@ -1,58 +1,27 @@ import { default as discourseComputed } from 'discourse-common/utils/decorators'; -import { scheduleOnce } from "@ember/runloop"; import Controller from "@ember/controller"; export default Controller.extend({ title: 'admin.wizard.after_time_modal.title', setup() { - const dateTime = this.get('model.dateTime'); - const ROUNDING = 30 * 60 * 1000; - const nextInterval = moment(Math.ceil((+moment()) / ROUNDING) * ROUNDING); - const mDateTime = dateTime ? moment(dateTime) : nextInterval; - const mDateTimeLocal = mDateTime.local(); - const date = mDateTimeLocal.format('YYYY-MM-DD'); - const time = mDateTimeLocal.format('HH:mm'); - - this.setProperties({ date, time }); - - scheduleOnce('afterRender', this, () => { - const $timePicker = $("#time-picker"); - $timePicker.timepicker({ timeFormat: 'H:i' }); - $timePicker.timepicker('setTime', time); - $timePicker.change(() => this.set('time', $timePicker.val())); - }); + this.set('bufferedDateTime', moment(this.model.dateTime)); }, - @discourseComputed('date', 'time') - dateTime: function(date, time) { - return moment(date + 'T' + time).format(); - }, - - @discourseComputed('dateTime') + @discourseComputed('bufferedDateTime') submitDisabled(dateTime) { return moment().isAfter(dateTime); }, - resetProperties() { - this.setProperties({ - date: null, - time: null - }); - }, - actions: { - clear() { - this.resetProperties(); - this.get('model.update')(null); - }, - submit() { - const dateTime = this.get('dateTime'); - const formatted = moment(dateTime).utc().toISOString(); - this.get('model.update')(formatted); - this.resetProperties(); + const dateTime = this.get('bufferedDateTime'); + this.get('model.update')(moment(dateTime).utc().toISOString()); this.send("closeModal"); + }, + + dateTimeChanged(dateTime) { + this.set('bufferedDateTime', dateTime); } } }); diff --git a/assets/javascripts/discourse/templates/modal/next-session-scheduled.hbs b/assets/javascripts/discourse/templates/modal/next-session-scheduled.hbs index 36c08a3f..1b138360 100644 --- a/assets/javascripts/discourse/templates/modal/next-session-scheduled.hbs +++ b/assets/javascripts/discourse/templates/modal/next-session-scheduled.hbs @@ -1,24 +1,16 @@ {{#d-modal-body class="next-session-time-modal" title=title}} -
- -
-
+ {{date-time-input + date=bufferedDateTime + onChange=(action "dateTimeChanged") + showTime=true + clearable=true + }} {{/d-modal-body}} diff --git a/assets/stylesheets/common/wizard-admin.scss b/assets/stylesheets/common/wizard-admin.scss index fba44a3e..5eacc613 100644 --- a/assets/stylesheets/common/wizard-admin.scss +++ b/assets/stylesheets/common/wizard-admin.scss @@ -481,54 +481,12 @@ min-height: 150px; } -.next-session-time-modal { - text-align: center; - - .date-time-card { - width: 270px; - padding: 10px 20px; - text-align: left; - } - - .modal-date-time-set{ - padding-top: 3px; - padding-bottom: 4px; - display: flex; - flex-direction: row; - - .modal-date-area{ - order: 1; - } - - .modal-time-area{ - order: 2; - margin-left: 10px; - - .modal-time{ - width: 127px; - } - } - } - - .ui-timepicker-input { - width: 119px; - text-align: center; - } - - .date-picker{ - width: 121px; - } - - .pika-single { - position: relative !important; - - .pika-lendar { - border: 1px solid #eee; - padding: 14px; - margin: 0; - float: none; - width: auto; - } +.modal .modal-body.next-session-time-modal { + overflow: visible; + + .picker-container { + position: absolute; + top: 30px; } } From f4a9cf86f2156df9215bda5635a2daf9ebc60238 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Fri, 22 May 2020 23:42:26 +0100 Subject: [PATCH 08/33] FEATURE: added ability for user to selected watched categories in wizard --- .../components/wizard-custom-action.js.es6 | 1 + .../discourse/lib/wizard-schema.js.es6 | 5 ++ .../components/wizard-custom-action.hbs | 63 +++++++++++++------ config/locales/client.en.yml | 3 + controllers/custom_wizard/admin/wizard.rb | 1 + lib/custom_wizard/action.rb | 12 ++++ lib/custom_wizard/mapper.rb | 5 +- 7 files changed, 68 insertions(+), 22 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 95ac4dd7..23cd5d27 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -12,6 +12,7 @@ export default Component.extend(UndoChanges, { visible: computed('currentActionId', function() { return this.action.id === this.currentActionId }), createTopic: equal('action.type', 'create_topic'), updateProfile: equal('action.type', 'update_profile'), + watchCategories: equal('action.type', 'watch_categories'), sendMessage: equal('action.type', 'send_message'), openComposer: equal('action.type', 'open_composer'), sendToApi: equal('action.type', 'send_to_api'), diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index bd99ba7b..c18913c0 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -141,6 +141,10 @@ const action = { profile_updates: null, custom_fields: null }, + watch_categories: { + category: null, + mute_remainder: null + }, add_to_group: { group: null }, @@ -158,6 +162,7 @@ const action = { 'recipient', 'profile_updates', 'group', + 'mute_remainder', 'url' ], advanced: [ diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index c27e56cd..7b9eeb2f 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -10,7 +10,7 @@
- +
{{combo-box value=action.type @@ -26,7 +26,7 @@
- +
{{combo-box value=action.run_after @@ -45,7 +45,7 @@
- +
{{wizard-mapper inputs=action.title @@ -102,7 +102,7 @@
- +
{{wizard-mapper inputs=action.category @@ -123,7 +123,7 @@
- +
{{wizard-mapper inputs=action.tags @@ -146,7 +146,7 @@
- +
{{wizard-mapper inputs=action.recipient @@ -170,7 +170,7 @@
- + {{wizard-mapper inputs=action.profile_updates property='profile_updates' @@ -191,7 +191,7 @@
- +
{{combo-box value=action.api @@ -208,7 +208,7 @@
- +
{{combo-box value=action.api_endpoint @@ -225,7 +225,7 @@
- +
{{wizard-text-editor value=action.api_body @@ -242,7 +242,7 @@
- +
{{wizard-mapper inputs=action.group @@ -265,7 +265,7 @@
- +
{{wizard-mapper inputs=action.url @@ -283,18 +283,41 @@
{{/if}} +{{#if watchCategories}} +
+
+ +
+ +
+ {{wizard-mapper + inputs=action.mute_remainder + property='mute_remainder' + onUpdate=(action 'mappedFieldUpdated') + options=(hash + context='action' + wizardFieldSelection=true + userFieldSelection='key,value' + groupSelection='key,value' + categorySelection='key,value' + userSelection='key,value' + )}} +
+
+{{/if}} + {{#if showAdvanced}} {{wizard-advanced-toggle showAdvanced=action.showAdvanced}} {{#if action.showAdvanced}}
- + {{#if hasCustomFields}}
- +
{{wizard-mapper inputs=action.custom_fields @@ -310,13 +333,13 @@
{{/if}} - + {{#if sendMessage}}
- +
{{wizard-mapper inputs=action.required @@ -332,23 +355,23 @@
{{/if}} - + {{#if showSkipRedirect}}
- +
{{input type='checkbox' checked=action.skip_redirect}} - + {{i18n 'admin.wizard.action.skip_redirect.description' type='topic'}}
{{/if}} - + {{#if routeTo}}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 0a79915d..f47d7e95 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -208,6 +208,9 @@ en: label: "Update Profile" setting: "Fields" key: "field" + watch_categories: + label: "Watch Categories" + mute_remainder: "Mute Remainder" post_builder: checkbox: "Post Builder" label: "Builder" diff --git a/controllers/custom_wizard/admin/wizard.rb b/controllers/custom_wizard/admin/wizard.rb index d7f87f9a..b15dcf65 100644 --- a/controllers/custom_wizard/admin/wizard.rb +++ b/controllers/custom_wizard/admin/wizard.rb @@ -122,6 +122,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController custom_fields: mapped_params, required: mapped_params, recipient: mapped_params, + mute_remainder: mapped_params, profile_updates: mapped_params, group: mapped_params, url: mapped_params diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index d85067bb..e0b84257 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -133,6 +133,18 @@ class CustomWizard::Action end end + def watch_categories + key, watched_categories = data.first + mute_remainder = data.values[1] + Category.all.each do |category| + if watched_categories.include?(category.id.to_s) + CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], category.id) + elsif mute_remainder + CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id) + end + end + end + def send_to_api api_body = nil diff --git a/lib/custom_wizard/mapper.rb b/lib/custom_wizard/mapper.rb index 19b40e6b..aafc317f 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -3,6 +3,7 @@ class CustomWizard::Mapper USER_FIELDS = ['name', 'username', 'email', 'date_of_birth', 'title', 'locale', 'trust_level'] PROFILE_FIELDS = ['location', 'website', 'bio_raw'] + CATEGORY_NOTIFICATION_LEVELS = ['regular','watching', 'tracking', 'watching_first_post','muted'] def self.user_fields USER_FIELDS + PROFILE_FIELDS @@ -115,10 +116,10 @@ class CustomWizard::Mapper end end end - + def validation_result(key, value, operator) result = nil - + if operator.is_a?(Hash) && (operator = operator[value.to_sym]).present? if value == "present" result = key.public_send(operator) From ca3bad6664e19a7dd6a09ffd5ad770f29a3c87a0 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 08:35:17 +0100 Subject: [PATCH 09/33] revert deletions of redundant spaces to improve clarity of PR --- .../components/wizard-custom-action.hbs | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 7b9eeb2f..5b520eea 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -10,7 +10,7 @@
- +
{{combo-box value=action.type @@ -26,7 +26,7 @@
- +
{{combo-box value=action.run_after @@ -45,7 +45,7 @@
- +
{{wizard-mapper inputs=action.title @@ -102,7 +102,7 @@
- +
{{wizard-mapper inputs=action.category @@ -123,7 +123,7 @@
- +
{{wizard-mapper inputs=action.tags @@ -146,7 +146,7 @@
- +
{{wizard-mapper inputs=action.recipient @@ -170,7 +170,7 @@
- + {{wizard-mapper inputs=action.profile_updates property='profile_updates' @@ -191,7 +191,7 @@
- +
{{combo-box value=action.api @@ -208,7 +208,7 @@
- +
{{combo-box value=action.api_endpoint @@ -225,7 +225,7 @@
- +
{{wizard-text-editor value=action.api_body @@ -242,7 +242,7 @@
- +
{{wizard-mapper inputs=action.group @@ -265,7 +265,7 @@
- +
{{wizard-mapper inputs=action.url @@ -311,13 +311,13 @@ {{#if action.showAdvanced}}
- + {{#if hasCustomFields}}
- +
{{wizard-mapper inputs=action.custom_fields @@ -333,13 +333,13 @@
{{/if}} - + {{#if sendMessage}}
- +
{{wizard-mapper inputs=action.required @@ -355,23 +355,23 @@
{{/if}} - + {{#if showSkipRedirect}}
- +
{{input type='checkbox' checked=action.skip_redirect}} - + {{i18n 'admin.wizard.action.skip_redirect.description' type='topic'}}
{{/if}} - + {{#if routeTo}}
From d3e7fceb56d7f7103a80b88bf3e49abf12ee59df Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 08:36:56 +0100 Subject: [PATCH 10/33] revert deletions of redundant spaces continued --- .../discourse/templates/components/wizard-custom-action.hbs | 4 ++-- 1 file 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 5b520eea..98b508a2 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -45,7 +45,7 @@
- +
{{wizard-mapper inputs=action.title @@ -311,7 +311,7 @@ {{#if action.showAdvanced}}
- + {{#if hasCustomFields}}
From beed6a93fc63da2a30473ce31d691cc5fbc9463f Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 08:38:54 +0100 Subject: [PATCH 11/33] revert deletions of redundant spaces continued#3 --- 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 aafc317f..1b1f8101 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -116,10 +116,10 @@ class CustomWizard::Mapper end end end - + def validation_result(key, value, operator) result = nil - + if operator.is_a?(Hash) && (operator = operator[value.to_sym]).present? if value == "present" result = key.public_send(operator) From 5fc5ce113e0377cd06e16a045894ce27a40b3c56 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 08:56:27 +0100 Subject: [PATCH 12/33] Update schema against PR feedback --- assets/javascripts/discourse/lib/wizard-schema.js.es6 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index c18913c0..f3c61cd8 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -142,7 +142,7 @@ const action = { custom_fields: null }, watch_categories: { - category: null, + categories: null, mute_remainder: null }, add_to_group: { @@ -162,8 +162,9 @@ const action = { 'recipient', 'profile_updates', 'group', - 'mute_remainder', - 'url' + 'url', + 'categories', + 'mute_remainder' ], advanced: [ 'code', From 9097e3cad253c3f5c144249a6b35695e84662c52 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 09:03:34 +0100 Subject: [PATCH 13/33] Remove unnecessary selection options --- .../discourse/templates/components/wizard-custom-action.hbs | 3 --- 1 file changed, 3 deletions(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 98b508a2..208007d7 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -298,9 +298,6 @@ context='action' wizardFieldSelection=true userFieldSelection='key,value' - groupSelection='key,value' - categorySelection='key,value' - userSelection='key,value' )}}
From f13c04043b877a42f0319d56462cc960e937b17c Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 09:07:47 +0100 Subject: [PATCH 14/33] remove unused constant --- lib/custom_wizard/mapper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/custom_wizard/mapper.rb b/lib/custom_wizard/mapper.rb index 1b1f8101..19b40e6b 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -3,7 +3,6 @@ class CustomWizard::Mapper USER_FIELDS = ['name', 'username', 'email', 'date_of_birth', 'title', 'locale', 'trust_level'] PROFILE_FIELDS = ['location', 'website', 'bio_raw'] - CATEGORY_NOTIFICATION_LEVELS = ['regular','watching', 'tracking', 'watching_first_post','muted'] def self.user_fields USER_FIELDS + PROFILE_FIELDS From 24585252060f78b0e3a8def709ba5ff734810a7c Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 11:20:15 +0100 Subject: [PATCH 15/33] utilise wizard mapper to retrieve values --- .../components/wizard-custom-action.hbs | 19 +++++++++++++++++++ config/locales/client.en.yml | 1 + controllers/custom_wizard/admin/wizard.rb | 1 + lib/custom_wizard/action.rb | 17 ++++++++++++++--- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 208007d7..40d6b31a 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -284,6 +284,25 @@ {{/if}} {{#if watchCategories}} +
+
+ +
+ +
+ {{wizard-mapper + inputs=action.categories + property='categories' + onUpdate=(action 'mappedFieldUpdated') + options=(hash + textSelection='key,value' + wizardFieldSelection=true + userFieldSelection='key,value' + context='action' + )}} +
+
+
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index f47d7e95..a601fbe5 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -211,6 +211,7 @@ en: watch_categories: label: "Watch Categories" mute_remainder: "Mute Remainder" + categories: "Categories" post_builder: checkbox: "Post Builder" label: "Builder" diff --git a/controllers/custom_wizard/admin/wizard.rb b/controllers/custom_wizard/admin/wizard.rb index b15dcf65..0f155fbe 100644 --- a/controllers/custom_wizard/admin/wizard.rb +++ b/controllers/custom_wizard/admin/wizard.rb @@ -122,6 +122,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController custom_fields: mapped_params, required: mapped_params, recipient: mapped_params, + categories: mapped_params, mute_remainder: mapped_params, profile_updates: mapped_params, group: mapped_params, diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index e0b84257..c3c6fbe5 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -134,10 +134,21 @@ class CustomWizard::Action end def watch_categories - key, watched_categories = data.first - mute_remainder = data.values[1] + + watched_categories_map = CustomWizard::Mapper.new( + inputs: action['categories'], + data: data, + user: user + ).perform + + mute_remainder = CustomWizard::Mapper.new( + inputs: action['mute_remainder'], + data: data, + user: user + ).perform + Category.all.each do |category| - if watched_categories.include?(category.id.to_s) + if watched_categories_map.include?(category.id.to_s) CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], category.id) elsif mute_remainder CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id) From 355d1abc544f3335bb4715126209af4e25c04092 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sun, 24 May 2020 11:23:17 +0100 Subject: [PATCH 16/33] simplify naming --- lib/custom_wizard/action.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index c3c6fbe5..e78353d9 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -135,7 +135,7 @@ class CustomWizard::Action def watch_categories - watched_categories_map = CustomWizard::Mapper.new( + watched_categories = CustomWizard::Mapper.new( inputs: action['categories'], data: data, user: user @@ -148,7 +148,7 @@ class CustomWizard::Action ).perform Category.all.each do |category| - if watched_categories_map.include?(category.id.to_s) + if watched_categories.include?(category.id.to_s) CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], category.id) elsif mute_remainder CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id) From c4471fa15f8832fdfbc68169d97ad8ddb2b85124 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Mon, 25 May 2020 14:59:31 +0100 Subject: [PATCH 17/33] Added notification level dropdown to allow admin to specify which level of tracking will be chosen during action --- .../components/wizard-custom-action.js.es6 | 7 +++++++ .../discourse/lib/wizard-schema.js.es6 | 5 ++++- assets/javascripts/discourse/lib/wizard.js.es6 | 9 +++++++++ .../components/wizard-custom-action.hbs | 17 +++++++++++++++++ config/locales/client.en.yml | 10 +++++++++- controllers/custom_wizard/admin/wizard.rb | 1 + lib/custom_wizard/action.rb | 4 +++- 7 files changed, 50 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 23cd5d27..205e3580 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -5,6 +5,7 @@ import { computed } from "@ember/object"; import wizardSchema from '../lib/wizard-schema'; import UndoChanges from '../mixins/undo-changes'; import Component from "@ember/component"; +import { notificationLevels } from '../lib/wizard'; export default Component.extend(UndoChanges, { componentType: 'action', @@ -32,6 +33,12 @@ export default Component.extend(UndoChanges, { name: I18n.t(`admin.wizard.action.${type}.label`) }; }), + availableNotificationLevels: notificationLevels.map((type, index) => { + return { + id: type, + name: I18n.t(`admin.wizard.action.watch_categories.notification_level.${type}`) + }; + }), messageUrl: 'https://thepavilion.io/t/2810', diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index f3c61cd8..599f4708 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -143,6 +143,7 @@ const action = { }, watch_categories: { categories: null, + notification_level: null, mute_remainder: null }, add_to_group: { @@ -164,6 +165,7 @@ const action = { 'group', 'url', 'categories', + // 'notification_level', 'mute_remainder' ], advanced: [ @@ -186,7 +188,8 @@ const wizardSchema = { wizard, step, field, - action + action, + } export function buildFieldTypes(types) { diff --git a/assets/javascripts/discourse/lib/wizard.js.es6 b/assets/javascripts/discourse/lib/wizard.js.es6 index 668ebe6a..4351367d 100644 --- a/assets/javascripts/discourse/lib/wizard.js.es6 +++ b/assets/javascripts/discourse/lib/wizard.js.es6 @@ -49,6 +49,14 @@ const userProperties = [ 'trust_level' ]; +const notificationLevels = [ + 'regular', + 'watching', + 'tracking', + 'watching_first_post', + 'muted' +]; + function listProperties(type, opts={}) { let properties = Object.keys(wizardSchema[type].basic); @@ -106,5 +114,6 @@ export { snakeCase, userProperties, listProperties, + notificationLevels, wizardFieldList }; \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index 40d6b31a..fa119d14 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -303,6 +303,23 @@
+
+
+ +
+ +
+ {{combo-box + value=action.notification_level + content=availableNotificationLevels + onChange=(action (mut action.notification_level)) + options=(hash + isDisabled=action.custom_title_enabled + none='admin.wizard.action.watch_categories.select_a_notification_level' + )}} +
+
+
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index a601fbe5..b7c3d73f 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -210,8 +210,16 @@ en: key: "field" watch_categories: label: "Watch Categories" - mute_remainder: "Mute Remainder" categories: "Categories" + mute_remainder: "Mute Remainder" + notification_level: + label: "Notification Level" + regular: "Normal" + watching: "Watching" + tracking: "Tracking" + watching_first_post: "Watching First Post" + muted: "Muted" + select_a_notification_level: "Select level" post_builder: checkbox: "Post Builder" label: "Builder" diff --git a/controllers/custom_wizard/admin/wizard.rb b/controllers/custom_wizard/admin/wizard.rb index 0f155fbe..5c3ade4e 100644 --- a/controllers/custom_wizard/admin/wizard.rb +++ b/controllers/custom_wizard/admin/wizard.rb @@ -116,6 +116,7 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController :post, :post_builder, :post_template, + :notification_level, title: mapped_params, category: mapped_params, tags: mapped_params, diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index e78353d9..2d539287 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -141,6 +141,8 @@ class CustomWizard::Action user: user ).perform + notification_level = action['notification_level'] + mute_remainder = CustomWizard::Mapper.new( inputs: action['mute_remainder'], data: data, @@ -149,7 +151,7 @@ class CustomWizard::Action Category.all.each do |category| if watched_categories.include?(category.id.to_s) - CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:watching], category.id) + CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[notification_level.to_sym], category.id) elsif mute_remainder CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id) end From 92f626196d9e2652b4b255c09cb06b8472d46c67 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 26 May 2020 09:53:01 +0100 Subject: [PATCH 18/33] remove commented out code --- assets/javascripts/discourse/lib/wizard-schema.js.es6 | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 599f4708..06fd6b50 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -165,7 +165,6 @@ const action = { 'group', 'url', 'categories', - // 'notification_level', 'mute_remainder' ], advanced: [ From 518a4f3dce4f783ff96ab6a23d4f370b86de8eaf Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 26 May 2020 10:59:11 +0100 Subject: [PATCH 19/33] added some checks on data in action to reduce runtime issues --- lib/custom_wizard/action.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index 2d539287..e45dab3a 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -143,6 +143,11 @@ class CustomWizard::Action notification_level = action['notification_level'] + if notification_level.blank? + log_error("Notifcation Level was not set! Exiting wizard action") + return + end + mute_remainder = CustomWizard::Mapper.new( inputs: action['mute_remainder'], data: data, @@ -150,7 +155,7 @@ class CustomWizard::Action ).perform Category.all.each do |category| - if watched_categories.include?(category.id.to_s) + if watched_categories.present? && watched_categories.include?(category.id.to_s) CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[notification_level.to_sym], category.id) elsif mute_remainder CategoryUser.set_notification_level_for_category(user, CategoryUser.notification_levels[:muted], category.id) From 1f0f7ff5f9252f3100bbb223d2e2efb4a91aa470 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 26 May 2020 11:16:06 +0100 Subject: [PATCH 20/33] Added categorySelection on the output --- .../discourse/templates/components/wizard-custom-action.hbs | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index fa119d14..fabc4b36 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -298,6 +298,7 @@ textSelection='key,value' wizardFieldSelection=true userFieldSelection='key,value' + categorySelection='output' context='action' )}}
From 33b20038270a1b97797e5414652e037e97e375e3 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 26 May 2020 11:47:15 +0100 Subject: [PATCH 21/33] improved layout so that mapped field settings have more room --- .../components/wizard-custom-action.hbs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index fabc4b36..c52f6cd1 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -304,24 +304,7 @@
-
-
- -
- -
- {{combo-box - value=action.notification_level - content=availableNotificationLevels - onChange=(action (mut action.notification_level)) - options=(hash - isDisabled=action.custom_title_enabled - none='admin.wizard.action.watch_categories.select_a_notification_level' - )}} -
-
- -
+
@@ -338,6 +321,23 @@ )}}
+ +
+
+ +
+ +
+ {{combo-box + value=action.notification_level + content=availableNotificationLevels + onChange=(action (mut action.notification_level)) + options=(hash + isDisabled=action.custom_title_enabled + none='admin.wizard.action.watch_categories.select_a_notification_level' + )}} +
+
{{/if}} {{#if showAdvanced}} From 99f9907b1be1daaed6ffffca000b75a41e106280 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Tue, 26 May 2020 11:52:25 +0100 Subject: [PATCH 22/33] fixed spurious line --- assets/javascripts/discourse/lib/wizard-schema.js.es6 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 06fd6b50..268306d3 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -187,8 +187,7 @@ const wizardSchema = { wizard, step, field, - action, - + action } export function buildFieldTypes(types) { From afb543e0de5b91b770871930d4336bac4e55a2a4 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 28 May 2020 11:26:39 +1000 Subject: [PATCH 23/33] Migrate from namespace to import --- .../discourse/controllers/admin-wizards-logs.js.es6 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/controllers/admin-wizards-logs.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-logs.js.es6 index 26e2d622..71ced3a5 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-logs.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-logs.js.es6 @@ -3,8 +3,9 @@ import { popupAjaxError } from 'discourse/lib/ajax-error'; import { ajax } from 'discourse/lib/ajax'; import { notEmpty } from "@ember/object/computed"; import CustomWizardLogs from '../models/custom-wizard-logs'; +import Controller from "@ember/controller"; -export default Ember.Controller.extend({ +export default Controller.extend({ refreshing: false, hasLogs: notEmpty("logs"), page: 0, From 0c7d6f97fcf3ee9edb4e67a3c5f269435133528c Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 28 May 2020 13:06:06 +1000 Subject: [PATCH 24/33] Import I18n --- .../javascripts/discourse/components/wizard-custom-action.js.es6 | 1 + assets/javascripts/discourse/components/wizard-export.js.es6 | 1 + assets/javascripts/discourse/components/wizard-import.js.es6 | 1 + .../discourse/components/wizard-mapper-connector.js.es6 | 1 + .../discourse/components/wizard-mapper-selector.js.es6 | 1 + assets/javascripts/discourse/components/wizard-message.js.es6 | 1 + .../javascripts/discourse/components/wizard-text-editor.js.es6 | 1 + .../discourse/controllers/admin-wizards-api-show.js.es6 | 1 + .../discourse/controllers/admin-wizards-wizard-show.js.es6 | 1 + assets/javascripts/discourse/lib/wizard-mapper.js.es6 | 1 + .../discourse/routes/admin-wizards-wizard-show.js.es6 | 1 + 11 files changed, 11 insertions(+) diff --git a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 index 205e3580..196bf328 100644 --- a/assets/javascripts/discourse/components/wizard-custom-action.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-action.js.es6 @@ -6,6 +6,7 @@ import wizardSchema from '../lib/wizard-schema'; import UndoChanges from '../mixins/undo-changes'; import Component from "@ember/component"; import { notificationLevels } from '../lib/wizard'; +import I18n from "I18n"; export default Component.extend(UndoChanges, { componentType: 'action', diff --git a/assets/javascripts/discourse/components/wizard-export.js.es6 b/assets/javascripts/discourse/components/wizard-export.js.es6 index 2537511d..c75b745e 100644 --- a/assets/javascripts/discourse/components/wizard-export.js.es6 +++ b/assets/javascripts/discourse/components/wizard-export.js.es6 @@ -1,5 +1,6 @@ import Component from "@ember/component"; import { A } from "@ember/array"; +import I18n from "I18n"; export default Component.extend({ classNames: ['container', 'export'], diff --git a/assets/javascripts/discourse/components/wizard-import.js.es6 b/assets/javascripts/discourse/components/wizard-import.js.es6 index d844d5a6..446d2b00 100644 --- a/assets/javascripts/discourse/components/wizard-import.js.es6 +++ b/assets/javascripts/discourse/components/wizard-import.js.es6 @@ -2,6 +2,7 @@ import { ajax } from 'discourse/lib/ajax'; import { default as discourseComputed } from 'discourse-common/utils/decorators'; import { notEmpty } from "@ember/object/computed"; import Component from "@ember/component"; +import I18n from "I18n"; export default Component.extend({ classNames: ['container', 'import'], diff --git a/assets/javascripts/discourse/components/wizard-mapper-connector.js.es6 b/assets/javascripts/discourse/components/wizard-mapper-connector.js.es6 index d2903005..58203e51 100644 --- a/assets/javascripts/discourse/components/wizard-mapper-connector.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper-connector.js.es6 @@ -4,6 +4,7 @@ import { computed } from "@ember/object"; import { defaultConnector } from '../lib/wizard-mapper'; import { later } from "@ember/runloop"; import { observes } from "discourse-common/utils/decorators"; +import I18n from "I18n"; export default Component.extend({ classNameBindings: [':mapper-connector', ':mapper-block', 'hasMultiple::single'], diff --git a/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 b/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 index b92ab4de..91af570b 100644 --- a/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 @@ -6,6 +6,7 @@ import { defaultSelectionType, selectionTypes } from '../lib/wizard-mapper'; import { snakeCase, generateName, userProperties } from '../lib/wizard'; import Component from "@ember/component"; import { bind, later } from "@ember/runloop"; +import I18n from "I18n"; export default Component.extend({ classNameBindings: [':mapper-selector', 'activeType'], diff --git a/assets/javascripts/discourse/components/wizard-message.js.es6 b/assets/javascripts/discourse/components/wizard-message.js.es6 index 1f1c56ef..0592e9ca 100644 --- a/assets/javascripts/discourse/components/wizard-message.js.es6 +++ b/assets/javascripts/discourse/components/wizard-message.js.es6 @@ -1,5 +1,6 @@ import { default as discourseComputed } from 'discourse-common/utils/decorators'; import Component from "@ember/component"; +import I18n from "I18n"; export default Component.extend({ classNames: 'wizard-message', diff --git a/assets/javascripts/discourse/components/wizard-text-editor.js.es6 b/assets/javascripts/discourse/components/wizard-text-editor.js.es6 index 2b54b56c..25cf05e8 100644 --- a/assets/javascripts/discourse/components/wizard-text-editor.js.es6 +++ b/assets/javascripts/discourse/components/wizard-text-editor.js.es6 @@ -3,6 +3,7 @@ import { notEmpty } from "@ember/object/computed"; import { userProperties } from '../lib/wizard'; import { scheduleOnce } from "@ember/runloop"; import Component from "@ember/component"; +import I18n from "I18n"; export default Component.extend({ classNames: 'wizard-text-editor', diff --git a/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 index f449e19a..da6822a3 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-api-show.js.es6 @@ -5,6 +5,7 @@ import { default as discourseComputed } from 'discourse-common/utils/decorators' import { not, and, equal } from "@ember/object/computed"; import { selectKitContent } from '../lib/wizard'; import Controller from "@ember/controller"; +import I18n from "I18n"; export default Controller.extend({ queryParams: ['refresh_list'], diff --git a/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 b/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 index 5f10283e..fd01f605 100644 --- a/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 +++ b/assets/javascripts/discourse/controllers/admin-wizards-wizard-show.js.es6 @@ -9,6 +9,7 @@ import { scheduleOnce, later } from "@ember/runloop"; import Controller from "@ember/controller"; import copyText from "discourse/lib/copy-text"; import CustomWizard from '../models/custom-wizard'; +import I18n from "I18n"; export default Controller.extend({ hasName: notEmpty('wizard.name'), diff --git a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 index 1b54572c..6d179ef6 100644 --- a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 @@ -1,5 +1,6 @@ import EmberObject from "@ember/object"; import { A } from "@ember/array"; +import I18n from "I18n"; // Inputs diff --git a/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 b/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 index 5530ec33..f8dd8479 100644 --- a/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 +++ b/assets/javascripts/discourse/routes/admin-wizards-wizard-show.js.es6 @@ -1,6 +1,7 @@ import CustomWizard from '../models/custom-wizard'; import { ajax } from 'discourse/lib/ajax'; import DiscourseRoute from "discourse/routes/discourse"; +import I18n from "I18n"; export default DiscourseRoute.extend({ model(params) { From 57aa93d9db7720215e8c40c9dd5843aaef844f8e Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 28 May 2020 13:06:24 +1000 Subject: [PATCH 25/33] raw-templates have been moved --- .../javascripts/wizard/components/wizard-composer-editor.js.es6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 b/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 index f7a89464..50061883 100644 --- a/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 +++ b/assets/javascripts/wizard/components/wizard-composer-editor.js.es6 @@ -1,6 +1,6 @@ import ComposerEditor from 'discourse/components/composer-editor'; import { default as computed, on } from 'discourse-common/utils/decorators'; -import { findRawTemplate } from "discourse/lib/raw-templates"; +import { findRawTemplate } from "discourse-common/lib/raw-templates"; import { throttle } from "@ember/runloop"; import { scheduleOnce } from "@ember/runloop"; import { safariHacksDisabled } from "discourse/lib/utilities"; From 72f81c4c4cf441b31160e53b3710056abbfc7609 Mon Sep 17 00:00:00 2001 From: Robert Barrow Date: Sat, 30 May 2020 20:26:14 +0100 Subject: [PATCH 26/33] FIX: add missing api actions meta --- assets/javascripts/discourse/lib/wizard-schema.js.es6 | 5 +++++ controllers/custom_wizard/admin/wizard.rb | 3 +++ 2 files changed, 8 insertions(+) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 268306d3..1b480471 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -146,6 +146,11 @@ const action = { notification_level: null, mute_remainder: null }, + send_to_api: { + api: null, + api_endpoint: null, + api_body: null + }, add_to_group: { group: null }, diff --git a/controllers/custom_wizard/admin/wizard.rb b/controllers/custom_wizard/admin/wizard.rb index 5c3ade4e..dcf6fa00 100644 --- a/controllers/custom_wizard/admin/wizard.rb +++ b/controllers/custom_wizard/admin/wizard.rb @@ -117,6 +117,9 @@ class CustomWizard::AdminWizardController < CustomWizard::AdminController :post_builder, :post_template, :notification_level, + :api, + :api_endpoint, + :api_body, title: mapped_params, category: mapped_params, tags: mapped_params, From 454872edc83d45f61ece47a03ff3d8f0fa9e2748 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 10 Jun 2020 19:52:28 +1000 Subject: [PATCH 27/33] Add more checks for edgecases (e.g. when user_field is removed) --- lib/custom_wizard/builder.rb | 4 +++- lib/custom_wizard/mapper.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/custom_wizard/builder.rb b/lib/custom_wizard/builder.rb index c04f11b1..611ed446 100644 --- a/lib/custom_wizard/builder.rb +++ b/lib/custom_wizard/builder.rb @@ -258,7 +258,9 @@ class CustomWizard::Builder } ).perform - if content.present? + if content.present? && + content[:result].present? + if content[:type] == 'association' content[:result] = content[:result].map do |item| { diff --git a/lib/custom_wizard/mapper.rb b/lib/custom_wizard/mapper.rb index 19b40e6b..50d28815 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -188,7 +188,7 @@ class CustomWizard::Mapper def map_user_field_options(value) if value.include?(User::USER_FIELD_PREFIX) - if field = UserField.find(value.split('_').last) + if field = UserField.find_by(id: value.split('_').last) field.user_field_options.map(&:value) end end From 841923b79cb8106427aae5443b16c8bfda8ebcd5 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 22 Jun 2020 10:13:10 +1000 Subject: [PATCH 28/33] Create CW-version of site singleton --- assets/javascripts/wizard/initializers/custom.js.es6 | 2 +- assets/javascripts/wizard/models/site.js.es6 | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 assets/javascripts/wizard/models/site.js.es6 diff --git a/assets/javascripts/wizard/initializers/custom.js.es6 b/assets/javascripts/wizard/initializers/custom.js.es6 index af3d64eb..f5f7128f 100644 --- a/assets/javascripts/wizard/initializers/custom.js.es6 +++ b/assets/javascripts/wizard/initializers/custom.js.es6 @@ -23,7 +23,7 @@ export default { const Store = requirejs("discourse/models/store").default; const registerRawHelpers = requirejs("discourse-common/lib/raw-handlebars-helpers").registerRawHelpers; const RawHandlebars = requirejs("discourse-common/lib/raw-handlebars").default; - const Site = requirejs("discourse/models/site").default; + const Site = requirejs("discourse/plugins/discourse-custom-wizard/wizard/models/site").default; const RestAdapter = requirejs("discourse/adapters/rest").default; Discourse.Model = EmberObject.extend(); diff --git a/assets/javascripts/wizard/models/site.js.es6 b/assets/javascripts/wizard/models/site.js.es6 new file mode 100644 index 00000000..f3a7d1e5 --- /dev/null +++ b/assets/javascripts/wizard/models/site.js.es6 @@ -0,0 +1,10 @@ +import Site from "discourse/models/site"; + +export default Site.reopenClass({ + // There is no site data actually loaded by the CW yet. This placeholder is + // needed by imported classes + createCurrent() { + const store = Discourse.__container__.lookup("service:store"); + return store.createRecord("site", {}); + }, +}) \ No newline at end of file From 802d74bab2ebe19a106f75275342dc2e9cc6066a Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 22 Jun 2020 20:47:42 +1000 Subject: [PATCH 29/33] Add text selection and conditional input type to dropdown content options --- .../discourse/components/wizard-custom-field.js.es6 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index d7d53e00..9251f433 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -63,7 +63,8 @@ export default Component.extend(UndoChanges, { if (this.isDropdown) { options.wizardFieldSelection = 'key,value'; options.userFieldOptionsSelection = 'output'; - options.inputTypes = 'association,assignment'; + options.textSelection = 'key,value,output'; + options.inputTypes = 'conditional,association,assignment'; options.pairConnector = 'association'; options.keyPlaceholder = 'admin.wizard.key'; options.valuePlaceholder = 'admin.wizard.value'; From e0a2525cb0f790fd4463437539d95c38c1959570 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 26 Jun 2020 20:28:13 +1000 Subject: [PATCH 30/33] Explicitly import d-textarea --- assets/javascripts/wizard-custom.js | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/javascripts/wizard-custom.js b/assets/javascripts/wizard-custom.js index 70bc4c8d..895a66a9 100644 --- a/assets/javascripts/wizard-custom.js +++ b/assets/javascripts/wizard-custom.js @@ -91,6 +91,7 @@ //= require discourse/app/components/input-tip //= require discourse/app/components/date-picker //= require discourse/app/components/text-field +//= require discourse/app/components/d-textarea //= require discourse/app/templates/components/conditional-loading-spinner //= require discourse/app/templates/components/d-button From 7841ee8101eff57aefc22192d2b89bd07df27dfd Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 2 Jul 2020 09:59:14 +1000 Subject: [PATCH 31/33] Add email_level as updatable user field --- assets/javascripts/discourse/lib/wizard.js.es6 | 3 ++- lib/custom_wizard/mapper.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/lib/wizard.js.es6 b/assets/javascripts/discourse/lib/wizard.js.es6 index 4351367d..852e4fa6 100644 --- a/assets/javascripts/discourse/lib/wizard.js.es6 +++ b/assets/javascripts/discourse/lib/wizard.js.es6 @@ -46,7 +46,8 @@ const userProperties = [ 'location', 'website', 'bio_raw', - 'trust_level' + 'trust_level', + 'email_level' ]; const notificationLevels = [ diff --git a/lib/custom_wizard/mapper.rb b/lib/custom_wizard/mapper.rb index 50d28815..b1fe585d 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -1,7 +1,7 @@ class CustomWizard::Mapper attr_accessor :inputs, :data, :user - USER_FIELDS = ['name', 'username', 'email', 'date_of_birth', 'title', 'locale', 'trust_level'] + USER_FIELDS = ['name', 'username', 'email', 'date_of_birth', 'title', 'locale', 'trust_level', 'email_level'] PROFILE_FIELDS = ['location', 'website', 'bio_raw'] def self.user_fields From fb06c0def23be9e1566802ce84d82f3632a41390 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 2 Jul 2020 10:02:40 +1000 Subject: [PATCH 32/33] Handle case of custom-field-only update --- lib/custom_wizard/action.rb | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index e45dab3a..a33a244f 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -97,19 +97,20 @@ class CustomWizard::Action end def update_profile - return unless (profile_updates = action['profile_updates']).length params = {} - profile_updates.first[:pairs].each do |pair| - if allowed_profile_field?(pair['key']) - key = cast_profile_key(pair['key']) - value = cast_profile_value(mapper.map_field(pair['value'], pair['value_type']), pair['key']) - - if user_field?(pair['key']) - params[:custom_fields] ||= {} - params[:custom_fields][key] = value - else - params[key.to_sym] = value + if (profile_updates = action['profile_updates']) + profile_updates.first[:pairs].each do |pair| + if allowed_profile_field?(pair['key']) + key = cast_profile_key(pair['key']) + value = cast_profile_value(mapper.map_field(pair['value'], pair['value_type']), pair['key']) + + if user_field?(pair['key']) + params[:custom_fields] ||= {} + params[:custom_fields][key] = value + else + params[key.to_sym] = value + end end end end From 1f7f17ee3006ae4856271a72ac64dfef908c0f32 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 2 Jul 2020 15:25:17 +1000 Subject: [PATCH 33/33] Add date field --- assets/javascripts/wizard-custom.js | 1 + .../templates/components/wizard-field-date.hbs | 4 ++++ config/locales/client.en.yml | 1 + lib/custom_wizard/builder.rb | 13 +++++++++++++ lib/custom_wizard/field.rb | 1 + 5 files changed, 20 insertions(+) create mode 100644 assets/javascripts/wizard/templates/components/wizard-field-date.hbs diff --git a/assets/javascripts/wizard-custom.js b/assets/javascripts/wizard-custom.js index 895a66a9..cef27152 100644 --- a/assets/javascripts/wizard-custom.js +++ b/assets/javascripts/wizard-custom.js @@ -96,6 +96,7 @@ //= require discourse/app/templates/components/conditional-loading-spinner //= require discourse/app/templates/components/d-button //= require discourse/app/templates/components/d-editor +//= require discourse/app/templates/components/date-picker //= require discourse/app/templates/components/emoji-picker //= require discourse/app/templates/components/popup-input-tip //= require discourse/app/templates/category-tag-autocomplete diff --git a/assets/javascripts/wizard/templates/components/wizard-field-date.hbs b/assets/javascripts/wizard/templates/components/wizard-field-date.hbs new file mode 100644 index 00000000..b2ac15d8 --- /dev/null +++ b/assets/javascripts/wizard/templates/components/wizard-field-date.hbs @@ -0,0 +1,4 @@ +{{date-picker + value=field.value + id=field.id +}} \ No newline at end of file diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index b7c3d73f..5d58200f 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -163,6 +163,7 @@ en: category: Category group: Group user_selector: User Selector + date: Date connector: and: "and" diff --git a/lib/custom_wizard/builder.rb b/lib/custom_wizard/builder.rb index 611ed446..ebe24a4a 100644 --- a/lib/custom_wizard/builder.rb +++ b/lib/custom_wizard/builder.rb @@ -326,6 +326,10 @@ class CustomWizard::Builder if type === 'upload' && value.present? && !validate_file_type(value, file_types) updater.errors.add(id, I18n.t('wizard.field.invalid_file', label: label, types: file_types)) end + + if type === 'date' && value.present? && !validate_date(value) + updater.errors.add(id, I18n.t('wizard.field.invalid_date')) + end CustomWizard::Builder.field_validators.each do |validator| if type === validator[:type] @@ -339,6 +343,15 @@ class CustomWizard::Builder .map { |t| t.gsub('.', '') } .include?(File.extname(value['original_filename'])[1..-1]) end + + def validate_date(value) + begin + Date.parse(value) + true + rescue ArgumentError + false + end + end def is_text_type(field) ['text', 'textarea'].include? field['type'] diff --git a/lib/custom_wizard/field.rb b/lib/custom_wizard/field.rb index 77838cd0..dff610ce 100644 --- a/lib/custom_wizard/field.rb +++ b/lib/custom_wizard/field.rb @@ -11,6 +11,7 @@ class CustomWizard::Field min_length: nil }, text_only: {}, + date: {}, number: {}, checkbox: {}, url: {