@beinformed/ui 1.22.1 → 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 +14 -0
- package/esm/models/attributes/layouthint-rules/DependentAttribute.js +24 -15
- package/esm/models/attributes/layouthint-rules/DependentAttribute.js.map +1 -1
- package/lib/models/attributes/layouthint-rules/DependentAttribute.js +24 -15
- package/lib/models/attributes/layouthint-rules/DependentAttribute.js.flow +16 -3
- 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 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
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
|
+
|
|
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)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **DependentAttribute:** DependentAttribute extended to work with empty and not empty attribute value ([73473cf](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/73473cff35ca5c7974a3800df5e49bdb1a9031ea))
|
|
18
|
+
|
|
5
19
|
### [1.22.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.22.0...v1.22.1) (2022-09-07)
|
|
6
20
|
|
|
7
21
|
## [1.22.0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.21.7...v1.22.0) (2022-09-05)
|
|
@@ -12,6 +12,8 @@ const EQUALS = "equals";
|
|
|
12
12
|
const INCLUDES = "includes";
|
|
13
13
|
const NOT_EQUALS = "notEquals";
|
|
14
14
|
const NOT_INCLUDES = "notIncludes";
|
|
15
|
+
const NOT_IS_EMPTY = "notIsEmpty";
|
|
16
|
+
const IS_EMPTY = "isEmpty";
|
|
15
17
|
const SHOW = "show";
|
|
16
18
|
const HIDE = "hide";
|
|
17
19
|
/**
|
|
@@ -52,20 +54,21 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
52
54
|
|
|
53
55
|
|
|
54
56
|
static initHint(hint) {
|
|
55
|
-
var _context3, _context4, _context5, _context6;
|
|
57
|
+
var _context3, _context4, _context5, _context6, _context7, _context8, _context9, _context10;
|
|
56
58
|
|
|
57
59
|
const rule = this.getRuleInstance();
|
|
58
60
|
|
|
59
|
-
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);
|
|
60
62
|
|
|
61
|
-
const regex = new RegExp(_concatInstanceProperty(
|
|
62
|
-
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);
|
|
63
66
|
|
|
64
67
|
if (result) {
|
|
65
68
|
rule.action = result[1];
|
|
66
69
|
rule.control = result[2];
|
|
67
70
|
rule.operator = result[3];
|
|
68
|
-
rule.options = result[4];
|
|
71
|
+
rule.options = !result[4] ? "" : result[4];
|
|
69
72
|
} else {
|
|
70
73
|
throw new ConfigurationException("No dependent information found on layout hint: ".concat(hint));
|
|
71
74
|
}
|
|
@@ -126,9 +129,9 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
126
129
|
|
|
127
130
|
|
|
128
131
|
set options(options) {
|
|
129
|
-
var
|
|
132
|
+
var _context11;
|
|
130
133
|
|
|
131
|
-
this._options = _mapInstanceProperty(
|
|
134
|
+
this._options = _mapInstanceProperty(_context11 = options.split("|")).call(_context11, option => _trimInstanceProperty(option).call(option));
|
|
132
135
|
}
|
|
133
136
|
/**
|
|
134
137
|
*/
|
|
@@ -137,9 +140,9 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
137
140
|
processEqualsOptions(controlAttribute) {
|
|
138
141
|
if (controlAttribute instanceof ChoiceAttributeModel || controlAttribute instanceof BooleanAttributeModel) {
|
|
139
142
|
return this.options.every(option => {
|
|
140
|
-
var
|
|
143
|
+
var _context12;
|
|
141
144
|
|
|
142
|
-
return _includesInstanceProperty(
|
|
145
|
+
return _includesInstanceProperty(_context12 = controlAttribute.selected).call(_context12, option);
|
|
143
146
|
});
|
|
144
147
|
}
|
|
145
148
|
|
|
@@ -152,9 +155,9 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
152
155
|
processIncludesOptions(controlAttribute) {
|
|
153
156
|
if (controlAttribute instanceof ChoiceAttributeModel) {
|
|
154
157
|
return this.options.some(option => {
|
|
155
|
-
var
|
|
158
|
+
var _context13;
|
|
156
159
|
|
|
157
|
-
return _includesInstanceProperty(
|
|
160
|
+
return _includesInstanceProperty(_context13 = controlAttribute.selected).call(_context13, option);
|
|
158
161
|
});
|
|
159
162
|
}
|
|
160
163
|
|
|
@@ -178,6 +181,12 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
178
181
|
case NOT_INCLUDES:
|
|
179
182
|
return !this.processIncludesOptions(controlAttribute);
|
|
180
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
|
+
|
|
181
190
|
default:
|
|
182
191
|
throw new ConfigurationException("Unsupported operator for dependent question: ".concat(this.operator));
|
|
183
192
|
}
|
|
@@ -187,9 +196,9 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
187
196
|
|
|
188
197
|
|
|
189
198
|
getControlAttribute(attributes) {
|
|
190
|
-
var
|
|
199
|
+
var _context14, _context15;
|
|
191
200
|
|
|
192
|
-
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));
|
|
193
202
|
|
|
194
203
|
if (attribute instanceof ChoiceAttributeModel || attribute instanceof BooleanAttributeModel) {
|
|
195
204
|
return attribute;
|
|
@@ -222,9 +231,9 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
222
231
|
} else if (this.action === HIDE) {
|
|
223
232
|
attribute.isHidden = result;
|
|
224
233
|
} else {
|
|
225
|
-
var
|
|
234
|
+
var _context16;
|
|
226
235
|
|
|
227
|
-
throw new ConfigurationException(_concatInstanceProperty(
|
|
236
|
+
throw new ConfigurationException(_concatInstanceProperty(_context16 = "Unsupported action ".concat(this.action, " for dependent question on attribute: ")).call(_context16, attribute.label));
|
|
228
237
|
}
|
|
229
238
|
}
|
|
230
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","SHOW","HIDE","DependentAttribute","isApplicableForHint","hint","regex","RegExp","test","getRuleInstance","initHint","rule","OPERATORS","result","match","action","control","operator","options","_action","_control","_operator","_options","split","option","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\";\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}`;\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 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 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,MA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zB,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,MAAM1B,MAAM,GAAG,KAAKkB,cAAL,CAAoBL,gBAApB,CAAf;;IACA,IAAI,KAAKX,MAAL,KAAgBd,IAApB,EAA0B;MACxBiC,SAAS,CAACI,QAAV,GAAqB,CAACzB,MAAtB;IACD,CAFD,MAEO,IAAI,KAAKE,MAAL,KAAgBb,IAApB,EAA0B;MAC/BgC,SAAS,CAACI,QAAV,GAAqBzB,MAArB;IACD,CAFM,MAEA;MAAA;;MACL,MAAM,IAAIjB,sBAAJ,mEACkB,KAAKmB,MADvB,8DACsEmB,SAAS,CAACM,KADhF,EAAN;IAGD;EACF;;AA1MiD;;gBAA9CrC,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,oBAAP,MAAiC,yBAAjC;AACA,OAAOC,qBAAP,MAAkC,0BAAlC;AAEA,SAASC,sBAAT,QAAuC,qBAAvC;AAKA,MAAMC,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,SAAiCd,kBAAjC,CAAoD;EAAA;IAAA;;IAAA;;IA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AO,IAAP;EACD;EAED;AACF;;;EACEE,OAAO,CAACF,SAAD,EAA4BD,UAA5B,EAA6D;IAClE,MAAMR,gBAAgB,GAAG,KAAKO,mBAAL,CAAyBC,UAAzB,CAAzB;;IACA,IAAI,CAACR,gBAAL,EAAuB;MACrB;IACD;;IAEDA,gBAAgB,CAACY,sBAAjB,CAAwCJ,UAAxC;;IACA,IAAIR,gBAAgB,CAACa,QAArB,EAA+B;MAC7BJ,SAAS,CAACK,IAAV;MACA;IACD;;IAED,MAAM3B,MAAM,GAAG,KAAKkB,cAAL,CAAoBL,gBAApB,CAAf;;IACA,IAAI,KAAKX,MAAL,KAAgBf,IAApB,EAA0B;MACxBmC,SAAS,CAACI,QAAV,GAAqB,CAAC1B,MAAtB;IACD,CAFD,MAEO,IAAI,KAAKE,MAAL,KAAgBd,IAApB,EAA0B;MAC/BkC,SAAS,CAACI,QAAV,GAAqB1B,MAArB;IACD,CAFM,MAEA;MAAA;;MACL,MAAM,IAAIpB,sBAAJ,mEACkB,KAAKsB,MADvB,8DACsEoB,SAAS,CAACM,KADhF,EAAN;IAGD;EACF;;AArNiD;;gBAA9CvC,kB,4BAQqC,I;;AAgN3C,eAAeA,kBAAf"}
|
|
@@ -31,6 +31,8 @@ const EQUALS = "equals";
|
|
|
31
31
|
const INCLUDES = "includes";
|
|
32
32
|
const NOT_EQUALS = "notEquals";
|
|
33
33
|
const NOT_INCLUDES = "notIncludes";
|
|
34
|
+
const NOT_IS_EMPTY = "notIsEmpty";
|
|
35
|
+
const IS_EMPTY = "isEmpty";
|
|
34
36
|
const SHOW = "show";
|
|
35
37
|
const HIDE = "hide";
|
|
36
38
|
/**
|
|
@@ -67,18 +69,19 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
67
69
|
|
|
68
70
|
|
|
69
71
|
static initHint(hint) {
|
|
70
|
-
var _context3, _context4, _context5, _context6;
|
|
72
|
+
var _context3, _context4, _context5, _context6, _context7, _context8, _context9, _context10;
|
|
71
73
|
|
|
72
74
|
const rule = this.getRuleInstance();
|
|
73
|
-
const OPERATORS = (0, _concat.default)(_context3 = (0, _concat.default)(_context4 = "".concat(EQUALS, "|").concat(INCLUDES, "|")).call(
|
|
74
|
-
const regex = new RegExp((0, _concat.default)(
|
|
75
|
-
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);
|
|
76
79
|
|
|
77
80
|
if (result) {
|
|
78
81
|
rule.action = result[1];
|
|
79
82
|
rule.control = result[2];
|
|
80
83
|
rule.operator = result[3];
|
|
81
|
-
rule.options = result[4];
|
|
84
|
+
rule.options = !result[4] ? "" : result[4];
|
|
82
85
|
} else {
|
|
83
86
|
throw new _exceptions.ConfigurationException("No dependent information found on layout hint: ".concat(hint));
|
|
84
87
|
}
|
|
@@ -139,9 +142,9 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
139
142
|
|
|
140
143
|
|
|
141
144
|
set options(options) {
|
|
142
|
-
var
|
|
145
|
+
var _context11;
|
|
143
146
|
|
|
144
|
-
this._options = (0, _map.default)(
|
|
147
|
+
this._options = (0, _map.default)(_context11 = options.split("|")).call(_context11, option => (0, _trim.default)(option).call(option));
|
|
145
148
|
}
|
|
146
149
|
/**
|
|
147
150
|
*/
|
|
@@ -150,9 +153,9 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
150
153
|
processEqualsOptions(controlAttribute) {
|
|
151
154
|
if (controlAttribute instanceof _ChoiceAttributeModel.default || controlAttribute instanceof _BooleanAttributeModel.default) {
|
|
152
155
|
return this.options.every(option => {
|
|
153
|
-
var
|
|
156
|
+
var _context12;
|
|
154
157
|
|
|
155
|
-
return (0, _includes.default)(
|
|
158
|
+
return (0, _includes.default)(_context12 = controlAttribute.selected).call(_context12, option);
|
|
156
159
|
});
|
|
157
160
|
}
|
|
158
161
|
|
|
@@ -165,9 +168,9 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
165
168
|
processIncludesOptions(controlAttribute) {
|
|
166
169
|
if (controlAttribute instanceof _ChoiceAttributeModel.default) {
|
|
167
170
|
return this.options.some(option => {
|
|
168
|
-
var
|
|
171
|
+
var _context13;
|
|
169
172
|
|
|
170
|
-
return (0, _includes.default)(
|
|
173
|
+
return (0, _includes.default)(_context13 = controlAttribute.selected).call(_context13, option);
|
|
171
174
|
});
|
|
172
175
|
}
|
|
173
176
|
|
|
@@ -191,6 +194,12 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
191
194
|
case NOT_INCLUDES:
|
|
192
195
|
return !this.processIncludesOptions(controlAttribute);
|
|
193
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
|
+
|
|
194
203
|
default:
|
|
195
204
|
throw new _exceptions.ConfigurationException("Unsupported operator for dependent question: ".concat(this.operator));
|
|
196
205
|
}
|
|
@@ -200,9 +209,9 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
200
209
|
|
|
201
210
|
|
|
202
211
|
getControlAttribute(attributes) {
|
|
203
|
-
var
|
|
212
|
+
var _context14, _context15;
|
|
204
213
|
|
|
205
|
-
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));
|
|
206
215
|
|
|
207
216
|
if (attribute instanceof _ChoiceAttributeModel.default || attribute instanceof _BooleanAttributeModel.default) {
|
|
208
217
|
return attribute;
|
|
@@ -235,9 +244,9 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
235
244
|
} else if (this.action === HIDE) {
|
|
236
245
|
attribute.isHidden = result;
|
|
237
246
|
} else {
|
|
238
|
-
var
|
|
247
|
+
var _context16;
|
|
239
248
|
|
|
240
|
-
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));
|
|
241
250
|
}
|
|
242
251
|
}
|
|
243
252
|
|
|
@@ -18,6 +18,8 @@ const EQUALS = "equals";
|
|
|
18
18
|
const INCLUDES = "includes";
|
|
19
19
|
const NOT_EQUALS = "notEquals";
|
|
20
20
|
const NOT_INCLUDES = "notIncludes";
|
|
21
|
+
const NOT_IS_EMPTY = "notIsEmpty";
|
|
22
|
+
const IS_EMPTY = "isEmpty";
|
|
21
23
|
|
|
22
24
|
const SHOW = "show";
|
|
23
25
|
const HIDE = "hide";
|
|
@@ -58,18 +60,25 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
58
60
|
static initHint(hint: string): any {
|
|
59
61
|
const rule = this.getRuleInstance();
|
|
60
62
|
|
|
61
|
-
const OPERATORS = `${EQUALS}|${INCLUDES}|${NOT_EQUALS}|${NOT_INCLUDES}`;
|
|
63
|
+
const OPERATORS = `${EQUALS}|${INCLUDES}|${NOT_EQUALS}|${NOT_INCLUDES}|${NOT_IS_EMPTY}|${IS_EMPTY}`;
|
|
62
64
|
const regex = new RegExp(
|
|
63
65
|
`${DEPENDENT_ATTRIBUTE}\\s?(\\S*)\\swhen ${DEPENDENT_ATTRIBUTE_CONTROL}:\\s?(.*?)\\s*(${OPERATORS})\\s(.*)`,
|
|
64
66
|
"i"
|
|
65
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);
|
|
66
76
|
|
|
67
|
-
const result = hint.match(regex);
|
|
68
77
|
if (result) {
|
|
69
78
|
rule.action = result[1];
|
|
70
79
|
rule.control = result[2];
|
|
71
80
|
rule.operator = result[3];
|
|
72
|
-
rule.options = result[4];
|
|
81
|
+
rule.options = !result[4] ? "" : result[4];
|
|
73
82
|
} else {
|
|
74
83
|
throw new ConfigurationException(
|
|
75
84
|
`No dependent information found on layout hint: ${hint}`
|
|
@@ -176,6 +185,10 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
176
185
|
return !this.processEqualsOptions(controlAttribute);
|
|
177
186
|
case NOT_INCLUDES:
|
|
178
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;
|
|
179
192
|
default:
|
|
180
193
|
throw new ConfigurationException(
|
|
181
194
|
`Unsupported operator for dependent question: ${this.operator}`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependentAttribute.js","names":["EQUALS","INCLUDES","NOT_EQUALS","NOT_INCLUDES","SHOW","HIDE","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","option","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\";\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}`;\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 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 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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EAA0B;MACxBuC,SAAS,CAACI,QAAV,GAAqB,CAAC5B,MAAtB;IACD,CAFD,MAEO,IAAI,KAAKE,MAAL,KAAgBhB,IAApB,EAA0B;MAC/BsC,SAAS,CAACI,QAAV,GAAqB5B,MAArB;IACD,CAFM,MAEA;MAAA;;MACL,MAAM,IAAIM,kCAAJ,gEACkB,KAAKJ,MADvB,8DACsEsB,SAAS,CAACM,KADhF,EAAN;IAGD;EACF;;AA1MiD;;8BAA9C3C,kB,4BAQqC,I;eAqM5BA,kB"}
|
|
1
|
+
{"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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ACD,CAFD,MAEO,IAAI,KAAKE,MAAL,KAAgBjB,IAApB,EAA0B;MAC/BwC,SAAS,CAACI,QAAV,GAAqB7B,MAArB;IACD,CAFM,MAEA;MAAA;;MACL,MAAM,IAAIM,kCAAJ,gEACkB,KAAKJ,MADvB,8DACsEuB,SAAS,CAACM,KADhF,EAAN;IAGD;EACF;;AArNiD;;8BAA9C7C,kB,4BAQqC,I;eAgN5BA,kB"}
|
package/package.json
CHANGED
|
@@ -18,6 +18,8 @@ const EQUALS = "equals";
|
|
|
18
18
|
const INCLUDES = "includes";
|
|
19
19
|
const NOT_EQUALS = "notEquals";
|
|
20
20
|
const NOT_INCLUDES = "notIncludes";
|
|
21
|
+
const NOT_IS_EMPTY = "notIsEmpty";
|
|
22
|
+
const IS_EMPTY = "isEmpty";
|
|
21
23
|
|
|
22
24
|
const SHOW = "show";
|
|
23
25
|
const HIDE = "hide";
|
|
@@ -58,18 +60,25 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
58
60
|
static initHint(hint: string): any {
|
|
59
61
|
const rule = this.getRuleInstance();
|
|
60
62
|
|
|
61
|
-
const OPERATORS = `${EQUALS}|${INCLUDES}|${NOT_EQUALS}|${NOT_INCLUDES}`;
|
|
63
|
+
const OPERATORS = `${EQUALS}|${INCLUDES}|${NOT_EQUALS}|${NOT_INCLUDES}|${NOT_IS_EMPTY}|${IS_EMPTY}`;
|
|
62
64
|
const regex = new RegExp(
|
|
63
65
|
`${DEPENDENT_ATTRIBUTE}\\s?(\\S*)\\swhen ${DEPENDENT_ATTRIBUTE_CONTROL}:\\s?(.*?)\\s*(${OPERATORS})\\s(.*)`,
|
|
64
66
|
"i"
|
|
65
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);
|
|
66
76
|
|
|
67
|
-
const result = hint.match(regex);
|
|
68
77
|
if (result) {
|
|
69
78
|
rule.action = result[1];
|
|
70
79
|
rule.control = result[2];
|
|
71
80
|
rule.operator = result[3];
|
|
72
|
-
rule.options = result[4];
|
|
81
|
+
rule.options = !result[4] ? "" : result[4];
|
|
73
82
|
} else {
|
|
74
83
|
throw new ConfigurationException(
|
|
75
84
|
`No dependent information found on layout hint: ${hint}`
|
|
@@ -176,6 +185,10 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
176
185
|
return !this.processEqualsOptions(controlAttribute);
|
|
177
186
|
case NOT_INCLUDES:
|
|
178
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;
|
|
179
192
|
default:
|
|
180
193
|
throw new ConfigurationException(
|
|
181
194
|
`Unsupported operator for dependent question: ${this.operator}`
|