@beinformed/ui 1.24.1-beta.4 → 1.24.1-beta.6
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 +12 -0
- package/esm/models/attributes/ChoiceAttributeOptionCollection.js +12 -0
- package/esm/models/attributes/ChoiceAttributeOptionCollection.js.map +1 -1
- package/esm/models/href/Href.js +7 -12
- package/esm/models/href/Href.js.map +1 -1
- package/lib/models/attributes/ChoiceAttributeOptionCollection.js +12 -0
- package/lib/models/attributes/ChoiceAttributeOptionCollection.js.flow +19 -0
- package/lib/models/attributes/ChoiceAttributeOptionCollection.js.map +1 -1
- package/lib/models/attributes/__tests__/ChoiceAttributeModel.spec.js.flow +10 -2
- package/lib/models/href/Href.js +7 -12
- package/lib/models/href/Href.js.flow +10 -15
- package/lib/models/href/Href.js.map +1 -1
- package/package.json +1 -1
- package/src/models/attributes/ChoiceAttributeOptionCollection.js +19 -0
- package/src/models/attributes/__tests__/ChoiceAttributeModel.spec.js +10 -2
- package/src/models/href/Href.js +10 -15
- package/types/models/href/Href.d.ts +180 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
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.24.1-beta.6](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.24.1-beta.5...v1.24.1-beta.6) (2022-12-09)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
- **choice:** update children of taxonomy codemap or taxonomy-attribute ([1b46069](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/1b46069a481662b85e1d1d92585a3da9f1a64526))
|
|
10
|
+
|
|
11
|
+
### [1.24.1-beta.5](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.24.1-beta.4...v1.24.1-beta.5) (2022-12-09)
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
- **typescript:** improve Href for typescript typings ([1736e70](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/1736e7022183f5db2a914fb6d09ac7e25a112376))
|
|
16
|
+
|
|
5
17
|
### [1.24.1-beta.4](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.24.1-beta.3...v1.24.1-beta.4) (2022-12-06)
|
|
6
18
|
|
|
7
19
|
### Bug Fixes
|
|
@@ -273,6 +273,18 @@ class ChoiceAttributeOptionCollection extends ResourceCollection {
|
|
|
273
273
|
}
|
|
274
274
|
});
|
|
275
275
|
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
*/
|
|
279
|
+
some(callbackfn, thisArg) {
|
|
280
|
+
return this.collection.some((option, optionIndex, collectionArray) => {
|
|
281
|
+
const result = callbackfn(option, optionIndex, collectionArray);
|
|
282
|
+
if (!result && option.children) {
|
|
283
|
+
return option.children.some(callbackfn, thisArg);
|
|
284
|
+
}
|
|
285
|
+
return result;
|
|
286
|
+
});
|
|
287
|
+
}
|
|
276
288
|
}
|
|
277
289
|
export default ChoiceAttributeOptionCollection;
|
|
278
290
|
//# sourceMappingURL=ChoiceAttributeOptionCollection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChoiceAttributeOptionCollection.js","names":["ResourceCollection","ChoiceAttributeOptionModel","ListHeaderModel","DateUtil","ChoiceAttributeOptionCollection","sortOptions","_sortOptions","collection","forEach","option","children","create","data","contributions","referenceDate","now","type","addBooleanOptions","value","dynamicschema","addDynamicSchema","options","addOptions","addHeaders","all","a","b","label","localeCompare","getSelectedOptions","selectedOptions","Array","isArray","push","selected","key","toString","getOptionCount","code","foundOption","count","selectedValues","optionContributions","optionCode","addOption","optionDynamicschema","elementsContributions","addBooleanOption","defaultLabel","isBooleanType","hasAlternativeLabel","getDefaultValueForOption","layouthints","layouthint","requireDefaultValue","optionValue","optionModel","add","deselectAll","newOption","clone","select","toggle","deselect","action","setReferenceDate","date","headers","_headers","child","mergeOptions","withOptions","addNotExistingOptions","some","opt","withOption","mergeOption"],"sources":["../../../src/models/attributes/ChoiceAttributeOptionCollection.js"],"sourcesContent":["// @flow\nimport ResourceCollection from \"../base/ResourceCollection\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\nimport ListHeaderModel from \"../list/ListHeaderModel\";\n\nimport { DateUtil } from \"../../utils/datetime/DateTimeUtil\";\n\n/**\n */\nclass ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceAttributeOptionModel> {\n _headers: Array<ListHeaderModel> = [];\n _sortOptions: boolean = false;\n\n /**\n */\n set sortOptions(sortOptions: boolean) {\n this._sortOptions = sortOptions;\n\n this.collection.forEach((option) => {\n if (option.children) {\n option.children.sortOptions = sortOptions;\n }\n });\n }\n\n /**\n */\n get sortOptions(): boolean {\n return this._sortOptions;\n }\n\n /**\n */\n static create(\n data: Object = {},\n contributions: Object = {},\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const collection = new ChoiceAttributeOptionCollection();\n\n if (contributions.type === \"boolean\") {\n collection.addBooleanOptions(data.value, contributions);\n } else if (data.dynamicschema != null) {\n collection.addDynamicSchema(data, contributions, referenceDate);\n } else if (contributions.options != null) {\n collection.addOptions(data, contributions, referenceDate);\n }\n\n if (contributions.children != null) {\n collection.addHeaders(contributions.children);\n }\n\n return collection;\n }\n\n /**\n * Retrieve all items in collection\n */\n get all(): Array<ChoiceAttributeOptionModel> {\n return this.sortOptions\n ? this.collection.sort((a, b) => a.label.localeCompare(b.label))\n : this.collection;\n }\n\n /**\n */\n getSelectedOptions(data: Object): Array<string> {\n const selectedOptions = [];\n\n if (Array.isArray(data.options)) {\n selectedOptions.push(\n ...data.options\n .filter((option) => option.selected)\n .map((option) => option.key)\n );\n } else if (Array.isArray(data.value)) {\n selectedOptions.push(...data.value);\n } else if (typeof data.value === \"boolean\") {\n selectedOptions.push(data.value.toString());\n } else {\n selectedOptions.push(data.value);\n }\n\n return selectedOptions;\n }\n\n /**\n */\n getOptionCount(code: string, options: Array<Object>): number | null {\n if (Array.isArray(options)) {\n const foundOption = options.find((option) => option.key === code);\n if (foundOption) {\n return foundOption.count;\n }\n }\n\n return null;\n }\n\n /**\n */\n addOptions(\n data: Object,\n contributions: Object,\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n\n contributions.options.forEach((optionContributions) => {\n const optionCode = optionContributions.code || optionContributions.key;\n\n this.addOption(\n selectedValues,\n {\n ...optionContributions,\n count: this.getOptionCount(optionCode, data.options),\n },\n referenceDate\n );\n });\n\n return this;\n }\n\n /**\n * Create options based on data and dynamischema\n */\n addDynamicSchema(\n data: Object,\n contributions: Object,\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n data.dynamicschema.forEach((optionDynamicschema) => {\n this.addOption(\n selectedValues,\n {\n ...optionDynamicschema,\n count: this.getOptionCount(optionDynamicschema.code, data.options),\n elementsContributions: contributions.children,\n },\n referenceDate\n );\n });\n\n return this;\n }\n\n /**\n */\n addBooleanOption(\n code: \"true\" | \"false\",\n defaultLabel: string,\n data: string | Array<string>,\n options: Array<Object> = []\n ) {\n const foundOption = options.find((option) => option.code === code);\n\n const label = foundOption ? foundOption.label : defaultLabel;\n\n this.addOption(data, {\n code,\n label,\n isBooleanType: true,\n hasAlternativeLabel: foundOption != null,\n });\n }\n\n /**\n */\n getDefaultValueForOption(value: any, contributions: Object): string {\n const layouthints = contributions.layouthint ?? [];\n\n const requireDefaultValue =\n layouthints.includes(\"checkbox\") || layouthints.includes(\"toggle\");\n\n return requireDefaultValue ? \"false\" : \"\";\n }\n\n /**\n * Create two static options for true and false,\n * there might be alternative labels configured for each option value\n */\n addBooleanOptions(\n value: any,\n contributions: Object\n ): ChoiceAttributeOptionCollection {\n const optionValue =\n value == null\n ? this.getDefaultValueForOption(value, contributions)\n : value.toString();\n\n this.addBooleanOption(\"true\", \"Yes\", [optionValue], contributions.options);\n this.addBooleanOption(\"false\", \"No\", [optionValue], contributions.options);\n\n return this;\n }\n\n /**\n */\n addOption(\n data: string | Array<string>,\n contributions: Object,\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const optionModel = new ChoiceAttributeOptionModel(\n Array.isArray(data) ? data : [data],\n contributions,\n referenceDate\n );\n\n this.add(optionModel);\n\n return this;\n }\n\n /**\n * Get all options that have selected property true\n */\n get selected(): Array<ChoiceAttributeOptionModel> {\n const selectedOptions = [];\n\n this.collection.forEach((option: ChoiceAttributeOptionModel) => {\n if (option.selected && option.selected === true) {\n selectedOptions.push(option);\n }\n\n if (option.children) {\n selectedOptions.push(...option.children.selected);\n }\n });\n\n return selectedOptions;\n }\n\n /**\n * Deselect all options\n */\n deselectAll() {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n newOption.selected = false;\n\n if (newOption.children) {\n newOption.children.deselectAll();\n }\n\n return newOption;\n });\n }\n\n /**\n * Select an option by it's code\n */\n select(optionCode: string) {\n this.toggle(optionCode, \"select\");\n }\n\n /**\n * Deselect an option by it's code\n */\n deselect(optionCode: string) {\n this.toggle(optionCode, \"deselect\");\n }\n\n /**\n * Toggle an option by it's code\n */\n toggle(optionCode: string, action: \"select\" | \"deselect\") {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n if (newOption.code === optionCode) {\n newOption.selected = action === \"select\";\n } else if (newOption.children) {\n newOption.children.toggle(optionCode, action);\n }\n\n return newOption;\n });\n }\n\n /**\n */\n setReferenceDate(date: ISO_DATE): Array<ChoiceAttributeOptionModel> {\n return this.collection.map((option) => {\n option.referenceDate = date;\n if (option.children) {\n option.children.referenceDate = date;\n }\n\n return option;\n });\n }\n\n /**\n */\n set referenceDate(date: ISO_DATE) {\n this.collection = this.setReferenceDate(date);\n }\n\n /**\n */\n addHeaders(headers: Array<Object>) {\n this._headers = headers.map((child) => new ListHeaderModel(child));\n }\n\n /**\n */\n get headers(): Array<ListHeaderModel> {\n if (this._headers) {\n return this._headers;\n }\n\n return [];\n }\n\n /**\n */\n mergeOptions(\n withOptions: ChoiceAttributeOptionCollection,\n addNotExistingOptions: boolean = false\n ) {\n if (addNotExistingOptions) {\n this.collection = [\n ...this.collection,\n ...withOptions.filter(\n (option) => !this.collection.some((opt) => opt.code === option.code)\n ),\n ];\n }\n\n this.collection.forEach((option) => {\n const foundOption = withOptions.find(\n (withOption) => withOption.code === option.code\n );\n if (foundOption) {\n option.mergeOption(foundOption);\n }\n });\n }\n}\n\nexport default ChoiceAttributeOptionCollection;\n"],"mappings":";;;;;;AACA,OAAOA,kBAAkB,MAAM,4BAA4B;AAC3D,OAAOC,0BAA0B,MAAM,8BAA8B;AACrE,OAAOC,eAAe,MAAM,yBAAyB;AAErD,SAASC,QAAQ,QAAQ,mCAAmC;;AAE5D;AACA;AACA,MAAMC,+BAA+B,SAASJ,kBAAkB,CAA6B;EAAA;IAAA;IAAA,kCACxD,EAAE;IAAA,sCACb,KAAK;EAAA;EAE7B;AACF;EACE,IAAIK,WAAW,CAACA,WAAoB,EAAE;IACpC,IAAI,CAACC,YAAY,GAAGD,WAAW;IAE/B,IAAI,CAACE,UAAU,CAACC,OAAO,CAAEC,MAAM,IAAK;MAClC,IAAIA,MAAM,CAACC,QAAQ,EAAE;QACnBD,MAAM,CAACC,QAAQ,CAACL,WAAW,GAAGA,WAAW;MAC3C;IACF,CAAC,CAAC;EACJ;;EAEA;AACF;EACE,IAAIA,WAAW,GAAY;IACzB,OAAO,IAAI,CAACC,YAAY;EAC1B;;EAEA;AACF;EACE,OAAOK,MAAM,GAIsB;IAAA,IAHjCC,IAAY,uEAAG,CAAC,CAAC;IAAA,IACjBC,aAAqB,uEAAG,CAAC,CAAC;IAAA,IAC1BC,aAAuB,uEAAGX,QAAQ,CAAC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OptionCollection.js","names":["ResourceCollection","ChoiceAttributeOptionModel","ListHeaderModel","DateUtil","ChoiceAttributeOptionCollection","sortOptions","_sortOptions","collection","forEach","option","children","create","data","contributions","referenceDate","now","type","addBooleanOptions","value","dynamicschema","addDynamicSchema","options","addOptions","addHeaders","all","a","b","label","localeCompare","getSelectedOptions","selectedOptions","Array","isArray","push","selected","key","toString","getOptionCount","code","foundOption","count","selectedValues","optionContributions","optionCode","addOption","optionDynamicschema","elementsContributions","addBooleanOption","defaultLabel","isBooleanType","hasAlternativeLabel","getDefaultValueForOption","layouthints","layouthint","requireDefaultValue","optionValue","optionModel","add","deselectAll","newOption","clone","select","toggle","deselect","action","setReferenceDate","date","headers","_headers","child","mergeOptions","withOptions","addNotExistingOptions","some","opt","withOption","mergeOption","callbackfn","thisArg","optionIndex","collectionArray","result"],"sources":["../../../src/models/attributes/ChoiceAttributeOptionCollection.js"],"sourcesContent":["// @flow\nimport ResourceCollection from \"../base/ResourceCollection\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\nimport ListHeaderModel from \"../list/ListHeaderModel\";\n\nimport { DateUtil } from \"../../utils/datetime/DateTimeUtil\";\n\n/**\n */\nclass ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceAttributeOptionModel> {\n _headers: Array<ListHeaderModel> = [];\n _sortOptions: boolean = false;\n\n /**\n */\n set sortOptions(sortOptions: boolean) {\n this._sortOptions = sortOptions;\n\n this.collection.forEach((option) => {\n if (option.children) {\n option.children.sortOptions = sortOptions;\n }\n });\n }\n\n /**\n */\n get sortOptions(): boolean {\n return this._sortOptions;\n }\n\n /**\n */\n static create(\n data: Object = {},\n contributions: Object = {},\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const collection = new ChoiceAttributeOptionCollection();\n\n if (contributions.type === \"boolean\") {\n collection.addBooleanOptions(data.value, contributions);\n } else if (data.dynamicschema != null) {\n collection.addDynamicSchema(data, contributions, referenceDate);\n } else if (contributions.options != null) {\n collection.addOptions(data, contributions, referenceDate);\n }\n\n if (contributions.children != null) {\n collection.addHeaders(contributions.children);\n }\n\n return collection;\n }\n\n /**\n * Retrieve all items in collection\n */\n get all(): Array<ChoiceAttributeOptionModel> {\n return this.sortOptions\n ? this.collection.sort((a, b) => a.label.localeCompare(b.label))\n : this.collection;\n }\n\n /**\n */\n getSelectedOptions(data: Object): Array<string> {\n const selectedOptions = [];\n\n if (Array.isArray(data.options)) {\n selectedOptions.push(\n ...data.options\n .filter((option) => option.selected)\n .map((option) => option.key)\n );\n } else if (Array.isArray(data.value)) {\n selectedOptions.push(...data.value);\n } else if (typeof data.value === \"boolean\") {\n selectedOptions.push(data.value.toString());\n } else {\n selectedOptions.push(data.value);\n }\n\n return selectedOptions;\n }\n\n /**\n */\n getOptionCount(code: string, options: Array<Object>): number | null {\n if (Array.isArray(options)) {\n const foundOption = options.find((option) => option.key === code);\n if (foundOption) {\n return foundOption.count;\n }\n }\n\n return null;\n }\n\n /**\n */\n addOptions(\n data: Object,\n contributions: Object,\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n\n contributions.options.forEach((optionContributions) => {\n const optionCode = optionContributions.code || optionContributions.key;\n\n this.addOption(\n selectedValues,\n {\n ...optionContributions,\n count: this.getOptionCount(optionCode, data.options),\n },\n referenceDate\n );\n });\n\n return this;\n }\n\n /**\n * Create options based on data and dynamischema\n */\n addDynamicSchema(\n data: Object,\n contributions: Object,\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n data.dynamicschema.forEach((optionDynamicschema) => {\n this.addOption(\n selectedValues,\n {\n ...optionDynamicschema,\n count: this.getOptionCount(optionDynamicschema.code, data.options),\n elementsContributions: contributions.children,\n },\n referenceDate\n );\n });\n\n return this;\n }\n\n /**\n */\n addBooleanOption(\n code: \"true\" | \"false\",\n defaultLabel: string,\n data: string | Array<string>,\n options: Array<Object> = []\n ) {\n const foundOption = options.find((option) => option.code === code);\n\n const label = foundOption ? foundOption.label : defaultLabel;\n\n this.addOption(data, {\n code,\n label,\n isBooleanType: true,\n hasAlternativeLabel: foundOption != null,\n });\n }\n\n /**\n */\n getDefaultValueForOption(value: any, contributions: Object): string {\n const layouthints = contributions.layouthint ?? [];\n\n const requireDefaultValue =\n layouthints.includes(\"checkbox\") || layouthints.includes(\"toggle\");\n\n return requireDefaultValue ? \"false\" : \"\";\n }\n\n /**\n * Create two static options for true and false,\n * there might be alternative labels configured for each option value\n */\n addBooleanOptions(\n value: any,\n contributions: Object\n ): ChoiceAttributeOptionCollection {\n const optionValue =\n value == null\n ? this.getDefaultValueForOption(value, contributions)\n : value.toString();\n\n this.addBooleanOption(\"true\", \"Yes\", [optionValue], contributions.options);\n this.addBooleanOption(\"false\", \"No\", [optionValue], contributions.options);\n\n return this;\n }\n\n /**\n */\n addOption(\n data: string | Array<string>,\n contributions: Object,\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const optionModel = new ChoiceAttributeOptionModel(\n Array.isArray(data) ? data : [data],\n contributions,\n referenceDate\n );\n\n this.add(optionModel);\n\n return this;\n }\n\n /**\n * Get all options that have selected property true\n */\n get selected(): Array<ChoiceAttributeOptionModel> {\n const selectedOptions = [];\n\n this.collection.forEach((option: ChoiceAttributeOptionModel) => {\n if (option.selected && option.selected === true) {\n selectedOptions.push(option);\n }\n\n if (option.children) {\n selectedOptions.push(...option.children.selected);\n }\n });\n\n return selectedOptions;\n }\n\n /**\n * Deselect all options\n */\n deselectAll() {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n newOption.selected = false;\n\n if (newOption.children) {\n newOption.children.deselectAll();\n }\n\n return newOption;\n });\n }\n\n /**\n * Select an option by it's code\n */\n select(optionCode: string) {\n this.toggle(optionCode, \"select\");\n }\n\n /**\n * Deselect an option by it's code\n */\n deselect(optionCode: string) {\n this.toggle(optionCode, \"deselect\");\n }\n\n /**\n * Toggle an option by it's code\n */\n toggle(optionCode: string, action: \"select\" | \"deselect\") {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n if (newOption.code === optionCode) {\n newOption.selected = action === \"select\";\n } else if (newOption.children) {\n newOption.children.toggle(optionCode, action);\n }\n\n return newOption;\n });\n }\n\n /**\n */\n setReferenceDate(date: ISO_DATE): Array<ChoiceAttributeOptionModel> {\n return this.collection.map((option) => {\n option.referenceDate = date;\n if (option.children) {\n option.children.referenceDate = date;\n }\n\n return option;\n });\n }\n\n /**\n */\n set referenceDate(date: ISO_DATE) {\n this.collection = this.setReferenceDate(date);\n }\n\n /**\n */\n addHeaders(headers: Array<Object>) {\n this._headers = headers.map((child) => new ListHeaderModel(child));\n }\n\n /**\n */\n get headers(): Array<ListHeaderModel> {\n if (this._headers) {\n return this._headers;\n }\n\n return [];\n }\n\n /**\n */\n mergeOptions(\n withOptions: ChoiceAttributeOptionCollection,\n addNotExistingOptions: boolean = false\n ) {\n if (addNotExistingOptions) {\n this.collection = [\n ...this.collection,\n ...withOptions.filter(\n (option) => !this.collection.some((opt) => opt.code === option.code)\n ),\n ];\n }\n\n this.collection.forEach((option) => {\n const foundOption = withOptions.find(\n (withOption) => withOption.code === option.code\n );\n if (foundOption) {\n option.mergeOption(foundOption);\n }\n });\n }\n\n /**\n */\n some(\n callbackfn: (\n value: ChoiceAttributeOptionModel,\n index: number,\n array: Array<ChoiceAttributeOptionModel>\n ) => any,\n thisArg?: any\n ): boolean {\n return this.collection.some((option, optionIndex, collectionArray) => {\n const result = callbackfn(option, optionIndex, collectionArray);\n if (!result && option.children) {\n return option.children.some(callbackfn, thisArg);\n }\n return result;\n });\n }\n}\n\nexport default ChoiceAttributeOptionCollection;\n"],"mappings":";;;;;;AACA,OAAOA,kBAAkB,MAAM,4BAA4B;AAC3D,OAAOC,0BAA0B,MAAM,8BAA8B;AACrE,OAAOC,eAAe,MAAM,yBAAyB;AAErD,SAASC,QAAQ,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IAAIA,qBAAqB,EAAE;MACzB,IAAI,CAACjE,UAAU,GAAG,CAChB,GAAG,IAAI,CAACA,UAAU,EAClB,GAAG,wBAAAgE,WAAW,OAAXA,WAAW,EACX9D,MAAM,IAAK,CAAC,IAAI,CAACF,UAAU,CAACkE,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACpC,IAAI,KAAK7B,MAAM,CAAC6B,IAAI,CAAC,CACrE,CACF;IACH;IAEA,IAAI,CAAC/B,UAAU,CAACC,OAAO,CAAEC,MAAM,IAAK;MAClC,MAAM8B,WAAW,GAAG,sBAAAgC,WAAW,OAAXA,WAAW,EAC5BI,UAAU,IAAKA,UAAU,CAACrC,IAAI,KAAK7B,MAAM,CAAC6B,IAAI,CAChD;MACD,IAAIC,WAAW,EAAE;QACf9B,MAAM,CAACmE,WAAW,CAACrC,WAAW,CAAC;MACjC;IACF,CAAC,CAAC;EACJ;;EAEA;AACF;EACEkC,IAAI,CACFI,UAIQ,EACRC,OAAa,EACJ;IACT,OAAO,IAAI,CAACvE,UAAU,CAACkE,IAAI,CAAC,CAAChE,MAAM,EAAEsE,WAAW,EAAEC,eAAe,KAAK;MACpE,MAAMC,MAAM,GAAGJ,UAAU,CAACpE,MAAM,EAAEsE,WAAW,EAAEC,eAAe,CAAC;MAC/D,IAAI,CAACC,MAAM,IAAIxE,MAAM,CAACC,QAAQ,EAAE;QAC9B,OAAOD,MAAM,CAACC,QAAQ,CAAC+D,IAAI,CAACI,UAAU,EAAEC,OAAO,CAAC;MAClD;MACA,OAAOG,MAAM;IACf,CAAC,CAAC;EACJ;AACF;AAEA,eAAe7E,+BAA+B"}
|
package/esm/models/href/Href.js
CHANGED
|
@@ -15,18 +15,13 @@ class Href {
|
|
|
15
15
|
* Create a Href
|
|
16
16
|
*/
|
|
17
17
|
constructor(href, resourcetype) {
|
|
18
|
-
_defineProperty(this, "_path",
|
|
19
|
-
_defineProperty(this, "_hash",
|
|
20
|
-
_defineProperty(this, "_parameters",
|
|
21
|
-
_defineProperty(this, "_resourcetype",
|
|
22
|
-
_defineProperty(this, "_method",
|
|
23
|
-
_defineProperty(this, "_state",
|
|
24
|
-
this.
|
|
25
|
-
this.parameters = [];
|
|
26
|
-
this.hash = "";
|
|
27
|
-
this.state = null;
|
|
28
|
-
this.method = HTTP_METHODS.GET;
|
|
29
|
-
this.resourcetype = resourcetype || "";
|
|
18
|
+
_defineProperty(this, "_path", "");
|
|
19
|
+
_defineProperty(this, "_hash", "");
|
|
20
|
+
_defineProperty(this, "_parameters", []);
|
|
21
|
+
_defineProperty(this, "_resourcetype", "");
|
|
22
|
+
_defineProperty(this, "_method", HTTP_METHODS.GET);
|
|
23
|
+
_defineProperty(this, "_state", null);
|
|
24
|
+
this.resourcetype = resourcetype ?? "";
|
|
30
25
|
if (href instanceof Href) {
|
|
31
26
|
this.setFromHref(href);
|
|
32
27
|
} else if (typeof href === "string") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Href.js","names":["BASE","CONTENT_PATH","HTTP_METHODS","Parameter","IllegalArgumentException","Href","constructor","href","resourcetype","path","parameters","hash","state","method","GET","setFromHref","setFromString","setFromLocationOrObject","pathname","_path","search","addParametersFromString","Array","isArray","_parameters","param","addParameter","_name","_value","_prefix","getHashFromString","_hash","_state","getPathFromString","isChangePassword","isCamelRoute","checkAbsoluteUrl","checkAbsolute","RegExp","test","isExternal","decodedHref","decodeURI","hrefNoHash","substr","indexOf","split","forEach","paramFromString","fromString","setParameter","name","value","prefix","removeParameter","push","getParameter","hasParameter","undefined","_method","getQuerystring","withPrefix","toQuerystring","join","getQuerystringForModularUI","isModUIParameter","querystring","setState","_resourcetype","absolutepath","length","absolutehref","absolutehrefPrefixedQuerystring","startsWith","thisPath","otherPath","equals","equalsWithParameters","thisParams","toString","every","isContent","toLocation"],"sources":["../../../src/models/href/Href.js"],"sourcesContent":["// @flow\nimport { BASE, CONTENT_PATH, HTTP_METHODS } from \"../../constants/Constants\";\n\nimport Parameter from \"../parameter/Parameter\";\nimport { IllegalArgumentException } from \"../../exceptions\";\n\nimport type { LocationShape } from \"react-router\";\n\ntype HrefObject = {\n _path: string,\n _hash: string,\n _parameters: Array<Parameter>,\n _resourcetype: string,\n _method: $Keys<typeof HTTP_METHODS>,\n _state: ?{ [key: string]: any },\n pathname: ?string,\n};\n\nexport type HrefInput = Href | HrefObject | LocationShape | string;\n\n/**\n * Defines a Href with the parameters\n */\nclass Href {\n _path: string;\n _hash: string;\n _parameters: Array<Parameter>;\n _resourcetype: string;\n _method: $Keys<typeof HTTP_METHODS>;\n _state: ?{ +[key: string]: any };\n\n /**\n * Create a Href\n */\n constructor(href?: HrefInput, resourcetype?: string) {\n this.path = \"\";\n this.parameters = [];\n this.hash = \"\";\n this.state = null;\n this.method = HTTP_METHODS.GET;\n this.resourcetype = resourcetype || \"\";\n\n if (href instanceof Href) {\n this.setFromHref(href);\n } else if (typeof href === \"string\") {\n this.setFromString(href);\n } else if (typeof href === \"object\") {\n this.setFromLocationOrObject(href);\n }\n }\n\n /**\n * Set parameters from Href model input\n */\n setFromHref(href: Href) {\n this.path = href.path;\n this.parameters = href.parameters;\n this.hash = href.hash;\n this.state = href.state;\n }\n\n /**\n */\n setFromLocationOrObject(href: LocationShape | HrefObject) {\n if (typeof href[\"pathname\"] === \"string\") {\n this.path = href.pathname;\n } else if (typeof href._path === \"string\") {\n this.path = href._path;\n }\n\n if (href.search) {\n this.addParametersFromString(href.search);\n } else if (Array.isArray(href._parameters)) {\n // $FlowExpectedError[incompatible-call]\n href._parameters.map((param: Parameter) =>\n this.addParameter(param._name, param._value, param._prefix)\n );\n }\n\n if (href.hash) {\n this.hash = Href.getHashFromString(href.hash);\n } else if (typeof href._hash === \"string\") {\n this.hash = href._hash;\n }\n\n if (href.state) {\n this.state = href.state || null;\n } else if (typeof href._state === \"object\") {\n this.state = href._state;\n }\n }\n\n /**\n * Set parameters from string input\n */\n setFromString(href: string) {\n this.path = Href.getPathFromString(href);\n this.addParametersFromString(href);\n this.hash = Href.getHashFromString(href);\n }\n\n /**\n */\n get isChangePassword(): boolean {\n return this._path.includes(\"/change-password\");\n }\n\n /**\n * check if the path is referencing a camel route\n */\n static isCamelRoute(path: string): boolean {\n return (\n path.startsWith(\"/restServices\") && !path.startsWith(\"/restServices/ui\")\n );\n }\n\n /**\n */\n static checkAbsoluteUrl(href: string): boolean {\n const checkAbsolute = new RegExp(\"^(?:[a-z]+:)?//\", \"i\");\n return checkAbsolute.test(href);\n }\n\n // Check if url is relative (not checking for absolute urls with same domain)\n /**\n */\n get isExternal(): boolean {\n return Href.checkAbsoluteUrl(this.path);\n }\n\n /**\n * Retrieve the relative path part of a href string, e.g. https://www.beinformed.com/BeInformed/tab/view?q=url => /tab/view\n */\n static getPathFromString(href: string): string {\n const decodedHref = decodeURI(href);\n\n const hrefNoHash = decodedHref.includes(\"#\")\n ? decodedHref.substr(0, decodedHref.indexOf(\"#\"))\n : decodedHref;\n\n return hrefNoHash.includes(\"?\") ? hrefNoHash.split(\"?\")[0] : hrefNoHash;\n }\n\n /**\n * Retrieve hash of href string\n */\n static getHashFromString(href: string = \"\"): string {\n return href.includes(\"#\") ? href.substr(href.indexOf(\"#\") + 1) : \"\";\n }\n\n /**\n * Add a parameter for each parameter found in the querystring of an URL string, e.g. https://www.beinformed.com?q=url => q=url\n */\n addParametersFromString(href: string): Href {\n if (href.includes(\"?\")) {\n href\n .split(\"?\")[1]\n .split(\"&\")\n .forEach((param) => {\n const paramFromString = Parameter.fromString(param);\n if (paramFromString) {\n this.setParameter(\n paramFromString.name,\n paramFromString.value,\n paramFromString.prefix\n );\n }\n });\n }\n\n return this;\n }\n\n /**\n * Add a querystring parameter to the parameter collection of this Href, skips parameters that have a value of null\n */\n addParameter(name: string, value: ?string, prefix: ?string): Href {\n if (value !== null) {\n this.removeParameter(name, prefix);\n this._parameters.push(new Parameter(prefix, name, value));\n }\n\n return this;\n }\n\n /**\n * Adds or overwrites a parameter when it exists and value is not null.\n * Removes the parameter when the value is null\n */\n setParameter(name: string, value: ?string, prefix: ?string): Href {\n if (value === null) {\n this.removeParameter(name, prefix);\n } else {\n this.addParameter(name, value, prefix);\n }\n\n return this;\n }\n\n /**\n * Retrieve a parameter by it's name and (optionally) prefix\n */\n getParameter(name: string, prefix: ?string): ?Parameter {\n return this._parameters.find(\n (param) => param.prefix === prefix && param.name === name\n );\n }\n\n /**\n */\n hasParameter(name: string, prefix: ?string): boolean {\n return this.getParameter(name, prefix) !== undefined;\n }\n\n /**\n * Get request method\n */\n get method(): $Keys<typeof HTTP_METHODS> {\n return this._method;\n }\n\n /**\n * Set request method\n */\n set method(method: $Keys<typeof HTTP_METHODS>) {\n this._method = method || HTTP_METHODS.GET;\n }\n\n /**\n * Retrieve all paremters\n */\n get parameters(): Array<Parameter> {\n return this._parameters;\n }\n\n /**\n * Replace parameters of Href\n */\n set parameters(parameters: Array<Parameter>) {\n this._parameters = parameters;\n }\n\n /**\n * Remove a parameter from the parameter collection\n */\n removeParameter(name: string, prefix: ?string): Href {\n this._parameters = this._parameters.filter(\n (param) => param.prefix !== prefix || param.name !== name\n );\n\n return this;\n }\n\n /**\n * Get the parameters as a querystring, e.g. param1=value1¶m2=value2, optionally with prefix\n */\n getQuerystring(withPrefix: boolean = false): string {\n return this.parameters\n .filter((param) => param.value != null)\n .map((param) => param.toQuerystring(withPrefix))\n .join(\"&\");\n }\n\n /**\n * Retrieve a querystring that only contains parameter that can be send to the modular ui, parameters are filtered by prefix\n */\n getQuerystringForModularUI(prefix: string = \"\"): string {\n return this.parameters\n .filter(\n (param) =>\n param.isModUIParameter &&\n (!prefix || !param.prefix || param.prefix === prefix) &&\n param.value != null\n )\n .map((param) => param.toQuerystring(false))\n .join(\"&\");\n }\n\n /**\n * Retrieve all parameters from the parameter collection in a querystring style name1=value1&name2=value2, without the prefix\n */\n get querystring(): string {\n return this.getQuerystring(false);\n }\n\n /**\n * Set the path of the Href, the part before the querystring question mark\n */\n set path(path: string) {\n this._path = path;\n }\n\n /**\n * Retrieve the path\n */\n get path(): string {\n return this._path || \"\";\n }\n\n /**\n * Set hash\n */\n set hash(hash: string) {\n this._hash = hash;\n }\n\n /**\n * Retrieve hash\n */\n get hash(): string {\n return this._hash;\n }\n\n /**\n */\n set state(state: ?{ +[key: string]: any }) {\n this._state = state;\n }\n\n /**\n */\n get state(): ?{ +[key: string]: any } {\n return this._state;\n }\n\n /**\n */\n setState(state: { [key: string]: any }): Href {\n this.state = state;\n\n return this;\n }\n\n /**\n * Set resourctype\n */\n set resourcetype(resourcetype: string) {\n this._resourcetype = resourcetype;\n }\n\n /**\n * Retrieve resourceType\n */\n get resourcetype(): string {\n return this._resourcetype;\n }\n\n /**\n * Retrieve the path combined with the BASE of the application, e.g. /BeInformed\n */\n get absolutepath(): string {\n if (this.isExternal) {\n return this.path;\n }\n\n return BASE + this.path;\n }\n\n /**\n * Retrieves the combination of the path and the querystring\n */\n get href(): string {\n return this.querystring.length > 0\n ? [this.path, this.querystring].join(\"?\")\n : this.path;\n }\n\n /**\n * Getting the URL including the base path, querystring is prefixed\n */\n get absolutehref(): string {\n const querystring = this.getQuerystring(false);\n\n return querystring.length > 0\n ? [this.absolutepath, querystring].join(\"?\")\n : this.absolutepath;\n }\n\n /**\n * Getting the URL including the base path, the querystring is prefixed\n */\n get absolutehrefPrefixedQuerystring(): string {\n const querystring = this.getQuerystring(true);\n\n return querystring.length > 0\n ? [this.absolutepath, querystring].join(\"?\")\n : this.absolutepath;\n }\n\n /**\n * Checks if the URL starts within the given href\n */\n startsWith(href: Href | string): boolean {\n const thisPath = `${this.path}/`;\n const otherPath = href instanceof Href ? `${href.path}/` : href;\n\n return thisPath.startsWith(otherPath);\n }\n\n /**\n * Checks if the given Href equals this Href\n */\n equals(href: Href | string): boolean {\n if (href instanceof Href) {\n return this.path === href.path;\n }\n\n return this.path === href;\n }\n\n /**\n */\n equalsWithParameters(href: Href): boolean {\n if (!this.equals(href)) {\n return false;\n }\n\n if (href instanceof Href) {\n if (this.parameters.length !== href.parameters.length) {\n return false;\n }\n\n if (this.parameters.length === 0 && href.parameters.length === 0) {\n return true;\n }\n\n const thisParams = this.parameters.map((param) => param.toString());\n\n return href.parameters.every((param) =>\n thisParams.includes(param.toString())\n );\n }\n\n throw new IllegalArgumentException(`${href} is not an instance of Href`);\n }\n\n /**\n * Indicates if the link is a content link\n */\n get isContent(): boolean {\n return this.absolutepath.startsWith(CONTENT_PATH);\n }\n\n /**\n * Returns a complete url from the Href\n */\n toString(): string {\n return this.href;\n }\n\n /**\n */\n toLocation(): LocationShape {\n return {\n pathname: this.path,\n search: this.querystring.length > 0 ? `?${this.querystring}` : \"\",\n hash: this.hash.length > 0 ? `#${this.hash}` : \"\",\n state: this.state,\n };\n }\n}\n\nexport default Href;\n"],"mappings":";;;;;;AACA,SAASA,IAAI,EAAEC,YAAY,EAAEC,YAAY,QAAQ,2BAA2B;AAE5E,OAAOC,SAAS,MAAM,wBAAwB;AAC9C,SAASC,wBAAwB,QAAQ,kBAAkB;AAgB3D;AACA;AACA;AACA,MAAMC,IAAI,CAAC;EAQT;AACF;AACA;EACEC,WAAW,CAACC,IAAgB,EAAEC,YAAqB,EAAE;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IACnD,IAAI,CAACC,IAAI,GAAG,EAAE;IACd,IAAI,CAACC,UAAU,GAAG,EAAE;IACpB,IAAI,CAACC,IAAI,GAAG,EAAE;IACd,IAAI,CAACC,KAAK,GAAG,IAAI;IACjB,IAAI,CAACC,MAAM,GAAGX,YAAY,CAACY,GAAG;IAC9B,IAAI,CAACN,YAAY,GAAGA,YAAY,IAAI,EAAE;IAEtC,IAAID,IAAI,YAAYF,IAAI,EAAE;MACxB,IAAI,CAACU,WAAW,CAACR,IAAI,CAAC;IACxB,CAAC,MAAM,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MACnC,IAAI,CAACS,aAAa,CAACT,IAAI,CAAC;IAC1B,CAAC,MAAM,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MACnC,IAAI,CAACU,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sD,QAAQ,EAAE,CAAC,CACtC;IACH;IAEA,MAAM,IAAI3E,wBAAwB,CAAE,GAAEG,IAAK,6BAA4B,CAAC;EAC1E;;EAEA;AACF;AACA;EACE,IAAI0E,SAAS,GAAY;IAAA;IACvB,OAAO,6CAAI,CAACZ,YAAY,mBAAYpE,YAAY,CAAC;EACnD;;EAEA;AACF;AACA;EACE8E,QAAQ,GAAW;IACjB,OAAO,IAAI,CAACxE,IAAI;EAClB;;EAEA;AACF;EACE2E,UAAU,GAAkB;IAC1B,OAAO;MACLhE,QAAQ,EAAE,IAAI,CAACT,IAAI;MACnBW,MAAM,EAAE,IAAI,CAAC8C,WAAW,CAACI,MAAM,GAAG,CAAC,GAAI,IAAG,IAAI,CAACJ,WAAY,EAAC,GAAG,EAAE;MACjEvD,IAAI,EAAE,IAAI,CAACA,IAAI,CAAC2D,MAAM,GAAG,CAAC,GAAI,IAAG,IAAI,CAAC3D,IAAK,EAAC,GAAG,EAAE;MACjDC,KAAK,EAAE,IAAI,CAACA;IACd,CAAC;EACH;AACF;AAEA,eAAeP,IAAI"}
|
|
1
|
+
{"version":3,"file":"Href.js","names":["BASE","CONTENT_PATH","HTTP_METHODS","Parameter","IllegalArgumentException","Href","constructor","href","resourcetype","GET","setFromHref","setFromString","setFromLocationOrObject","path","parameters","hash","state","pathname","_path","search","addParametersFromString","Array","isArray","_parameters","param","addParameter","_name","_value","_prefix","getHashFromString","_hash","_state","getPathFromString","isChangePassword","isCamelRoute","checkAbsoluteUrl","checkAbsolute","RegExp","test","isExternal","decodedHref","decodeURI","hrefNoHash","substr","indexOf","split","forEach","paramFromString","fromString","setParameter","name","value","prefix","removeParameter","push","getParameter","hasParameter","undefined","method","_method","getQuerystring","withPrefix","toQuerystring","join","getQuerystringForModularUI","isModUIParameter","querystring","setState","_resourcetype","absolutepath","length","absolutehref","absolutehrefPrefixedQuerystring","startsWith","thisPath","otherPath","equals","equalsWithParameters","thisParams","toString","every","isContent","toLocation"],"sources":["../../../src/models/href/Href.js"],"sourcesContent":["// @flow\nimport { BASE, CONTENT_PATH, HTTP_METHODS } from \"../../constants/Constants\";\n\nimport Parameter from \"../parameter/Parameter\";\nimport { IllegalArgumentException } from \"../../exceptions\";\n\nimport type { LocationShape } from \"react-router\";\n\ntype HrefObject = {\n _path: string,\n _hash: string,\n _parameters: Array<Parameter>,\n _resourcetype: string,\n _method: $Keys<typeof HTTP_METHODS>,\n _state: ?{ [key: string]: any },\n pathname: ?string,\n};\n\nexport type HrefInput = Href | HrefObject | LocationShape | string;\n\n/**\n * Defines a Href with the parameters\n */\nclass Href {\n _path: string = \"\";\n _hash: string = \"\";\n _parameters: Array<Parameter> = [];\n _resourcetype: string = \"\";\n _method: $Keys<typeof HTTP_METHODS> = HTTP_METHODS.GET;\n _state: any = null;\n\n /**\n * Create a Href\n */\n constructor(href?: HrefInput, resourcetype?: string) {\n this.resourcetype = resourcetype ?? \"\";\n\n if (href instanceof Href) {\n this.setFromHref(href);\n } else if (typeof href === \"string\") {\n this.setFromString(href);\n } else if (typeof href === \"object\") {\n this.setFromLocationOrObject(href);\n }\n }\n\n /**\n * Set parameters from Href model input\n */\n setFromHref(href: Href) {\n this.path = href.path;\n this.parameters = href.parameters;\n this.hash = href.hash;\n this.state = href.state;\n }\n\n /**\n */\n setFromLocationOrObject(href: LocationShape | HrefObject) {\n if (typeof href[\"pathname\"] === \"string\") {\n this.path = href.pathname;\n } else if (typeof href._path === \"string\") {\n this.path = href._path;\n }\n\n if (href.search) {\n this.addParametersFromString(href.search);\n } else if (Array.isArray(href._parameters)) {\n // $FlowExpectedError[incompatible-call]\n href._parameters.map((param: Parameter) =>\n this.addParameter(param._name, param._value, param._prefix)\n );\n }\n\n if (href.hash) {\n this.hash = Href.getHashFromString(href.hash);\n } else if (typeof href._hash === \"string\") {\n this.hash = href._hash;\n }\n\n if (href.state) {\n this.state = href.state || null;\n } else if (typeof href._state === \"object\") {\n this.state = href._state;\n }\n }\n\n /**\n * Set parameters from string input\n */\n setFromString(href: string) {\n this.path = Href.getPathFromString(href);\n this.addParametersFromString(href);\n this.hash = Href.getHashFromString(href);\n }\n\n /**\n */\n get isChangePassword(): boolean {\n return this._path.includes(\"/change-password\");\n }\n\n /**\n * check if the path is referencing a camel route\n */\n static isCamelRoute(path: string): boolean {\n return (\n path.startsWith(\"/restServices\") && !path.startsWith(\"/restServices/ui\")\n );\n }\n\n /**\n */\n static checkAbsoluteUrl(href: string): boolean {\n const checkAbsolute = new RegExp(\"^(?:[a-z]+:)?//\", \"i\");\n return checkAbsolute.test(href);\n }\n\n // Check if url is relative (not checking for absolute urls with same domain)\n /**\n */\n get isExternal(): boolean {\n return Href.checkAbsoluteUrl(this.path);\n }\n\n /**\n * Retrieve the relative path part of a href string, e.g. https://www.beinformed.com/BeInformed/tab/view?q=url => /tab/view\n */\n static getPathFromString(href: string): string {\n const decodedHref = decodeURI(href);\n\n const hrefNoHash = decodedHref.includes(\"#\")\n ? decodedHref.substr(0, decodedHref.indexOf(\"#\"))\n : decodedHref;\n\n return hrefNoHash.includes(\"?\") ? hrefNoHash.split(\"?\")[0] : hrefNoHash;\n }\n\n /**\n * Retrieve hash of href string\n */\n static getHashFromString(href: string = \"\"): string {\n return href.includes(\"#\") ? href.substr(href.indexOf(\"#\") + 1) : \"\";\n }\n\n /**\n * Add a parameter for each parameter found in the querystring of an URL string, e.g. https://www.beinformed.com?q=url => q=url\n */\n addParametersFromString(href: string): Href {\n if (href.includes(\"?\")) {\n href\n .split(\"?\")[1]\n .split(\"&\")\n .forEach((param) => {\n const paramFromString = Parameter.fromString(param);\n if (paramFromString) {\n this.setParameter(\n paramFromString.name,\n paramFromString.value,\n paramFromString.prefix\n );\n }\n });\n }\n\n return this;\n }\n\n /**\n * Add a querystring parameter to the parameter collection of this Href, skips parameters that have a value of null\n */\n addParameter(name: string, value: ?string, prefix: ?string): Href {\n if (value !== null) {\n this.removeParameter(name, prefix);\n this._parameters.push(new Parameter(prefix, name, value));\n }\n\n return this;\n }\n\n /**\n * Adds or overwrites a parameter when it exists and value is not null.\n * Removes the parameter when the value is null\n */\n setParameter(name: string, value: ?string, prefix: ?string): Href {\n if (value === null) {\n this.removeParameter(name, prefix);\n } else {\n this.addParameter(name, value, prefix);\n }\n\n return this;\n }\n\n /**\n * Retrieve a parameter by it's name and (optionally) prefix\n */\n getParameter(name: string, prefix: ?string): ?Parameter {\n return this._parameters.find(\n (param) => param.prefix === prefix && param.name === name\n );\n }\n\n /**\n */\n hasParameter(name: string, prefix: ?string): boolean {\n return this.getParameter(name, prefix) !== undefined;\n }\n\n /**\n * Get request method\n */\n get method(): $Keys<typeof HTTP_METHODS> {\n return this._method;\n }\n\n /**\n * Set request method\n */\n set method(method: $Keys<typeof HTTP_METHODS>) {\n this._method = method || HTTP_METHODS.GET;\n }\n\n /**\n * Retrieve all paremters\n */\n get parameters(): Array<Parameter> {\n return this._parameters;\n }\n\n /**\n * Replace parameters of Href\n */\n set parameters(parameters: Array<Parameter>) {\n this._parameters = parameters;\n }\n\n /**\n * Remove a parameter from the parameter collection\n */\n removeParameter(name: string, prefix: ?string): Href {\n this._parameters = this._parameters.filter(\n (param) => param.prefix !== prefix || param.name !== name\n );\n\n return this;\n }\n\n /**\n * Get the parameters as a querystring, e.g. param1=value1¶m2=value2, optionally with prefix\n */\n getQuerystring(withPrefix: boolean = false): string {\n return this.parameters\n .filter((param) => param.value != null)\n .map((param) => param.toQuerystring(withPrefix))\n .join(\"&\");\n }\n\n /**\n * Retrieve a querystring that only contains parameter that can be send to the modular ui, parameters are filtered by prefix\n */\n getQuerystringForModularUI(prefix: string = \"\"): string {\n return this.parameters\n .filter(\n (param) =>\n param.isModUIParameter &&\n (!prefix || !param.prefix || param.prefix === prefix) &&\n param.value != null\n )\n .map((param) => param.toQuerystring(false))\n .join(\"&\");\n }\n\n /**\n * Retrieve all parameters from the parameter collection in a querystring style name1=value1&name2=value2, without the prefix\n */\n get querystring(): string {\n return this.getQuerystring(false);\n }\n\n /**\n * Set the path of the Href, the part before the querystring question mark\n */\n set path(path: string) {\n this._path = path;\n }\n\n /**\n * Retrieve the path\n */\n get path(): string {\n return this._path || \"\";\n }\n\n /**\n * Set hash\n */\n set hash(hash: string) {\n this._hash = hash;\n }\n\n /**\n * Retrieve hash\n */\n get hash(): string {\n return this._hash;\n }\n\n /**\n */\n set state(state: any) {\n this._state = state;\n }\n\n /**\n */\n get state(): any {\n return this._state;\n }\n\n /**\n */\n setState(state: any): Href {\n this.state = state;\n\n return this;\n }\n\n /**\n * Set resourctype\n */\n set resourcetype(resourcetype: string) {\n this._resourcetype = resourcetype;\n }\n\n /**\n * Retrieve resourceType\n */\n get resourcetype(): string {\n return this._resourcetype;\n }\n\n /**\n * Retrieve the path combined with the BASE of the application, e.g. /BeInformed\n */\n get absolutepath(): string {\n if (this.isExternal) {\n return this.path;\n }\n\n return BASE + this.path;\n }\n\n /**\n * Retrieves the combination of the path and the querystring\n */\n get href(): string {\n return this.querystring.length > 0\n ? [this.path, this.querystring].join(\"?\")\n : this.path;\n }\n\n /**\n * Getting the URL including the base path, querystring is prefixed\n */\n get absolutehref(): string {\n const querystring = this.getQuerystring(false);\n\n return querystring.length > 0\n ? [this.absolutepath, querystring].join(\"?\")\n : this.absolutepath;\n }\n\n /**\n * Getting the URL including the base path, the querystring is prefixed\n */\n get absolutehrefPrefixedQuerystring(): string {\n const querystring = this.getQuerystring(true);\n\n return querystring.length > 0\n ? [this.absolutepath, querystring].join(\"?\")\n : this.absolutepath;\n }\n\n /**\n * Checks if the URL starts within the given href\n */\n startsWith(href: Href | string): boolean {\n const thisPath = `${this.path}/`;\n const otherPath = href instanceof Href ? `${href.path}/` : href;\n\n return thisPath.startsWith(otherPath);\n }\n\n /**\n * Checks if the given Href equals this Href\n */\n equals(href: Href | string): boolean {\n if (href instanceof Href) {\n return this.path === href.path;\n }\n\n return this.path === href;\n }\n\n /**\n */\n equalsWithParameters(href: Href): boolean {\n if (!this.equals(href)) {\n return false;\n }\n\n if (href instanceof Href) {\n if (this.parameters.length !== href.parameters.length) {\n return false;\n }\n\n if (this.parameters.length === 0 && href.parameters.length === 0) {\n return true;\n }\n\n const thisParams = this.parameters.map((param) => param.toString());\n\n return href.parameters.every((param) =>\n thisParams.includes(param.toString())\n );\n }\n\n throw new IllegalArgumentException(`${href} is not an instance of Href`);\n }\n\n /**\n * Indicates if the link is a content link\n */\n get isContent(): boolean {\n return this.absolutepath.startsWith(CONTENT_PATH);\n }\n\n /**\n * Returns a complete url from the Href\n */\n toString(): string {\n return this.href;\n }\n\n /**\n */\n toLocation(): LocationShape {\n return {\n pathname: this.path,\n search: this.querystring.length > 0 ? `?${this.querystring}` : \"\",\n hash: this.hash.length > 0 ? `#${this.hash}` : \"\",\n state: this.state,\n };\n }\n}\n\nexport default Href;\n"],"mappings":";;;;;;AACA,SAASA,IAAI,EAAEC,YAAY,EAAEC,YAAY,QAAQ,2BAA2B;AAE5E,OAAOC,SAAS,MAAM,wBAAwB;AAC9C,SAASC,wBAAwB,QAAQ,kBAAkB;AAgB3D;AACA;AACA;AACA,MAAMC,IAAI,CAAC;EAQT;AACF;AACA;EACEC,WAAW,CAACC,IAAgB,EAAEC,YAAqB,EAAE;IAAA,+BAVrC,EAAE;IAAA,+BACF,EAAE;IAAA,qCACc,EAAE;IAAA,uCACV,EAAE;IAAA,iCACYN,YAAY,CAACO,GAAG;IAAA,gCACxC,IAAI;IAMhB,IAAI,CAACD,YAAY,GAAGA,YAAY,IAAI,EAAE;IAEtC,IAAID,IAAI,YAAYF,IAAI,EAAE;MACxB,IAAI,CAACK,WAAW,CAACH,IAAI,CAAC;IACxB,CAAC,MAAM,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MACnC,IAAI,CAACI,aAAa,CAACJ,IAAI,CAAC;IAC1B,CAAC,MAAM,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MACnC,IAAI,CAACK,uBAAuB,CAACL,IAAI,CAAC;IACpC;EACF;;EAEA;AACF;AACA;EACEG,WAAW,CAACH,IAAU,EAAE;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A;EACE,IAAI0E,SAAS,GAAY;IAAA;IACvB,OAAO,6CAAI,CAACZ,YAAY,mBAAYpE,YAAY,CAAC;EACnD;;EAEA;AACF;AACA;EACE8E,QAAQ,GAAW;IACjB,OAAO,IAAI,CAACxE,IAAI;EAClB;;EAEA;AACF;EACE2E,UAAU,GAAkB;IAC1B,OAAO;MACLjE,QAAQ,EAAE,IAAI,CAACJ,IAAI;MACnBM,MAAM,EAAE,IAAI,CAAC+C,WAAW,CAACI,MAAM,GAAG,CAAC,GAAI,IAAG,IAAI,CAACJ,WAAY,EAAC,GAAG,EAAE;MACjEnD,IAAI,EAAE,IAAI,CAACA,IAAI,CAACuD,MAAM,GAAG,CAAC,GAAI,IAAG,IAAI,CAACvD,IAAK,EAAC,GAAG,EAAE;MACjDC,KAAK,EAAE,IAAI,CAACA;IACd,CAAC;EACH;AACF;AAEA,eAAeX,IAAI"}
|
|
@@ -279,6 +279,18 @@ class ChoiceAttributeOptionCollection extends _ResourceCollection.default {
|
|
|
279
279
|
}
|
|
280
280
|
});
|
|
281
281
|
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
*/
|
|
285
|
+
some(callbackfn, thisArg) {
|
|
286
|
+
return this.collection.some((option, optionIndex, collectionArray) => {
|
|
287
|
+
const result = callbackfn(option, optionIndex, collectionArray);
|
|
288
|
+
if (!result && option.children) {
|
|
289
|
+
return option.children.some(callbackfn, thisArg);
|
|
290
|
+
}
|
|
291
|
+
return result;
|
|
292
|
+
});
|
|
293
|
+
}
|
|
282
294
|
}
|
|
283
295
|
var _default = ChoiceAttributeOptionCollection;
|
|
284
296
|
exports.default = _default;
|
|
@@ -340,6 +340,25 @@ class ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceAttribute
|
|
|
340
340
|
}
|
|
341
341
|
});
|
|
342
342
|
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
*/
|
|
346
|
+
some(
|
|
347
|
+
callbackfn: (
|
|
348
|
+
value: ChoiceAttributeOptionModel,
|
|
349
|
+
index: number,
|
|
350
|
+
array: Array<ChoiceAttributeOptionModel>
|
|
351
|
+
) => any,
|
|
352
|
+
thisArg?: any
|
|
353
|
+
): boolean {
|
|
354
|
+
return this.collection.some((option, optionIndex, collectionArray) => {
|
|
355
|
+
const result = callbackfn(option, optionIndex, collectionArray);
|
|
356
|
+
if (!result && option.children) {
|
|
357
|
+
return option.children.some(callbackfn, thisArg);
|
|
358
|
+
}
|
|
359
|
+
return result;
|
|
360
|
+
});
|
|
361
|
+
}
|
|
343
362
|
}
|
|
344
363
|
|
|
345
364
|
export default ChoiceAttributeOptionCollection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChoiceAttributeOptionCollection.js","names":["ChoiceAttributeOptionCollection","ResourceCollection","sortOptions","_sortOptions","collection","forEach","option","children","create","data","contributions","referenceDate","DateUtil","now","type","addBooleanOptions","value","dynamicschema","addDynamicSchema","options","addOptions","addHeaders","all","a","b","label","localeCompare","getSelectedOptions","selectedOptions","Array","isArray","push","selected","key","toString","getOptionCount","code","foundOption","count","selectedValues","optionContributions","optionCode","addOption","optionDynamicschema","elementsContributions","addBooleanOption","defaultLabel","isBooleanType","hasAlternativeLabel","getDefaultValueForOption","layouthints","layouthint","requireDefaultValue","optionValue","optionModel","ChoiceAttributeOptionModel","add","deselectAll","newOption","clone","select","toggle","deselect","action","setReferenceDate","date","headers","_headers","child","ListHeaderModel","mergeOptions","withOptions","addNotExistingOptions","some","opt","withOption","mergeOption"],"sources":["../../../src/models/attributes/ChoiceAttributeOptionCollection.js"],"sourcesContent":["// @flow\nimport ResourceCollection from \"../base/ResourceCollection\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\nimport ListHeaderModel from \"../list/ListHeaderModel\";\n\nimport { DateUtil } from \"../../utils/datetime/DateTimeUtil\";\n\n/**\n */\nclass ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceAttributeOptionModel> {\n _headers: Array<ListHeaderModel> = [];\n _sortOptions: boolean = false;\n\n /**\n */\n set sortOptions(sortOptions: boolean) {\n this._sortOptions = sortOptions;\n\n this.collection.forEach((option) => {\n if (option.children) {\n option.children.sortOptions = sortOptions;\n }\n });\n }\n\n /**\n */\n get sortOptions(): boolean {\n return this._sortOptions;\n }\n\n /**\n */\n static create(\n data: Object = {},\n contributions: Object = {},\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const collection = new ChoiceAttributeOptionCollection();\n\n if (contributions.type === \"boolean\") {\n collection.addBooleanOptions(data.value, contributions);\n } else if (data.dynamicschema != null) {\n collection.addDynamicSchema(data, contributions, referenceDate);\n } else if (contributions.options != null) {\n collection.addOptions(data, contributions, referenceDate);\n }\n\n if (contributions.children != null) {\n collection.addHeaders(contributions.children);\n }\n\n return collection;\n }\n\n /**\n * Retrieve all items in collection\n */\n get all(): Array<ChoiceAttributeOptionModel> {\n return this.sortOptions\n ? this.collection.sort((a, b) => a.label.localeCompare(b.label))\n : this.collection;\n }\n\n /**\n */\n getSelectedOptions(data: Object): Array<string> {\n const selectedOptions = [];\n\n if (Array.isArray(data.options)) {\n selectedOptions.push(\n ...data.options\n .filter((option) => option.selected)\n .map((option) => option.key)\n );\n } else if (Array.isArray(data.value)) {\n selectedOptions.push(...data.value);\n } else if (typeof data.value === \"boolean\") {\n selectedOptions.push(data.value.toString());\n } else {\n selectedOptions.push(data.value);\n }\n\n return selectedOptions;\n }\n\n /**\n */\n getOptionCount(code: string, options: Array<Object>): number | null {\n if (Array.isArray(options)) {\n const foundOption = options.find((option) => option.key === code);\n if (foundOption) {\n return foundOption.count;\n }\n }\n\n return null;\n }\n\n /**\n */\n addOptions(\n data: Object,\n contributions: Object,\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n\n contributions.options.forEach((optionContributions) => {\n const optionCode = optionContributions.code || optionContributions.key;\n\n this.addOption(\n selectedValues,\n {\n ...optionContributions,\n count: this.getOptionCount(optionCode, data.options),\n },\n referenceDate\n );\n });\n\n return this;\n }\n\n /**\n * Create options based on data and dynamischema\n */\n addDynamicSchema(\n data: Object,\n contributions: Object,\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n data.dynamicschema.forEach((optionDynamicschema) => {\n this.addOption(\n selectedValues,\n {\n ...optionDynamicschema,\n count: this.getOptionCount(optionDynamicschema.code, data.options),\n elementsContributions: contributions.children,\n },\n referenceDate\n );\n });\n\n return this;\n }\n\n /**\n */\n addBooleanOption(\n code: \"true\" | \"false\",\n defaultLabel: string,\n data: string | Array<string>,\n options: Array<Object> = []\n ) {\n const foundOption = options.find((option) => option.code === code);\n\n const label = foundOption ? foundOption.label : defaultLabel;\n\n this.addOption(data, {\n code,\n label,\n isBooleanType: true,\n hasAlternativeLabel: foundOption != null,\n });\n }\n\n /**\n */\n getDefaultValueForOption(value: any, contributions: Object): string {\n const layouthints = contributions.layouthint ?? [];\n\n const requireDefaultValue =\n layouthints.includes(\"checkbox\") || layouthints.includes(\"toggle\");\n\n return requireDefaultValue ? \"false\" : \"\";\n }\n\n /**\n * Create two static options for true and false,\n * there might be alternative labels configured for each option value\n */\n addBooleanOptions(\n value: any,\n contributions: Object\n ): ChoiceAttributeOptionCollection {\n const optionValue =\n value == null\n ? this.getDefaultValueForOption(value, contributions)\n : value.toString();\n\n this.addBooleanOption(\"true\", \"Yes\", [optionValue], contributions.options);\n this.addBooleanOption(\"false\", \"No\", [optionValue], contributions.options);\n\n return this;\n }\n\n /**\n */\n addOption(\n data: string | Array<string>,\n contributions: Object,\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const optionModel = new ChoiceAttributeOptionModel(\n Array.isArray(data) ? data : [data],\n contributions,\n referenceDate\n );\n\n this.add(optionModel);\n\n return this;\n }\n\n /**\n * Get all options that have selected property true\n */\n get selected(): Array<ChoiceAttributeOptionModel> {\n const selectedOptions = [];\n\n this.collection.forEach((option: ChoiceAttributeOptionModel) => {\n if (option.selected && option.selected === true) {\n selectedOptions.push(option);\n }\n\n if (option.children) {\n selectedOptions.push(...option.children.selected);\n }\n });\n\n return selectedOptions;\n }\n\n /**\n * Deselect all options\n */\n deselectAll() {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n newOption.selected = false;\n\n if (newOption.children) {\n newOption.children.deselectAll();\n }\n\n return newOption;\n });\n }\n\n /**\n * Select an option by it's code\n */\n select(optionCode: string) {\n this.toggle(optionCode, \"select\");\n }\n\n /**\n * Deselect an option by it's code\n */\n deselect(optionCode: string) {\n this.toggle(optionCode, \"deselect\");\n }\n\n /**\n * Toggle an option by it's code\n */\n toggle(optionCode: string, action: \"select\" | \"deselect\") {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n if (newOption.code === optionCode) {\n newOption.selected = action === \"select\";\n } else if (newOption.children) {\n newOption.children.toggle(optionCode, action);\n }\n\n return newOption;\n });\n }\n\n /**\n */\n setReferenceDate(date: ISO_DATE): Array<ChoiceAttributeOptionModel> {\n return this.collection.map((option) => {\n option.referenceDate = date;\n if (option.children) {\n option.children.referenceDate = date;\n }\n\n return option;\n });\n }\n\n /**\n */\n set referenceDate(date: ISO_DATE) {\n this.collection = this.setReferenceDate(date);\n }\n\n /**\n */\n addHeaders(headers: Array<Object>) {\n this._headers = headers.map((child) => new ListHeaderModel(child));\n }\n\n /**\n */\n get headers(): Array<ListHeaderModel> {\n if (this._headers) {\n return this._headers;\n }\n\n return [];\n }\n\n /**\n */\n mergeOptions(\n withOptions: ChoiceAttributeOptionCollection,\n addNotExistingOptions: boolean = false\n ) {\n if (addNotExistingOptions) {\n this.collection = [\n ...this.collection,\n ...withOptions.filter(\n (option) => !this.collection.some((opt) => opt.code === option.code)\n ),\n ];\n }\n\n this.collection.forEach((option) => {\n const foundOption = withOptions.find(\n (withOption) => withOption.code === option.code\n );\n if (foundOption) {\n option.mergeOption(foundOption);\n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F;EACEG,YAAY,CACVC,WAA4C,EAE5C;IAAA,IADAC,qBAA8B,uEAAG,KAAK;IAEtC,IAAIA,qBAAqB,EAAE;MACzB,IAAI,CAACpE,UAAU,GAAG,CAChB,GAAG,IAAI,CAACA,UAAU,EAClB,GAAG,qBAAAmE,WAAW,OAAXA,WAAW,EACXjE,MAAM,IAAK,CAAC,IAAI,CAACF,UAAU,CAACqE,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACtC,IAAI,KAAK9B,MAAM,CAAC8B,IAAI,CAAC,CACrE,CACF;IACH;IAEA,IAAI,CAAChC,UAAU,CAACC,OAAO,CAAEC,MAAM,IAAK;MAClC,MAAM+B,WAAW,GAAG,mBAAAkC,WAAW,OAAXA,WAAW,EAC5BI,UAAU,IAAKA,UAAU,CAACvC,IAAI,KAAK9B,MAAM,CAAC8B,IAAI,CAChD;MACD,IAAIC,WAAW,EAAE;QACf/B,MAAM,CAACsE,WAAW,CAACvC,WAAW,CAAC;MACjC;IACF,CAAC,CAAC;EACJ;AACF;AAAC,eAEcrC,+BAA+B;AAAA"}
|
|
1
|
+
{"version":3,"file":"ChoiceAttributeOptionCollection.js","names":["ChoiceAttributeOptionCollection","ResourceCollection","sortOptions","_sortOptions","collection","forEach","option","children","create","data","contributions","referenceDate","DateUtil","now","type","addBooleanOptions","value","dynamicschema","addDynamicSchema","options","addOptions","addHeaders","all","a","b","label","localeCompare","getSelectedOptions","selectedOptions","Array","isArray","push","selected","key","toString","getOptionCount","code","foundOption","count","selectedValues","optionContributions","optionCode","addOption","optionDynamicschema","elementsContributions","addBooleanOption","defaultLabel","isBooleanType","hasAlternativeLabel","getDefaultValueForOption","layouthints","layouthint","requireDefaultValue","optionValue","optionModel","ChoiceAttributeOptionModel","add","deselectAll","newOption","clone","select","toggle","deselect","action","setReferenceDate","date","headers","_headers","child","ListHeaderModel","mergeOptions","withOptions","addNotExistingOptions","some","opt","withOption","mergeOption","callbackfn","thisArg","optionIndex","collectionArray","result"],"sources":["../../../src/models/attributes/ChoiceAttributeOptionCollection.js"],"sourcesContent":["// @flow\nimport ResourceCollection from \"../base/ResourceCollection\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\nimport ListHeaderModel from \"../list/ListHeaderModel\";\n\nimport { DateUtil } from \"../../utils/datetime/DateTimeUtil\";\n\n/**\n */\nclass ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceAttributeOptionModel> {\n _headers: Array<ListHeaderModel> = [];\n _sortOptions: boolean = false;\n\n /**\n */\n set sortOptions(sortOptions: boolean) {\n this._sortOptions = sortOptions;\n\n this.collection.forEach((option) => {\n if (option.children) {\n option.children.sortOptions = sortOptions;\n }\n });\n }\n\n /**\n */\n get sortOptions(): boolean {\n return this._sortOptions;\n }\n\n /**\n */\n static create(\n data: Object = {},\n contributions: Object = {},\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const collection = new ChoiceAttributeOptionCollection();\n\n if (contributions.type === \"boolean\") {\n collection.addBooleanOptions(data.value, contributions);\n } else if (data.dynamicschema != null) {\n collection.addDynamicSchema(data, contributions, referenceDate);\n } else if (contributions.options != null) {\n collection.addOptions(data, contributions, referenceDate);\n }\n\n if (contributions.children != null) {\n collection.addHeaders(contributions.children);\n }\n\n return collection;\n }\n\n /**\n * Retrieve all items in collection\n */\n get all(): Array<ChoiceAttributeOptionModel> {\n return this.sortOptions\n ? this.collection.sort((a, b) => a.label.localeCompare(b.label))\n : this.collection;\n }\n\n /**\n */\n getSelectedOptions(data: Object): Array<string> {\n const selectedOptions = [];\n\n if (Array.isArray(data.options)) {\n selectedOptions.push(\n ...data.options\n .filter((option) => option.selected)\n .map((option) => option.key)\n );\n } else if (Array.isArray(data.value)) {\n selectedOptions.push(...data.value);\n } else if (typeof data.value === \"boolean\") {\n selectedOptions.push(data.value.toString());\n } else {\n selectedOptions.push(data.value);\n }\n\n return selectedOptions;\n }\n\n /**\n */\n getOptionCount(code: string, options: Array<Object>): number | null {\n if (Array.isArray(options)) {\n const foundOption = options.find((option) => option.key === code);\n if (foundOption) {\n return foundOption.count;\n }\n }\n\n return null;\n }\n\n /**\n */\n addOptions(\n data: Object,\n contributions: Object,\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n\n contributions.options.forEach((optionContributions) => {\n const optionCode = optionContributions.code || optionContributions.key;\n\n this.addOption(\n selectedValues,\n {\n ...optionContributions,\n count: this.getOptionCount(optionCode, data.options),\n },\n referenceDate\n );\n });\n\n return this;\n }\n\n /**\n * Create options based on data and dynamischema\n */\n addDynamicSchema(\n data: Object,\n contributions: Object,\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const selectedValues = this.getSelectedOptions(data);\n data.dynamicschema.forEach((optionDynamicschema) => {\n this.addOption(\n selectedValues,\n {\n ...optionDynamicschema,\n count: this.getOptionCount(optionDynamicschema.code, data.options),\n elementsContributions: contributions.children,\n },\n referenceDate\n );\n });\n\n return this;\n }\n\n /**\n */\n addBooleanOption(\n code: \"true\" | \"false\",\n defaultLabel: string,\n data: string | Array<string>,\n options: Array<Object> = []\n ) {\n const foundOption = options.find((option) => option.code === code);\n\n const label = foundOption ? foundOption.label : defaultLabel;\n\n this.addOption(data, {\n code,\n label,\n isBooleanType: true,\n hasAlternativeLabel: foundOption != null,\n });\n }\n\n /**\n */\n getDefaultValueForOption(value: any, contributions: Object): string {\n const layouthints = contributions.layouthint ?? [];\n\n const requireDefaultValue =\n layouthints.includes(\"checkbox\") || layouthints.includes(\"toggle\");\n\n return requireDefaultValue ? \"false\" : \"\";\n }\n\n /**\n * Create two static options for true and false,\n * there might be alternative labels configured for each option value\n */\n addBooleanOptions(\n value: any,\n contributions: Object\n ): ChoiceAttributeOptionCollection {\n const optionValue =\n value == null\n ? this.getDefaultValueForOption(value, contributions)\n : value.toString();\n\n this.addBooleanOption(\"true\", \"Yes\", [optionValue], contributions.options);\n this.addBooleanOption(\"false\", \"No\", [optionValue], contributions.options);\n\n return this;\n }\n\n /**\n */\n addOption(\n data: string | Array<string>,\n contributions: Object,\n referenceDate: ISO_DATE = DateUtil.now()\n ): ChoiceAttributeOptionCollection {\n const optionModel = new ChoiceAttributeOptionModel(\n Array.isArray(data) ? data : [data],\n contributions,\n referenceDate\n );\n\n this.add(optionModel);\n\n return this;\n }\n\n /**\n * Get all options that have selected property true\n */\n get selected(): Array<ChoiceAttributeOptionModel> {\n const selectedOptions = [];\n\n this.collection.forEach((option: ChoiceAttributeOptionModel) => {\n if (option.selected && option.selected === true) {\n selectedOptions.push(option);\n }\n\n if (option.children) {\n selectedOptions.push(...option.children.selected);\n }\n });\n\n return selectedOptions;\n }\n\n /**\n * Deselect all options\n */\n deselectAll() {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n newOption.selected = false;\n\n if (newOption.children) {\n newOption.children.deselectAll();\n }\n\n return newOption;\n });\n }\n\n /**\n * Select an option by it's code\n */\n select(optionCode: string) {\n this.toggle(optionCode, \"select\");\n }\n\n /**\n * Deselect an option by it's code\n */\n deselect(optionCode: string) {\n this.toggle(optionCode, \"deselect\");\n }\n\n /**\n * Toggle an option by it's code\n */\n toggle(optionCode: string, action: \"select\" | \"deselect\") {\n this.collection = this.collection.map((option) => {\n const newOption = option.clone();\n\n if (newOption.code === optionCode) {\n newOption.selected = action === \"select\";\n } else if (newOption.children) {\n newOption.children.toggle(optionCode, action);\n }\n\n return newOption;\n });\n }\n\n /**\n */\n setReferenceDate(date: ISO_DATE): Array<ChoiceAttributeOptionModel> {\n return this.collection.map((option) => {\n option.referenceDate = date;\n if (option.children) {\n option.children.referenceDate = date;\n }\n\n return option;\n });\n }\n\n /**\n */\n set referenceDate(date: ISO_DATE) {\n this.collection = this.setReferenceDate(date);\n }\n\n /**\n */\n addHeaders(headers: Array<Object>) {\n this._headers = headers.map((child) => new ListHeaderModel(child));\n }\n\n /**\n */\n get headers(): Array<ListHeaderModel> {\n if (this._headers) {\n return this._headers;\n }\n\n return [];\n }\n\n /**\n */\n mergeOptions(\n withOptions: ChoiceAttributeOptionCollection,\n addNotExistingOptions: boolean = false\n ) {\n if (addNotExistingOptions) {\n this.collection = [\n ...this.collection,\n ...withOptions.filter(\n (option) => !this.collection.some((opt) => opt.code === option.code)\n ),\n ];\n }\n\n this.collection.forEach((option) => {\n const foundOption = withOptions.find(\n (withOption) => withOption.code === option.code\n );\n if (foundOption) {\n option.mergeOption(foundOption);\n }\n });\n }\n\n /**\n */\n some(\n callbackfn: (\n value: ChoiceAttributeOptionModel,\n index: number,\n array: Array<ChoiceAttributeOptionModel>\n ) => any,\n thisArg?: any\n ): boolean {\n return this.collection.some((option, optionIndex, collectionArray) => {\n const result = callbackfn(option, optionIndex, collectionArray);\n if (!result && option.children) {\n return option.children.some(callbackfn, thisArg);\n }\n return result;\n });\n }\n}\n\nexport default ChoiceAttributeOptionCollection;\n"],"mappings":";;;;;;;;;;;;;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA,MAAMA,+BAA+B,SAASC,2BAAkB,CAA6B;EAAA;IAAA;IAAA,gDACxD,EAAE;IAAA,oDACb,KAAK;EAAA;EAE7B;AACF;EACE,IAAIC,WAAW,CAACA,WAAoB,EAAE;IACpC,IAAI,CAACC,YAAY,GAAGD,WAAW;IAE/B,IAAI,CAACE,UAAU,CAACC,OAAO,CAAEC,MAAM,IAAK;MAClC,IAAIA,MAAM,CAACC,QAAQ,EAAE;QACnBD,MAAM,CAACC,QAAQ,CAACL,WAAW,GAAGA,WAAW;MAC3C;IACF,CAAC,CAAC;EACJ;;EAEA;AACF;EACE,IAAIA,WAAW,GAAY;IACzB,OAAO,IAAI,CAACC,YAAY;EAC1B;;EAEA;AACF;EACE,OAAOK,MAAM,GAIsB;IAAA,IAHjCC,IAAY,uEAAG,CAAC,CAAC;IAAA,IACjBC,aAAqB,uEAAG,CAAC,CAAC;IAAA,IAC1BC,aAAuB,uEAAGC,sBAAQ,CAACC,GAAG,EAAE;IAExC,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1E,UAAU,CAACqE,IAAI,CAAC,CAACnE,MAAM,EAAEyE,WAAW,EAAEC,eAAe,KAAK;MACpE,MAAMC,MAAM,GAAGJ,UAAU,CAACvE,MAAM,EAAEyE,WAAW,EAAEC,eAAe,CAAC;MAC/D,IAAI,CAACC,MAAM,IAAI3E,MAAM,CAACC,QAAQ,EAAE;QAC9B,OAAOD,MAAM,CAACC,QAAQ,CAACkE,IAAI,CAACI,UAAU,EAAEC,OAAO,CAAC;MAClD;MACA,OAAOG,MAAM;IACf,CAAC,CAAC;EACJ;AACF;AAAC,eAEcjF,+BAA+B;AAAA"}
|
|
@@ -364,8 +364,8 @@ describe("choiceAttributeModel", () => {
|
|
|
364
364
|
label: "Taxonomy Native Country",
|
|
365
365
|
type: "string",
|
|
366
366
|
mandatory: false,
|
|
367
|
-
multiplechoice:
|
|
368
|
-
layouthint: ["
|
|
367
|
+
multiplechoice: true,
|
|
368
|
+
layouthint: ["checkbox"],
|
|
369
369
|
enumerated: true,
|
|
370
370
|
options: [
|
|
371
371
|
{
|
|
@@ -399,6 +399,14 @@ describe("choiceAttributeModel", () => {
|
|
|
399
399
|
expect(attribute.options.first.children).toHaveLength(4);
|
|
400
400
|
expect(attribute.readonlyvalue).toBe("United Kingdom");
|
|
401
401
|
expect(attribute.isTree).toBeTruthy();
|
|
402
|
+
|
|
403
|
+
attribute.update(["Netherlands", "Germany"]);
|
|
404
|
+
expect(attribute.readonlyvalue).toBe(
|
|
405
|
+
"Netherlands, United Kingdom, Germany"
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
attribute.update(["UnitedKingdom"]);
|
|
409
|
+
expect(attribute.readonlyvalue).toBe("Netherlands, Germany");
|
|
402
410
|
});
|
|
403
411
|
|
|
404
412
|
it("can create a choice attribute from choice filter input", () => {
|
package/lib/models/href/Href.js
CHANGED
|
@@ -22,18 +22,13 @@ class Href {
|
|
|
22
22
|
* Create a Href
|
|
23
23
|
*/
|
|
24
24
|
constructor(href, resourcetype) {
|
|
25
|
-
(0, _defineProperty2.default)(this, "_path",
|
|
26
|
-
(0, _defineProperty2.default)(this, "_hash",
|
|
27
|
-
(0, _defineProperty2.default)(this, "_parameters",
|
|
28
|
-
(0, _defineProperty2.default)(this, "_resourcetype",
|
|
29
|
-
(0, _defineProperty2.default)(this, "_method",
|
|
30
|
-
(0, _defineProperty2.default)(this, "_state",
|
|
31
|
-
this.
|
|
32
|
-
this.parameters = [];
|
|
33
|
-
this.hash = "";
|
|
34
|
-
this.state = null;
|
|
35
|
-
this.method = _Constants.HTTP_METHODS.GET;
|
|
36
|
-
this.resourcetype = resourcetype || "";
|
|
25
|
+
(0, _defineProperty2.default)(this, "_path", "");
|
|
26
|
+
(0, _defineProperty2.default)(this, "_hash", "");
|
|
27
|
+
(0, _defineProperty2.default)(this, "_parameters", []);
|
|
28
|
+
(0, _defineProperty2.default)(this, "_resourcetype", "");
|
|
29
|
+
(0, _defineProperty2.default)(this, "_method", _Constants.HTTP_METHODS.GET);
|
|
30
|
+
(0, _defineProperty2.default)(this, "_state", null);
|
|
31
|
+
this.resourcetype = resourcetype ?? "";
|
|
37
32
|
if (href instanceof Href) {
|
|
38
33
|
this.setFromHref(href);
|
|
39
34
|
} else if (typeof href === "string") {
|
|
@@ -22,23 +22,18 @@ export type HrefInput = Href | HrefObject | LocationShape | string;
|
|
|
22
22
|
* Defines a Href with the parameters
|
|
23
23
|
*/
|
|
24
24
|
class Href {
|
|
25
|
-
_path: string;
|
|
26
|
-
_hash: string;
|
|
27
|
-
_parameters: Array<Parameter
|
|
28
|
-
_resourcetype: string;
|
|
29
|
-
_method: $Keys<typeof HTTP_METHODS
|
|
30
|
-
_state:
|
|
25
|
+
_path: string = "";
|
|
26
|
+
_hash: string = "";
|
|
27
|
+
_parameters: Array<Parameter> = [];
|
|
28
|
+
_resourcetype: string = "";
|
|
29
|
+
_method: $Keys<typeof HTTP_METHODS> = HTTP_METHODS.GET;
|
|
30
|
+
_state: any = null;
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Create a Href
|
|
34
34
|
*/
|
|
35
35
|
constructor(href?: HrefInput, resourcetype?: string) {
|
|
36
|
-
this.
|
|
37
|
-
this.parameters = [];
|
|
38
|
-
this.hash = "";
|
|
39
|
-
this.state = null;
|
|
40
|
-
this.method = HTTP_METHODS.GET;
|
|
41
|
-
this.resourcetype = resourcetype || "";
|
|
36
|
+
this.resourcetype = resourcetype ?? "";
|
|
42
37
|
|
|
43
38
|
if (href instanceof Href) {
|
|
44
39
|
this.setFromHref(href);
|
|
@@ -313,19 +308,19 @@ class Href {
|
|
|
313
308
|
|
|
314
309
|
/**
|
|
315
310
|
*/
|
|
316
|
-
set state(state:
|
|
311
|
+
set state(state: any) {
|
|
317
312
|
this._state = state;
|
|
318
313
|
}
|
|
319
314
|
|
|
320
315
|
/**
|
|
321
316
|
*/
|
|
322
|
-
get state():
|
|
317
|
+
get state(): any {
|
|
323
318
|
return this._state;
|
|
324
319
|
}
|
|
325
320
|
|
|
326
321
|
/**
|
|
327
322
|
*/
|
|
328
|
-
setState(state:
|
|
323
|
+
setState(state: any): Href {
|
|
329
324
|
this.state = state;
|
|
330
325
|
|
|
331
326
|
return this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Href.js","names":["Href","constructor","href","resourcetype","path","parameters","hash","state","method","HTTP_METHODS","GET","setFromHref","setFromString","setFromLocationOrObject","pathname","_path","search","addParametersFromString","Array","isArray","_parameters","param","addParameter","_name","_value","_prefix","getHashFromString","_hash","_state","getPathFromString","isChangePassword","isCamelRoute","checkAbsoluteUrl","checkAbsolute","RegExp","test","isExternal","decodedHref","decodeURI","hrefNoHash","substr","indexOf","split","forEach","paramFromString","Parameter","fromString","setParameter","name","value","prefix","removeParameter","push","getParameter","hasParameter","undefined","_method","getQuerystring","withPrefix","toQuerystring","join","getQuerystringForModularUI","isModUIParameter","querystring","setState","_resourcetype","absolutepath","BASE","length","absolutehref","absolutehrefPrefixedQuerystring","startsWith","thisPath","otherPath","equals","equalsWithParameters","thisParams","toString","every","IllegalArgumentException","isContent","CONTENT_PATH","toLocation"],"sources":["../../../src/models/href/Href.js"],"sourcesContent":["// @flow\nimport { BASE, CONTENT_PATH, HTTP_METHODS } from \"../../constants/Constants\";\n\nimport Parameter from \"../parameter/Parameter\";\nimport { IllegalArgumentException } from \"../../exceptions\";\n\nimport type { LocationShape } from \"react-router\";\n\ntype HrefObject = {\n _path: string,\n _hash: string,\n _parameters: Array<Parameter>,\n _resourcetype: string,\n _method: $Keys<typeof HTTP_METHODS>,\n _state: ?{ [key: string]: any },\n pathname: ?string,\n};\n\nexport type HrefInput = Href | HrefObject | LocationShape | string;\n\n/**\n * Defines a Href with the parameters\n */\nclass Href {\n _path: string;\n _hash: string;\n _parameters: Array<Parameter>;\n _resourcetype: string;\n _method: $Keys<typeof HTTP_METHODS>;\n _state: ?{ +[key: string]: any };\n\n /**\n * Create a Href\n */\n constructor(href?: HrefInput, resourcetype?: string) {\n this.path = \"\";\n this.parameters = [];\n this.hash = \"\";\n this.state = null;\n this.method = HTTP_METHODS.GET;\n this.resourcetype = resourcetype || \"\";\n\n if (href instanceof Href) {\n this.setFromHref(href);\n } else if (typeof href === \"string\") {\n this.setFromString(href);\n } else if (typeof href === \"object\") {\n this.setFromLocationOrObject(href);\n }\n }\n\n /**\n * Set parameters from Href model input\n */\n setFromHref(href: Href) {\n this.path = href.path;\n this.parameters = href.parameters;\n this.hash = href.hash;\n this.state = href.state;\n }\n\n /**\n */\n setFromLocationOrObject(href: LocationShape | HrefObject) {\n if (typeof href[\"pathname\"] === \"string\") {\n this.path = href.pathname;\n } else if (typeof href._path === \"string\") {\n this.path = href._path;\n }\n\n if (href.search) {\n this.addParametersFromString(href.search);\n } else if (Array.isArray(href._parameters)) {\n // $FlowExpectedError[incompatible-call]\n href._parameters.map((param: Parameter) =>\n this.addParameter(param._name, param._value, param._prefix)\n );\n }\n\n if (href.hash) {\n this.hash = Href.getHashFromString(href.hash);\n } else if (typeof href._hash === \"string\") {\n this.hash = href._hash;\n }\n\n if (href.state) {\n this.state = href.state || null;\n } else if (typeof href._state === \"object\") {\n this.state = href._state;\n }\n }\n\n /**\n * Set parameters from string input\n */\n setFromString(href: string) {\n this.path = Href.getPathFromString(href);\n this.addParametersFromString(href);\n this.hash = Href.getHashFromString(href);\n }\n\n /**\n */\n get isChangePassword(): boolean {\n return this._path.includes(\"/change-password\");\n }\n\n /**\n * check if the path is referencing a camel route\n */\n static isCamelRoute(path: string): boolean {\n return (\n path.startsWith(\"/restServices\") && !path.startsWith(\"/restServices/ui\")\n );\n }\n\n /**\n */\n static checkAbsoluteUrl(href: string): boolean {\n const checkAbsolute = new RegExp(\"^(?:[a-z]+:)?//\", \"i\");\n return checkAbsolute.test(href);\n }\n\n // Check if url is relative (not checking for absolute urls with same domain)\n /**\n */\n get isExternal(): boolean {\n return Href.checkAbsoluteUrl(this.path);\n }\n\n /**\n * Retrieve the relative path part of a href string, e.g. https://www.beinformed.com/BeInformed/tab/view?q=url => /tab/view\n */\n static getPathFromString(href: string): string {\n const decodedHref = decodeURI(href);\n\n const hrefNoHash = decodedHref.includes(\"#\")\n ? decodedHref.substr(0, decodedHref.indexOf(\"#\"))\n : decodedHref;\n\n return hrefNoHash.includes(\"?\") ? hrefNoHash.split(\"?\")[0] : hrefNoHash;\n }\n\n /**\n * Retrieve hash of href string\n */\n static getHashFromString(href: string = \"\"): string {\n return href.includes(\"#\") ? href.substr(href.indexOf(\"#\") + 1) : \"\";\n }\n\n /**\n * Add a parameter for each parameter found in the querystring of an URL string, e.g. https://www.beinformed.com?q=url => q=url\n */\n addParametersFromString(href: string): Href {\n if (href.includes(\"?\")) {\n href\n .split(\"?\")[1]\n .split(\"&\")\n .forEach((param) => {\n const paramFromString = Parameter.fromString(param);\n if (paramFromString) {\n this.setParameter(\n paramFromString.name,\n paramFromString.value,\n paramFromString.prefix\n );\n }\n });\n }\n\n return this;\n }\n\n /**\n * Add a querystring parameter to the parameter collection of this Href, skips parameters that have a value of null\n */\n addParameter(name: string, value: ?string, prefix: ?string): Href {\n if (value !== null) {\n this.removeParameter(name, prefix);\n this._parameters.push(new Parameter(prefix, name, value));\n }\n\n return this;\n }\n\n /**\n * Adds or overwrites a parameter when it exists and value is not null.\n * Removes the parameter when the value is null\n */\n setParameter(name: string, value: ?string, prefix: ?string): Href {\n if (value === null) {\n this.removeParameter(name, prefix);\n } else {\n this.addParameter(name, value, prefix);\n }\n\n return this;\n }\n\n /**\n * Retrieve a parameter by it's name and (optionally) prefix\n */\n getParameter(name: string, prefix: ?string): ?Parameter {\n return this._parameters.find(\n (param) => param.prefix === prefix && param.name === name\n );\n }\n\n /**\n */\n hasParameter(name: string, prefix: ?string): boolean {\n return this.getParameter(name, prefix) !== undefined;\n }\n\n /**\n * Get request method\n */\n get method(): $Keys<typeof HTTP_METHODS> {\n return this._method;\n }\n\n /**\n * Set request method\n */\n set method(method: $Keys<typeof HTTP_METHODS>) {\n this._method = method || HTTP_METHODS.GET;\n }\n\n /**\n * Retrieve all paremters\n */\n get parameters(): Array<Parameter> {\n return this._parameters;\n }\n\n /**\n * Replace parameters of Href\n */\n set parameters(parameters: Array<Parameter>) {\n this._parameters = parameters;\n }\n\n /**\n * Remove a parameter from the parameter collection\n */\n removeParameter(name: string, prefix: ?string): Href {\n this._parameters = this._parameters.filter(\n (param) => param.prefix !== prefix || param.name !== name\n );\n\n return this;\n }\n\n /**\n * Get the parameters as a querystring, e.g. param1=value1¶m2=value2, optionally with prefix\n */\n getQuerystring(withPrefix: boolean = false): string {\n return this.parameters\n .filter((param) => param.value != null)\n .map((param) => param.toQuerystring(withPrefix))\n .join(\"&\");\n }\n\n /**\n * Retrieve a querystring that only contains parameter that can be send to the modular ui, parameters are filtered by prefix\n */\n getQuerystringForModularUI(prefix: string = \"\"): string {\n return this.parameters\n .filter(\n (param) =>\n param.isModUIParameter &&\n (!prefix || !param.prefix || param.prefix === prefix) &&\n param.value != null\n )\n .map((param) => param.toQuerystring(false))\n .join(\"&\");\n }\n\n /**\n * Retrieve all parameters from the parameter collection in a querystring style name1=value1&name2=value2, without the prefix\n */\n get querystring(): string {\n return this.getQuerystring(false);\n }\n\n /**\n * Set the path of the Href, the part before the querystring question mark\n */\n set path(path: string) {\n this._path = path;\n }\n\n /**\n * Retrieve the path\n */\n get path(): string {\n return this._path || \"\";\n }\n\n /**\n * Set hash\n */\n set hash(hash: string) {\n this._hash = hash;\n }\n\n /**\n * Retrieve hash\n */\n get hash(): string {\n return this._hash;\n }\n\n /**\n */\n set state(state: ?{ +[key: string]: any }) {\n this._state = state;\n }\n\n /**\n */\n get state(): ?{ +[key: string]: any } {\n return this._state;\n }\n\n /**\n */\n setState(state: { [key: string]: any }): Href {\n this.state = state;\n\n return this;\n }\n\n /**\n * Set resourctype\n */\n set resourcetype(resourcetype: string) {\n this._resourcetype = resourcetype;\n }\n\n /**\n * Retrieve resourceType\n */\n get resourcetype(): string {\n return this._resourcetype;\n }\n\n /**\n * Retrieve the path combined with the BASE of the application, e.g. /BeInformed\n */\n get absolutepath(): string {\n if (this.isExternal) {\n return this.path;\n }\n\n return BASE + this.path;\n }\n\n /**\n * Retrieves the combination of the path and the querystring\n */\n get href(): string {\n return this.querystring.length > 0\n ? [this.path, this.querystring].join(\"?\")\n : this.path;\n }\n\n /**\n * Getting the URL including the base path, querystring is prefixed\n */\n get absolutehref(): string {\n const querystring = this.getQuerystring(false);\n\n return querystring.length > 0\n ? [this.absolutepath, querystring].join(\"?\")\n : this.absolutepath;\n }\n\n /**\n * Getting the URL including the base path, the querystring is prefixed\n */\n get absolutehrefPrefixedQuerystring(): string {\n const querystring = this.getQuerystring(true);\n\n return querystring.length > 0\n ? [this.absolutepath, querystring].join(\"?\")\n : this.absolutepath;\n }\n\n /**\n * Checks if the URL starts within the given href\n */\n startsWith(href: Href | string): boolean {\n const thisPath = `${this.path}/`;\n const otherPath = href instanceof Href ? `${href.path}/` : href;\n\n return thisPath.startsWith(otherPath);\n }\n\n /**\n * Checks if the given Href equals this Href\n */\n equals(href: Href | string): boolean {\n if (href instanceof Href) {\n return this.path === href.path;\n }\n\n return this.path === href;\n }\n\n /**\n */\n equalsWithParameters(href: Href): boolean {\n if (!this.equals(href)) {\n return false;\n }\n\n if (href instanceof Href) {\n if (this.parameters.length !== href.parameters.length) {\n return false;\n }\n\n if (this.parameters.length === 0 && href.parameters.length === 0) {\n return true;\n }\n\n const thisParams = this.parameters.map((param) => param.toString());\n\n return href.parameters.every((param) =>\n thisParams.includes(param.toString())\n );\n }\n\n throw new IllegalArgumentException(`${href} is not an instance of Href`);\n }\n\n /**\n * Indicates if the link is a content link\n */\n get isContent(): boolean {\n return this.absolutepath.startsWith(CONTENT_PATH);\n }\n\n /**\n * Returns a complete url from the Href\n */\n toString(): string {\n return this.href;\n }\n\n /**\n */\n toLocation(): LocationShape {\n return {\n pathname: this.path,\n search: this.querystring.length > 0 ? `?${this.querystring}` : \"\",\n hash: this.hash.length > 0 ? `#${this.hash}` : \"\",\n state: this.state,\n };\n }\n}\n\nexport default Href;\n"],"mappings":";;;;;;;;;;;;;AACA;AAEA;AACA;AAgBA;AACA;AACA;AACA,MAAMA,IAAI,CAAC;EAQT;AACF;AACA;EACEC,WAAW,CAACC,IAAgB,EAAEC,YAAqB,EAAE;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IACnD,IAAI,CAACC,IAAI,GAAG,EAAE;IACd,IAAI,CAACC,UAAU,GAAG,EAAE;IACpB,IAAI,CAACC,IAAI,GAAG,EAAE;IACd,IAAI,CAACC,KAAK,GAAG,IAAI;IACjB,IAAI,CAACC,MAAM,GAAGC,uBAAY,CAACC,GAAG;IAC9B,IAAI,CAACP,YAAY,GAAGA,YAAY,IAAI,EAAE;IAEtC,IAAID,IAAI,YAAYF,IAAI,EAAE;MACxB,IAAI,CAACW,WAAW,CAACT,IAAI,CAAC;IACxB,CAAC,MAAM,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MACnC,IAAI,CAACU,aAAa,CAACV,IAAI,CAAC;IAC1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ACyE,KAAK,CAAEzD,KAAK,IACjC,uBAAAuD,UAAU,OAAVA,UAAU,EAAUvD,KAAK,CAACwD,QAAQ,EAAE,CAAC,CACtC;IACH;IAEA,MAAM,IAAIE,oCAAwB,CAAE,GAAE7E,IAAK,6BAA4B,CAAC;EAC1E;;EAEA;AACF;AACA;EACE,IAAI8E,SAAS,GAAY;IAAA;IACvB,OAAO,0CAAI,CAACd,YAAY,mBAAYe,uBAAY,CAAC;EACnD;;EAEA;AACF;AACA;EACEJ,QAAQ,GAAW;IACjB,OAAO,IAAI,CAAC3E,IAAI;EAClB;;EAEA;AACF;EACEgF,UAAU,GAAkB;IAC1B,OAAO;MACLpE,QAAQ,EAAE,IAAI,CAACV,IAAI;MACnBY,MAAM,EAAE,IAAI,CAAC+C,WAAW,CAACK,MAAM,GAAG,CAAC,GAAI,IAAG,IAAI,CAACL,WAAY,EAAC,GAAG,EAAE;MACjEzD,IAAI,EAAE,IAAI,CAACA,IAAI,CAAC8D,MAAM,GAAG,CAAC,GAAI,IAAG,IAAI,CAAC9D,IAAK,EAAC,GAAG,EAAE;MACjDC,KAAK,EAAE,IAAI,CAACA;IACd,CAAC;EACH;AACF;AAAC,eAEcP,IAAI;AAAA"}
|
|
1
|
+
{"version":3,"file":"Href.js","names":["Href","constructor","href","resourcetype","HTTP_METHODS","GET","setFromHref","setFromString","setFromLocationOrObject","path","parameters","hash","state","pathname","_path","search","addParametersFromString","Array","isArray","_parameters","param","addParameter","_name","_value","_prefix","getHashFromString","_hash","_state","getPathFromString","isChangePassword","isCamelRoute","checkAbsoluteUrl","checkAbsolute","RegExp","test","isExternal","decodedHref","decodeURI","hrefNoHash","substr","indexOf","split","forEach","paramFromString","Parameter","fromString","setParameter","name","value","prefix","removeParameter","push","getParameter","hasParameter","undefined","method","_method","getQuerystring","withPrefix","toQuerystring","join","getQuerystringForModularUI","isModUIParameter","querystring","setState","_resourcetype","absolutepath","BASE","length","absolutehref","absolutehrefPrefixedQuerystring","startsWith","thisPath","otherPath","equals","equalsWithParameters","thisParams","toString","every","IllegalArgumentException","isContent","CONTENT_PATH","toLocation"],"sources":["../../../src/models/href/Href.js"],"sourcesContent":["// @flow\nimport { BASE, CONTENT_PATH, HTTP_METHODS } from \"../../constants/Constants\";\n\nimport Parameter from \"../parameter/Parameter\";\nimport { IllegalArgumentException } from \"../../exceptions\";\n\nimport type { LocationShape } from \"react-router\";\n\ntype HrefObject = {\n _path: string,\n _hash: string,\n _parameters: Array<Parameter>,\n _resourcetype: string,\n _method: $Keys<typeof HTTP_METHODS>,\n _state: ?{ [key: string]: any },\n pathname: ?string,\n};\n\nexport type HrefInput = Href | HrefObject | LocationShape | string;\n\n/**\n * Defines a Href with the parameters\n */\nclass Href {\n _path: string = \"\";\n _hash: string = \"\";\n _parameters: Array<Parameter> = [];\n _resourcetype: string = \"\";\n _method: $Keys<typeof HTTP_METHODS> = HTTP_METHODS.GET;\n _state: any = null;\n\n /**\n * Create a Href\n */\n constructor(href?: HrefInput, resourcetype?: string) {\n this.resourcetype = resourcetype ?? \"\";\n\n if (href instanceof Href) {\n this.setFromHref(href);\n } else if (typeof href === \"string\") {\n this.setFromString(href);\n } else if (typeof href === \"object\") {\n this.setFromLocationOrObject(href);\n }\n }\n\n /**\n * Set parameters from Href model input\n */\n setFromHref(href: Href) {\n this.path = href.path;\n this.parameters = href.parameters;\n this.hash = href.hash;\n this.state = href.state;\n }\n\n /**\n */\n setFromLocationOrObject(href: LocationShape | HrefObject) {\n if (typeof href[\"pathname\"] === \"string\") {\n this.path = href.pathname;\n } else if (typeof href._path === \"string\") {\n this.path = href._path;\n }\n\n if (href.search) {\n this.addParametersFromString(href.search);\n } else if (Array.isArray(href._parameters)) {\n // $FlowExpectedError[incompatible-call]\n href._parameters.map((param: Parameter) =>\n this.addParameter(param._name, param._value, param._prefix)\n );\n }\n\n if (href.hash) {\n this.hash = Href.getHashFromString(href.hash);\n } else if (typeof href._hash === \"string\") {\n this.hash = href._hash;\n }\n\n if (href.state) {\n this.state = href.state || null;\n } else if (typeof href._state === \"object\") {\n this.state = href._state;\n }\n }\n\n /**\n * Set parameters from string input\n */\n setFromString(href: string) {\n this.path = Href.getPathFromString(href);\n this.addParametersFromString(href);\n this.hash = Href.getHashFromString(href);\n }\n\n /**\n */\n get isChangePassword(): boolean {\n return this._path.includes(\"/change-password\");\n }\n\n /**\n * check if the path is referencing a camel route\n */\n static isCamelRoute(path: string): boolean {\n return (\n path.startsWith(\"/restServices\") && !path.startsWith(\"/restServices/ui\")\n );\n }\n\n /**\n */\n static checkAbsoluteUrl(href: string): boolean {\n const checkAbsolute = new RegExp(\"^(?:[a-z]+:)?//\", \"i\");\n return checkAbsolute.test(href);\n }\n\n // Check if url is relative (not checking for absolute urls with same domain)\n /**\n */\n get isExternal(): boolean {\n return Href.checkAbsoluteUrl(this.path);\n }\n\n /**\n * Retrieve the relative path part of a href string, e.g. https://www.beinformed.com/BeInformed/tab/view?q=url => /tab/view\n */\n static getPathFromString(href: string): string {\n const decodedHref = decodeURI(href);\n\n const hrefNoHash = decodedHref.includes(\"#\")\n ? decodedHref.substr(0, decodedHref.indexOf(\"#\"))\n : decodedHref;\n\n return hrefNoHash.includes(\"?\") ? hrefNoHash.split(\"?\")[0] : hrefNoHash;\n }\n\n /**\n * Retrieve hash of href string\n */\n static getHashFromString(href: string = \"\"): string {\n return href.includes(\"#\") ? href.substr(href.indexOf(\"#\") + 1) : \"\";\n }\n\n /**\n * Add a parameter for each parameter found in the querystring of an URL string, e.g. https://www.beinformed.com?q=url => q=url\n */\n addParametersFromString(href: string): Href {\n if (href.includes(\"?\")) {\n href\n .split(\"?\")[1]\n .split(\"&\")\n .forEach((param) => {\n const paramFromString = Parameter.fromString(param);\n if (paramFromString) {\n this.setParameter(\n paramFromString.name,\n paramFromString.value,\n paramFromString.prefix\n );\n }\n });\n }\n\n return this;\n }\n\n /**\n * Add a querystring parameter to the parameter collection of this Href, skips parameters that have a value of null\n */\n addParameter(name: string, value: ?string, prefix: ?string): Href {\n if (value !== null) {\n this.removeParameter(name, prefix);\n this._parameters.push(new Parameter(prefix, name, value));\n }\n\n return this;\n }\n\n /**\n * Adds or overwrites a parameter when it exists and value is not null.\n * Removes the parameter when the value is null\n */\n setParameter(name: string, value: ?string, prefix: ?string): Href {\n if (value === null) {\n this.removeParameter(name, prefix);\n } else {\n this.addParameter(name, value, prefix);\n }\n\n return this;\n }\n\n /**\n * Retrieve a parameter by it's name and (optionally) prefix\n */\n getParameter(name: string, prefix: ?string): ?Parameter {\n return this._parameters.find(\n (param) => param.prefix === prefix && param.name === name\n );\n }\n\n /**\n */\n hasParameter(name: string, prefix: ?string): boolean {\n return this.getParameter(name, prefix) !== undefined;\n }\n\n /**\n * Get request method\n */\n get method(): $Keys<typeof HTTP_METHODS> {\n return this._method;\n }\n\n /**\n * Set request method\n */\n set method(method: $Keys<typeof HTTP_METHODS>) {\n this._method = method || HTTP_METHODS.GET;\n }\n\n /**\n * Retrieve all paremters\n */\n get parameters(): Array<Parameter> {\n return this._parameters;\n }\n\n /**\n * Replace parameters of Href\n */\n set parameters(parameters: Array<Parameter>) {\n this._parameters = parameters;\n }\n\n /**\n * Remove a parameter from the parameter collection\n */\n removeParameter(name: string, prefix: ?string): Href {\n this._parameters = this._parameters.filter(\n (param) => param.prefix !== prefix || param.name !== name\n );\n\n return this;\n }\n\n /**\n * Get the parameters as a querystring, e.g. param1=value1¶m2=value2, optionally with prefix\n */\n getQuerystring(withPrefix: boolean = false): string {\n return this.parameters\n .filter((param) => param.value != null)\n .map((param) => param.toQuerystring(withPrefix))\n .join(\"&\");\n }\n\n /**\n * Retrieve a querystring that only contains parameter that can be send to the modular ui, parameters are filtered by prefix\n */\n getQuerystringForModularUI(prefix: string = \"\"): string {\n return this.parameters\n .filter(\n (param) =>\n param.isModUIParameter &&\n (!prefix || !param.prefix || param.prefix === prefix) &&\n param.value != null\n )\n .map((param) => param.toQuerystring(false))\n .join(\"&\");\n }\n\n /**\n * Retrieve all parameters from the parameter collection in a querystring style name1=value1&name2=value2, without the prefix\n */\n get querystring(): string {\n return this.getQuerystring(false);\n }\n\n /**\n * Set the path of the Href, the part before the querystring question mark\n */\n set path(path: string) {\n this._path = path;\n }\n\n /**\n * Retrieve the path\n */\n get path(): string {\n return this._path || \"\";\n }\n\n /**\n * Set hash\n */\n set hash(hash: string) {\n this._hash = hash;\n }\n\n /**\n * Retrieve hash\n */\n get hash(): string {\n return this._hash;\n }\n\n /**\n */\n set state(state: any) {\n this._state = state;\n }\n\n /**\n */\n get state(): any {\n return this._state;\n }\n\n /**\n */\n setState(state: any): Href {\n this.state = state;\n\n return this;\n }\n\n /**\n * Set resourctype\n */\n set resourcetype(resourcetype: string) {\n this._resourcetype = resourcetype;\n }\n\n /**\n * Retrieve resourceType\n */\n get resourcetype(): string {\n return this._resourcetype;\n }\n\n /**\n * Retrieve the path combined with the BASE of the application, e.g. /BeInformed\n */\n get absolutepath(): string {\n if (this.isExternal) {\n return this.path;\n }\n\n return BASE + this.path;\n }\n\n /**\n * Retrieves the combination of the path and the querystring\n */\n get href(): string {\n return this.querystring.length > 0\n ? [this.path, this.querystring].join(\"?\")\n : this.path;\n }\n\n /**\n * Getting the URL including the base path, querystring is prefixed\n */\n get absolutehref(): string {\n const querystring = this.getQuerystring(false);\n\n return querystring.length > 0\n ? [this.absolutepath, querystring].join(\"?\")\n : this.absolutepath;\n }\n\n /**\n * Getting the URL including the base path, the querystring is prefixed\n */\n get absolutehrefPrefixedQuerystring(): string {\n const querystring = this.getQuerystring(true);\n\n return querystring.length > 0\n ? [this.absolutepath, querystring].join(\"?\")\n : this.absolutepath;\n }\n\n /**\n * Checks if the URL starts within the given href\n */\n startsWith(href: Href | string): boolean {\n const thisPath = `${this.path}/`;\n const otherPath = href instanceof Href ? `${href.path}/` : href;\n\n return thisPath.startsWith(otherPath);\n }\n\n /**\n * Checks if the given Href equals this Href\n */\n equals(href: Href | string): boolean {\n if (href instanceof Href) {\n return this.path === href.path;\n }\n\n return this.path === href;\n }\n\n /**\n */\n equalsWithParameters(href: Href): boolean {\n if (!this.equals(href)) {\n return false;\n }\n\n if (href instanceof Href) {\n if (this.parameters.length !== href.parameters.length) {\n return false;\n }\n\n if (this.parameters.length === 0 && href.parameters.length === 0) {\n return true;\n }\n\n const thisParams = this.parameters.map((param) => param.toString());\n\n return href.parameters.every((param) =>\n thisParams.includes(param.toString())\n );\n }\n\n throw new IllegalArgumentException(`${href} is not an instance of Href`);\n }\n\n /**\n * Indicates if the link is a content link\n */\n get isContent(): boolean {\n return this.absolutepath.startsWith(CONTENT_PATH);\n }\n\n /**\n * Returns a complete url from the Href\n */\n toString(): string {\n return this.href;\n }\n\n /**\n */\n toLocation(): LocationShape {\n return {\n pathname: this.path,\n search: this.querystring.length > 0 ? `?${this.querystring}` : \"\",\n hash: this.hash.length > 0 ? `#${this.hash}` : \"\",\n state: this.state,\n };\n }\n}\n\nexport default Href;\n"],"mappings":";;;;;;;;;;;;;AACA;AAEA;AACA;AAgBA;AACA;AACA;AACA,MAAMA,IAAI,CAAC;EAQT;AACF;AACA;EACEC,WAAW,CAACC,IAAgB,EAAEC,YAAqB,EAAE;IAAA,6CAVrC,EAAE;IAAA,6CACF,EAAE;IAAA,mDACc,EAAE;IAAA,qDACV,EAAE;IAAA,+CACYC,uBAAY,CAACC,GAAG;IAAA,8CACxC,IAAI;IAMhB,IAAI,CAACF,YAAY,GAAGA,YAAY,IAAI,EAAE;IAEtC,IAAID,IAAI,YAAYF,IAAI,EAAE;MACxB,IAAI,CAACM,WAAW,CAACJ,IAAI,CAAC;IACxB,CAAC,MAAM,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MACnC,IAAI,CAACK,aAAa,CAACL,IAAI,CAAC;IAC1B,CAAC,MAAM,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MACnC,IAAI,CAACM,uBAAuB,CAACN,IAAI,CAAC;IACpC;EACF;;EAEA;AACF;AACA;EACEI,WAAW,CAACJ,IAAU,EAAE;IACtB,IAAI,CAACO,IAAI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8E,SAAS,GAAY;IAAA;IACvB,OAAO,0CAAI,CAACd,YAAY,mBAAYe,uBAAY,CAAC;EACnD;;EAEA;AACF;AACA;EACEJ,QAAQ,GAAW;IACjB,OAAO,IAAI,CAAC3E,IAAI;EAClB;;EAEA;AACF;EACEgF,UAAU,GAAkB;IAC1B,OAAO;MACLrE,QAAQ,EAAE,IAAI,CAACJ,IAAI;MACnBM,MAAM,EAAE,IAAI,CAACgD,WAAW,CAACK,MAAM,GAAG,CAAC,GAAI,IAAG,IAAI,CAACL,WAAY,EAAC,GAAG,EAAE;MACjEpD,IAAI,EAAE,IAAI,CAACA,IAAI,CAACyD,MAAM,GAAG,CAAC,GAAI,IAAG,IAAI,CAACzD,IAAK,EAAC,GAAG,EAAE;MACjDC,KAAK,EAAE,IAAI,CAACA;IACd,CAAC;EACH;AACF;AAAC,eAEcZ,IAAI;AAAA"}
|
package/package.json
CHANGED
|
@@ -340,6 +340,25 @@ class ChoiceAttributeOptionCollection extends ResourceCollection<ChoiceAttribute
|
|
|
340
340
|
}
|
|
341
341
|
});
|
|
342
342
|
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
*/
|
|
346
|
+
some(
|
|
347
|
+
callbackfn: (
|
|
348
|
+
value: ChoiceAttributeOptionModel,
|
|
349
|
+
index: number,
|
|
350
|
+
array: Array<ChoiceAttributeOptionModel>
|
|
351
|
+
) => any,
|
|
352
|
+
thisArg?: any
|
|
353
|
+
): boolean {
|
|
354
|
+
return this.collection.some((option, optionIndex, collectionArray) => {
|
|
355
|
+
const result = callbackfn(option, optionIndex, collectionArray);
|
|
356
|
+
if (!result && option.children) {
|
|
357
|
+
return option.children.some(callbackfn, thisArg);
|
|
358
|
+
}
|
|
359
|
+
return result;
|
|
360
|
+
});
|
|
361
|
+
}
|
|
343
362
|
}
|
|
344
363
|
|
|
345
364
|
export default ChoiceAttributeOptionCollection;
|
|
@@ -364,8 +364,8 @@ describe("choiceAttributeModel", () => {
|
|
|
364
364
|
label: "Taxonomy Native Country",
|
|
365
365
|
type: "string",
|
|
366
366
|
mandatory: false,
|
|
367
|
-
multiplechoice:
|
|
368
|
-
layouthint: ["
|
|
367
|
+
multiplechoice: true,
|
|
368
|
+
layouthint: ["checkbox"],
|
|
369
369
|
enumerated: true,
|
|
370
370
|
options: [
|
|
371
371
|
{
|
|
@@ -399,6 +399,14 @@ describe("choiceAttributeModel", () => {
|
|
|
399
399
|
expect(attribute.options.first.children).toHaveLength(4);
|
|
400
400
|
expect(attribute.readonlyvalue).toBe("United Kingdom");
|
|
401
401
|
expect(attribute.isTree).toBeTruthy();
|
|
402
|
+
|
|
403
|
+
attribute.update(["Netherlands", "Germany"]);
|
|
404
|
+
expect(attribute.readonlyvalue).toBe(
|
|
405
|
+
"Netherlands, United Kingdom, Germany"
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
attribute.update(["UnitedKingdom"]);
|
|
409
|
+
expect(attribute.readonlyvalue).toBe("Netherlands, Germany");
|
|
402
410
|
});
|
|
403
411
|
|
|
404
412
|
it("can create a choice attribute from choice filter input", () => {
|
package/src/models/href/Href.js
CHANGED
|
@@ -22,23 +22,18 @@ export type HrefInput = Href | HrefObject | LocationShape | string;
|
|
|
22
22
|
* Defines a Href with the parameters
|
|
23
23
|
*/
|
|
24
24
|
class Href {
|
|
25
|
-
_path: string;
|
|
26
|
-
_hash: string;
|
|
27
|
-
_parameters: Array<Parameter
|
|
28
|
-
_resourcetype: string;
|
|
29
|
-
_method: $Keys<typeof HTTP_METHODS
|
|
30
|
-
_state:
|
|
25
|
+
_path: string = "";
|
|
26
|
+
_hash: string = "";
|
|
27
|
+
_parameters: Array<Parameter> = [];
|
|
28
|
+
_resourcetype: string = "";
|
|
29
|
+
_method: $Keys<typeof HTTP_METHODS> = HTTP_METHODS.GET;
|
|
30
|
+
_state: any = null;
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Create a Href
|
|
34
34
|
*/
|
|
35
35
|
constructor(href?: HrefInput, resourcetype?: string) {
|
|
36
|
-
this.
|
|
37
|
-
this.parameters = [];
|
|
38
|
-
this.hash = "";
|
|
39
|
-
this.state = null;
|
|
40
|
-
this.method = HTTP_METHODS.GET;
|
|
41
|
-
this.resourcetype = resourcetype || "";
|
|
36
|
+
this.resourcetype = resourcetype ?? "";
|
|
42
37
|
|
|
43
38
|
if (href instanceof Href) {
|
|
44
39
|
this.setFromHref(href);
|
|
@@ -313,19 +308,19 @@ class Href {
|
|
|
313
308
|
|
|
314
309
|
/**
|
|
315
310
|
*/
|
|
316
|
-
set state(state:
|
|
311
|
+
set state(state: any) {
|
|
317
312
|
this._state = state;
|
|
318
313
|
}
|
|
319
314
|
|
|
320
315
|
/**
|
|
321
316
|
*/
|
|
322
|
-
get state():
|
|
317
|
+
get state(): any {
|
|
323
318
|
return this._state;
|
|
324
319
|
}
|
|
325
320
|
|
|
326
321
|
/**
|
|
327
322
|
*/
|
|
328
|
-
setState(state:
|
|
323
|
+
setState(state: any): Href {
|
|
329
324
|
this.state = state;
|
|
330
325
|
|
|
331
326
|
return this;
|
|
@@ -4,6 +4,25 @@ export default Href;
|
|
|
4
4
|
* Defines a Href with the parameters
|
|
5
5
|
*/
|
|
6
6
|
declare class Href {
|
|
7
|
+
/**
|
|
8
|
+
* check if the path is referencing a camel route
|
|
9
|
+
*/
|
|
10
|
+
static isCamelRoute(path: string): boolean;
|
|
11
|
+
/**
|
|
12
|
+
*/
|
|
13
|
+
static checkAbsoluteUrl(href: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Retrieve the relative path part of a href string, e.g. https://www.beinformed.com/BeInformed/tab/view?q=url => /tab/view
|
|
16
|
+
*/
|
|
17
|
+
static getPathFromString(href: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Retrieve hash of href string
|
|
20
|
+
*/
|
|
21
|
+
static getHashFromString(href?: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Create a Href
|
|
24
|
+
*/
|
|
25
|
+
constructor(href?: HrefInput, resourcetype?: string);
|
|
7
26
|
_path: string;
|
|
8
27
|
_hash: string;
|
|
9
28
|
_parameters: Array<Parameter>;
|
|
@@ -12,6 +31,166 @@ declare class Href {
|
|
|
12
31
|
POST: string;
|
|
13
32
|
GET: string;
|
|
14
33
|
}>;
|
|
15
|
-
_state:
|
|
34
|
+
_state: any;
|
|
35
|
+
/**
|
|
36
|
+
* Set resourctype
|
|
37
|
+
*/
|
|
38
|
+
set resourcetype(arg: string);
|
|
39
|
+
/**
|
|
40
|
+
* Retrieve resourceType
|
|
41
|
+
*/
|
|
42
|
+
get resourcetype(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Set parameters from Href model input
|
|
45
|
+
*/
|
|
46
|
+
setFromHref(href: Href): void;
|
|
47
|
+
/**
|
|
48
|
+
* Set the path of the Href, the part before the querystring question mark
|
|
49
|
+
*/
|
|
50
|
+
set path(arg: string);
|
|
51
|
+
/**
|
|
52
|
+
* Retrieve the path
|
|
53
|
+
*/
|
|
54
|
+
get path(): string;
|
|
55
|
+
/**
|
|
56
|
+
* Replace parameters of Href
|
|
57
|
+
*/
|
|
58
|
+
set parameters(arg: Parameter[]);
|
|
59
|
+
/**
|
|
60
|
+
* Retrieve all paremters
|
|
61
|
+
*/
|
|
62
|
+
get parameters(): Parameter[];
|
|
63
|
+
/**
|
|
64
|
+
* Set hash
|
|
65
|
+
*/
|
|
66
|
+
set hash(arg: string);
|
|
67
|
+
/**
|
|
68
|
+
* Retrieve hash
|
|
69
|
+
*/
|
|
70
|
+
get hash(): string;
|
|
71
|
+
/**
|
|
72
|
+
*/
|
|
73
|
+
set state(arg: any);
|
|
74
|
+
/**
|
|
75
|
+
*/
|
|
76
|
+
get state(): any;
|
|
77
|
+
/**
|
|
78
|
+
*/
|
|
79
|
+
setFromLocationOrObject(href: LocationShape | HrefObject): void;
|
|
80
|
+
/**
|
|
81
|
+
* Set parameters from string input
|
|
82
|
+
*/
|
|
83
|
+
setFromString(href: string): void;
|
|
84
|
+
/**
|
|
85
|
+
*/
|
|
86
|
+
get isChangePassword(): boolean;
|
|
87
|
+
/**
|
|
88
|
+
*/
|
|
89
|
+
get isExternal(): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Add a parameter for each parameter found in the querystring of an URL string, e.g. https://www.beinformed.com?q=url => q=url
|
|
92
|
+
*/
|
|
93
|
+
addParametersFromString(href: string): Href;
|
|
94
|
+
/**
|
|
95
|
+
* Add a querystring parameter to the parameter collection of this Href, skips parameters that have a value of null
|
|
96
|
+
*/
|
|
97
|
+
addParameter(name: string, value: string | null, prefix: string | null): Href;
|
|
98
|
+
/**
|
|
99
|
+
* Adds or overwrites a parameter when it exists and value is not null.
|
|
100
|
+
* Removes the parameter when the value is null
|
|
101
|
+
*/
|
|
102
|
+
setParameter(name: string, value: string | null, prefix: string | null): Href;
|
|
103
|
+
/**
|
|
104
|
+
* Retrieve a parameter by it's name and (optionally) prefix
|
|
105
|
+
*/
|
|
106
|
+
getParameter(name: string, prefix: string | null): Parameter | null;
|
|
107
|
+
/**
|
|
108
|
+
*/
|
|
109
|
+
hasParameter(name: string, prefix: string | null): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Set request method
|
|
112
|
+
*/
|
|
113
|
+
set method(arg: $Keys<{
|
|
114
|
+
POST: string;
|
|
115
|
+
GET: string;
|
|
116
|
+
}>);
|
|
117
|
+
/**
|
|
118
|
+
* Get request method
|
|
119
|
+
*/
|
|
120
|
+
get method(): $Keys<{
|
|
121
|
+
POST: string;
|
|
122
|
+
GET: string;
|
|
123
|
+
}>;
|
|
124
|
+
/**
|
|
125
|
+
* Remove a parameter from the parameter collection
|
|
126
|
+
*/
|
|
127
|
+
removeParameter(name: string, prefix: string | null): Href;
|
|
128
|
+
/**
|
|
129
|
+
* Get the parameters as a querystring, e.g. param1=value1¶m2=value2, optionally with prefix
|
|
130
|
+
*/
|
|
131
|
+
getQuerystring(withPrefix?: boolean): string;
|
|
132
|
+
/**
|
|
133
|
+
* Retrieve a querystring that only contains parameter that can be send to the modular ui, parameters are filtered by prefix
|
|
134
|
+
*/
|
|
135
|
+
getQuerystringForModularUI(prefix?: string): string;
|
|
136
|
+
/**
|
|
137
|
+
* Retrieve all parameters from the parameter collection in a querystring style name1=value1&name2=value2, without the prefix
|
|
138
|
+
*/
|
|
139
|
+
get querystring(): string;
|
|
140
|
+
/**
|
|
141
|
+
*/
|
|
142
|
+
setState(state: any): Href;
|
|
143
|
+
/**
|
|
144
|
+
* Retrieve the path combined with the BASE of the application, e.g. /BeInformed
|
|
145
|
+
*/
|
|
146
|
+
get absolutepath(): string;
|
|
147
|
+
/**
|
|
148
|
+
* Retrieves the combination of the path and the querystring
|
|
149
|
+
*/
|
|
150
|
+
get href(): string;
|
|
151
|
+
/**
|
|
152
|
+
* Getting the URL including the base path, querystring is prefixed
|
|
153
|
+
*/
|
|
154
|
+
get absolutehref(): string;
|
|
155
|
+
/**
|
|
156
|
+
* Getting the URL including the base path, the querystring is prefixed
|
|
157
|
+
*/
|
|
158
|
+
get absolutehrefPrefixedQuerystring(): string;
|
|
159
|
+
/**
|
|
160
|
+
* Checks if the URL starts within the given href
|
|
161
|
+
*/
|
|
162
|
+
startsWith(href: Href | string): boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Checks if the given Href equals this Href
|
|
165
|
+
*/
|
|
166
|
+
equals(href: Href | string): boolean;
|
|
167
|
+
/**
|
|
168
|
+
*/
|
|
169
|
+
equalsWithParameters(href: Href): boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Indicates if the link is a content link
|
|
172
|
+
*/
|
|
173
|
+
get isContent(): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Returns a complete url from the Href
|
|
176
|
+
*/
|
|
177
|
+
toString(): string;
|
|
178
|
+
/**
|
|
179
|
+
*/
|
|
180
|
+
toLocation(): LocationShape;
|
|
16
181
|
}
|
|
17
182
|
import Parameter from "../parameter/Parameter";
|
|
183
|
+
type HrefObject = {
|
|
184
|
+
_path: string;
|
|
185
|
+
_hash: string;
|
|
186
|
+
_parameters: Parameter[];
|
|
187
|
+
_resourcetype: string;
|
|
188
|
+
_method: $Keys<{
|
|
189
|
+
POST: string;
|
|
190
|
+
GET: string;
|
|
191
|
+
}>;
|
|
192
|
+
_state: {
|
|
193
|
+
[key: string]: any;
|
|
194
|
+
};
|
|
195
|
+
pathname: string;
|
|
196
|
+
};
|