From c45e51fcb61e30f882491374294638939428f135 Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Tue, 16 Feb 2021 11:43:00 +1100 Subject: [PATCH] Various fixes * Code formatting * Both "type" and "name" are used to refer to the validation type. Changed all to "type". * Added proper abstraction of realtime validation classes on server * UI improvements in admin and wizard --- .../components/wizard-custom-field.js.es6 | 1 + .../wizard-realtime-validations.js.es6 | 7 ++-- .../wizard-realtime-validations.hbs | 12 +++--- .../similar-topics-validator.js.es6 | 29 +++++++++++-- .../wizard/components/validator.js.es6 | 8 ++-- .../templates/components/field-validators.hbs | 8 ++-- .../components/similar-topics-validator.hbs | 22 ++++++---- assets/stylesheets/common/wizard-admin.scss | 12 ++++-- assets/stylesheets/wizard/custom/field.scss | 14 +------ .../stylesheets/wizard/custom/validators.scss | 30 +++++++++++++ assets/stylesheets/wizard/wizard_custom.scss | 1 + config/locales/client.en.yml | 8 +++- .../custom_wizard/realtime_validations.rb | 17 +++++--- lib/custom_wizard/realtime_validation.rb | 37 ++++------------ .../realtime_validations/result.rb | 11 +++++ .../realtime_validations/similar_topics.rb | 42 +++++++++++++++++++ plugin.rb | 3 ++ .../similar_topics_serializer.rb | 2 + .../custom_wizard/wizard_field_serializer.rb | 4 +- 19 files changed, 186 insertions(+), 82 deletions(-) create mode 100644 assets/stylesheets/wizard/custom/validators.scss create mode 100644 lib/custom_wizard/realtime_validations/result.rb create mode 100644 lib/custom_wizard/realtime_validations/similar_topics.rb create mode 100644 serializers/custom_wizard/realtime_validation/similar_topics_serializer.rb diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index cc9d56eb..9f9470ac 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -30,6 +30,7 @@ export default Component.extend(UndoChanges, { @discourseComputed('field.type') validations(type) { const applicableToField = []; + for(let validation in wizardSchema.field.validations) { if ((wizardSchema.field.validations[validation]["types"]).includes(type)) { applicableToField.push(validation) diff --git a/assets/javascripts/discourse/components/wizard-realtime-validations.js.es6 b/assets/javascripts/discourse/components/wizard-realtime-validations.js.es6 index 6e7daa9e..5bafaac3 100644 --- a/assets/javascripts/discourse/components/wizard-realtime-validations.js.es6 +++ b/assets/javascripts/discourse/components/wizard-realtime-validations.js.es6 @@ -12,6 +12,7 @@ export default Component.extend({ if (!this.field.validations) { const validations = {}; + this.validations.forEach((validation) => { validations[validation] = {}; }); @@ -32,10 +33,10 @@ export default Component.extend({ }, actions: { - updateValidationCategories(name, validation, categories) { - this.set(`validationBuffer.${name}.categories`, categories); + updateValidationCategories(type, validation, categories) { + this.set(`validationBuffer.${type}.categories`, categories); this.set( - `field.validations.${name}.categories`, + `field.validations.${type}.categories`, categories.map((category) => category.id) ); }, diff --git a/assets/javascripts/discourse/templates/components/wizard-realtime-validations.hbs b/assets/javascripts/discourse/templates/components/wizard-realtime-validations.hbs index 8a381c9f..fe053bc3 100644 --- a/assets/javascripts/discourse/templates/components/wizard-realtime-validations.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-realtime-validations.hbs @@ -1,10 +1,10 @@

{{i18n 'admin.wizard.field.validations.header'}}