@beinformed/ui 1.22.1 → 1.23.0
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 +24 -15
- package/esm/models/attributes/layouthint-rules/DependentAttribute.js.map +1 -1
- package/lib/models/attributes/layouthint-rules/DependentAttribute.js +27 -18
- package/lib/models/attributes/layouthint-rules/DependentAttribute.js.flow +19 -2
- package/lib/models/attributes/layouthint-rules/DependentAttribute.js.map +1 -1
- package/package.json +1 -1
- package/src/models/attributes/layouthint-rules/DependentAttribute.js +19 -2
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.0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.22.1...v1.23.0) (2022-09-22)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **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))
|
|
11
|
+
|
|
5
12
|
### [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
13
|
|
|
7
14
|
## [1.22.0](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.21.7...v1.22.0) (2022-09-05)
|
|
@@ -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";
|
|
2
3
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
3
4
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
4
5
|
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";
|
|
@@ -12,12 +12,29 @@ 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";
|
|
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
|
+
};
|
|
17
33
|
/**
|
|
18
34
|
* Depending attributes hint logic
|
|
19
35
|
*/
|
|
20
36
|
|
|
37
|
+
|
|
21
38
|
class DependentAttribute extends BaseLayoutHintRule {
|
|
22
39
|
constructor() {
|
|
23
40
|
super(...arguments);
|
|
@@ -136,11 +153,7 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
136
153
|
|
|
137
154
|
processEqualsOptions(controlAttribute) {
|
|
138
155
|
if (controlAttribute instanceof ChoiceAttributeModel || controlAttribute instanceof BooleanAttributeModel) {
|
|
139
|
-
return this.options.every(option =>
|
|
140
|
-
var _context8;
|
|
141
|
-
|
|
142
|
-
return _includesInstanceProperty(_context8 = controlAttribute.selected).call(_context8, option);
|
|
143
|
-
});
|
|
156
|
+
return this.options.every(option => compareSelectedAttribute(option, controlAttribute === null || controlAttribute === void 0 ? void 0 : controlAttribute.selected));
|
|
144
157
|
}
|
|
145
158
|
|
|
146
159
|
throw new ConfigurationException("Dependent control in combination with equals operator must be a choice, string or number attribute");
|
|
@@ -151,11 +164,7 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
151
164
|
|
|
152
165
|
processIncludesOptions(controlAttribute) {
|
|
153
166
|
if (controlAttribute instanceof ChoiceAttributeModel) {
|
|
154
|
-
return this.options.some(option =>
|
|
155
|
-
var _context9;
|
|
156
|
-
|
|
157
|
-
return _includesInstanceProperty(_context9 = controlAttribute.selected).call(_context9, option);
|
|
158
|
-
});
|
|
167
|
+
return this.options.some(option => compareSelectedAttribute(option, controlAttribute === null || controlAttribute === void 0 ? void 0 : controlAttribute.selected));
|
|
159
168
|
}
|
|
160
169
|
|
|
161
170
|
throw new ConfigurationException("Dependent control in combination with includes operator must be a choice attribute");
|
|
@@ -187,9 +196,9 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
187
196
|
|
|
188
197
|
|
|
189
198
|
getControlAttribute(attributes) {
|
|
190
|
-
var
|
|
199
|
+
var _context8, _context9;
|
|
191
200
|
|
|
192
|
-
const attribute = attributes.getAttributeByLayoutHint(_concatInstanceProperty(
|
|
201
|
+
const attribute = attributes.getAttributeByLayoutHint(_concatInstanceProperty(_context8 = "".concat(DEPENDENT_ATTRIBUTE_CONTROL, ":")).call(_context8, this.control), _concatInstanceProperty(_context9 = "".concat(DEPENDENT_ATTRIBUTE_CONTROL, ": ")).call(_context9, 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 _context10;
|
|
226
235
|
|
|
227
|
-
throw new ConfigurationException(_concatInstanceProperty(
|
|
236
|
+
throw new ConfigurationException(_concatInstanceProperty(_context10 = "Unsupported action ".concat(this.action, " for dependent question on attribute: ")).call(_context10, 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,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;AAEA,MAAMC,IAAI,GAAG,MAAb;AACA,MAAMC,IAAI,GAAG,MAAb;AAEA;AACA;AACA;;AACA,MAAMC,kBAAN,SAAiCZ,kBAAjC,CAAoD;EAAA;IAAA;;IAAA;;IAAA;;IAAA;;IAAA;EAAA;;EAUlD;AACF;EAC4B,OAAnBa,mBAAmB,CAACC,IAAD,EAAwB;IAAA;;IAChD,MAAMC,KAAK,GAAG,IAAIC,MAAJ,mFACRd,mBADQ,4BACmBQ,IADnB,uBAC2BC,IAD3B,QAEZ,GAFY,CAAd;IAKA,OAAOI,KAAK,CAACE,IAAN,CAAWH,IAAX,CAAP;EACD;EAED;AACF;AACA;;;EACwB,OAAfI,eAAe,GAAuB;IAC3C,OAAO,IAAIN,kBAAJ,EAAP;EACD;EAED;AACF;;;EACiB,OAARO,QAAQ,CAACL,IAAD,EAAoB;IAAA;;IACjC,MAAMM,IAAI,GAAG,KAAKF,eAAL,EAAb;;IAEA,MAAMG,SAAS,qFAAMf,MAAN,cAAgBC,QAAhB,wBAA4BC,UAA5B,wBAA0CC,YAA1C,CAAf;;IACA,MAAMM,KAAK,GAAG,IAAIC,MAAJ,mFACTd,mBADS,yCAC+BD,2BAD/B,sCAC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IACAwC,SAAS,YAAYvC,qBAFvB,EAGE;MACA,OAAOuC,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,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","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,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;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FvB,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"}
|
|
@@ -7,16 +7,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
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
|
+
|
|
10
14
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
11
15
|
|
|
12
16
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
13
17
|
|
|
14
18
|
var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
|
|
15
19
|
|
|
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");
|
|
@@ -31,12 +31,29 @@ 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";
|
|
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
|
+
};
|
|
36
52
|
/**
|
|
37
53
|
* Depending attributes hint logic
|
|
38
54
|
*/
|
|
39
55
|
|
|
56
|
+
|
|
40
57
|
class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
41
58
|
constructor() {
|
|
42
59
|
super(...arguments);
|
|
@@ -149,11 +166,7 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
149
166
|
|
|
150
167
|
processEqualsOptions(controlAttribute) {
|
|
151
168
|
if (controlAttribute instanceof _ChoiceAttributeModel.default || controlAttribute instanceof _BooleanAttributeModel.default) {
|
|
152
|
-
return this.options.every(option =>
|
|
153
|
-
var _context8;
|
|
154
|
-
|
|
155
|
-
return (0, _includes.default)(_context8 = controlAttribute.selected).call(_context8, option);
|
|
156
|
-
});
|
|
169
|
+
return this.options.every(option => compareSelectedAttribute(option, controlAttribute === null || controlAttribute === void 0 ? void 0 : controlAttribute.selected));
|
|
157
170
|
}
|
|
158
171
|
|
|
159
172
|
throw new _exceptions.ConfigurationException("Dependent control in combination with equals operator must be a choice, string or number attribute");
|
|
@@ -164,11 +177,7 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
164
177
|
|
|
165
178
|
processIncludesOptions(controlAttribute) {
|
|
166
179
|
if (controlAttribute instanceof _ChoiceAttributeModel.default) {
|
|
167
|
-
return this.options.some(option =>
|
|
168
|
-
var _context9;
|
|
169
|
-
|
|
170
|
-
return (0, _includes.default)(_context9 = controlAttribute.selected).call(_context9, option);
|
|
171
|
-
});
|
|
180
|
+
return this.options.some(option => compareSelectedAttribute(option, controlAttribute === null || controlAttribute === void 0 ? void 0 : controlAttribute.selected));
|
|
172
181
|
}
|
|
173
182
|
|
|
174
183
|
throw new _exceptions.ConfigurationException("Dependent control in combination with includes operator must be a choice attribute");
|
|
@@ -200,9 +209,9 @@ class DependentAttribute extends _BaseLayoutHintRule.default {
|
|
|
200
209
|
|
|
201
210
|
|
|
202
211
|
getControlAttribute(attributes) {
|
|
203
|
-
var
|
|
212
|
+
var _context8, _context9;
|
|
204
213
|
|
|
205
|
-
const attribute = attributes.getAttributeByLayoutHint((0, _concat.default)(
|
|
214
|
+
const attribute = attributes.getAttributeByLayoutHint((0, _concat.default)(_context8 = "".concat(_constants.DEPENDENT_ATTRIBUTE_CONTROL, ":")).call(_context8, this.control), (0, _concat.default)(_context9 = "".concat(_constants.DEPENDENT_ATTRIBUTE_CONTROL, ": ")).call(_context9, 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 _context10;
|
|
239
248
|
|
|
240
|
-
throw new _exceptions.ConfigurationException((0, _concat.default)(
|
|
249
|
+
throw new _exceptions.ConfigurationException((0, _concat.default)(_context10 = "Unsupported action ".concat(this.action, " for dependent question on attribute: ")).call(_context10, attribute.label));
|
|
241
250
|
}
|
|
242
251
|
}
|
|
243
252
|
|
|
@@ -18,10 +18,27 @@ 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";
|
|
24
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
|
+
|
|
25
42
|
/**
|
|
26
43
|
* Depending attributes hint logic
|
|
27
44
|
*/
|
|
@@ -137,7 +154,7 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
137
154
|
controlAttribute instanceof BooleanAttributeModel
|
|
138
155
|
) {
|
|
139
156
|
return this.options.every((option) =>
|
|
140
|
-
controlAttribute
|
|
157
|
+
compareSelectedAttribute(option, controlAttribute?.selected)
|
|
141
158
|
);
|
|
142
159
|
}
|
|
143
160
|
|
|
@@ -153,7 +170,7 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
153
170
|
): boolean {
|
|
154
171
|
if (controlAttribute instanceof ChoiceAttributeModel) {
|
|
155
172
|
return this.options.some((option) =>
|
|
156
|
-
controlAttribute
|
|
173
|
+
compareSelectedAttribute(option, controlAttribute?.selected)
|
|
157
174
|
);
|
|
158
175
|
}
|
|
159
176
|
|
|
@@ -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,GAAG,WAAnB;AACA,MAAMC,YAAY,GAAG,aAArB;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,+EAAMjB,MAAN,cAAgBC,QAAhB,wBAA4BC,UAA5B,wBAA0CC,YAA1C,CAAf;IACA,MAAMO,KAAK,GAAG,IAAIC,MAAJ,6EACTC,8BADS,yCAC+BM,sCAD/B,sCAC4ED,SAD5E,eAEZ,GAFY,CAAd;IAKA,MAAME,MAAM,GAAGV,IAAI,CAACW,KAAL,CAAWV,KAAX,CAAf;;IACA,IAAIS,MAAJ,EAAY;MACVH,IAAI,CAACK,MAAL,GAAcF,MAAM,CAAC,CAAD,CAApB;MACAH,IAAI,C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ACT,gBAAL,EAAuB;MACrB;IACD;;IAEDA,gBAAgB,CAACa,sBAAjB,CAAwCJ,UAAxC;;IACA,IAAIT,gBAAgB,CAACc,QAArB,EAA+B;MAC7BJ,SAAS,CAACK,IAAV;MACA;IACD;;IAED,MAAM7B,MAAM,GAAG,KAAKqB,cAAL,CAAoBP,gBAApB,CAAf;;IACA,IAAI,KAAKZ,MAAL,KAAgBjB,IAApB,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","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;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AApB,CAAf;;IACA,IAAI,KAAKX,MAAL,KAAgBrB,IAApB,EAA0B;MACxB0C,SAAS,CAACI,QAAV,GAAqB,CAAC3B,MAAtB;IACD,CAFD,MAEO,IAAI,KAAKE,MAAL,KAAgBpB,IAApB,EAA0B;MAC/ByC,SAAS,CAACI,QAAV,GAAqB3B,MAArB;IACD,CAFM,MAEA;MAAA;;MACL,MAAM,IAAIM,kCAAJ,gEACkB,KAAKJ,MADvB,8DACsEqB,SAAS,CAACM,KADhF,EAAN;IAGD;EACF;;AA1MiD;;8BAA9C1C,kB,4BAQqC,I;eAqM5BA,kB"}
|
package/package.json
CHANGED
|
@@ -18,10 +18,27 @@ 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";
|
|
24
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
|
+
|
|
25
42
|
/**
|
|
26
43
|
* Depending attributes hint logic
|
|
27
44
|
*/
|
|
@@ -137,7 +154,7 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
137
154
|
controlAttribute instanceof BooleanAttributeModel
|
|
138
155
|
) {
|
|
139
156
|
return this.options.every((option) =>
|
|
140
|
-
controlAttribute
|
|
157
|
+
compareSelectedAttribute(option, controlAttribute?.selected)
|
|
141
158
|
);
|
|
142
159
|
}
|
|
143
160
|
|
|
@@ -153,7 +170,7 @@ class DependentAttribute extends BaseLayoutHintRule {
|
|
|
153
170
|
): boolean {
|
|
154
171
|
if (controlAttribute instanceof ChoiceAttributeModel) {
|
|
155
172
|
return this.options.some((option) =>
|
|
156
|
-
controlAttribute
|
|
173
|
+
compareSelectedAttribute(option, controlAttribute?.selected)
|
|
157
174
|
);
|
|
158
175
|
}
|
|
159
176
|
|