From ade8eaaeaa4a6a51a90b8860b90d5610a26e0189 Mon Sep 17 00:00:00 2001 From: angusmcleod Date: Mon, 19 Apr 2021 17:38:35 +1000 Subject: [PATCH] WIP https://thepavilion.io/t/add-group-user-field-and-type-selector-to-if-statements/3985 --- .../components/wizard-mapper-selector.js.es6 | 15 ++++++++++++++- .../discourse/lib/wizard-mapper.js.es6 | 3 +++ .../templates/components/wizard-custom-action.hbs | 2 ++ .../components/wizard-mapper-selector.hbs | 4 ++++ assets/stylesheets/common/wizard-mapper.scss | 9 +++++++++ config/locales/client.en.yml | 5 +++++ lib/custom_wizard/mapper.rb | 15 ++++++++++++++- 7 files changed, 51 insertions(+), 2 deletions(-) diff --git a/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 b/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 index 6d65d782..bddc4bcf 100644 --- a/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 +++ b/assets/javascripts/discourse/components/wizard-mapper-selector.js.es6 @@ -17,6 +17,9 @@ export default Component.extend({ showText: computed("activeType", function () { return this.showInput("text"); }), + showLabel: computed("activeType", function() { + return this.showInput("wizardUser"); + }), showWizardField: computed("activeType", function () { return this.showInput("wizardField"); }), @@ -38,6 +41,9 @@ export default Component.extend({ showGroup: computed("activeType", function () { return this.showInput("group"); }), + showGroupUsers: computed("activeType", function () { + return this.showInput("groupUsers"); + }), showUser: computed("activeType", function () { return this.showInput("user"); }), @@ -98,9 +104,15 @@ export default Component.extend({ groupEnabled: computed("options.groupSelection", "inputType", function () { return this.optionEnabled("groupSelection"); }), + groupUsersEnabled: computed("options.groupUsersSelection", "inputType", function () { + return this.optionEnabled("groupUsersSelection"); + }), userEnabled: computed("options.userSelection", "inputType", function () { return this.optionEnabled("userSelection"); }), + wizardUserEnabled: computed("options.wizardUserSelection", "inputType", function () { + return this.optionEnabled("wizardUserSelection"); + }), listEnabled: computed("options.listSelection", "inputType", function () { return this.optionEnabled("listSelection"); }), @@ -114,7 +126,7 @@ export default Component.extend({ "showUserFieldOptions", "showCustomField" ), - showMultiSelect: or("showCategory", "showGroup"), + showMultiSelect: or("showCategory", "showGroup", "showGroupUsers"), hasTypes: gt("selectorTypes.length", 1), showTypes: false, @@ -245,6 +257,7 @@ export default Component.extend({ return { category: this.categories, group: this.groups, + groupUsers: this.groups, list: "", }[activeType]; }, diff --git a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 index 29315b9c..71c69484 100644 --- a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 @@ -41,6 +41,7 @@ const connectors = { "less_or_equal", "regex", "is", + "in" ], output: ["then", "set"], }; @@ -101,8 +102,10 @@ const selectionTypes = [ "userField", "userFieldOptions", "group", + "groupUsers", "category", "tag", + "wizardUser", "user", "customField", ]; diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs index f06e0d89..e6818504 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-action.hbs @@ -274,6 +274,8 @@ userFieldSelection="key,value,assignment" wizardActionSelection=true groupSelection="value,output" + wizardUserSelection="key" + groupUsersSelection="value" outputDefaultSelection="group" context="action" )}} diff --git a/assets/javascripts/discourse/templates/components/wizard-mapper-selector.hbs b/assets/javascripts/discourse/templates/components/wizard-mapper-selector.hbs index 94870416..10e8f015 100644 --- a/assets/javascripts/discourse/templates/components/wizard-mapper-selector.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-mapper-selector.hbs @@ -20,6 +20,10 @@
+ {{#if showLabel}} +
{{i18n placeholderKey}}
+ {{/if}} + {{#if showText}} {{input type="text" diff --git a/assets/stylesheets/common/wizard-mapper.scss b/assets/stylesheets/common/wizard-mapper.scss index 69e9c88e..415783a5 100644 --- a/assets/stylesheets/common/wizard-mapper.scss +++ b/assets/stylesheets/common/wizard-mapper.scss @@ -175,6 +175,15 @@ overflow: hidden; } } + + .input > .label { + padding: 4px 10px; + border: 1px solid var(--primary-medium); + font-size: 1em; + line-height: 1; + min-height: 30px; + box-sizing: border-box; + } } .mapper-pairs { diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 1ebe3a83..82340d5e 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -112,12 +112,14 @@ en: text: "text" wizard_field: "wizard field" wizard_action: "wizard action" + wizard_user: "current user" user_field: "user field" user_field_options: "user field options" user: "user" category: "category" tag: "tag" group: "group" + group_users: "group members" list: "list" custom_field: "custom field" @@ -126,12 +128,14 @@ en: property: "Select property" wizard_field: "Select field" wizard_action: "Select action" + wizard_user: "Current user" user_field: "Select field" user_field_options: "Select field" user: "Select user" category: "Select category" tag: "Select tag" group: "Select group" + group_users: "Select group" list: "Enter item" custom_field: "Select field" @@ -222,6 +226,7 @@ en: regex: '=~' association: '→' is: 'is' + in: 'in' action: header: "Actions" diff --git a/lib/custom_wizard/mapper.rb b/lib/custom_wizard/mapper.rb index c1187b0f..310ab57e 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -32,7 +32,8 @@ class CustomWizard::Mapper present: "present?", true: "==", false: "==" - } + }, + in: 'in' } def initialize(params) @@ -138,6 +139,8 @@ class CustomWizard::Mapper elsif ["true", "false"].include?(value) result = key.public_send(operator, ActiveRecord::Type::Boolean.new.cast(value)) end + elsif operator === 'in' + result = value.includes?(key) elsif [key, value, operator].all? { |i| !i.nil? } result = key.public_send(operator, value) else @@ -213,6 +216,16 @@ class CustomWizard::Mapper end end + def map_current_user(value) + @user.username + end + + def map_group_users(value) + if group = Group.find_by(id: value) + group.users.map(&:username) + end + end + def interpolate(string, opts = { user: true, wizard: true, value: true, template: false }) return string if string.blank?