1
0
Fork 0

Commits vergleichen

...

6 Commits

Autor SHA1 Nachricht Datum
Faizaan Gagan
001651d153 added documentation for adding an new operator to the mapper 2021-05-10 11:00:59 +05:30
Faizaan Gagan
f3c29aba3c Merge branch 'master' into mapper_documentation 2021-05-10 05:57:57 +05:30
Faizaan Gagan
401c711fad FIX: removed redundant conditional 2021-05-02 23:03:29 +05:30
Faizaan Gagan
3e950036d0 various fixes 2021-04-26 06:46:23 +05:30
Faizaan Gagan
3d4c24d362 Merge branch 'master' into mapper_documentation 2021-04-26 01:51:11 +05:30
angusmcleod
ade8eaaeaa WIP
https://thepavilion.io/t/add-group-user-field-and-type-selector-to-if-statements/3985
2021-04-19 17:38:35 +10:00
8 geänderte Dateien mit 97 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -17,6 +17,9 @@ export default Component.extend({
showText: computed("activeType", function () { showText: computed("activeType", function () {
return this.showInput("text"); return this.showInput("text");
}), }),
showLabel: computed("activeType", function() {
return this.showInput("wizardUser");
}),
showWizardField: computed("activeType", function () { showWizardField: computed("activeType", function () {
return this.showInput("wizardField"); return this.showInput("wizardField");
}), }),
@ -38,6 +41,9 @@ export default Component.extend({
showGroup: computed("activeType", function () { showGroup: computed("activeType", function () {
return this.showInput("group"); return this.showInput("group");
}), }),
showGroupUsers: computed("activeType", function () {
return this.showInput("groupUsers");
}),
showUser: computed("activeType", function () { showUser: computed("activeType", function () {
return this.showInput("user"); return this.showInput("user");
}), }),
@ -98,9 +104,15 @@ export default Component.extend({
groupEnabled: computed("options.groupSelection", "inputType", function () { groupEnabled: computed("options.groupSelection", "inputType", function () {
return this.optionEnabled("groupSelection"); return this.optionEnabled("groupSelection");
}), }),
groupUsersEnabled: computed("options.groupUsersSelection", "inputType", function () {
return this.optionEnabled("groupUsersSelection");
}),
userEnabled: computed("options.userSelection", "inputType", function () { userEnabled: computed("options.userSelection", "inputType", function () {
return this.optionEnabled("userSelection"); return this.optionEnabled("userSelection");
}), }),
wizardUserEnabled: computed("options.wizardUserSelection", "inputType", function () {
return this.optionEnabled("wizardUserSelection");
}),
listEnabled: computed("options.listSelection", "inputType", function () { listEnabled: computed("options.listSelection", "inputType", function () {
return this.optionEnabled("listSelection"); return this.optionEnabled("listSelection");
}), }),
@ -114,7 +126,7 @@ export default Component.extend({
"showUserFieldOptions", "showUserFieldOptions",
"showCustomField" "showCustomField"
), ),
showMultiSelect: or("showCategory", "showGroup"), showMultiSelect: or("showCategory", "showGroup", "showGroupUsers"),
hasTypes: gt("selectorTypes.length", 1), hasTypes: gt("selectorTypes.length", 1),
showTypes: false, showTypes: false,
@ -245,6 +257,7 @@ export default Component.extend({
return { return {
category: this.categories, category: this.categories,
group: this.groups, group: this.groups,
groupUsers: this.groups,
list: "", list: "",
}[activeType]; }[activeType];
}, },

Datei anzeigen

@ -41,6 +41,7 @@ const connectors = {
"less_or_equal", "less_or_equal",
"regex", "regex",
"is", "is",
"in"
], ],
output: ["then", "set"], output: ["then", "set"],
}; };
@ -101,8 +102,10 @@ const selectionTypes = [
"userField", "userField",
"userFieldOptions", "userFieldOptions",
"group", "group",
"groupUsers",
"category", "category",
"tag", "tag",
"wizardUser",
"user", "user",
"customField", "customField",
]; ];

Datei anzeigen

@ -161,7 +161,7 @@ const CustomWizard = EmberObject.extend({
input.pairs = []; input.pairs = [];
inpt.pairs.forEach((pr) => { inpt.pairs.forEach((pr) => {
if (present(pr.key) && present(pr.value)) { if ((present(pr.key) && present(pr.value)) || pr.key_type == "wizardUser") {
let pairParams = { let pairParams = {
index: pr.index, index: pr.index,
key: pr.key, key: pr.key,

Datei anzeigen

@ -274,6 +274,8 @@
userFieldSelection="key,value,assignment" userFieldSelection="key,value,assignment"
wizardActionSelection=true wizardActionSelection=true
groupSelection="value,output" groupSelection="value,output"
wizardUserSelection="key"
groupUsersSelection="value"
outputDefaultSelection="group" outputDefaultSelection="group"
context="action" context="action"
)}} )}}

Datei anzeigen

@ -20,6 +20,10 @@
</div> </div>
<div class="input"> <div class="input">
{{#if showLabel}}
<div class="label">{{i18n placeholderKey}}</div>
{{/if}}
{{#if showText}} {{#if showText}}
{{input {{input
type="text" type="text"

Datei anzeigen

@ -175,6 +175,15 @@
overflow: hidden; 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 { .mapper-pairs {

Datei anzeigen

@ -114,12 +114,14 @@ en:
text: "text" text: "text"
wizard_field: "wizard field" wizard_field: "wizard field"
wizard_action: "wizard action" wizard_action: "wizard action"
wizard_user: "current user"
user_field: "user field" user_field: "user field"
user_field_options: "user field options" user_field_options: "user field options"
user: "user" user: "user"
category: "category" category: "category"
tag: "tag" tag: "tag"
group: "group" group: "group"
group_users: "group members"
list: "list" list: "list"
custom_field: "custom field" custom_field: "custom field"
@ -128,12 +130,14 @@ en:
property: "Select property" property: "Select property"
wizard_field: "Select field" wizard_field: "Select field"
wizard_action: "Select action" wizard_action: "Select action"
wizard_user: "Current user"
user_field: "Select field" user_field: "Select field"
user_field_options: "Select field" user_field_options: "Select field"
user: "Select user" user: "Select user"
category: "Select category" category: "Select category"
tag: "Select tag" tag: "Select tag"
group: "Select group" group: "Select group"
group_users: "Select group"
list: "Enter item" list: "Enter item"
custom_field: "Select field" custom_field: "Select field"
@ -227,6 +231,14 @@ en:
regex: '=~' regex: '=~'
association: '→' association: '→'
is: 'is' is: 'is'
##
# unit: custom_wizard:mapper adding_an_operator
# type: step
# number: 4
# title: Adding client translation for the operator
# description: Add the translation string for the said operator
##
in: 'in'
action: action:
header: "Actions" header: "Actions"

Datei anzeigen

@ -1,4 +1,13 @@
# frozen_string_literal: true # frozen_string_literal: true
##
# unit: custom_wizard:mapper adding_an_operator
# type: introduction
# title: Adding a new operator to the mapper
# description: In this unit, we'll learn about adding a new operator to
# custom wizard's mapper
##
class CustomWizard::Mapper class CustomWizard::Mapper
attr_accessor :inputs, :data, :user attr_accessor :inputs, :data, :user
@ -32,7 +41,17 @@ class CustomWizard::Mapper
present: "present?", present: "present?",
true: "==", true: "==",
false: "==" false: "=="
} },
##
# unit: custom_wizard:mapper adding_an_operator
# type: step
# number: 1
# title: Adding the operator to the OPERATORS hash
# description: Add operator to this hash. The key will be used in code
# to refer to it and the value is generally the ruby operator
# to be used between the key and value
##
in: 'in'
} }
def initialize(params) def initialize(params)
@ -118,6 +137,16 @@ class CustomWizard::Mapper
def cast_value(value, key, connector) def cast_value(value, key, connector)
if connector == 'regex' if connector == 'regex'
Regexp.new(value) Regexp.new(value)
##
# unit: custom_wizard:mapper adding_an_operator
# type: step
# number: 3
# title: Type casting mapper value
# description: You may want to typecast mapper values, based on certain conditions. Here,
# we're typecasting the value to an array so that we can use check for value contains key
##
elsif connector == 'in'
value.to_a
else else
if key.is_a?(String) if key.is_a?(String)
value.to_s value.to_s
@ -131,13 +160,24 @@ class CustomWizard::Mapper
def validation_result(key, value, operator) def validation_result(key, value, operator)
result = nil result = nil
##
# unit: custom_wizard:mapper adding_an_operator
# type: step
# number: 2
# title: Defining operator's behaviour
# description: Define what happens when your operator is used between a key
# and value. The default behaviour is to use the operator hash value as a ruby
# operator between key and value. i.e. if operator is `equal`, then key == value or
# key.public_send('==', value).
##
if operator.is_a?(Hash) && (operator = operator[value.to_sym]).present? if operator.is_a?(Hash) && (operator = operator[value.to_sym]).present?
if value == "present" if value == "present"
result = key.public_send(operator) result = key.public_send(operator)
elsif ["true", "false"].include?(value) elsif ["true", "false"].include?(value)
result = key.public_send(operator, ActiveRecord::Type::Boolean.new.cast(value)) result = key.public_send(operator, ActiveRecord::Type::Boolean.new.cast(value))
end end
elsif operator === 'in'
result = value.include?(key)
elsif [key, value, operator].all? { |i| !i.nil? } elsif [key, value, operator].all? { |i| !i.nil? }
result = key.public_send(operator, value) result = key.public_send(operator, value)
else else
@ -213,6 +253,16 @@ class CustomWizard::Mapper
end end
end end
def map_wizard_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 }) def interpolate(string, opts = { user: true, wizard: true, value: true, template: false })
return string if string.blank? return string if string.blank?