@beinformed/ui 1.23.0 → 1.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/esm/models/attributes/layouthint-rules/DependentAttribute.js +29 -29
- package/esm/models/attributes/layouthint-rules/DependentAttribute.js.map +1 -1
- package/lib/models/attributes/layouthint-rules/DependentAttribute.js +32 -32
- package/lib/models/attributes/layouthint-rules/DependentAttribute.js.flow +16 -20
- package/lib/models/attributes/layouthint-rules/DependentAttribute.js.map +1 -1
- package/package.json +1 -1
- package/src/models/attributes/layouthint-rules/DependentAttribute.js +16 -20
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.23.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.23.0...v1.23.1) (2022-09-26)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **DependentAttribute:** DependentAttribute extended to work with empty and not empty attribute value ([9cf3864](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/9cf38644e032b0cfea0e8a8561baa2ca7aa9eb49))
|
|
11
|
+
|
|
5
12
|
## [1.23.0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.22.1...v1.23.0) (2022-09-22)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
2
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
3
2
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
4
3
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
5
4
|
import _trimInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/trim";
|
|
5
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
6
6
|
import BaseLayoutHintRule from "./BaseLayoutHintRule";
|
|
7
7
|
import { DEPENDENT_ATTRIBUTE_CONTROL, DEPENDENT_ATTRIBUTE } from "../../../constants";
|
|
8
8
|
import ChoiceAttributeModel from "../ChoiceAttributeModel";
|
|
@@ -16,25 +16,10 @@ const NOT_IS_EMPTY = "notIsEmpty";
|
|
|
16
16
|
const IS_EMPTY = "isEmpty";
|
|
17
17
|
const SHOW = "show";
|
|
18
18
|
const HIDE = "hide";
|
|
19
|
-
/**
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
const compareSelectedAttribute = (option, selectedAttribute) => {
|
|
23
|
-
if (option === NOT_IS_EMPTY && (selectedAttribute === null || selectedAttribute === void 0 ? void 0 : selectedAttribute.length) !== 0) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (option === IS_EMPTY && (selectedAttribute === null || selectedAttribute === void 0 ? void 0 : selectedAttribute.length) === 0) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return selectedAttribute === null || selectedAttribute === void 0 ? void 0 : _includesInstanceProperty(selectedAttribute).call(selectedAttribute, option);
|
|
32
|
-
};
|
|
33
19
|
/**
|
|
34
20
|
* Depending attributes hint logic
|
|
35
21
|
*/
|
|
36
22
|
|
|
37
|
-
|
|
38
23
|
class DependentAttribute extends BaseLayoutHintRule {
|
|
39
24
|
constructor() {
|
|
40
25
|
super(...arguments);
|
|
@@ -69,20 +54,21 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
69
54
|
|
|
70
55
|
|
|
71
56
|
static initHint(hint) {
|
|
72
|
-
var _context3, _context4, _context5, _context6;
|
|
57
|
+
var _context3, _context4, _context5, _context6, _context7, _context8, _context9, _context10;
|
|
73
58
|
|
|
74
59
|
const rule = this.getRuleInstance();
|
|
75
60
|
|
|
76
|
-
const OPERATORS = _concatInstanceProperty(_context3 = _concatInstanceProperty(_context4 = "".concat(EQUALS, "|").concat(INCLUDES, "|")).call(
|
|
61
|
+
const OPERATORS = _concatInstanceProperty(_context3 = _concatInstanceProperty(_context4 = _concatInstanceProperty(_context5 = _concatInstanceProperty(_context6 = "".concat(EQUALS, "|").concat(INCLUDES, "|")).call(_context6, NOT_EQUALS, "|")).call(_context5, NOT_INCLUDES, "|")).call(_context4, NOT_IS_EMPTY, "|")).call(_context3, IS_EMPTY);
|
|
77
62
|
|
|
78
|
-
const regex = new RegExp(_concatInstanceProperty(
|
|
79
|
-
const
|
|
63
|
+
const regex = new RegExp(_concatInstanceProperty(_context7 = _concatInstanceProperty(_context8 = "".concat(DEPENDENT_ATTRIBUTE, "\\s?(\\S*)\\swhen ")).call(_context8, DEPENDENT_ATTRIBUTE_CONTROL, ":\\s?(.*?)\\s*(")).call(_context7, OPERATORS, ")\\s(.*)"), "i");
|
|
64
|
+
const isEmpyNotIsEmptRegex = new RegExp(_concatInstanceProperty(_context9 = _concatInstanceProperty(_context10 = "".concat(DEPENDENT_ATTRIBUTE, "\\s?(\\S*)\\swhen ")).call(_context10, DEPENDENT_ATTRIBUTE_CONTROL, ":\\s?(.*?)\\s*(")).call(_context9, OPERATORS, ")"), "i");
|
|
65
|
+
const result = hint.match(regex) ? hint.match(regex) : hint.match(isEmpyNotIsEmptRegex);
|
|
80
66
|
|
|
81
67
|
if (result) {
|
|
82
68
|
rule.action = result[1];
|
|
83
69
|
rule.control = result[2];
|
|
84
70
|
rule.operator = result[3];
|
|
85
|
-
rule.options = result[4];
|
|
71
|
+
rule.options = !result[4] ? "" : result[4];
|
|
86
72
|
} else {
|
|
87
73
|
throw new ConfigurationException("No dependent information found on layout hint: ".concat(hint));
|
|
88
74
|
}
|
|
@@ -143,9 +129,9 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
143
129
|
|
|
144
130
|
|
|
145
131
|
set options(options) {
|
|
146
|
-
var
|
|
132
|
+
var _context11;
|
|
147
133
|
|
|
148
|
-
this._options = _mapInstanceProperty(
|
|
134
|
+
this._options = _mapInstanceProperty(_context11 = options.split("|")).call(_context11, option => _trimInstanceProperty(option).call(option));
|
|
149
135
|
}
|
|
150
136
|
/**
|
|
151
137
|
*/
|
|
@@ -153,7 +139,11 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
153
139
|
|
|
154
140
|
processEqualsOptions(controlAttribute) {
|
|
155
141
|
if (controlAttribute instanceof ChoiceAttributeModel || controlAttribute instanceof BooleanAttributeModel) {
|
|
156
|
-
return this.options.every(option =>
|
|
142
|
+
return this.options.every(option => {
|
|
143
|
+
var _context12;
|
|
144
|
+
|
|
145
|
+
return _includesInstanceProperty(_context12 = controlAttribute.selected).call(_context12, option);
|
|
146
|
+
});
|
|
157
147
|
}
|
|
158
148
|
|
|
159
149
|
throw new ConfigurationException("Dependent control in combination with equals operator must be a choice, string or number attribute");
|
|
@@ -164,7 +154,11 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
164
154
|
|
|
165
155
|
processIncludesOptions(controlAttribute) {
|
|
166
156
|
if (controlAttribute instanceof ChoiceAttributeModel) {
|
|
167
|
-
return this.options.some(option =>
|
|
157
|
+
return this.options.some(option => {
|
|
158
|
+
var _context13;
|
|
159
|
+
|
|
160
|
+
return _includesInstanceProperty(_context13 = controlAttribute.selected).call(_context13, option);
|
|
161
|
+
});
|
|
168
162
|
}
|
|
169
163
|
|
|
170
164
|
throw new ConfigurationException("Dependent control in combination with includes operator must be a choice attribute");
|
|
@@ -187,6 +181,12 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
187
181
|
case NOT_INCLUDES:
|
|
188
182
|
return !this.processIncludesOptions(controlAttribute);
|
|
189
183
|
|
|
184
|
+
case NOT_IS_EMPTY:
|
|
185
|
+
return (controlAttribute === null || controlAttribute === void 0 ? void 0 : controlAttribute.selected.length) !== 0;
|
|
186
|
+
|
|
187
|
+
case IS_EMPTY:
|
|
188
|
+
return (controlAttribute === null || controlAttribute === void 0 ? void 0 : controlAttribute.selected.length) === 0;
|
|
189
|
+
|
|
190
190
|
default:
|
|
191
191
|
throw new ConfigurationException("Unsupported operator for dependent question: ".concat(this.operator));
|
|
192
192
|
}
|
|
@@ -196,9 +196,9 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
196
196
|
|
|
197
197
|
|
|
198
198
|
getControlAttribute(attributes) {
|
|
199
|
-
var
|
|
199
|
+
var _context14, _context15;
|
|
200
200
|
|
|
201
|
-
const attribute = attributes.getAttributeByLayoutHint(_concatInstanceProperty(
|
|
201
|
+
const attribute = attributes.getAttributeByLayoutHint(_concatInstanceProperty(_context14 = "".concat(DEPENDENT_ATTRIBUTE_CONTROL, ":")).call(_context14, this.control), _concatInstanceProperty(_context15 = "".concat(DEPENDENT_ATTRIBUTE_CONTROL, ": ")).call(_context15, this.control));
|
|
202
202
|
|
|
203
203
|
if (attribute instanceof ChoiceAttributeModel || attribute instanceof BooleanAttributeModel) {
|
|
204
204
|
return attribute;
|
|
@@ -231,9 +231,9 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
231
231
|
} else if (this.action === HIDE) {
|
|
232
232
|
attribute.isHidden = result;
|
|
233
233
|
} else {
|
|
234
|
-
var
|
|
234
|
+
var _context16;
|
|
235
235
|
|
|
236
|
-
throw new ConfigurationException(_concatInstanceProperty(
|
|
236
|
+
throw new ConfigurationException(_concatInstanceProperty(_context16 = "Unsupported action ".concat(this.action, " for dependent question on attribute: ")).call(_context16, attribute.label));
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependentAttribute.js","names":["BaseLayoutHintRule","DEPENDENT_ATTRIBUTE_CONTROL","DEPENDENT_ATTRIBUTE","ChoiceAttributeModel","BooleanAttributeModel","ConfigurationException","EQUALS","INCLUDES","NOT_EQUALS","NOT_INCLUDES","NOT_IS_EMPTY","IS_EMPTY","SHOW","HIDE","compareSelectedAttribute","option","selectedAttribute","length","DependentAttribute","isApplicableForHint","hint","regex","RegExp","test","getRuleInstance","initHint","rule","OPERATORS","result","match","action","control","operator","options","_action","_control","_operator","_options","split","processEqualsOptions","controlAttribute","every","selected","processIncludesOptions","some","handleOperator","getControlAttribute","attributes","attribute","getAttributeByLayoutHint","process","processLayoutHintRules","isHidden","hide","label"],"sources":["../../../../src/models/attributes/layouthint-rules/DependentAttribute.js"],"sourcesContent":["// @flow\nimport BaseLayoutHintRule from \"./BaseLayoutHintRule\";\n\nimport {\n DEPENDENT_ATTRIBUTE_CONTROL,\n DEPENDENT_ATTRIBUTE,\n} from \"../../../constants\";\n\nimport ChoiceAttributeModel from \"../ChoiceAttributeModel\";\nimport BooleanAttributeModel from \"../BooleanAttributeModel\";\n\nimport { ConfigurationException } from \"../../../exceptions\";\n\nimport type AttributeCollection from \"../AttributeCollection\";\nimport type AttributeModel from \"../AttributeModel\";\n\nconst EQUALS = \"equals\";\nconst INCLUDES = \"includes\";\nconst NOT_EQUALS = \"notEquals\";\nconst NOT_INCLUDES = \"notIncludes\";\nconst NOT_IS_EMPTY = \"notIsEmpty\";\nconst IS_EMPTY = \"isEmpty\";\n\nconst SHOW = \"show\";\nconst HIDE = \"hide\";\n\n/**\n */\nconst compareSelectedAttribute = (\n option: string,\n selectedAttribute: Array<string>\n) => {\n if (option === NOT_IS_EMPTY && selectedAttribute?.length !== 0) {\n return true;\n }\n if (option === IS_EMPTY && selectedAttribute?.length === 0) {\n return true;\n }\n return selectedAttribute?.includes(option);\n};\n\n/**\n * Depending attributes hint logic\n */\nclass DependentAttribute extends BaseLayoutHintRule {\n _action: string;\n _control: string;\n _operator: string;\n _options: Array<string>;\n\n /**\n */\n static checkHintApplicability: boolean = true;\n\n /**\n */\n static isApplicableForHint(hint: string): boolean {\n const regex = new RegExp(\n `^${DEPENDENT_ATTRIBUTE}\\\\s?(${SHOW}|${HIDE})`,\n \"i\"\n );\n\n return regex.test(hint);\n }\n\n /**\n * Used on initHint to create an instance of this rule\n */\n static getRuleInstance(): DependentAttribute {\n return new DependentAttribute();\n }\n\n /**\n */\n static initHint(hint: string): any {\n const rule = this.getRuleInstance();\n\n const OPERATORS = `${EQUALS}|${INCLUDES}|${NOT_EQUALS}|${NOT_INCLUDES}`;\n const regex = new RegExp(\n `${DEPENDENT_ATTRIBUTE}\\\\s?(\\\\S*)\\\\swhen ${DEPENDENT_ATTRIBUTE_CONTROL}:\\\\s?(.*?)\\\\s*(${OPERATORS})\\\\s(.*)`,\n \"i\"\n );\n\n const result = hint.match(regex);\n if (result) {\n rule.action = result[1];\n rule.control = result[2];\n rule.operator = result[3];\n rule.options = result[4];\n } else {\n throw new ConfigurationException(\n `No dependent information found on layout hint: ${hint}`\n );\n }\n\n return rule;\n }\n\n /**\n */\n get action(): string {\n return this._action;\n }\n\n /**\n */\n set action(action: string) {\n this._action = action;\n }\n\n /**\n */\n get control(): string {\n return this._control;\n }\n\n /**\n */\n set control(control: string) {\n this._control = control;\n }\n\n /**\n */\n get operator(): string {\n return this._operator;\n }\n\n /**\n */\n set operator(operator: string) {\n this._operator = operator;\n }\n\n /**\n */\n get options(): Array<string> {\n return this._options;\n }\n\n /**\n */\n set options(options: string): void {\n this._options = options.split(\"|\").map((option) => option.trim());\n }\n\n /**\n */\n processEqualsOptions(\n controlAttribute: ChoiceAttributeModel | BooleanAttributeModel\n ): boolean {\n if (\n controlAttribute instanceof ChoiceAttributeModel ||\n controlAttribute instanceof BooleanAttributeModel\n ) {\n return this.options.every((option) =>\n compareSelectedAttribute(option, controlAttribute?.selected)\n );\n }\n\n throw new ConfigurationException(\n \"Dependent control in combination with equals operator must be a choice, string or number attribute\"\n );\n }\n\n /**\n */\n processIncludesOptions(\n controlAttribute: ChoiceAttributeModel | BooleanAttributeModel\n ): boolean {\n if (controlAttribute instanceof ChoiceAttributeModel) {\n return this.options.some((option) =>\n compareSelectedAttribute(option, controlAttribute?.selected)\n );\n }\n\n throw new ConfigurationException(\n \"Dependent control in combination with includes operator must be a choice attribute\"\n );\n }\n\n /**\n */\n handleOperator(\n controlAttribute: ChoiceAttributeModel | BooleanAttributeModel\n ): boolean {\n switch (this.operator) {\n case EQUALS:\n return this.processEqualsOptions(controlAttribute);\n case INCLUDES:\n return this.processIncludesOptions(controlAttribute);\n case NOT_EQUALS:\n return !this.processEqualsOptions(controlAttribute);\n case NOT_INCLUDES:\n return !this.processIncludesOptions(controlAttribute);\n default:\n throw new ConfigurationException(\n `Unsupported operator for dependent question: ${this.operator}`\n );\n }\n }\n\n /**\n */\n getControlAttribute(\n attributes: AttributeCollection\n ): ChoiceAttributeModel | BooleanAttributeModel | null {\n const attribute = attributes.getAttributeByLayoutHint(\n `${DEPENDENT_ATTRIBUTE_CONTROL}:${this.control}`,\n `${DEPENDENT_ATTRIBUTE_CONTROL}: ${this.control}`\n );\n\n if (\n attribute instanceof ChoiceAttributeModel ||\n attribute instanceof BooleanAttributeModel\n ) {\n return attribute;\n }\n\n return null;\n }\n\n /**\n */\n process(attribute: AttributeModel, attributes: AttributeCollection) {\n const controlAttribute = this.getControlAttribute(attributes);\n if (!controlAttribute) {\n return;\n }\n\n controlAttribute.processLayoutHintRules(attributes);\n if (controlAttribute.isHidden) {\n attribute.hide();\n return;\n }\n\n const result = this.handleOperator(controlAttribute);\n if (this.action === SHOW) {\n attribute.isHidden = !result;\n } else if (this.action === HIDE) {\n attribute.isHidden = result;\n } else {\n throw new ConfigurationException(\n `Unsupported action ${this.action} for dependent question on attribute: ${attribute.label}`\n );\n }\n }\n}\n\nexport default DependentAttribute;\n"],"mappings":";;;;;AACA,OAAOA,kBAAP,MAA+B,sBAA/B;AAEA,SACEC,2BADF,EAEEC,mBAFF,QAGO,oBAHP;AAKA,OAAOC,oBAAP,MAAiC,yBAAjC;AACA,OAAOC,qBAAP,MAAkC,0BAAlC;AAEA,SAASC,sBAAT,QAAuC,qBAAvC;AAKA,MA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EAcD;EAED;AACF;;;EACEc,mBAAmB,CACjBC,UADiB,EAEoC;IAAA;;IACrD,MAAMC,SAAS,GAAGD,UAAU,CAACE,wBAAX,+CACbhD,2BADa,wBACkB,KAAK8B,OADvB,iDAEb9B,2BAFa,yBAEmB,KAAK8B,OAFxB,EAAlB;;IAKA,IACEiB,SAAS,YAAY7C,oBAArB,IACA6C,SAAS,YAAY5C,qBAFvB,EAGE;MACA,OAAO4C,SAAP;IACD;;IAED,OAAO,IAAP;EACD;EAED;AACF;;;EACEE,OAAO,CAACF,SAAD,EAA4BD,UAA5B,EAA6D;IAClE,MAAMP,gBAAgB,GAAG,KAAKM,mBAAL,CAAyBC,UAAzB,CAAzB;;IACA,IAAI,CAACP,gBAAL,EAAuB;MACrB;IACD;;IAEDA,gBAAgB,CAACW,sBAAjB,CAAwCJ,UAAxC;;IACA,IAAIP,gBAAgB,CAACY,QAArB,EAA+B;MAC7BJ,SAAS,CAACK,IAAV;MACA;IACD;;IAED,MAAMzB,MAAM,GAAG,KAAKiB,cAAL,CAAoBL,gBAApB,CAAf;;IACA,IAAI,KAAKV,MAAL,KAAgBlB,IAApB,EAA0B;MACxBoC,SAAS,CAACI,QAAV,GAAqB,CAACxB,MAAtB;IACD,CAFD,MAEO,IAAI,KAAKE,MAAL,KAAgBjB,IAApB,EAA0B;MAC/BmC,SAAS,CAACI,QAAV,GAAqBxB,MAArB;IACD,CAFM,MAEA;MAAA;;MACL,MAAM,IAAIvB,sBAAJ,mEACkB,KAAKyB,MADvB,8DACsEkB,SAAS,CAACM,KADhF,EAAN;IAGD;EACF;;AA1MiD;;gBAA9CpC,kB,4BAQqC,I;;AAqM3C,eAAeA,kBAAf"}
|
|
1
|
+
{"version":3,"file":"DependentAttribute.js","names":["BaseLayoutHintRule","DEPENDENT_ATTRIBUTE_CONTROL","DEPENDENT_ATTRIBUTE","ChoiceAttributeModel","BooleanAttributeModel","ConfigurationException","EQUALS","INCLUDES","NOT_EQUALS","NOT_INCLUDES","NOT_IS_EMPTY","IS_EMPTY","SHOW","HIDE","DependentAttribute","isApplicableForHint","hint","regex","RegExp","test","getRuleInstance","initHint","rule","OPERATORS","isEmpyNotIsEmptRegex","result","match","action","control","operator","options","_action","_control","_operator","_options","split","option","processEqualsOptions","controlAttribute","every","selected","processIncludesOptions","some","handleOperator","length","getControlAttribute","attributes","attribute","getAttributeByLayoutHint","process","processLayoutHintRules","isHidden","hide","label"],"sources":["../../../../src/models/attributes/layouthint-rules/DependentAttribute.js"],"sourcesContent":["// @flow\nimport BaseLayoutHintRule from \"./BaseLayoutHintRule\";\n\nimport {\n DEPENDENT_ATTRIBUTE_CONTROL,\n DEPENDENT_ATTRIBUTE,\n} from \"../../../constants\";\n\nimport ChoiceAttributeModel from \"../ChoiceAttributeModel\";\nimport BooleanAttributeModel from \"../BooleanAttributeModel\";\n\nimport { ConfigurationException } from \"../../../exceptions\";\n\nimport type AttributeCollection from \"../AttributeCollection\";\nimport type AttributeModel from \"../AttributeModel\";\n\nconst EQUALS = \"equals\";\nconst INCLUDES = \"includes\";\nconst NOT_EQUALS = \"notEquals\";\nconst NOT_INCLUDES = \"notIncludes\";\nconst NOT_IS_EMPTY = \"notIsEmpty\";\nconst IS_EMPTY = \"isEmpty\";\n\nconst SHOW = \"show\";\nconst HIDE = \"hide\";\n\n/**\n * Depending attributes hint logic\n */\nclass DependentAttribute extends BaseLayoutHintRule {\n _action: string;\n _control: string;\n _operator: string;\n _options: Array<string>;\n\n /**\n */\n static checkHintApplicability: boolean = true;\n\n /**\n */\n static isApplicableForHint(hint: string): boolean {\n const regex = new RegExp(\n `^${DEPENDENT_ATTRIBUTE}\\\\s?(${SHOW}|${HIDE})`,\n \"i\"\n );\n\n return regex.test(hint);\n }\n\n /**\n * Used on initHint to create an instance of this rule\n */\n static getRuleInstance(): DependentAttribute {\n return new DependentAttribute();\n }\n\n /**\n */\n static initHint(hint: string): any {\n const rule = this.getRuleInstance();\n\n const OPERATORS = `${EQUALS}|${INCLUDES}|${NOT_EQUALS}|${NOT_INCLUDES}|${NOT_IS_EMPTY}|${IS_EMPTY}`;\n const regex = new RegExp(\n `${DEPENDENT_ATTRIBUTE}\\\\s?(\\\\S*)\\\\swhen ${DEPENDENT_ATTRIBUTE_CONTROL}:\\\\s?(.*?)\\\\s*(${OPERATORS})\\\\s(.*)`,\n \"i\"\n );\n const isEmpyNotIsEmptRegex = new RegExp(\n `${DEPENDENT_ATTRIBUTE}\\\\s?(\\\\S*)\\\\swhen ${DEPENDENT_ATTRIBUTE_CONTROL}:\\\\s?(.*?)\\\\s*(${OPERATORS})`,\n \"i\"\n );\n\n const result = hint.match(regex)\n ? hint.match(regex)\n : hint.match(isEmpyNotIsEmptRegex);\n\n if (result) {\n rule.action = result[1];\n rule.control = result[2];\n rule.operator = result[3];\n rule.options = !result[4] ? \"\" : result[4];\n } else {\n throw new ConfigurationException(\n `No dependent information found on layout hint: ${hint}`\n );\n }\n\n return rule;\n }\n\n /**\n */\n get action(): string {\n return this._action;\n }\n\n /**\n */\n set action(action: string) {\n this._action = action;\n }\n\n /**\n */\n get control(): string {\n return this._control;\n }\n\n /**\n */\n set control(control: string) {\n this._control = control;\n }\n\n /**\n */\n get operator(): string {\n return this._operator;\n }\n\n /**\n */\n set operator(operator: string) {\n this._operator = operator;\n }\n\n /**\n */\n get options(): Array<string> {\n return this._options;\n }\n\n /**\n */\n set options(options: string): void {\n this._options = options.split(\"|\").map((option) => option.trim());\n }\n\n /**\n */\n processEqualsOptions(\n controlAttribute: ChoiceAttributeModel | BooleanAttributeModel\n ): boolean {\n if (\n controlAttribute instanceof ChoiceAttributeModel ||\n controlAttribute instanceof BooleanAttributeModel\n ) {\n return this.options.every((option) =>\n controlAttribute.selected.includes(option)\n );\n }\n\n throw new ConfigurationException(\n \"Dependent control in combination with equals operator must be a choice, string or number attribute\"\n );\n }\n\n /**\n */\n processIncludesOptions(\n controlAttribute: ChoiceAttributeModel | BooleanAttributeModel\n ): boolean {\n if (controlAttribute instanceof ChoiceAttributeModel) {\n return this.options.some((option) =>\n controlAttribute.selected.includes(option)\n );\n }\n\n throw new ConfigurationException(\n \"Dependent control in combination with includes operator must be a choice attribute\"\n );\n }\n\n /**\n */\n handleOperator(\n controlAttribute: ChoiceAttributeModel | BooleanAttributeModel\n ): boolean {\n switch (this.operator) {\n case EQUALS:\n return this.processEqualsOptions(controlAttribute);\n case INCLUDES:\n return this.processIncludesOptions(controlAttribute);\n case NOT_EQUALS:\n return !this.processEqualsOptions(controlAttribute);\n case NOT_INCLUDES:\n return !this.processIncludesOptions(controlAttribute);\n case NOT_IS_EMPTY:\n return controlAttribute?.selected.length !== 0;\n case IS_EMPTY:\n return controlAttribute?.selected.length === 0;\n default:\n throw new ConfigurationException(\n `Unsupported operator for dependent question: ${this.operator}`\n );\n }\n }\n\n /**\n */\n getControlAttribute(\n attributes: AttributeCollection\n ): ChoiceAttributeModel | BooleanAttributeModel | null {\n const attribute = attributes.getAttributeByLayoutHint(\n `${DEPENDENT_ATTRIBUTE_CONTROL}:${this.control}`,\n `${DEPENDENT_ATTRIBUTE_CONTROL}: ${this.control}`\n );\n\n if (\n attribute instanceof ChoiceAttributeModel ||\n attribute instanceof BooleanAttributeModel\n ) {\n return attribute;\n }\n\n return null;\n }\n\n /**\n */\n process(attribute: AttributeModel, attributes: AttributeCollection) {\n const controlAttribute = this.getControlAttribute(attributes);\n if (!controlAttribute) {\n return;\n }\n\n controlAttribute.processLayoutHintRules(attributes);\n if (controlAttribute.isHidden) {\n attribute.hide();\n return;\n }\n\n const result = this.handleOperator(controlAttribute);\n if (this.action === SHOW) {\n attribute.isHidden = !result;\n } else if (this.action === HIDE) {\n attribute.isHidden = result;\n } else {\n throw new ConfigurationException(\n `Unsupported action ${this.action} for dependent question on attribute: ${attribute.label}`\n );\n }\n }\n}\n\nexport default DependentAttribute;\n"],"mappings":";;;;;AACA,OAAOA,kBAAP,MAA+B,sBAA/B;AAEA,SACEC,2BADF,EAEEC,mBAFF,QAGO,oBAHP;AAKA,OAAOC,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|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
13
|
-
|
|
14
10
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
15
11
|
|
|
16
12
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
17
13
|
|
|
18
14
|
var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
|
|
19
15
|
|
|
16
|
+
var _includes = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/includes"));
|
|
17
|
+
|
|
18
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
19
|
+
|
|
20
20
|
var _BaseLayoutHintRule = _interopRequireDefault(require("./BaseLayoutHintRule"));
|
|
21
21
|
|
|
22
22
|
var _constants = require("../../../constants");
|
|
@@ -35,25 +35,10 @@ const NOT_IS_EMPTY = "notIsEmpty";
|
|
|
35
35
|
const IS_EMPTY = "isEmpty";
|
|
36
36
|
const SHOW = "show";
|
|
37
37
|
const HIDE = "hide";
|
|
38
|
-
/**
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
const compareSelectedAttribute = (option, selectedAttribute) => {
|
|
42
|
-
if (option === NOT_IS_EMPTY && (selectedAttribute === null || selectedAttribute === void 0 ? void 0 : selectedAttribute.length) !== 0) {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (option === IS_EMPTY && (selectedAttribute === null || selectedAttribute === void 0 ? void 0 : selectedAttribute.length) === 0) {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return selectedAttribute === null || selectedAttribute === void 0 ? void 0 : (0, _includes.default)(selectedAttribute).call(selectedAttribute, option);
|
|
51
|
-
};
|
|
52
38
|
/**
|
|
53
39
|
* Depending attributes hint logic
|
|
54
40
|
*/
|
|
55
41
|
|
|
56
|
-
|
|
57
42
|
class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
58
43
|
constructor() {
|
|
59
44
|
super(...arguments);
|
|
@@ -84,18 +69,19 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
84
69
|
|
|
85
70
|
|
|
86
71
|
static initHint(hint) {
|
|
87
|
-
var _context3, _context4, _context5, _context6;
|
|
72
|
+
var _context3, _context4, _context5, _context6, _context7, _context8, _context9, _context10;
|
|
88
73
|
|
|
89
74
|
const rule = this.getRuleInstance();
|
|
90
|
-
const OPERATORS = (0, _concat.default)(_context3 = (0, _concat.default)(_context4 = "".concat(EQUALS, "|").concat(INCLUDES, "|")).call(
|
|
91
|
-
const regex = new RegExp((0, _concat.default)(
|
|
92
|
-
const
|
|
75
|
+
const OPERATORS = (0, _concat.default)(_context3 = (0, _concat.default)(_context4 = (0, _concat.default)(_context5 = (0, _concat.default)(_context6 = "".concat(EQUALS, "|").concat(INCLUDES, "|")).call(_context6, NOT_EQUALS, "|")).call(_context5, NOT_INCLUDES, "|")).call(_context4, NOT_IS_EMPTY, "|")).call(_context3, IS_EMPTY);
|
|
76
|
+
const regex = new RegExp((0, _concat.default)(_context7 = (0, _concat.default)(_context8 = "".concat(_constants.DEPENDENT_ATTRIBUTE, "\\s?(\\S*)\\swhen ")).call(_context8, _constants.DEPENDENT_ATTRIBUTE_CONTROL, ":\\s?(.*?)\\s*(")).call(_context7, OPERATORS, ")\\s(.*)"), "i");
|
|
77
|
+
const isEmpyNotIsEmptRegex = new RegExp((0, _concat.default)(_context9 = (0, _concat.default)(_context10 = "".concat(_constants.DEPENDENT_ATTRIBUTE, "\\s?(\\S*)\\swhen ")).call(_context10, _constants.DEPENDENT_ATTRIBUTE_CONTROL, ":\\s?(.*?)\\s*(")).call(_context9, OPERATORS, ")"), "i");
|
|
78
|
+
const result = hint.match(regex) ? hint.match(regex) : hint.match(isEmpyNotIsEmptRegex);
|
|
93
79
|
|
|
94
80
|
if (result) {
|
|
95
81
|
rule.action = result[1];
|
|
96
82
|
rule.control = result[2];
|
|
97
83
|
rule.operator = result[3];
|
|
98
|
-
rule.options = result[4];
|
|
84
|
+
rule.options = !result[4] ? "" : result[4];
|
|
99
85
|
} else {
|
|
100
86
|
throw new _exceptions.ConfigurationException("No dependent information found on layout hint: ".concat(hint));
|
|
101
87
|
}
|
|
@@ -156,9 +142,9 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
156
142
|
|
|
157
143
|
|
|
158
144
|
set options(options) {
|
|
159
|
-
var
|
|
145
|
+
var _context11;
|
|
160
146
|
|
|
161
|
-
this._options = (0, _map.default)(
|
|
147
|
+
this._options = (0, _map.default)(_context11 = options.split("|")).call(_context11, option => (0, _trim.default)(option).call(option));
|
|
162
148
|
}
|
|
163
149
|
/**
|
|
164
150
|
*/
|
|
@@ -166,7 +152,11 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
166
152
|
|
|
167
153
|
processEqualsOptions(controlAttribute) {
|
|
168
154
|
if (controlAttribute instanceof _ChoiceAttributeModel.default || controlAttribute instanceof _BooleanAttributeModel.default) {
|
|
169
|
-
return this.options.every(option =>
|
|
155
|
+
return this.options.every(option => {
|
|
156
|
+
var _context12;
|
|
157
|
+
|
|
158
|
+
return (0, _includes.default)(_context12 = controlAttribute.selected).call(_context12, option);
|
|
159
|
+
});
|
|
170
160
|
}
|
|
171
161
|
|
|
172
162
|
throw new _exceptions.ConfigurationException("Dependent control in combination with equals operator must be a choice, string or number attribute");
|
|
@@ -177,7 +167,11 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
177
167
|
|
|
178
168
|
processIncludesOptions(controlAttribute) {
|
|
179
169
|
if (controlAttribute instanceof _ChoiceAttributeModel.default) {
|
|
180
|
-
return this.options.some(option =>
|
|
170
|
+
return this.options.some(option => {
|
|
171
|
+
var _context13;
|
|
172
|
+
|
|
173
|
+
return (0, _includes.default)(_context13 = controlAttribute.selected).call(_context13, option);
|
|
174
|
+
});
|
|
181
175
|
}
|
|
182
176
|
|
|
183
177
|
throw new _exceptions.ConfigurationException("Dependent control in combination with includes operator must be a choice attribute");
|
|
@@ -200,6 +194,12 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
200
194
|
case NOT_INCLUDES:
|
|
201
195
|
return !this.processIncludesOptions(controlAttribute);
|
|
202
196
|
|
|
197
|
+
case NOT_IS_EMPTY:
|
|
198
|
+
return (controlAttribute === null || controlAttribute === void 0 ? void 0 : controlAttribute.selected.length) !== 0;
|
|
199
|
+
|
|
200
|
+
case IS_EMPTY:
|
|
201
|
+
return (controlAttribute === null || controlAttribute === void 0 ? void 0 : controlAttribute.selected.length) === 0;
|
|
202
|
+
|
|
203
203
|
default:
|
|
204
204
|
throw new _exceptions.ConfigurationException("Unsupported operator for dependent question: ".concat(this.operator));
|
|
205
205
|
}
|
|
@@ -209,9 +209,9 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
209
209
|
|
|
210
210
|
|
|
211
211
|
getControlAttribute(attributes) {
|
|
212
|
-
var
|
|
212
|
+
var _context14, _context15;
|
|
213
213
|
|
|
214
|
-
const attribute = attributes.getAttributeByLayoutHint((0, _concat.default)(
|
|
214
|
+
const attribute = attributes.getAttributeByLayoutHint((0, _concat.default)(_context14 = "".concat(_constants.DEPENDENT_ATTRIBUTE_CONTROL, ":")).call(_context14, this.control), (0, _concat.default)(_context15 = "".concat(_constants.DEPENDENT_ATTRIBUTE_CONTROL, ": ")).call(_context15, this.control));
|
|
215
215
|
|
|
216
216
|
if (attribute instanceof _ChoiceAttributeModel.default || attribute instanceof _BooleanAttributeModel.default) {
|
|
217
217
|
return attribute;
|
|
@@ -244,9 +244,9 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
244
244
|
} else if (this.action === HIDE) {
|
|
245
245
|
attribute.isHidden = result;
|
|
246
246
|
} else {
|
|
247
|
-
var
|
|
247
|
+
var _context16;
|
|
248
248
|
|
|
249
|
-
throw new _exceptions.ConfigurationException((0, _concat.default)(
|
|
249
|
+
throw new _exceptions.ConfigurationException((0, _concat.default)(_context16 = "Unsupported action ".concat(this.action, " for dependent question on attribute: ")).call(_context16, attribute.label));
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
|
|
@@ -24,21 +24,6 @@ const IS_EMPTY = "isEmpty";
|
|
|
24
24
|
const SHOW = "show";
|
|
25
25
|
const HIDE = "hide";
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
*/
|
|
29
|
-
const compareSelectedAttribute = (
|
|
30
|
-
option: string,
|
|
31
|
-
selectedAttribute: Array<string>
|
|
32
|
-
) => {
|
|
33
|
-
if (option === NOT_IS_EMPTY && selectedAttribute?.length !== 0) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
if (option === IS_EMPTY && selectedAttribute?.length === 0) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
return selectedAttribute?.includes(option);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
27
|
/**
|
|
43
28
|
* Depending attributes hint logic
|
|
44
29
|
*/
|
|
@@ -75,18 +60,25 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
75
60
|
static initHint(hint: string): any {
|
|
76
61
|
const rule = this.getRuleInstance();
|
|
77
62
|
|
|
78
|
-
const OPERATORS = `${EQUALS}|${INCLUDES}|${NOT_EQUALS}|${NOT_INCLUDES}`;
|
|
63
|
+
const OPERATORS = `${EQUALS}|${INCLUDES}|${NOT_EQUALS}|${NOT_INCLUDES}|${NOT_IS_EMPTY}|${IS_EMPTY}`;
|
|
79
64
|
const regex = new RegExp(
|
|
80
65
|
`${DEPENDENT_ATTRIBUTE}\\s?(\\S*)\\swhen ${DEPENDENT_ATTRIBUTE_CONTROL}:\\s?(.*?)\\s*(${OPERATORS})\\s(.*)`,
|
|
81
66
|
"i"
|
|
82
67
|
);
|
|
68
|
+
const isEmpyNotIsEmptRegex = new RegExp(
|
|
69
|
+
`${DEPENDENT_ATTRIBUTE}\\s?(\\S*)\\swhen ${DEPENDENT_ATTRIBUTE_CONTROL}:\\s?(.*?)\\s*(${OPERATORS})`,
|
|
70
|
+
"i"
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const result = hint.match(regex)
|
|
74
|
+
? hint.match(regex)
|
|
75
|
+
: hint.match(isEmpyNotIsEmptRegex);
|
|
83
76
|
|
|
84
|
-
const result = hint.match(regex);
|
|
85
77
|
if (result) {
|
|
86
78
|
rule.action = result[1];
|
|
87
79
|
rule.control = result[2];
|
|
88
80
|
rule.operator = result[3];
|
|
89
|
-
rule.options = result[4];
|
|
81
|
+
rule.options = !result[4] ? "" : result[4];
|
|
90
82
|
} else {
|
|
91
83
|
throw new ConfigurationException(
|
|
92
84
|
`No dependent information found on layout hint: ${hint}`
|
|
@@ -154,7 +146,7 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
154
146
|
controlAttribute instanceof BooleanAttributeModel
|
|
155
147
|
) {
|
|
156
148
|
return this.options.every((option) =>
|
|
157
|
-
|
|
149
|
+
controlAttribute.selected.includes(option)
|
|
158
150
|
);
|
|
159
151
|
}
|
|
160
152
|
|
|
@@ -170,7 +162,7 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
170
162
|
): boolean {
|
|
171
163
|
if (controlAttribute instanceof ChoiceAttributeModel) {
|
|
172
164
|
return this.options.some((option) =>
|
|
173
|
-
|
|
165
|
+
controlAttribute.selected.includes(option)
|
|
174
166
|
);
|
|
175
167
|
}
|
|
176
168
|
|
|
@@ -193,6 +185,10 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
193
185
|
return !this.processEqualsOptions(controlAttribute);
|
|
194
186
|
case NOT_INCLUDES:
|
|
195
187
|
return !this.processIncludesOptions(controlAttribute);
|
|
188
|
+
case NOT_IS_EMPTY:
|
|
189
|
+
return controlAttribute?.selected.length !== 0;
|
|
190
|
+
case IS_EMPTY:
|
|
191
|
+
return controlAttribute?.selected.length === 0;
|
|
196
192
|
default:
|
|
197
193
|
throw new ConfigurationException(
|
|
198
194
|
`Unsupported operator for dependent question: ${this.operator}`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependentAttribute.js","names":["EQUALS","INCLUDES","NOT_EQUALS","NOT_INCLUDES","NOT_IS_EMPTY","IS_EMPTY","SHOW","HIDE","compareSelectedAttribute","option","selectedAttribute","length","DependentAttribute","BaseLayoutHintRule","isApplicableForHint","hint","regex","RegExp","DEPENDENT_ATTRIBUTE","test","getRuleInstance","initHint","rule","OPERATORS","DEPENDENT_ATTRIBUTE_CONTROL","result","match","action","control","operator","options","ConfigurationException","_action","_control","_operator","_options","split","processEqualsOptions","controlAttribute","ChoiceAttributeModel","BooleanAttributeModel","every","selected","processIncludesOptions","some","handleOperator","getControlAttribute","attributes","attribute","getAttributeByLayoutHint","process","processLayoutHintRules","isHidden","hide","label"],"sources":["../../../../src/models/attributes/layouthint-rules/DependentAttribute.js"],"sourcesContent":["// @flow\nimport BaseLayoutHintRule from \"./BaseLayoutHintRule\";\n\nimport {\n DEPENDENT_ATTRIBUTE_CONTROL,\n DEPENDENT_ATTRIBUTE,\n} from \"../../../constants\";\n\nimport ChoiceAttributeModel from \"../ChoiceAttributeModel\";\nimport BooleanAttributeModel from \"../BooleanAttributeModel\";\n\nimport { ConfigurationException } from \"../../../exceptions\";\n\nimport type AttributeCollection from \"../AttributeCollection\";\nimport type AttributeModel from \"../AttributeModel\";\n\nconst EQUALS = \"equals\";\nconst INCLUDES = \"includes\";\nconst NOT_EQUALS = \"notEquals\";\nconst NOT_INCLUDES = \"notIncludes\";\nconst NOT_IS_EMPTY = \"notIsEmpty\";\nconst IS_EMPTY = \"isEmpty\";\n\nconst SHOW = \"show\";\nconst HIDE = \"hide\";\n\n/**\n */\nconst compareSelectedAttribute = (\n option: string,\n selectedAttribute: Array<string>\n) => {\n if (option === NOT_IS_EMPTY && selectedAttribute?.length !== 0) {\n return true;\n }\n if (option === IS_EMPTY && selectedAttribute?.length === 0) {\n return true;\n }\n return selectedAttribute?.includes(option);\n};\n\n/**\n * Depending attributes hint logic\n */\nclass DependentAttribute extends BaseLayoutHintRule {\n _action: string;\n _control: string;\n _operator: string;\n _options: Array<string>;\n\n /**\n */\n static checkHintApplicability: boolean = true;\n\n /**\n */\n static isApplicableForHint(hint: string): boolean {\n const regex = new RegExp(\n `^${DEPENDENT_ATTRIBUTE}\\\\s?(${SHOW}|${HIDE})`,\n \"i\"\n );\n\n return regex.test(hint);\n }\n\n /**\n * Used on initHint to create an instance of this rule\n */\n static getRuleInstance(): DependentAttribute {\n return new DependentAttribute();\n }\n\n /**\n */\n static initHint(hint: string): any {\n const rule = this.getRuleInstance();\n\n const OPERATORS = `${EQUALS}|${INCLUDES}|${NOT_EQUALS}|${NOT_INCLUDES}`;\n const regex = new RegExp(\n `${DEPENDENT_ATTRIBUTE}\\\\s?(\\\\S*)\\\\swhen ${DEPENDENT_ATTRIBUTE_CONTROL}:\\\\s?(.*?)\\\\s*(${OPERATORS})\\\\s(.*)`,\n \"i\"\n );\n\n const result = hint.match(regex);\n if (result) {\n rule.action = result[1];\n rule.control = result[2];\n rule.operator = result[3];\n rule.options = result[4];\n } else {\n throw new ConfigurationException(\n `No dependent information found on layout hint: ${hint}`\n );\n }\n\n return rule;\n }\n\n /**\n */\n get action(): string {\n return this._action;\n }\n\n /**\n */\n set action(action: string) {\n this._action = action;\n }\n\n /**\n */\n get control(): string {\n return this._control;\n }\n\n /**\n */\n set control(control: string) {\n this._control = control;\n }\n\n /**\n */\n get operator(): string {\n return this._operator;\n }\n\n /**\n */\n set operator(operator: string) {\n this._operator = operator;\n }\n\n /**\n */\n get options(): Array<string> {\n return this._options;\n }\n\n /**\n */\n set options(options: string): void {\n this._options = options.split(\"|\").map((option) => option.trim());\n }\n\n /**\n */\n processEqualsOptions(\n controlAttribute: ChoiceAttributeModel | BooleanAttributeModel\n ): boolean {\n if (\n controlAttribute instanceof ChoiceAttributeModel ||\n controlAttribute instanceof BooleanAttributeModel\n ) {\n return this.options.every((option) =>\n compareSelectedAttribute(option, controlAttribute?.selected)\n );\n }\n\n throw new ConfigurationException(\n \"Dependent control in combination with equals operator must be a choice, string or number attribute\"\n );\n }\n\n /**\n */\n processIncludesOptions(\n controlAttribute: ChoiceAttributeModel | BooleanAttributeModel\n ): boolean {\n if (controlAttribute instanceof ChoiceAttributeModel) {\n return this.options.some((option) =>\n compareSelectedAttribute(option, controlAttribute?.selected)\n );\n }\n\n throw new ConfigurationException(\n \"Dependent control in combination with includes operator must be a choice attribute\"\n );\n }\n\n /**\n */\n handleOperator(\n controlAttribute: ChoiceAttributeModel | BooleanAttributeModel\n ): boolean {\n switch (this.operator) {\n case EQUALS:\n return this.processEqualsOptions(controlAttribute);\n case INCLUDES:\n return this.processIncludesOptions(controlAttribute);\n case NOT_EQUALS:\n return !this.processEqualsOptions(controlAttribute);\n case NOT_INCLUDES:\n return !this.processIncludesOptions(controlAttribute);\n default:\n throw new ConfigurationException(\n `Unsupported operator for dependent question: ${this.operator}`\n );\n }\n }\n\n /**\n */\n getControlAttribute(\n attributes: AttributeCollection\n ): ChoiceAttributeModel | BooleanAttributeModel | null {\n const attribute = attributes.getAttributeByLayoutHint(\n `${DEPENDENT_ATTRIBUTE_CONTROL}:${this.control}`,\n `${DEPENDENT_ATTRIBUTE_CONTROL}: ${this.control}`\n );\n\n if (\n attribute instanceof ChoiceAttributeModel ||\n attribute instanceof BooleanAttributeModel\n ) {\n return attribute;\n }\n\n return null;\n }\n\n /**\n */\n process(attribute: AttributeModel, attributes: AttributeCollection) {\n const controlAttribute = this.getControlAttribute(attributes);\n if (!controlAttribute) {\n return;\n }\n\n controlAttribute.processLayoutHintRules(attributes);\n if (controlAttribute.isHidden) {\n attribute.hide();\n return;\n }\n\n const result = this.handleOperator(controlAttribute);\n if (this.action === SHOW) {\n attribute.isHidden = !result;\n } else if (this.action === HIDE) {\n attribute.isHidden = result;\n } else {\n throw new ConfigurationException(\n `Unsupported action ${this.action} for dependent question on attribute: ${attribute.label}`\n );\n }\n }\n}\n\nexport default DependentAttribute;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AACA;;AAEA;;AAKA;;AACA;;AAEA;;AAKA,MAAMA,MAAM,GAAG,QAAf;AACA,MAAMC,QAAQ,GAAG,UAAjB;AACA,MAAMC,UAAU,GAAG,WAAnB;AACA,MAAMC,YAAY,GAAG,aAArB;AACA,MAAMC,YAAY,GAAG,YAArB;AACA,MAAMC,QAAQ,GAAG,SAAjB;AAEA,MAAMC,IAAI,GAAG,MAAb;AACA,MAAMC,IAAI,GAAG,MAAb;AAEA;AACA;;AACA,MAAMC,wBAAwB,GAAG,CAC/BC,MAD+B,EAE/BC,iBAF+B,KAG5B;EACH,IAAID,MAAM,KAAKL,YAAX,IAA2B,CAAAM,iBAAiB,SAAjB,IAAAA,iBAAiB,WAAjB,YAAAA,iBAAiB,CAAEC,MAAnB,MAA8B,CAA7D,EAAgE;IAC9D,OAAO,IAAP;EACD;;EACD,IAAIF,MAAM,KAAKJ,QAAX,IAAuB,CAAAK,iBAAiB,SAAjB,IAAAA,iBAAiB,WAAjB,YAAAA,iBAAiB,CAAEC,MAAnB,MAA8B,CAAzD,EAA4D;IAC1D,OAAO,IAAP;EACD;;EACD,OAAOD,iBAAP,aAAOA,iBAAP,uBAAO,uBAAAA,iBAAiB,MAAjB,CAAAA,iBAAiB,EAAWD,MAAX,CAAxB;AACD,CAXD;AAaA;AACA;AACA;;;AACA,MAAMG,kBAAN,SAAiCC,2BAAjC,CAAoD;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;;EAUlD;AACF;EAC4B,OAAnBC,mBAAmB,CAACC,IAAD,EAAwB;IAAA;;IAChD,MAAMC,KAAK,GAAG,IAAIC,MAAJ,6EACRC,8BADQ,4BACmBZ,IADnB,uBAC2BC,IA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|
+
{"version":3,"file":"DependentAttribute.js","names":["EQUALS","INCLUDES","NOT_EQUALS","NOT_INCLUDES","NOT_IS_EMPTY","IS_EMPTY","SHOW","HIDE","DependentAttribute","BaseLayoutHintRule","isApplicableForHint","hint","regex","RegExp","DEPENDENT_ATTRIBUTE","test","getRuleInstance","initHint","rule","OPERATORS","DEPENDENT_ATTRIBUTE_CONTROL","isEmpyNotIsEmptRegex","result","match","action","control","operator","options","ConfigurationException","_action","_control","_operator","_options","split","option","processEqualsOptions","controlAttribute","ChoiceAttributeModel","BooleanAttributeModel","every","selected","processIncludesOptions","some","handleOperator","length","getControlAttribute","attributes","attribute","getAttributeByLayoutHint","process","processLayoutHintRules","isHidden","hide","label"],"sources":["../../../../src/models/attributes/layouthint-rules/DependentAttribute.js"],"sourcesContent":["// @flow\nimport BaseLayoutHintRule from \"./BaseLayoutHintRule\";\n\nimport {\n DEPENDENT_ATTRIBUTE_CONTROL,\n DEPENDENT_ATTRIBUTE,\n} from \"../../../constants\";\n\nimport ChoiceAttributeModel from \"../ChoiceAttributeModel\";\nimport BooleanAttributeModel from \"../BooleanAttributeModel\";\n\nimport { ConfigurationException } from \"../../../exceptions\";\n\nimport type AttributeCollection from \"../AttributeCollection\";\nimport type AttributeModel from \"../AttributeModel\";\n\nconst EQUALS = \"equals\";\nconst INCLUDES = \"includes\";\nconst NOT_EQUALS = \"notEquals\";\nconst NOT_INCLUDES = \"notIncludes\";\nconst NOT_IS_EMPTY = \"notIsEmpty\";\nconst IS_EMPTY = \"isEmpty\";\n\nconst SHOW = \"show\";\nconst HIDE = \"hide\";\n\n/**\n * Depending attributes hint logic\n */\nclass DependentAttribute extends BaseLayoutHintRule {\n _action: string;\n _control: string;\n _operator: string;\n _options: Array<string>;\n\n /**\n */\n static checkHintApplicability: boolean = true;\n\n /**\n */\n static isApplicableForHint(hint: string): boolean {\n const regex = new RegExp(\n `^${DEPENDENT_ATTRIBUTE}\\\\s?(${SHOW}|${HIDE})`,\n \"i\"\n );\n\n return regex.test(hint);\n }\n\n /**\n * Used on initHint to create an instance of this rule\n */\n static getRuleInstance(): DependentAttribute {\n return new DependentAttribute();\n }\n\n /**\n */\n static initHint(hint: string): any {\n const rule = this.getRuleInstance();\n\n const OPERATORS = `${EQUALS}|${INCLUDES}|${NOT_EQUALS}|${NOT_INCLUDES}|${NOT_IS_EMPTY}|${IS_EMPTY}`;\n const regex = new RegExp(\n `${DEPENDENT_ATTRIBUTE}\\\\s?(\\\\S*)\\\\swhen ${DEPENDENT_ATTRIBUTE_CONTROL}:\\\\s?(.*?)\\\\s*(${OPERATORS})\\\\s(.*)`,\n \"i\"\n );\n const isEmpyNotIsEmptRegex = new RegExp(\n `${DEPENDENT_ATTRIBUTE}\\\\s?(\\\\S*)\\\\swhen ${DEPENDENT_ATTRIBUTE_CONTROL}:\\\\s?(.*?)\\\\s*(${OPERATORS})`,\n \"i\"\n );\n\n const result = hint.match(regex)\n ? hint.match(regex)\n : hint.match(isEmpyNotIsEmptRegex);\n\n if (result) {\n rule.action = result[1];\n rule.control = result[2];\n rule.operator = result[3];\n rule.options = !result[4] ? \"\" : result[4];\n } else {\n throw new ConfigurationException(\n `No dependent information found on layout hint: ${hint}`\n );\n }\n\n return rule;\n }\n\n /**\n */\n get action(): string {\n return this._action;\n }\n\n /**\n */\n set action(action: string) {\n this._action = action;\n }\n\n /**\n */\n get control(): string {\n return this._control;\n }\n\n /**\n */\n set control(control: string) {\n this._control = control;\n }\n\n /**\n */\n get operator(): string {\n return this._operator;\n }\n\n /**\n */\n set operator(operator: string) {\n this._operator = operator;\n }\n\n /**\n */\n get options(): Array<string> {\n return this._options;\n }\n\n /**\n */\n set options(options: string): void {\n this._options = options.split(\"|\").map((option) => option.trim());\n }\n\n /**\n */\n processEqualsOptions(\n controlAttribute: ChoiceAttributeModel | BooleanAttributeModel\n ): boolean {\n if (\n controlAttribute instanceof ChoiceAttributeModel ||\n controlAttribute instanceof BooleanAttributeModel\n ) {\n return this.options.every((option) =>\n controlAttribute.selected.includes(option)\n );\n }\n\n throw new ConfigurationException(\n \"Dependent control in combination with equals operator must be a choice, string or number attribute\"\n );\n }\n\n /**\n */\n processIncludesOptions(\n controlAttribute: ChoiceAttributeModel | BooleanAttributeModel\n ): boolean {\n if (controlAttribute instanceof ChoiceAttributeModel) {\n return this.options.some((option) =>\n controlAttribute.selected.includes(option)\n );\n }\n\n throw new ConfigurationException(\n \"Dependent control in combination with includes operator must be a choice attribute\"\n );\n }\n\n /**\n */\n handleOperator(\n controlAttribute: ChoiceAttributeModel | BooleanAttributeModel\n ): boolean {\n switch (this.operator) {\n case EQUALS:\n return this.processEqualsOptions(controlAttribute);\n case INCLUDES:\n return this.processIncludesOptions(controlAttribute);\n case NOT_EQUALS:\n return !this.processEqualsOptions(controlAttribute);\n case NOT_INCLUDES:\n return !this.processIncludesOptions(controlAttribute);\n case NOT_IS_EMPTY:\n return controlAttribute?.selected.length !== 0;\n case IS_EMPTY:\n return controlAttribute?.selected.length === 0;\n default:\n throw new ConfigurationException(\n `Unsupported operator for dependent question: ${this.operator}`\n );\n }\n }\n\n /**\n */\n getControlAttribute(\n attributes: AttributeCollection\n ): ChoiceAttributeModel | BooleanAttributeModel | null {\n const attribute = attributes.getAttributeByLayoutHint(\n `${DEPENDENT_ATTRIBUTE_CONTROL}:${this.control}`,\n `${DEPENDENT_ATTRIBUTE_CONTROL}: ${this.control}`\n );\n\n if (\n attribute instanceof ChoiceAttributeModel ||\n attribute instanceof BooleanAttributeModel\n ) {\n return attribute;\n }\n\n return null;\n }\n\n /**\n */\n process(attribute: AttributeModel, attributes: AttributeCollection) {\n const controlAttribute = this.getControlAttribute(attributes);\n if (!controlAttribute) {\n return;\n }\n\n controlAttribute.processLayoutHintRules(attributes);\n if (controlAttribute.isHidden) {\n attribute.hide();\n return;\n }\n\n const result = this.handleOperator(controlAttribute);\n if (this.action === SHOW) {\n attribute.isHidden = !result;\n } else if (this.action === HIDE) {\n attribute.isHidden = result;\n } else {\n throw new ConfigurationException(\n `Unsupported action ${this.action} for dependent question on attribute: ${attribute.label}`\n );\n }\n }\n}\n\nexport default DependentAttribute;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AACA;;AAEA;;AAKA;;AACA;;AAEA;;AAKA,MAAMA,MAAM,GAAG,QAAf;AACA,MAAMC,QAAQ,GAAG,UAAjB;AACA,MAAMC,UAAU,GAAG,WAAnB;AACA,MAAMC,YAAY,GAAG,aAArB;AACA,MAAMC,YAAY,GAAG,YAArB;AACA,MAAMC,QAAQ,GAAG,SAAjB;AAEA,MAAMC,IAAI,GAAG,MAAb;AACA,MAAMC,IAAI,GAAG,MAAb;AAEA;AACA;AACA;;AACA,MAAMC,kBAAN,SAAiCC,2BAAjC,CAAoD;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;;EAUlD;AACF;EAC4B,OAAnBC,mBAAmB,CAACC,IAAD,EAAwB;IAAA;;IAChD,MAAMC,KAAK,GAAG,IAAIC,MAAJ,6EACRC,8BADQ,4BACmBR,IADnB,uBAC2BC,IAD3B,QAEZ,GAFY,CAAd;IAKA,OAAOK,KAAK,CAACG,IAAN,CAAWJ,IAAX,CAAP;EACD;EAED;AACF;AACA;;;EACwB,OAAfK,eAAe,GAAuB;IAC3C,OAAO,IAAIR,kBAAJ,EAAP;EACD;EAED;AACF;;;EACiB,OAARS,QAAQ,CAACN,IAAD,EAAoB;IAAA;;IACjC,MAAMO,IAAI,GAAG,KAAKF,eAAL,EAAb;IAEA,MAAMG,SAAS,iJAAMnB,MAAN,cAAgBC,QAAhB,wBAA4BC,UAA5B,wBAA0CC,YAA1C,wBAA0DC,YAA1D,wBAA0EC,QAA1E,CAAf;IACA,MAAMO,KAAK,GAAG,IAAIC,MAAJ,6EACTC,8BADS,yCAC+BM,sCAD/B,sCAC4ED,SAD5E,eAEZ,GAFY,CAAd;IAIA,MAAME,oBAAoB,GAAG,IAAIR,MAAJ,8EACxBC,8BADwB,0CACgBM,sCADhB,sCAC6DD,SAD7D,QAE3B,GAF2B,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
24
24
|
const SHOW = "show";
|
|
25
25
|
const HIDE = "hide";
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
*/
|
|
29
|
-
const compareSelectedAttribute = (
|
|
30
|
-
option: string,
|
|
31
|
-
selectedAttribute: Array<string>
|
|
32
|
-
) => {
|
|
33
|
-
if (option === NOT_IS_EMPTY && selectedAttribute?.length !== 0) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
if (option === IS_EMPTY && selectedAttribute?.length === 0) {
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
return selectedAttribute?.includes(option);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
27
|
/**
|
|
43
28
|
* Depending attributes hint logic
|
|
44
29
|
*/
|
|
@@ -75,18 +60,25 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
75
60
|
static initHint(hint: string): any {
|
|
76
61
|
const rule = this.getRuleInstance();
|
|
77
62
|
|
|
78
|
-
const OPERATORS = `${EQUALS}|${INCLUDES}|${NOT_EQUALS}|${NOT_INCLUDES}`;
|
|
63
|
+
const OPERATORS = `${EQUALS}|${INCLUDES}|${NOT_EQUALS}|${NOT_INCLUDES}|${NOT_IS_EMPTY}|${IS_EMPTY}`;
|
|
79
64
|
const regex = new RegExp(
|
|
80
65
|
`${DEPENDENT_ATTRIBUTE}\\s?(\\S*)\\swhen ${DEPENDENT_ATTRIBUTE_CONTROL}:\\s?(.*?)\\s*(${OPERATORS})\\s(.*)`,
|
|
81
66
|
"i"
|
|
82
67
|
);
|
|
68
|
+
const isEmpyNotIsEmptRegex = new RegExp(
|
|
69
|
+
`${DEPENDENT_ATTRIBUTE}\\s?(\\S*)\\swhen ${DEPENDENT_ATTRIBUTE_CONTROL}:\\s?(.*?)\\s*(${OPERATORS})`,
|
|
70
|
+
"i"
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const result = hint.match(regex)
|
|
74
|
+
? hint.match(regex)
|
|
75
|
+
: hint.match(isEmpyNotIsEmptRegex);
|
|
83
76
|
|
|
84
|
-
const result = hint.match(regex);
|
|
85
77
|
if (result) {
|
|
86
78
|
rule.action = result[1];
|
|
87
79
|
rule.control = result[2];
|
|
88
80
|
rule.operator = result[3];
|
|
89
|
-
rule.options = result[4];
|
|
81
|
+
rule.options = !result[4] ? "" : result[4];
|
|
90
82
|
} else {
|
|
91
83
|
throw new ConfigurationException(
|
|
92
84
|
`No dependent information found on layout hint: ${hint}`
|
|
@@ -154,7 +146,7 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
154
146
|
controlAttribute instanceof BooleanAttributeModel
|
|
155
147
|
) {
|
|
156
148
|
return this.options.every((option) =>
|
|
157
|
-
|
|
149
|
+
controlAttribute.selected.includes(option)
|
|
158
150
|
);
|
|
159
151
|
}
|
|
160
152
|
|
|
@@ -170,7 +162,7 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
170
162
|
): boolean {
|
|
171
163
|
if (controlAttribute instanceof ChoiceAttributeModel) {
|
|
172
164
|
return this.options.some((option) =>
|
|
173
|
-
|
|
165
|
+
controlAttribute.selected.includes(option)
|
|
174
166
|
);
|
|
175
167
|
}
|
|
176
168
|
|
|
@@ -193,6 +185,10 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
193
185
|
return !this.processEqualsOptions(controlAttribute);
|
|
194
186
|
case NOT_INCLUDES:
|
|
195
187
|
return !this.processIncludesOptions(controlAttribute);
|
|
188
|
+
case NOT_IS_EMPTY:
|
|
189
|
+
return controlAttribute?.selected.length !== 0;
|
|
190
|
+
case IS_EMPTY:
|
|
191
|
+
return controlAttribute?.selected.length === 0;
|
|
196
192
|
default:
|
|
197
193
|
throw new ConfigurationException(
|
|
198
194
|
`Unsupported operator for dependent question: ${this.operator}`
|