@beinformed/ui 1.21.2 → 1.21.5
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 +17 -6
- package/esm/models/attributes/AttributeModel.js +2 -2
- package/esm/models/attributes/AttributeModel.js.map +1 -1
- package/esm/models/attributes/ChoiceAttributeModel.js +3 -2
- package/esm/models/attributes/ChoiceAttributeModel.js.map +1 -1
- package/esm/models/attributes/DatetimeAttributeModel.js +3 -2
- package/esm/models/attributes/DatetimeAttributeModel.js.map +1 -1
- package/esm/models/error/ErrorCollection.js +7 -6
- package/esm/models/error/ErrorCollection.js.map +1 -1
- package/esm/models/error/ErrorModel.js +2 -1
- package/esm/models/error/ErrorModel.js.map +1 -1
- package/esm/models/error/ErrorResponse.js +11 -5
- package/esm/models/error/ErrorResponse.js.map +1 -1
- package/esm/models/form/FormModel.js +5 -4
- package/esm/models/form/FormModel.js.map +1 -1
- package/esm/models/form/FormObjectModel.js +1 -1
- package/esm/models/form/FormObjectModel.js.map +1 -1
- package/esm/models/grouping/GroupingModel.js +36 -8
- package/esm/models/grouping/GroupingModel.js.map +1 -1
- package/esm/models/types.js.map +1 -1
- package/lib/models/attributes/AttributeModel.js +2 -2
- package/lib/models/attributes/AttributeModel.js.flow +4 -2
- package/lib/models/attributes/AttributeModel.js.map +1 -1
- package/lib/models/attributes/ChoiceAttributeModel.js +3 -2
- package/lib/models/attributes/ChoiceAttributeModel.js.flow +2 -2
- package/lib/models/attributes/ChoiceAttributeModel.js.map +1 -1
- package/lib/models/attributes/DatetimeAttributeModel.js +3 -2
- package/lib/models/attributes/DatetimeAttributeModel.js.flow +2 -2
- package/lib/models/attributes/DatetimeAttributeModel.js.map +1 -1
- package/lib/models/error/ErrorCollection.js +7 -5
- package/lib/models/error/ErrorCollection.js.flow +8 -5
- package/lib/models/error/ErrorCollection.js.map +1 -1
- package/lib/models/error/ErrorModel.js +2 -1
- package/lib/models/error/ErrorModel.js.flow +5 -2
- package/lib/models/error/ErrorModel.js.map +1 -1
- package/lib/models/error/ErrorResponse.js +11 -5
- package/lib/models/error/ErrorResponse.js.flow +4 -4
- package/lib/models/error/ErrorResponse.js.map +1 -1
- package/lib/models/form/FormModel.js +5 -3
- package/lib/models/form/FormModel.js.flow +11 -3
- package/lib/models/form/FormModel.js.map +1 -1
- package/lib/models/form/FormObjectModel.js +1 -1
- package/lib/models/form/FormObjectModel.js.flow +2 -1
- package/lib/models/form/FormObjectModel.js.map +1 -1
- package/lib/models/grouping/GroupingModel.js +36 -8
- package/lib/models/grouping/GroupingModel.js.flow +38 -10
- package/lib/models/grouping/GroupingModel.js.map +1 -1
- package/lib/models/types.js.flow +1 -1
- package/lib/models/types.js.map +1 -1
- package/package.json +1 -1
- package/src/models/attributes/AttributeModel.js +4 -2
- package/src/models/attributes/ChoiceAttributeModel.js +2 -2
- package/src/models/attributes/DatetimeAttributeModel.js +2 -2
- package/src/models/error/ErrorCollection.js +8 -5
- package/src/models/error/ErrorModel.js +5 -2
- package/src/models/error/ErrorResponse.js +4 -4
- package/src/models/form/FormModel.js +11 -3
- package/src/models/form/FormObjectModel.js +2 -1
- package/src/models/grouping/GroupingModel.js +38 -10
- package/src/models/types.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChoiceAttributeModel.js","names":["ChoiceAttributeModel","AttributeModel","constructor","attribute","attributeContributions","_referenceDate","getData","DateUtil","now","_options","ChoiceAttributeOptionCollection","create","referenceDate","layouthint","has","SORT_OPTIONS","sortOptions","isApplicableModel","contributions","type","optionMode","getContribution","hasLookupLink","lookupLink","lookupListLink","getInitialChildModelLinks","links","hasContentConfiguration","hasContentFromData","conceptLink","push","options","setChildModels","models","conceptLinkHref","href","concept","model","selfhref","equalsWithParameters","getLinkByKey","lookupListLabel","lookupList","label","date","selected","option","code","readonlyvalue","join","initvalue","Array","isArray","_initvalue","length","getValue","hasValue","getInputValue","toggleOption","disableOption","enableOption","isMultiple","deselectAll","select","inputvalue","deselect","addOption","opt","choicetype","hint","multiplechoice","isTree","some","reset","mergeAttribute","oldAttribute","readonly","mergeOptions","isValid","update","value","updateLastModification","values","split","forEach","val","ChoiceAttributeOptionModel","equals","add","toString","_hasContentConfiguration","contentConfiguration","content","optionElements","optionElementConfig","optionElement","contentElement","RENDER_SECTION_LABEL","ContentConfigurationElements","placeholder","addServerError","error","id","message","properties","ANSWER_OPTION_KEY","optionKey","foundOption","getContentConfiguredLabel","_errorCollection","readonlyWidth","ATTRIBUTE_WIDTH","SMALL","MEDIUM"],"sources":["../../../src/models/attributes/ChoiceAttributeModel.js"],"sourcesContent":["// @flow\nimport { has } from \"../../utils/helpers/objects\";\nimport { DateUtil } from \"../../utils/datetime/DateTimeUtil\";\n\nimport AttributeModel from \"./AttributeModel\";\nimport ChoiceAttributeOptionCollection from \"./ChoiceAttributeOptionCollection\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\nimport ContentConfigurationElements from \"../contentconfiguration/ContentConfigurationElements\";\n\nimport {\n RENDER_SECTION_LABEL,\n SORT_OPTIONS,\n} from \"../../constants/LayoutHints\";\nimport { ATTRIBUTE_WIDTH } from \"../../constants\";\n\nimport type { ModularUIModel, AttributeType, FormErrorAnchor } from \"../types\";\nimport type LinkModel from \"../links/LinkModel\";\n\n/**\n * Model for a choice attribute\n */\nexport default class ChoiceAttributeModel extends AttributeModel {\n _referenceDate: ISO_DATE;\n _options: ChoiceAttributeOptionCollection;\n _hasContentConfiguration: boolean;\n\n /**\n * Constructs a choice attribute\n */\n constructor(attribute: Object, attributeContributions: Object) {\n super(attribute, attributeContributions);\n\n this._referenceDate = this.getData(\"referenceDate\", DateUtil.now());\n this._options = ChoiceAttributeOptionCollection.create(\n attribute,\n attributeContributions,\n this.referenceDate\n );\n\n if (this.layouthint.has(SORT_OPTIONS)) {\n this._options.sortOptions = true;\n }\n }\n\n /**\n */\n static isApplicableModel(contributions: Object): boolean {\n return (\n contributions.type !== \"composite\" &&\n contributions.type !== \"boolean\" &&\n (contributions.type === \"choice\" ||\n contributions.type === \"array\" ||\n has(contributions, \"enumerated\") ||\n has(contributions, \"options\"))\n );\n }\n\n /**\n */\n get type(): string {\n const optionMode = this.getContribution(\"optionMode\", \"\");\n const hasLookupLink = this.lookupLink || this.lookupListLink;\n\n if (\n optionMode === \"lookup\" ||\n (optionMode === \"dynamicWithThreshold\" && hasLookupLink)\n ) {\n return \"lookup\";\n }\n\n return \"choice\";\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n const links = [];\n\n if (this.hasContentConfiguration) {\n if (!this.hasContentFromData && this.conceptLink) {\n links.push(this.conceptLink);\n }\n\n links.push(...this.options.getInitialChildModelLinks());\n }\n\n return links;\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n const conceptLinkHref = this.conceptLink?.href;\n if (conceptLinkHref) {\n this.concept = models.find(\n (model) =>\n model.type === \"ConceptDetail\" &&\n model.selfhref.equalsWithParameters(conceptLinkHref)\n );\n }\n\n this.options.setChildModels(models);\n }\n\n /**\n * Retrieve lookup service link\n */\n get lookupLink(): LinkModel | null {\n return this.links.getLinkByKey(\"lookupOptions\");\n }\n\n /**\n * Retrieve lookup service as list link\n */\n get lookupListLink(): LinkModel | null {\n return this.links.getLinkByKey(\"lookupList\");\n }\n\n /**\n */\n get lookupListLabel(): string {\n return this.contributions.lookupList?.label ?? \"\";\n }\n\n /**\n * Retrieve reference date of attribute which can be used as entryDate for content\n */\n get referenceDate(): ISO_DATE {\n return this._referenceDate;\n }\n\n /**\n * Set reference date for concepts and content\n */\n set referenceDate(date: string) {\n this._referenceDate = date;\n\n this.options.referenceDate = date;\n }\n\n /**\n * Retrieve available choice options\n */\n get options(): ChoiceAttributeOptionCollection {\n return this._options;\n }\n\n /**\n * Getting all enabled options\n */\n get selected(): Array<string> {\n // $FlowFixMe[incompatible-call]\n return this.options.selected.map<string, ChoiceAttributeOptionModel>(\n (option: ChoiceAttributeOptionModel) => option.code\n );\n }\n\n /**\n * Flatten options and filter out the options that are not selected\n */\n get readonlyvalue(): string {\n return this.options.selected.map((option) => option.label).join(\", \");\n }\n\n /**\n */\n get initvalue(): any {\n if (Array.isArray(this._initvalue) && this._initvalue.length === 0) {\n return null;\n }\n\n return this._initvalue;\n }\n\n /**\n * Retrieve list of selected options, joined with comma\n */\n getValue(): string | null {\n return this.options.selected.length > 0\n ? this.options.selected.map((option) => option.code).join(\",\")\n : null;\n }\n\n /**\n */\n hasValue(): boolean {\n return this.options.selected.length > 0;\n }\n\n /**\n * Get input value of attribute\n */\n getInputValue(): string {\n return this.selected.join(\",\");\n }\n\n /**\n * Setting an option selected or unselected based on the current state\n */\n toggleOption(code: string) {\n if (this.selected.includes(code)) {\n this.disableOption(code);\n } else {\n this.enableOption(code);\n }\n }\n\n /**\n * Enable a option\n */\n enableOption(code: string) {\n if (!this.isMultiple) {\n this.options.deselectAll();\n }\n\n this.options.select(code);\n this.inputvalue = this.getInputValue();\n }\n\n /**\n * Disable a option\n */\n disableOption(code: string) {\n this.options.deselect(code);\n this.inputvalue = this.getInputValue();\n }\n\n /**\n * Add a new option to the collection of lookup options\n */\n addOption(option: Object) {\n if (!this.isMultiple) {\n this.options.deselectAll();\n }\n\n if (this.options.find((opt) => opt.code === option.code) === null) {\n this.options.addOption(option.code, option);\n }\n }\n\n /**\n * Getting the type of choice filter. For instance checkbox, radiobutton, combobox.\n */\n get choicetype():\n | \"checkbox\"\n | \"radiobutton\"\n | \"combobox\"\n | \"list\"\n | \"listview\"\n | \"table\"\n | \"longlist\"\n | \"toggle\" {\n return (\n [\n \"checkbox\",\n \"radiobutton\",\n \"combobox\",\n \"list\",\n \"listview\",\n \"table\",\n \"longlist\",\n \"toggle\",\n ].find((hint) => this.layouthint.has(hint)) || \"checkbox\"\n );\n }\n\n /**\n * Can multiple options be selected\n */\n get isMultiple(): boolean {\n return this.contributions.multiplechoice || this.choicetype === \"checkbox\";\n }\n\n /**\n * Check if options need to be rendered as tree\n */\n get isTree(): boolean {\n return (\n has(this.contributions, \"options\") &&\n this.contributions.options.some((option) => has(option, \"children\"))\n );\n }\n\n /**\n * Reset choice attribute to unselected list\n */\n reset() {\n this.options.deselectAll();\n }\n\n /**\n */\n mergeAttribute(oldAttribute: AttributeType) {\n // when attribute is readonly, don't merge the options no modifications necessary\n if (!this.readonly && oldAttribute instanceof ChoiceAttributeModel) {\n this.concept = oldAttribute.concept;\n this.options.mergeOptions(oldAttribute.options, this.type === \"lookup\");\n this.options.deselectAll();\n\n if (oldAttribute.isValid && oldAttribute.inputvalue !== null) {\n this.update(oldAttribute.inputvalue);\n }\n }\n }\n\n /**\n * Update attribute by name and value\n */\n update(value: any): ChoiceAttributeModel {\n if (this.readonly) {\n return this;\n }\n\n this.updateLastModification();\n\n let values;\n\n if (Array.isArray(value)) {\n values = value;\n } else if (typeof value === \"string\" && this.isMultiple) {\n values = value.split(\",\");\n } else {\n values = [value];\n }\n values.forEach((val) => {\n if (val instanceof ChoiceAttributeOptionModel) {\n if (!this.options.some((option) => option.equals(val))) {\n this.options.add(val);\n }\n\n this.toggleOption(val.code);\n } else if (\n typeof val === \"string\" &&\n this.options.some((option) => option.code.toString() === val)\n ) {\n this.toggleOption(val);\n }\n });\n\n return this;\n }\n\n /**\n */\n set hasContentConfiguration(hasContentConfiguration: boolean) {\n this._hasContentConfiguration =\n this.contentConfiguration !== null || hasContentConfiguration;\n }\n\n /**\n */\n get hasContentConfiguration(): boolean {\n return this._hasContentConfiguration;\n }\n\n /**\n * Get content configuration configured on the attribute.\n * Only applicable for taxonomy element and knowledge codemaps,\n * content configuration for instrument questions is available on the form object\n */\n get contentConfiguration(): ContentConfigurationElements | null {\n if (\n !this.contributions.content ||\n !this.contributions.content.optionElements\n ) {\n return null;\n }\n\n // Add RENDER_SECTION_LABEL to all content configuration to make sure the label of a section is always rendered on taxonomy and knowlege codemaps\n const optionElementConfig = this.contributions.content.optionElements.map(\n (optionElement) => {\n if (\"contentElement\" in optionElement) {\n return {\n contentElement: {\n ...optionElement.contentElement,\n layouthint: [RENDER_SECTION_LABEL],\n },\n };\n }\n\n return optionElement;\n }\n );\n\n return new ContentConfigurationElements(optionElementConfig);\n }\n\n /**\n * Get placeholder text\n */\n get placeholder(): string {\n return this.getContribution(\"placeholder\", \"\");\n }\n\n /**\n * Registers an error that was received from a server response\n */\n addServerError(error: FormErrorAnchor) {\n const { id, message, properties } = error;\n\n const ANSWER_OPTION_KEY = \"answer-option-key\";\n\n if (properties && has(properties, ANSWER_OPTION_KEY)) {\n const optionKey = properties[ANSWER_OPTION_KEY];\n const foundOption = this.options.find(\n (option) => option.code === optionKey\n );\n if (foundOption) {\n properties[ANSWER_OPTION_KEY] = foundOption.getContentConfiguredLabel(\n this.contentConfiguration\n );\n }\n }\n\n this._errorCollection.addServerError(id, message, properties);\n }\n\n /**\n */\n get readonlyWidth(): $Keys<typeof ATTRIBUTE_WIDTH> {\n if (this.type === \"lookup\") {\n return ATTRIBUTE_WIDTH.SMALL;\n }\n\n return ATTRIBUTE_WIDTH.MEDIUM;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAEA;;AAIA;;AAKA;AACA;AACA;AACe,MAAMA,oBAAN,SAAmCC,uBAAnC,CAAkD;EAK/D;AACF;AACA;EACEC,WAAW,CAACC,SAAD,EAAoBC,sBAApB,EAAoD;IAC7D,MAAMD,SAAN,EAAiBC,sBAAjB;IAD6D;IAAA;IAAA;IAG7D,KAAKC,cAAL,GAAsB,KAAKC,OAAL,CAAa,eAAb,EAA8BC,sBAAA,CAASC,GAAT,EAA9B,CAAtB;IACA,KAAKC,QAAL,GAAgBC,wCAAA,CAAgCC,MAAhC,CACdR,SADc,EAEdC,sBAFc,EAGd,KAAKQ,aAHS,CAAhB;;IAMA,IAAI,KAAKC,UAAL,CAAgBC,GAAhB,CAAoBC,yBAApB,CAAJ,EAAuC;MACrC,KAAKN,QAAL,CAAcO,WAAd,GAA4B,IAA5B;IACD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,cAAtB,CAAqCE,EAArC,EAAyCC,OAAzC,EAAkDC,UAAlD;EACD;EAED;AACF;;;EACmB,IAAbM,aAAa,GAAkC;IACjD,IAAI,KAAK3F,IAAL,KAAc,QAAlB,EAA4B;MAC1B,OAAO4F,0BAAA,CAAgBC,KAAvB;IACD;;IAED,OAAOD,0BAAA,CAAgBE,MAAvB;EACD;;AApZ8D"}
|
|
1
|
+
{"version":3,"file":"ChoiceAttributeModel.js","names":["ChoiceAttributeModel","AttributeModel","constructor","attribute","attributeContributions","_referenceDate","getData","DateUtil","now","_options","ChoiceAttributeOptionCollection","create","referenceDate","layouthint","has","SORT_OPTIONS","sortOptions","isApplicableModel","contributions","type","optionMode","getContribution","hasLookupLink","lookupLink","lookupListLink","getInitialChildModelLinks","links","hasContentConfiguration","hasContentFromData","conceptLink","push","options","setChildModels","models","conceptLinkHref","href","concept","model","selfhref","equalsWithParameters","getLinkByKey","lookupListLabel","lookupList","label","date","selected","option","code","readonlyvalue","join","initvalue","Array","isArray","_initvalue","length","getValue","hasValue","getInputValue","toggleOption","disableOption","enableOption","isMultiple","deselectAll","select","inputvalue","deselect","addOption","opt","choicetype","hint","multiplechoice","isTree","some","reset","mergeAttribute","oldAttribute","readonly","mergeOptions","isValid","update","value","updateLastModification","values","split","forEach","val","ChoiceAttributeOptionModel","equals","add","toString","_hasContentConfiguration","contentConfiguration","content","optionElements","optionElementConfig","optionElement","contentElement","RENDER_SECTION_LABEL","ContentConfigurationElements","placeholder","addServerError","error","id","message","properties","ANSWER_OPTION_KEY","optionKey","foundOption","getContentConfiguredLabel","_errorCollection","readonlyWidth","ATTRIBUTE_WIDTH","SMALL","MEDIUM"],"sources":["../../../src/models/attributes/ChoiceAttributeModel.js"],"sourcesContent":["// @flow\nimport { has } from \"../../utils/helpers/objects\";\nimport { DateUtil } from \"../../utils/datetime/DateTimeUtil\";\n\nimport AttributeModel from \"./AttributeModel\";\nimport ChoiceAttributeOptionCollection from \"./ChoiceAttributeOptionCollection\";\nimport ChoiceAttributeOptionModel from \"./ChoiceAttributeOptionModel\";\nimport ContentConfigurationElements from \"../contentconfiguration/ContentConfigurationElements\";\n\nimport {\n RENDER_SECTION_LABEL,\n SORT_OPTIONS,\n} from \"../../constants/LayoutHints\";\nimport { ATTRIBUTE_WIDTH } from \"../../constants\";\n\nimport type { ModularUIModel, AttributeType, FormErrorAnchor } from \"../types\";\nimport type LinkModel from \"../links/LinkModel\";\n\n/**\n * Model for a choice attribute\n */\nexport default class ChoiceAttributeModel extends AttributeModel {\n _referenceDate: ISO_DATE;\n _options: ChoiceAttributeOptionCollection;\n _hasContentConfiguration: boolean;\n\n /**\n * Constructs a choice attribute\n */\n constructor(attribute: Object, attributeContributions: Object) {\n super(attribute, attributeContributions);\n\n this._referenceDate = this.getData(\"referenceDate\", DateUtil.now());\n this._options = ChoiceAttributeOptionCollection.create(\n attribute,\n attributeContributions,\n this.referenceDate\n );\n\n if (this.layouthint.has(SORT_OPTIONS)) {\n this._options.sortOptions = true;\n }\n }\n\n /**\n */\n static isApplicableModel(contributions: Object): boolean {\n return (\n contributions.type !== \"composite\" &&\n contributions.type !== \"boolean\" &&\n (contributions.type === \"choice\" ||\n contributions.type === \"array\" ||\n has(contributions, \"enumerated\") ||\n has(contributions, \"options\"))\n );\n }\n\n /**\n */\n get type(): string {\n const optionMode = this.getContribution(\"optionMode\", \"\");\n const hasLookupLink = this.lookupLink || this.lookupListLink;\n\n if (\n optionMode === \"lookup\" ||\n (optionMode === \"dynamicWithThreshold\" && hasLookupLink)\n ) {\n return \"lookup\";\n }\n\n return \"choice\";\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n const links = [];\n\n if (this.hasContentConfiguration) {\n if (!this.hasContentFromData && this.conceptLink) {\n links.push(this.conceptLink);\n }\n\n links.push(...this.options.getInitialChildModelLinks());\n }\n\n return links;\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n const conceptLinkHref = this.conceptLink?.href;\n if (conceptLinkHref) {\n this.concept = models.find(\n (model) =>\n model.type === \"ConceptDetail\" &&\n model.selfhref.equalsWithParameters(conceptLinkHref)\n );\n }\n\n this.options.setChildModels(models);\n }\n\n /**\n * Retrieve lookup service link\n */\n get lookupLink(): LinkModel | null {\n return this.links.getLinkByKey(\"lookupOptions\");\n }\n\n /**\n * Retrieve lookup service as list link\n */\n get lookupListLink(): LinkModel | null {\n return this.links.getLinkByKey(\"lookupList\");\n }\n\n /**\n */\n get lookupListLabel(): string {\n return this.contributions.lookupList?.label ?? \"\";\n }\n\n /**\n * Retrieve reference date of attribute which can be used as entryDate for content\n */\n get referenceDate(): ISO_DATE {\n return this._referenceDate;\n }\n\n /**\n * Set reference date for concepts and content\n */\n set referenceDate(date: string) {\n this._referenceDate = date;\n\n this.options.referenceDate = date;\n }\n\n /**\n * Retrieve available choice options\n */\n get options(): ChoiceAttributeOptionCollection {\n return this._options;\n }\n\n /**\n * Getting all enabled options\n */\n get selected(): Array<string> {\n // $FlowFixMe[incompatible-call]\n return this.options.selected.map<string, ChoiceAttributeOptionModel>(\n (option: ChoiceAttributeOptionModel) => option.code\n );\n }\n\n /**\n * Flatten options and filter out the options that are not selected\n */\n get readonlyvalue(): string {\n return this.options.selected.map((option) => option.label).join(\", \");\n }\n\n /**\n */\n get initvalue(): any {\n if (Array.isArray(this._initvalue) && this._initvalue.length === 0) {\n return null;\n }\n\n return this._initvalue;\n }\n\n /**\n * Retrieve list of selected options, joined with comma\n */\n getValue(): string | null {\n return this.options.selected.length > 0\n ? this.options.selected.map((option) => option.code).join(\",\")\n : null;\n }\n\n /**\n */\n hasValue(): boolean {\n return this.options.selected.length > 0;\n }\n\n /**\n * Get input value of attribute\n */\n getInputValue(): string {\n return this.selected.join(\",\");\n }\n\n /**\n * Setting an option selected or unselected based on the current state\n */\n toggleOption(code: string) {\n if (this.selected.includes(code)) {\n this.disableOption(code);\n } else {\n this.enableOption(code);\n }\n }\n\n /**\n * Enable a option\n */\n enableOption(code: string) {\n if (!this.isMultiple) {\n this.options.deselectAll();\n }\n\n this.options.select(code);\n this.inputvalue = this.getInputValue();\n }\n\n /**\n * Disable a option\n */\n disableOption(code: string) {\n this.options.deselect(code);\n this.inputvalue = this.getInputValue();\n }\n\n /**\n * Add a new option to the collection of lookup options\n */\n addOption(option: Object) {\n if (!this.isMultiple) {\n this.options.deselectAll();\n }\n\n if (this.options.find((opt) => opt.code === option.code) === null) {\n this.options.addOption(option.code, option);\n }\n }\n\n /**\n * Getting the type of choice filter. For instance checkbox, radiobutton, combobox.\n */\n get choicetype():\n | \"checkbox\"\n | \"radiobutton\"\n | \"combobox\"\n | \"list\"\n | \"listview\"\n | \"table\"\n | \"longlist\"\n | \"toggle\" {\n return (\n [\n \"checkbox\",\n \"radiobutton\",\n \"combobox\",\n \"list\",\n \"listview\",\n \"table\",\n \"longlist\",\n \"toggle\",\n ].find((hint) => this.layouthint.has(hint)) || \"checkbox\"\n );\n }\n\n /**\n * Can multiple options be selected\n */\n get isMultiple(): boolean {\n return this.contributions.multiplechoice || this.choicetype === \"checkbox\";\n }\n\n /**\n * Check if options need to be rendered as tree\n */\n get isTree(): boolean {\n return (\n has(this.contributions, \"options\") &&\n this.contributions.options.some((option) => has(option, \"children\"))\n );\n }\n\n /**\n * Reset choice attribute to unselected list\n */\n reset() {\n this.options.deselectAll();\n }\n\n /**\n */\n mergeAttribute(oldAttribute: AttributeType) {\n // when attribute is readonly, don't merge the options no modifications necessary\n if (!this.readonly && oldAttribute instanceof ChoiceAttributeModel) {\n this.concept = oldAttribute.concept;\n this.options.mergeOptions(oldAttribute.options, this.type === \"lookup\");\n this.options.deselectAll();\n\n if (oldAttribute.isValid && oldAttribute.inputvalue !== null) {\n this.update(oldAttribute.inputvalue);\n }\n }\n }\n\n /**\n * Update attribute by name and value\n */\n update(value: any): ChoiceAttributeModel {\n if (this.readonly) {\n return this;\n }\n\n this.updateLastModification();\n\n let values;\n\n if (Array.isArray(value)) {\n values = value;\n } else if (typeof value === \"string\" && this.isMultiple) {\n values = value.split(\",\");\n } else {\n values = [value];\n }\n values.forEach((val) => {\n if (val instanceof ChoiceAttributeOptionModel) {\n if (!this.options.some((option) => option.equals(val))) {\n this.options.add(val);\n }\n\n this.toggleOption(val.code);\n } else if (\n typeof val === \"string\" &&\n this.options.some((option) => option.code.toString() === val)\n ) {\n this.toggleOption(val);\n }\n });\n\n return this;\n }\n\n /**\n */\n set hasContentConfiguration(hasContentConfiguration: boolean) {\n this._hasContentConfiguration =\n this.contentConfiguration !== null || hasContentConfiguration;\n }\n\n /**\n */\n get hasContentConfiguration(): boolean {\n return this._hasContentConfiguration;\n }\n\n /**\n * Get content configuration configured on the attribute.\n * Only applicable for taxonomy element and knowledge codemaps,\n * content configuration for instrument questions is available on the form object\n */\n get contentConfiguration(): ContentConfigurationElements | null {\n if (\n !this.contributions.content ||\n !this.contributions.content.optionElements\n ) {\n return null;\n }\n\n // Add RENDER_SECTION_LABEL to all content configuration to make sure the label of a section is always rendered on taxonomy and knowlege codemaps\n const optionElementConfig = this.contributions.content.optionElements.map(\n (optionElement) => {\n if (\"contentElement\" in optionElement) {\n return {\n contentElement: {\n ...optionElement.contentElement,\n layouthint: [RENDER_SECTION_LABEL],\n },\n };\n }\n\n return optionElement;\n }\n );\n\n return new ContentConfigurationElements(optionElementConfig);\n }\n\n /**\n * Get placeholder text\n */\n get placeholder(): string {\n return this.getContribution(\"placeholder\", \"\");\n }\n\n /**\n * Registers an error that was received from a server response\n */\n addServerError(error: FormErrorAnchor) {\n const { id, message, properties, layouthint } = error;\n\n const ANSWER_OPTION_KEY = \"answer-option-key\";\n\n if (properties && has(properties, ANSWER_OPTION_KEY)) {\n const optionKey = properties[ANSWER_OPTION_KEY];\n const foundOption = this.options.find(\n (option) => option.code === optionKey\n );\n if (foundOption) {\n properties[ANSWER_OPTION_KEY] = foundOption.getContentConfiguredLabel(\n this.contentConfiguration\n );\n }\n }\n\n this._errorCollection.addServerError(id, message, properties, layouthint);\n }\n\n /**\n */\n get readonlyWidth(): $Keys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,qCAAJ,CAAiCJ,mBAAjC,CAAP;EACD;EAED;AACF;AACA;;;EACiB,IAAXK,WAAW,GAAW;IACxB,OAAO,KAAK9E,eAAL,CAAqB,aAArB,EAAoC,EAApC,CAAP;EACD;EAED;AACF;AACA;;;EACE+E,cAAc,CAACC,KAAD,EAAyB;IACrC,MAAM;MAAEC,EAAF;MAAMC,OAAN;MAAeC,UAAf;MAA2B3F;IAA3B,IAA0CwF,KAAhD;IAEA,MAAMI,iBAAiB,GAAG,mBAA1B;;IAEA,IAAID,UAAU,IAAI,IAAA1F,YAAA,EAAI0F,UAAJ,EAAgBC,iBAAhB,CAAlB,EAAsD;MAAA;;MACpD,MAAMC,SAAS,GAAGF,UAAU,CAACC,iBAAD,CAA5B;MACA,MAAME,WAAW,GAAG,oCAAK5E,OAAL,kBACjBe,MAAD,IAAYA,MAAM,CAACC,IAAP,KAAgB2D,SADV,CAApB;;MAGA,IAAIC,WAAJ,EAAiB;QACfH,UAAU,CAACC,iBAAD,CAAV,GAAgCE,WAAW,CAACC,yBAAZ,CAC9B,KAAKjB,oBADyB,CAAhC;MAGD;IACF;;IAED,KAAKkB,gBAAL,CAAsBT,cAAtB,CAAqCE,EAArC,EAAyCC,OAAzC,EAAkDC,UAAlD,EAA8D3F,UAA9D;EACD;EAED;AACF;;;EACmB,IAAbiG,aAAa,GAAkC;IACjD,IAAI,KAAK3F,IAAL,KAAc,QAAlB,EAA4B;MAC1B,OAAO4F,0BAAA,CAAgBC,KAAvB;IACD;;IAED,OAAOD,0BAAA,CAAgBE,MAAvB;EACD;;AApZ8D"}
|
|
@@ -467,14 +467,15 @@ class DatetimeAttributeModel extends _StringAttributeModel.default {
|
|
|
467
467
|
const {
|
|
468
468
|
id,
|
|
469
469
|
message,
|
|
470
|
-
properties
|
|
470
|
+
properties,
|
|
471
|
+
layouthint
|
|
471
472
|
} = error;
|
|
472
473
|
|
|
473
474
|
if (properties && (0, _objects.has)(properties, "format") && this.formatLabel) {
|
|
474
475
|
properties.format = this.formatLabel;
|
|
475
476
|
}
|
|
476
477
|
|
|
477
|
-
this._errorCollection.addServerError(id, message, properties);
|
|
478
|
+
this._errorCollection.addServerError(id, message, properties, layouthint);
|
|
478
479
|
}
|
|
479
480
|
/**
|
|
480
481
|
*/
|
|
@@ -425,12 +425,12 @@ class DatetimeAttributeModel extends StringAttributeModel {
|
|
|
425
425
|
* Registers an error that was received from a server response
|
|
426
426
|
*/
|
|
427
427
|
addServerError(error: FormErrorAnchor) {
|
|
428
|
-
const { id, message, properties } = error;
|
|
428
|
+
const { id, message, properties, layouthint } = error;
|
|
429
429
|
if (properties && has(properties, "format") && this.formatLabel) {
|
|
430
430
|
properties.format = this.formatLabel;
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
-
this._errorCollection.addServerError(id, message, properties);
|
|
433
|
+
this._errorCollection.addServerError(id, message, properties, layouthint);
|
|
434
434
|
}
|
|
435
435
|
|
|
436
436
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatetimeAttributeModel.js","names":["PRODUCT_DEFAULT_DATE_FORMAT","DatetimeAttributeModel","StringAttributeModel","constructor","attribute","attributeContributions","updateInitValue","isApplicableModel","contributions","type","formatUtil","TimeUtil","TimestampUtil","DateTimeUtil","DateUtil","getInitValue","value","data","length","split","hasTime","getTimeValue","timeValue","timeInputFormat","toLowerCase","setHour","setMinute","setSecond","setMilliseconds","_initvalue","_inputvalue","getInitialInputValue","_value","initValue","toFormat","inputFormat","getContribution","getInputValue","toString","inputvalue","validate","toISO","format","convertFormat","operator","hasDate","formatLabel","dateInputFormat","ignoreFormatSetting","layouthint","has","IGNORE_FORMAT_SETTING","dateInputFormatSetting","getSetting","dateFormat","replace","dateReadonlyFormat","readonlyFormatSetting","placeholder","_placeholder","timeFormatParts","push","timeFormat","join","timeReadonlyFormat","dateInputValue","timeInputValue","formatValue","hasFormat","ISO_DATE_FORMAT","dateTimeReadonlyFormat","readonlyvalue","mindate","maxdate","addServerError","error","id","message","properties","_errorCollection","getFormatConstraint","DateTimeDateFormatConstraint","DateTimeTimeFormatConstraint","DatetimeFormatConstraint","addConstraints","constraints","ConstraintCollection","add","DateBoundaryConstraint","readonlyWidth","ATTRIBUTE_WIDTH","SMALL","MEDIUM"],"sources":["../../../src/models/attributes/DatetimeAttributeModel.js"],"sourcesContent":["// @flow\nimport { has } from \"../../utils/helpers/objects\";\n\nimport {\n DateUtil,\n DateTimeUtil,\n TimeUtil,\n TimestampUtil,\n} from \"../../utils/datetime/DateTimeUtil\";\n\nimport StringAttributeModel from \"./StringAttributeModel\";\n\nimport ConstraintCollection from \"./input-constraints/ConstraintCollection\";\nimport DateTimeDateFormatConstraint from \"./input-constraints/DateTimeDateFormatConstraint\";\nimport DateTimeTimeFormatConstraint from \"./input-constraints/DateTimeTimeFormatConstraint\";\nimport DatetimeFormatConstraint from \"./input-constraints/DatetimeFormatConstraint\";\nimport DateBoundaryConstraint from \"./input-constraints/DateBoundaryConstraint\";\n\nimport { ATTRIBUTE_WIDTH, ISO_DATE_FORMAT } from \"../../constants\";\nimport { getSetting } from \"../../constants/Settings\";\nimport { IGNORE_FORMAT_SETTING } from \"../../constants/LayoutHints\";\n\nimport type { FormErrorAnchor, IConstraintModel } from \"../types\";\n\n// date format of default\nconst PRODUCT_DEFAULT_DATE_FORMAT = \"dd-MM-yyyy\";\n\n/**\n */\nclass DatetimeAttributeModel extends StringAttributeModel {\n /**\n */\n constructor(attribute: Object, attributeContributions: Object) {\n super(attribute, attributeContributions);\n\n this.updateInitValue();\n }\n\n /**\n */\n static isApplicableModel(contributions: Object): boolean {\n return [\"date\", \"time\", \"datetime\", \"timestamp\"].includes(\n contributions.type\n );\n }\n\n /**\n */\n get formatUtil():\n | typeof TimeUtil\n | typeof TimestampUtil\n | typeof DateTimeUtil\n | typeof DateUtil {\n switch (this.type) {\n case \"time\":\n return TimeUtil;\n case \"timestamp\":\n return TimestampUtil;\n case \"datetime\":\n return DateTimeUtil;\n default:\n return DateUtil;\n }\n }\n\n /**\n */\n getInitValue(): string | null {\n let value = this.data.value;\n if (value != null) {\n if (this.type === \"time\" && value.length === 5) {\n value = `${value}:00`;\n }\n\n // handle old datetime values, which contained ms\n if (this.type === \"datetime\" && value.includes(\".\")) {\n value = value.split(\".\")[0];\n }\n\n if (this.hasTime) {\n value = this.getTimeValue(value);\n }\n }\n\n return value;\n }\n\n /**\n */\n getTimeValue(value: string): string {\n let timeValue = value;\n if (!this.timeInputFormat.toLowerCase().includes(\"h\")) {\n timeValue = this.formatUtil.setHour(value, 0);\n }\n if (!this.timeInputFormat.includes(\"m\")) {\n timeValue = this.formatUtil.setMinute(value, 0);\n }\n if (!this.timeInputFormat.includes(\"s\")) {\n timeValue = this.formatUtil.setSecond(value, 0);\n }\n if (this.type === \"timestamp\" && !this.timeInputFormat.includes(\"S\")) {\n timeValue = this.formatUtil.setMilliseconds(value, 0);\n }\n return timeValue;\n }\n\n /**\n * Set time in the correct value based on available elements in the time format\n */\n updateInitValue() {\n const value = this.getInitValue();\n if (value != null) {\n this._initvalue = value;\n this._inputvalue = this.getInitialInputValue(value);\n this._value = value;\n }\n }\n\n /**\n * Get initial user input value\n */\n getInitialInputValue(value?: string): string {\n if (!value) {\n return \"\";\n }\n\n let initValue = value;\n if (this.type === \"time\" && value.length === 5) {\n initValue = `${value}:00`;\n }\n\n return this.formatUtil.toFormat(initValue, this.inputFormat);\n }\n\n /**\n * Set type to date\n */\n get type(): string {\n return this.getContribution(\"type\", \"date\");\n }\n\n /**\n * Returns the value as entered by the user. This can differ from the internal iso value that is stored\n */\n getInputValue(): string {\n return this._inputvalue ? this._inputvalue.toString() : \"\";\n }\n\n /**\n * Get input value\n */\n get inputvalue(): string {\n return this.getInputValue();\n }\n\n /**\n * Sets the input value to the value entered by the user\n */\n set inputvalue(value: string) {\n this.validate(value);\n\n this._inputvalue = value;\n\n this.value =\n value !== null && value !== \"\"\n ? this.formatUtil.toISO(value, this.inputFormat)\n : null;\n }\n\n /**\n * Get date format\n */\n get format(): string {\n const format = this.getContribution(\"format\", \"\");\n return this.formatUtil.convertFormat(format);\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n get hasDate(): boolean {\n return (\n this.type === \"date\" ||\n this.type === \"datetime\" ||\n this.type === \"timestamp\"\n );\n }\n\n /**\n */\n get hasTime(): boolean {\n return (\n this.type === \"time\" ||\n this.type === \"datetime\" ||\n this.type === \"timestamp\"\n );\n }\n\n /**\n */\n get formatLabel(): string {\n switch (this.type) {\n case \"date\":\n return this.dateInputFormat.toLowerCase();\n case \"time\":\n return this.timeInputFormat.toLowerCase();\n default:\n return this.format.toLowerCase();\n }\n }\n\n /**\n */\n get inputFormat(): string {\n if (this.hasDate && this.hasTime) {\n return `${this.dateInputFormat} ${this.timeInputFormat}`.trim();\n }\n\n if (this.hasDate) {\n return this.dateInputFormat;\n }\n\n if (this.hasTime) {\n return this.timeInputFormat;\n }\n\n return \"\";\n }\n\n /**\n */\n get dateInputFormat(): string {\n if (!this.hasDate) {\n return \"\";\n }\n\n // setting for date input\n const ignoreFormatSetting = this.layouthint.has(IGNORE_FORMAT_SETTING);\n if (!ignoreFormatSetting) {\n const dateInputFormatSetting = getSetting(\"DATE_INPUT_FORMAT\", \"\");\n if (dateInputFormatSetting) {\n return dateInputFormatSetting;\n }\n }\n\n let format = this.format;\n\n let dateFormat = this.hasTime\n ? format.replace(this.timeInputFormat, \"\").trim()\n : format;\n\n return dateFormat;\n }\n\n /**\n */\n get dateReadonlyFormat(): string {\n if (!this.hasDate) {\n return \"\";\n }\n\n let format = this.format;\n\n let dateFormat = this.hasTime\n ? format.replace(this.timeInputFormat, \"\").trim()\n : format;\n\n const readonlyFormatSetting = getSetting(\"DATE_READONLY_FORMAT\", \"\");\n\n if (dateFormat === PRODUCT_DEFAULT_DATE_FORMAT && readonlyFormatSetting) {\n dateFormat = readonlyFormatSetting;\n }\n\n return dateFormat;\n }\n\n /**\n * return attribute placeholder or, if DATE_INPUT_FORMAT setting is used, lowercased setting, otherwise return formatlabel without time input format from contributions\n */\n get placeholder(): string {\n if (this._placeholder !== \"\") {\n return this._placeholder;\n }\n\n const dateInputFormatSetting = getSetting(\"DATE_INPUT_FORMAT\", \"\");\n\n if (dateInputFormatSetting) {\n return dateInputFormatSetting.toLowerCase();\n }\n\n const formatLabel = this.getContribution(\"formatlabel\", \"\");\n\n if (this.hasDate && this.hasTime && formatLabel.includes(\" \")) {\n // return first part of formatlabel to keep placeholder matching date input\n return formatLabel.split(\" \")[0];\n }\n\n return formatLabel;\n }\n\n /**\n * Set placeholder text\n */\n set placeholder(placeholder: string) {\n this._placeholder = placeholder;\n }\n\n /**\n */\n get timeInputFormat(): string {\n if (!this.hasTime) {\n return \"\";\n }\n\n const format = this.format;\n\n let timeFormatParts = [];\n if (format.includes(\"H\")) {\n timeFormatParts.push(\"HH\");\n } else if (format.includes(\"h\")) {\n timeFormatParts.push(\"hh\");\n }\n if (format.includes(\"m\")) {\n timeFormatParts.push(\"mm\");\n }\n if (format.includes(\"s\")) {\n timeFormatParts.push(\"ss\");\n }\n\n let timeFormat = timeFormatParts.join(\":\");\n if (format.includes(\"S\")) {\n timeFormat = `${timeFormat}.SSS`;\n }\n if (format.includes(\"a\")) {\n return `${timeFormat} a`;\n }\n return timeFormat;\n }\n\n /**\n */\n get timeReadonlyFormat(): string {\n if (!this.hasTime) {\n return \"\";\n }\n\n return this.timeInputFormat;\n }\n\n /**\n */\n get dateInputValue(): string {\n return typeof this.value === \"string\" && this.dateInputFormat !== \"\"\n ? this.formatUtil.toFormat(this.value, this.dateInputFormat)\n : \"\";\n }\n\n /**\n */\n get timeInputValue(): string {\n return typeof this.value === \"string\" && this.timeInputFormat !== \"\"\n ? this.formatUtil.toFormat(this.value, this.timeInputFormat)\n : \"\";\n }\n\n // format value in readonly rendering\n /**\n */\n formatValue(value: ?string): string {\n if (value == null || value.toString() === \"\") {\n return \"\";\n }\n\n // when the value is exactly an iso date, render as date\n if (\n (this.type === \"datetime\" || this.type === \"timestamp\") &&\n DateUtil.hasFormat(value, ISO_DATE_FORMAT)\n ) {\n return DateUtil.toFormat(value, this.dateReadonlyFormat);\n }\n\n if (this.hasDate && this.hasTime) {\n const dateTimeReadonlyFormat = `${this.dateReadonlyFormat} ${this.timeReadonlyFormat}`;\n return this.formatUtil.toFormat(value, dateTimeReadonlyFormat);\n }\n\n if (this.type === \"date\") {\n return this.formatUtil.toFormat(value, this.dateReadonlyFormat);\n }\n\n return this.formatUtil.toFormat(value, this.format);\n }\n\n /**\n * Retrieve readonly value, the date in the configurated format\n */\n get readonlyvalue(): string {\n if (typeof this.value === \"string\") {\n return this.formatValue(this.value.toString());\n }\n\n return \"\";\n }\n\n /**\n * Get minimum date\n */\n get mindate(): string | null {\n return this.getContribution(\"mindate\");\n }\n\n /**\n * Get maximum date\n */\n get maxdate(): string | null {\n return this.getContribution(\"maxdate\");\n }\n\n /**\n * Registers an error that was received from a server response\n */\n addServerError(error: FormErrorAnchor) {\n const { id, message, properties } = error;\n if (properties && has(properties, \"format\") && this.formatLabel) {\n properties.format = this.formatLabel;\n }\n\n this._errorCollection.addServerError(id, message, properties);\n }\n\n /**\n */\n getFormatConstraint(): IConstraintModel {\n switch (this.type) {\n case \"date\":\n return new DateTimeDateFormatConstraint(\n this.dateInputFormat,\n this.formatLabel\n );\n case \"time\":\n return new DateTimeTimeFormatConstraint(\n this.timeInputFormat,\n this.formatLabel\n );\n default:\n return new DatetimeFormatConstraint(\n this.type,\n this.inputFormat,\n this.formatLabel\n );\n }\n }\n\n /**\n * Add Date constraints for attribute\n */\n addConstraints(): ConstraintCollection {\n const constraints = new ConstraintCollection();\n\n constraints.add(this.getFormatConstraint());\n\n if (this.mindate || this.maxdate) {\n constraints.add(\n new DateBoundaryConstraint(\n this.type,\n this.mindate,\n this.maxdate,\n this.inputFormat\n )\n );\n }\n\n return constraints;\n }\n\n /**\n */\n get readonlyWidth(): $Keys<typeof ATTRIBUTE_WIDTH> {\n if (this.type === \"date\" || this.type ===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L,EAAhB;;IAEA,IAAI,KAAKR,OAAL,IAAgB,KAAKC,OAAzB,EAAkC;MAChCY,WAAW,CAACE,GAAZ,CACE,IAAIC,+BAAJ,CACE,KAAK/E,IADP,EAEE,KAAK+D,OAFP,EAGE,KAAKC,OAHP,EAIE,KAAKtC,WAJP,CADF;IAQD;;IAED,OAAOkD,WAAP;EACD;EAED;AACF;;;EACmB,IAAbI,aAAa,GAAkC;IACjD,IAAI,KAAKhF,IAAL,KAAc,MAAd,IAAwB,KAAKA,IAAL,KAAc,MAA1C,EAAkD;MAChD,OAAOiF,0BAAA,CAAgBC,KAAvB;IACD;;IAED,OAAOD,0BAAA,CAAgBE,MAAvB;EACD;;AA3cuD;;eA8c3C3F,sB"}
|
|
1
|
+
{"version":3,"file":"DatetimeAttributeModel.js","names":["PRODUCT_DEFAULT_DATE_FORMAT","DatetimeAttributeModel","StringAttributeModel","constructor","attribute","attributeContributions","updateInitValue","isApplicableModel","contributions","type","formatUtil","TimeUtil","TimestampUtil","DateTimeUtil","DateUtil","getInitValue","value","data","length","split","hasTime","getTimeValue","timeValue","timeInputFormat","toLowerCase","setHour","setMinute","setSecond","setMilliseconds","_initvalue","_inputvalue","getInitialInputValue","_value","initValue","toFormat","inputFormat","getContribution","getInputValue","toString","inputvalue","validate","toISO","format","convertFormat","operator","hasDate","formatLabel","dateInputFormat","ignoreFormatSetting","layouthint","has","IGNORE_FORMAT_SETTING","dateInputFormatSetting","getSetting","dateFormat","replace","dateReadonlyFormat","readonlyFormatSetting","placeholder","_placeholder","timeFormatParts","push","timeFormat","join","timeReadonlyFormat","dateInputValue","timeInputValue","formatValue","hasFormat","ISO_DATE_FORMAT","dateTimeReadonlyFormat","readonlyvalue","mindate","maxdate","addServerError","error","id","message","properties","_errorCollection","getFormatConstraint","DateTimeDateFormatConstraint","DateTimeTimeFormatConstraint","DatetimeFormatConstraint","addConstraints","constraints","ConstraintCollection","add","DateBoundaryConstraint","readonlyWidth","ATTRIBUTE_WIDTH","SMALL","MEDIUM"],"sources":["../../../src/models/attributes/DatetimeAttributeModel.js"],"sourcesContent":["// @flow\nimport { has } from \"../../utils/helpers/objects\";\n\nimport {\n DateUtil,\n DateTimeUtil,\n TimeUtil,\n TimestampUtil,\n} from \"../../utils/datetime/DateTimeUtil\";\n\nimport StringAttributeModel from \"./StringAttributeModel\";\n\nimport ConstraintCollection from \"./input-constraints/ConstraintCollection\";\nimport DateTimeDateFormatConstraint from \"./input-constraints/DateTimeDateFormatConstraint\";\nimport DateTimeTimeFormatConstraint from \"./input-constraints/DateTimeTimeFormatConstraint\";\nimport DatetimeFormatConstraint from \"./input-constraints/DatetimeFormatConstraint\";\nimport DateBoundaryConstraint from \"./input-constraints/DateBoundaryConstraint\";\n\nimport { ATTRIBUTE_WIDTH, ISO_DATE_FORMAT } from \"../../constants\";\nimport { getSetting } from \"../../constants/Settings\";\nimport { IGNORE_FORMAT_SETTING } from \"../../constants/LayoutHints\";\n\nimport type { FormErrorAnchor, IConstraintModel } from \"../types\";\n\n// date format of default\nconst PRODUCT_DEFAULT_DATE_FORMAT = \"dd-MM-yyyy\";\n\n/**\n */\nclass DatetimeAttributeModel extends StringAttributeModel {\n /**\n */\n constructor(attribute: Object, attributeContributions: Object) {\n super(attribute, attributeContributions);\n\n this.updateInitValue();\n }\n\n /**\n */\n static isApplicableModel(contributions: Object): boolean {\n return [\"date\", \"time\", \"datetime\", \"timestamp\"].includes(\n contributions.type\n );\n }\n\n /**\n */\n get formatUtil():\n | typeof TimeUtil\n | typeof TimestampUtil\n | typeof DateTimeUtil\n | typeof DateUtil {\n switch (this.type) {\n case \"time\":\n return TimeUtil;\n case \"timestamp\":\n return TimestampUtil;\n case \"datetime\":\n return DateTimeUtil;\n default:\n return DateUtil;\n }\n }\n\n /**\n */\n getInitValue(): string | null {\n let value = this.data.value;\n if (value != null) {\n if (this.type === \"time\" && value.length === 5) {\n value = `${value}:00`;\n }\n\n // handle old datetime values, which contained ms\n if (this.type === \"datetime\" && value.includes(\".\")) {\n value = value.split(\".\")[0];\n }\n\n if (this.hasTime) {\n value = this.getTimeValue(value);\n }\n }\n\n return value;\n }\n\n /**\n */\n getTimeValue(value: string): string {\n let timeValue = value;\n if (!this.timeInputFormat.toLowerCase().includes(\"h\")) {\n timeValue = this.formatUtil.setHour(value, 0);\n }\n if (!this.timeInputFormat.includes(\"m\")) {\n timeValue = this.formatUtil.setMinute(value, 0);\n }\n if (!this.timeInputFormat.includes(\"s\")) {\n timeValue = this.formatUtil.setSecond(value, 0);\n }\n if (this.type === \"timestamp\" && !this.timeInputFormat.includes(\"S\")) {\n timeValue = this.formatUtil.setMilliseconds(value, 0);\n }\n return timeValue;\n }\n\n /**\n * Set time in the correct value based on available elements in the time format\n */\n updateInitValue() {\n const value = this.getInitValue();\n if (value != null) {\n this._initvalue = value;\n this._inputvalue = this.getInitialInputValue(value);\n this._value = value;\n }\n }\n\n /**\n * Get initial user input value\n */\n getInitialInputValue(value?: string): string {\n if (!value) {\n return \"\";\n }\n\n let initValue = value;\n if (this.type === \"time\" && value.length === 5) {\n initValue = `${value}:00`;\n }\n\n return this.formatUtil.toFormat(initValue, this.inputFormat);\n }\n\n /**\n * Set type to date\n */\n get type(): string {\n return this.getContribution(\"type\", \"date\");\n }\n\n /**\n * Returns the value as entered by the user. This can differ from the internal iso value that is stored\n */\n getInputValue(): string {\n return this._inputvalue ? this._inputvalue.toString() : \"\";\n }\n\n /**\n * Get input value\n */\n get inputvalue(): string {\n return this.getInputValue();\n }\n\n /**\n * Sets the input value to the value entered by the user\n */\n set inputvalue(value: string) {\n this.validate(value);\n\n this._inputvalue = value;\n\n this.value =\n value !== null && value !== \"\"\n ? this.formatUtil.toISO(value, this.inputFormat)\n : null;\n }\n\n /**\n * Get date format\n */\n get format(): string {\n const format = this.getContribution(\"format\", \"\");\n return this.formatUtil.convertFormat(format);\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n get hasDate(): boolean {\n return (\n this.type === \"date\" ||\n this.type === \"datetime\" ||\n this.type === \"timestamp\"\n );\n }\n\n /**\n */\n get hasTime(): boolean {\n return (\n this.type === \"time\" ||\n this.type === \"datetime\" ||\n this.type === \"timestamp\"\n );\n }\n\n /**\n */\n get formatLabel(): string {\n switch (this.type) {\n case \"date\":\n return this.dateInputFormat.toLowerCase();\n case \"time\":\n return this.timeInputFormat.toLowerCase();\n default:\n return this.format.toLowerCase();\n }\n }\n\n /**\n */\n get inputFormat(): string {\n if (this.hasDate && this.hasTime) {\n return `${this.dateInputFormat} ${this.timeInputFormat}`.trim();\n }\n\n if (this.hasDate) {\n return this.dateInputFormat;\n }\n\n if (this.hasTime) {\n return this.timeInputFormat;\n }\n\n return \"\";\n }\n\n /**\n */\n get dateInputFormat(): string {\n if (!this.hasDate) {\n return \"\";\n }\n\n // setting for date input\n const ignoreFormatSetting = this.layouthint.has(IGNORE_FORMAT_SETTING);\n if (!ignoreFormatSetting) {\n const dateInputFormatSetting = getSetting(\"DATE_INPUT_FORMAT\", \"\");\n if (dateInputFormatSetting) {\n return dateInputFormatSetting;\n }\n }\n\n let format = this.format;\n\n let dateFormat = this.hasTime\n ? format.replace(this.timeInputFormat, \"\").trim()\n : format;\n\n return dateFormat;\n }\n\n /**\n */\n get dateReadonlyFormat(): string {\n if (!this.hasDate) {\n return \"\";\n }\n\n let format = this.format;\n\n let dateFormat = this.hasTime\n ? format.replace(this.timeInputFormat, \"\").trim()\n : format;\n\n const readonlyFormatSetting = getSetting(\"DATE_READONLY_FORMAT\", \"\");\n\n if (dateFormat === PRODUCT_DEFAULT_DATE_FORMAT && readonlyFormatSetting) {\n dateFormat = readonlyFormatSetting;\n }\n\n return dateFormat;\n }\n\n /**\n * return attribute placeholder or, if DATE_INPUT_FORMAT setting is used, lowercased setting, otherwise return formatlabel without time input format from contributions\n */\n get placeholder(): string {\n if (this._placeholder !== \"\") {\n return this._placeholder;\n }\n\n const dateInputFormatSetting = getSetting(\"DATE_INPUT_FORMAT\", \"\");\n\n if (dateInputFormatSetting) {\n return dateInputFormatSetting.toLowerCase();\n }\n\n const formatLabel = this.getContribution(\"formatlabel\", \"\");\n\n if (this.hasDate && this.hasTime && formatLabel.includes(\" \")) {\n // return first part of formatlabel to keep placeholder matching date input\n return formatLabel.split(\" \")[0];\n }\n\n return formatLabel;\n }\n\n /**\n * Set placeholder text\n */\n set placeholder(placeholder: string) {\n this._placeholder = placeholder;\n }\n\n /**\n */\n get timeInputFormat(): string {\n if (!this.hasTime) {\n return \"\";\n }\n\n const format = this.format;\n\n let timeFormatParts = [];\n if (format.includes(\"H\")) {\n timeFormatParts.push(\"HH\");\n } else if (format.includes(\"h\")) {\n timeFormatParts.push(\"hh\");\n }\n if (format.includes(\"m\")) {\n timeFormatParts.push(\"mm\");\n }\n if (format.includes(\"s\")) {\n timeFormatParts.push(\"ss\");\n }\n\n let timeFormat = timeFormatParts.join(\":\");\n if (format.includes(\"S\")) {\n timeFormat = `${timeFormat}.SSS`;\n }\n if (format.includes(\"a\")) {\n return `${timeFormat} a`;\n }\n return timeFormat;\n }\n\n /**\n */\n get timeReadonlyFormat(): string {\n if (!this.hasTime) {\n return \"\";\n }\n\n return this.timeInputFormat;\n }\n\n /**\n */\n get dateInputValue(): string {\n return typeof this.value === \"string\" && this.dateInputFormat !== \"\"\n ? this.formatUtil.toFormat(this.value, this.dateInputFormat)\n : \"\";\n }\n\n /**\n */\n get timeInputValue(): string {\n return typeof this.value === \"string\" && this.timeInputFormat !== \"\"\n ? this.formatUtil.toFormat(this.value, this.timeInputFormat)\n : \"\";\n }\n\n // format value in readonly rendering\n /**\n */\n formatValue(value: ?string): string {\n if (value == null || value.toString() === \"\") {\n return \"\";\n }\n\n // when the value is exactly an iso date, render as date\n if (\n (this.type === \"datetime\" || this.type === \"timestamp\") &&\n DateUtil.hasFormat(value, ISO_DATE_FORMAT)\n ) {\n return DateUtil.toFormat(value, this.dateReadonlyFormat);\n }\n\n if (this.hasDate && this.hasTime) {\n const dateTimeReadonlyFormat = `${this.dateReadonlyFormat} ${this.timeReadonlyFormat}`;\n return this.formatUtil.toFormat(value, dateTimeReadonlyFormat);\n }\n\n if (this.type === \"date\") {\n return this.formatUtil.toFormat(value, this.dateReadonlyFormat);\n }\n\n return this.formatUtil.toFormat(value, this.format);\n }\n\n /**\n * Retrieve readonly value, the date in the configurated format\n */\n get readonlyvalue(): string {\n if (typeof this.value === \"string\") {\n return this.formatValue(this.value.toString());\n }\n\n return \"\";\n }\n\n /**\n * Get minimum date\n */\n get mindate(): string | null {\n return this.getContribution(\"mindate\");\n }\n\n /**\n * Get maximum date\n */\n get maxdate(): string | null {\n return this.getContribution(\"maxdate\");\n }\n\n /**\n * Registers an error that was received from a server response\n */\n addServerError(error: FormErrorAnchor) {\n const { id, message, properties, layouthint } = error;\n if (properties && has(properties, \"format\") && this.formatLabel) {\n properties.format = this.formatLabel;\n }\n\n this._errorCollection.addServerError(id, message, properties, layouthint);\n }\n\n /**\n */\n getFormatConstraint(): IConstraintModel {\n switch (this.type) {\n case \"date\":\n return new DateTimeDateFormatConstraint(\n this.dateInputFormat,\n this.formatLabel\n );\n case \"time\":\n return new DateTimeTimeFormatConstraint(\n this.timeInputFormat,\n this.formatLabel\n );\n default:\n return new DatetimeFormatConstraint(\n this.type,\n this.inputFormat,\n this.formatLabel\n );\n }\n }\n\n /**\n * Add Date constraints for attribute\n */\n addConstraints(): ConstraintCollection {\n const constraints = new ConstraintCollection();\n\n constraints.add(this.getFormatConstraint());\n\n if (this.mindate || this.maxdate) {\n constraints.add(\n new DateBoundaryConstraint(\n this.type,\n this.mindate,\n this.maxdate,\n this.inputFormat\n )\n );\n }\n\n return constraints;\n }\n\n /**\n */\n get readonlyWidth(): $Keys<typeof ATTRIBUTE_WIDTH> {\n if (this.type === \"date\" || this.type === \"time\") {\n return ATTRIBUTE_WIDTH.SMALL;\n }\n\n return ATTRIBUTE_WIDTH.MEDIUM;\n }\n}\n\nexport default DatetimeAttributeModel;\n"],"mappings":";;;;;;;;;;;;;;;AAC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AAIC,+BAAJ,CACE,KAAK/E,IADP,EAEE,KAAK+D,OAFP,EAGE,KAAKC,OAHP,EAIE,KAAKtC,WAJP,CADF;IAQD;;IAED,OAAOkD,WAAP;EACD;EAED;AACF;;;EACmB,IAAbI,aAAa,GAAkC;IACjD,IAAI,KAAKhF,IAAL,KAAc,MAAd,IAAwB,KAAKA,IAAL,KAAc,MAA1C,EAAkD;MAChD,OAAOiF,0BAAA,CAAgBC,KAAvB;IACD;;IAED,OAAOD,0BAAA,CAAgBE,MAAvB;EACD;;AA3cuD;;eA8c3C3F,sB"}
|
|
@@ -19,6 +19,8 @@ var _BaseCollection = _interopRequireDefault(require("../base/BaseCollection"));
|
|
|
19
19
|
|
|
20
20
|
var _ErrorModel = _interopRequireDefault(require("./ErrorModel"));
|
|
21
21
|
|
|
22
|
+
var _LayoutHintCollection = _interopRequireDefault(require("../layouthint/LayoutHintCollection"));
|
|
23
|
+
|
|
22
24
|
/**
|
|
23
25
|
* Form Objects
|
|
24
26
|
*/
|
|
@@ -59,14 +61,14 @@ class ErrorCollection extends _BaseCollection.default {
|
|
|
59
61
|
*/
|
|
60
62
|
|
|
61
63
|
|
|
62
|
-
addError(id, defaultMessage, parameters) {
|
|
64
|
+
addError(id, defaultMessage, parameters, layouthint) {
|
|
63
65
|
const itemIdx = this.findById(id);
|
|
64
66
|
|
|
65
67
|
if (itemIdx > -1) {
|
|
66
68
|
this.removeByIndex(itemIdx);
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
this.add(new _ErrorModel.default(id, defaultMessage, parameters));
|
|
71
|
+
this.add(new _ErrorModel.default(id, defaultMessage, parameters, false, layouthint));
|
|
70
72
|
}
|
|
71
73
|
/**
|
|
72
74
|
*/
|
|
@@ -81,11 +83,11 @@ class ErrorCollection extends _BaseCollection.default {
|
|
|
81
83
|
*/
|
|
82
84
|
|
|
83
85
|
|
|
84
|
-
addServerError(id, defaultMessage, parameters) {
|
|
86
|
+
addServerError(id, defaultMessage, parameters, layouthint) {
|
|
85
87
|
if (parameters) {
|
|
86
|
-
this.addError(id, defaultMessage, parameters);
|
|
88
|
+
this.addError(id, defaultMessage, parameters, layouthint);
|
|
87
89
|
} else {
|
|
88
|
-
this.addError(id, defaultMessage);
|
|
90
|
+
this.addError(id, defaultMessage, undefined, layouthint);
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
/**
|
|
@@ -4,6 +4,7 @@ import ErrorModel from "./ErrorModel";
|
|
|
4
4
|
|
|
5
5
|
import type { MessageParameters } from "../../i18n/types";
|
|
6
6
|
import type { IConstraintModel } from "../types";
|
|
7
|
+
import LayoutHintCollection from "../layouthint/LayoutHintCollection";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Form Objects
|
|
@@ -43,7 +44,8 @@ export default class ErrorCollection extends BaseCollection<ErrorModel> {
|
|
|
43
44
|
addError(
|
|
44
45
|
id: string,
|
|
45
46
|
defaultMessage?: string,
|
|
46
|
-
parameters?: MessageParameters
|
|
47
|
+
parameters?: MessageParameters,
|
|
48
|
+
layouthint?: LayoutHintCollection
|
|
47
49
|
) {
|
|
48
50
|
const itemIdx = this.findById(id);
|
|
49
51
|
|
|
@@ -51,7 +53,7 @@ export default class ErrorCollection extends BaseCollection<ErrorModel> {
|
|
|
51
53
|
this.removeByIndex(itemIdx);
|
|
52
54
|
}
|
|
53
55
|
|
|
54
|
-
this.add(new ErrorModel(id, defaultMessage, parameters));
|
|
56
|
+
this.add(new ErrorModel(id, defaultMessage, parameters, false, layouthint));
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
/**
|
|
@@ -67,12 +69,13 @@ export default class ErrorCollection extends BaseCollection<ErrorModel> {
|
|
|
67
69
|
addServerError(
|
|
68
70
|
id: string,
|
|
69
71
|
defaultMessage?: string,
|
|
70
|
-
parameters?: MessageParameters
|
|
72
|
+
parameters?: MessageParameters,
|
|
73
|
+
layouthint?: LayoutHintCollection
|
|
71
74
|
) {
|
|
72
75
|
if (parameters) {
|
|
73
|
-
this.addError(id, defaultMessage, parameters);
|
|
76
|
+
this.addError(id, defaultMessage, parameters, layouthint);
|
|
74
77
|
} else {
|
|
75
|
-
this.addError(id, defaultMessage);
|
|
78
|
+
this.addError(id, defaultMessage, undefined, layouthint);
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorCollection.js","names":["ErrorCollection","BaseCollection","constructor","type","errorCollection","_type","collection","serverErrors","error","isClientConstraint","findById","id","item","addError","defaultMessage","parameters","itemIdx","removeByIndex","add","ErrorModel","removeError","addServerError","removeServerError","removeServerErrors","forEach","addErrors","errors","addConstraints","constraints","constraint","hasMandatoryError","some","isMandatoryConstraint"],"sources":["../../../src/models/error/ErrorCollection.js"],"sourcesContent":["// @flow\nimport BaseCollection from \"../base/BaseCollection\";\nimport ErrorModel from \"./ErrorModel\";\n\nimport type { MessageParameters } from \"../../i18n/types\";\nimport type { IConstraintModel } from \"../types\";\n\n/**\n * Form Objects\n */\nexport default class ErrorCollection extends BaseCollection<ErrorModel> {\n _type: string;\n\n /**\n * constructor\n */\n constructor(type: string, errorCollection?: ErrorCollection) {\n super();\n\n this._type = type;\n this.collection = [];\n\n if (errorCollection) {\n this.collection = [...errorCollection.collection];\n }\n }\n\n /**\n */\n get serverErrors(): Array<ErrorModel> {\n return this.collection.filter((error) => !error.isClientConstraint);\n }\n\n /**\n */\n findById(id: string): number {\n return this.collection.findIndex((item) => item.id === id);\n }\n\n /**\n * Add an error to the collection\n */\n addError(\n id: string,\n defaultMessage?: string,\n parameters?: MessageParameters\n ) {\n const itemIdx = this.findById(id);\n\n if (itemIdx > -1) {\n this.removeByIndex(itemIdx);\n }\n\n this.add(new ErrorModel(id, defaultMessage, parameters));\n }\n\n /**\n */\n removeError(id: string) {\n const itemIdx = this.findById(id);\n this.removeByIndex(itemIdx);\n }\n\n /**\n * Add a server error to the collection\n */\n addServerError(\n id: string,\n defaultMessage?: string,\n parameters?: MessageParameters\n ) {\n if (parameters) {\n this.addError(id, defaultMessage, parameters);\n } else {\n this.addError(id, defaultMessage);\n }\n }\n\n /**\n */\n removeServerError(id: string) {\n this.removeError(id);\n }\n\n /**\n */\n removeServerErrors() {\n this.serverErrors.forEach((error) => {\n this.removeError(error.id);\n });\n }\n\n /**\n */\n addErrors(errors: Array<ErrorModel>) {\n this.collection = [...this.collection, ...errors];\n }\n\n /**\n * Add constraints to error collection\n */\n addConstraints(constraints: Array<IConstraintModel>) {\n this.collection = [\n ...this.collection,\n ...constraints.map(\n (constraint) =>\n new ErrorModel(\n constraint.id,\n constraint.defaultMessage,\n constraint.parameters,\n true\n )\n ),\n ];\n }\n\n /**\n * Indicates if a mandatory constraint is available and if it is in error.\n * Rationale: When a mandatory constraint is in error other constraint probably don't mather because there is no value to check\n */\n hasMandatoryError(): boolean {\n return this.collection.some((error) => error.isMandatoryConstraint);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AACA;;AACA;;
|
|
1
|
+
{"version":3,"file":"ErrorCollection.js","names":["ErrorCollection","BaseCollection","constructor","type","errorCollection","_type","collection","serverErrors","error","isClientConstraint","findById","id","item","addError","defaultMessage","parameters","layouthint","itemIdx","removeByIndex","add","ErrorModel","removeError","addServerError","undefined","removeServerError","removeServerErrors","forEach","addErrors","errors","addConstraints","constraints","constraint","hasMandatoryError","some","isMandatoryConstraint"],"sources":["../../../src/models/error/ErrorCollection.js"],"sourcesContent":["// @flow\nimport BaseCollection from \"../base/BaseCollection\";\nimport ErrorModel from \"./ErrorModel\";\n\nimport type { MessageParameters } from \"../../i18n/types\";\nimport type { IConstraintModel } from \"../types\";\nimport LayoutHintCollection from \"../layouthint/LayoutHintCollection\";\n\n/**\n * Form Objects\n */\nexport default class ErrorCollection extends BaseCollection<ErrorModel> {\n _type: string;\n\n /**\n * constructor\n */\n constructor(type: string, errorCollection?: ErrorCollection) {\n super();\n\n this._type = type;\n this.collection = [];\n\n if (errorCollection) {\n this.collection = [...errorCollection.collection];\n }\n }\n\n /**\n */\n get serverErrors(): Array<ErrorModel> {\n return this.collection.filter((error) => !error.isClientConstraint);\n }\n\n /**\n */\n findById(id: string): number {\n return this.collection.findIndex((item) => item.id === id);\n }\n\n /**\n * Add an error to the collection\n */\n addError(\n id: string,\n defaultMessage?: string,\n parameters?: MessageParameters,\n layouthint?: LayoutHintCollection\n ) {\n const itemIdx = this.findById(id);\n\n if (itemIdx > -1) {\n this.removeByIndex(itemIdx);\n }\n\n this.add(new ErrorModel(id, defaultMessage, parameters, false, layouthint));\n }\n\n /**\n */\n removeError(id: string) {\n const itemIdx = this.findById(id);\n this.removeByIndex(itemIdx);\n }\n\n /**\n * Add a server error to the collection\n */\n addServerError(\n id: string,\n defaultMessage?: string,\n parameters?: MessageParameters,\n layouthint?: LayoutHintCollection\n ) {\n if (parameters) {\n this.addError(id, defaultMessage, parameters, layouthint);\n } else {\n this.addError(id, defaultMessage, undefined, layouthint);\n }\n }\n\n /**\n */\n removeServerError(id: string) {\n this.removeError(id);\n }\n\n /**\n */\n removeServerErrors() {\n this.serverErrors.forEach((error) => {\n this.removeError(error.id);\n });\n }\n\n /**\n */\n addErrors(errors: Array<ErrorModel>) {\n this.collection = [...this.collection, ...errors];\n }\n\n /**\n * Add constraints to error collection\n */\n addConstraints(constraints: Array<IConstraintModel>) {\n this.collection = [\n ...this.collection,\n ...constraints.map(\n (constraint) =>\n new ErrorModel(\n constraint.id,\n constraint.defaultMessage,\n constraint.parameters,\n true\n )\n ),\n ];\n }\n\n /**\n * Indicates if a mandatory constraint is available and if it is in error.\n * Rationale: When a mandatory constraint is in error other constraint probably don't mather because there is no value to check\n */\n hasMandatoryError(): boolean {\n return this.collection.some((error) => error.isMandatoryConstraint);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AACA;;AACA;;AAIA;;AAEA;AACA;AACA;AACe,MAAMA,eAAN,SAA8BC,uBAA9B,CAAyD;EAGtE;AACF;AACA;EACEC,WAAW,CAACC,IAAD,EAAeC,eAAf,E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A6CP,UAA7C;IACD;EACF;EAED;AACF;;;EACEQ,iBAAiB,CAACb,EAAD,EAAa;IAC5B,KAAKU,WAAL,CAAiBV,EAAjB;EACD;EAED;AACF;;;EACEc,kBAAkB,GAAG;IACnB,KAAKlB,YAAL,CAAkBmB,OAAlB,CAA2BlB,KAAD,IAAW;MACnC,KAAKa,WAAL,CAAiBb,KAAK,CAACG,EAAvB;IACD,CAFD;EAGD;EAED;AACF;;;EACEgB,SAAS,CAACC,MAAD,EAA4B;IACnC,KAAKtB,UAAL,GAAkB,CAAC,GAAG,KAAKA,UAAT,EAAqB,GAAGsB,MAAxB,CAAlB;EACD;EAED;AACF;AACA;;;EACEC,cAAc,CAACC,WAAD,EAAuC;IACnD,KAAKxB,UAAL,GAAkB,CAChB,GAAG,KAAKA,UADQ,EAEhB,GAAG,kBAAAwB,WAAW,MAAX,CAAAA,WAAW,EACXC,UAAD,IACE,IAAIX,mBAAJ,CACEW,UAAU,CAACpB,EADb,EAEEoB,UAAU,CAACjB,cAFb,EAGEiB,UAAU,CAAChB,UAHb,EAIE,IAJF,CAFU,CAFE,CAAlB;EAYD;EAED;AACF;AACA;AACA;;;EACEiB,iBAAiB,GAAY;IAC3B,OAAO,KAAK1B,UAAL,CAAgB2B,IAAhB,CAAsBzB,KAAD,IAAWA,KAAK,CAAC0B,qBAAtC,CAAP;EACD;;AAlHqE"}
|
|
@@ -20,6 +20,7 @@ class ErrorModel {
|
|
|
20
20
|
*/
|
|
21
21
|
constructor(id, defaultMessage, parameters) {
|
|
22
22
|
let isClientConstraint = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
23
|
+
let layouthint = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : new _LayoutHintCollection.default();
|
|
23
24
|
(0, _defineProperty2.default)(this, "_id", void 0);
|
|
24
25
|
(0, _defineProperty2.default)(this, "_defaultMessage", void 0);
|
|
25
26
|
(0, _defineProperty2.default)(this, "_parameters", void 0);
|
|
@@ -29,7 +30,7 @@ class ErrorModel {
|
|
|
29
30
|
this._parameters = parameters;
|
|
30
31
|
this._defaultMessage = defaultMessage;
|
|
31
32
|
this._isClientConstraint = isClientConstraint;
|
|
32
|
-
this._layouthint = new _LayoutHintCollection.default();
|
|
33
|
+
this._layouthint = Array.isArray(layouthint) ? new _LayoutHintCollection.default(layouthint) : layouthint;
|
|
33
34
|
}
|
|
34
35
|
/**
|
|
35
36
|
* Get id of error
|
|
@@ -19,13 +19,16 @@ class ErrorModel {
|
|
|
19
19
|
id: string,
|
|
20
20
|
defaultMessage: ?string,
|
|
21
21
|
parameters: ?MessageParameters,
|
|
22
|
-
isClientConstraint: boolean = false
|
|
22
|
+
isClientConstraint: boolean = false,
|
|
23
|
+
layouthint: LayoutHintCollection = new LayoutHintCollection()
|
|
23
24
|
) {
|
|
24
25
|
this._id = id;
|
|
25
26
|
this._parameters = parameters;
|
|
26
27
|
this._defaultMessage = defaultMessage;
|
|
27
28
|
this._isClientConstraint = isClientConstraint;
|
|
28
|
-
this._layouthint =
|
|
29
|
+
this._layouthint = Array.isArray(layouthint)
|
|
30
|
+
? new LayoutHintCollection(layouthint)
|
|
31
|
+
: layouthint;
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorModel.js","names":["ErrorModel","constructor","id","defaultMessage","parameters","isClientConstraint","_id","_parameters","_defaultMessage","_isClientConstraint","_layouthint","
|
|
1
|
+
{"version":3,"file":"ErrorModel.js","names":["ErrorModel","constructor","id","defaultMessage","parameters","isClientConstraint","layouthint","LayoutHintCollection","_id","_parameters","_defaultMessage","_isClientConstraint","_layouthint","Array","isArray","isMandatoryConstraint"],"sources":["../../../src/models/error/ErrorModel.js"],"sourcesContent":["// @flow\nimport type { MessageParameters } from \"../../i18n/types\";\nimport LayoutHintCollection from \"../layouthint/LayoutHintCollection\";\n\n/**\n * Wrapper around an error message / object\n */\nclass ErrorModel {\n _id: string;\n _defaultMessage: ?string;\n _parameters: ?MessageParameters;\n _isClientConstraint: boolean;\n _layouthint: LayoutHintCollection;\n\n /**\n * Contruct\n */\n constructor(\n id: string,\n defaultMessage: ?string,\n parameters: ?MessageParameters,\n isClientConstraint: boolean = false,\n layouthint: LayoutHintCollection = new LayoutHintCollection()\n ) {\n this._id = id;\n this._parameters = parameters;\n this._defaultMessage = defaultMessage;\n this._isClientConstraint = isClientConstraint;\n this._layouthint = Array.isArray(layouthint)\n ? new LayoutHintCollection(layouthint)\n : layouthint;\n }\n\n /**\n * Get id of error\n */\n get id(): string {\n return this._id;\n }\n\n /**\n */\n get defaultMessage(): ?string {\n return this._defaultMessage;\n }\n\n /**\n */\n get parameters(): ?MessageParameters {\n return this._parameters;\n }\n\n /**\n */\n get isClientConstraint(): boolean {\n return this._isClientConstraint || false;\n }\n\n /**\n */\n get layouthint(): LayoutHintCollection {\n return this._layouthint;\n }\n\n /**\n */\n get isMandatoryConstraint(): boolean {\n return this.id === \"Constraint.Mandatory\";\n }\n}\n\nexport default ErrorModel;\n"],"mappings":";;;;;;;;;;;AAEA;;AAEA;AACA;AACA;AACA,MAAMA,UAAN,CAAiB;EAOf;AACF;AACA;EACEC,WAAW,CACTC,EADS,EAETC,cAFS,EAGTC,UAHS,EAMT;IAAA,IAFAC,kBAEA,uEAF8B,KAE9B;IAAA,IADAC,UACA,uEADmC,IAAIC,6BAAJ,EACnC;IAAA;IAAA;IAAA;IAAA;IAAA;IACA,KAAKC,GAAL,GAAWN,EAAX;IACA,KAAKO,WAAL,GAAmBL,UAAnB;IACA,KAAKM,eAAL,GAAuBP,cAAvB;IACA,KAAKQ,mBAAL,GAA2BN,kBAA3B;IACA,KAAKO,WAAL,GAAmBC,KAAK,CAACC,OAAN,CAAcR,UAAd,IACf,IAAIC,6BAAJ,CAAyBD,UAAzB,CADe,GAEfA,UAFJ;EAGD;EAED;AACF;AACA;;;EACQ,IAAFJ,EAAE,GAAW;IACf,OAAO,KAAKM,GAAZ;EACD;EAED;AACF;;;EACoB,IAAdL,cAAc,GAAY;IAC5B,OAAO,KAAKO,eAAZ;EACD;EAED;AACF;;;EACgB,IAAVN,UAAU,GAAuB;IACnC,OAAO,KAAKK,WAAZ;EACD;EAED;AACF;;;EACwB,IAAlBJ,kBAAkB,GAAY;IAChC,OAAO,KAAKM,mBAAL,IAA4B,KAAnC;EACD;EAED;AACF;;;EACgB,IAAVL,UAAU,GAAyB;IACrC,OAAO,KAAKM,WAAZ;EACD;EAED;AACF;;;EAC2B,IAArBG,qBAAqB,GAAY;IACnC,OAAO,KAAKb,EAAL,KAAY,sBAAnB;EACD;;AA7Dc;;eAgEFF,U"}
|
|
@@ -139,9 +139,9 @@ class ErrorResponse {
|
|
|
139
139
|
|
|
140
140
|
|
|
141
141
|
get redirectText() {
|
|
142
|
-
var _this$response$redire;
|
|
142
|
+
var _this$response, _this$response$redire;
|
|
143
143
|
|
|
144
|
-
return ((_this$response
|
|
144
|
+
return ((_this$response = this.response) === null || _this$response === void 0 ? void 0 : (_this$response$redire = _this$response.redirect) === null || _this$response$redire === void 0 ? void 0 : _this$response$redire.text) || null;
|
|
145
145
|
}
|
|
146
146
|
/**
|
|
147
147
|
* Return response error redirect text id
|
|
@@ -182,7 +182,9 @@ class ErrorResponse {
|
|
|
182
182
|
var _this$response$redire8;
|
|
183
183
|
|
|
184
184
|
if ((_this$response$redire8 = this.response.redirect) !== null && _this$response$redire8 !== void 0 && _this$response$redire8.href) {
|
|
185
|
-
|
|
185
|
+
var _this$response$redire9;
|
|
186
|
+
|
|
187
|
+
return new _Href.default((_this$response$redire9 = this.response.redirect) === null || _this$response$redire9 === void 0 ? void 0 : _this$response$redire9.href);
|
|
186
188
|
}
|
|
187
189
|
|
|
188
190
|
return new _Href.default();
|
|
@@ -193,14 +195,18 @@ class ErrorResponse {
|
|
|
193
195
|
|
|
194
196
|
|
|
195
197
|
get layouthint() {
|
|
196
|
-
|
|
198
|
+
var _this$response2;
|
|
199
|
+
|
|
200
|
+
return new _LayoutHintCollection.default((_this$response2 = this.response) === null || _this$response2 === void 0 ? void 0 : _this$response2.layouthint);
|
|
197
201
|
}
|
|
198
202
|
/**
|
|
199
203
|
*/
|
|
200
204
|
|
|
201
205
|
|
|
202
206
|
get response() {
|
|
203
|
-
|
|
207
|
+
var _this$error, _this$error$response;
|
|
208
|
+
|
|
209
|
+
return ((_this$error = this.error) === null || _this$error === void 0 ? void 0 : (_this$error$response = _this$error.response) === null || _this$error$response === void 0 ? void 0 : _this$error$response.error) || {};
|
|
204
210
|
}
|
|
205
211
|
/**
|
|
206
212
|
*/
|
|
@@ -133,7 +133,7 @@ export default class ErrorResponse {
|
|
|
133
133
|
* Return response error redirect text
|
|
134
134
|
*/
|
|
135
135
|
get redirectText(): RedirectTextObject {
|
|
136
|
-
return this.response
|
|
136
|
+
return this.response?.redirect?.text || null;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/**
|
|
@@ -162,7 +162,7 @@ export default class ErrorResponse {
|
|
|
162
162
|
*/
|
|
163
163
|
get redirectHref(): Href {
|
|
164
164
|
if (this.response.redirect?.href) {
|
|
165
|
-
return new Href(this.response.redirect
|
|
165
|
+
return new Href(this.response.redirect?.href);
|
|
166
166
|
}
|
|
167
167
|
return new Href();
|
|
168
168
|
}
|
|
@@ -171,13 +171,13 @@ export default class ErrorResponse {
|
|
|
171
171
|
* Return error response layouthint
|
|
172
172
|
*/
|
|
173
173
|
get layouthint(): LayoutHintCollection {
|
|
174
|
-
return new LayoutHintCollection(this.response
|
|
174
|
+
return new LayoutHintCollection(this.response?.layouthint);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
/**
|
|
178
178
|
*/
|
|
179
179
|
get response(): Object {
|
|
180
|
-
return this.error
|
|
180
|
+
return this.error?.response?.error || {};
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorResponse.js","names":["ErrorResponse","constructor","data","connectKey","_error","_connectKey","key","error","status","NO_RESPONSE_CODE","DECIMAL_RADIX","parseInt","id","isResourceNotFound","name","message","responseMessage","response","title","titleMessage","undefined","titleId","titleProperties","properties","redirect","redirectText","text","redirectTextID","redirectTextProperties","redirectMessage","redirectHref","href","Href","layouthint","LayoutHintCollection","parameters","RESOURCE_NOT_FOUND_RESPONSE_CODE","isResourceNotFoundAfterReload","isReload","isUnauthorized","UNAUTHORIZED_RESPONSE_CODE","hasUnauthorizedStatus","hasUnauthorizedErrorId","hasLoginAction","action","isChangePassword","isConcurrentUser","isConcurrentError","isBlocked","isInvalidUsername","isTimeoutError","isRemoteServiceException","changePasswordHref","isBasicAuthentication","loginFailed","shouldThrowOnServer"],"sources":["../../../src/models/error/ErrorResponse.js"],"sourcesContent":["// @flow\nimport Href from \"../href/Href\";\n\nimport type { MessageParameters } from \"../../i18n/types\";\nimport LayoutHintCollection from \"../layouthint/LayoutHintCollection\";\n\n/**\n */\nexport type TitleObject = {\n +id: string,\n +properties?: Object,\n +message?: string,\n};\n/**\n */\nexport type RedirectTextObject = {\n +id: string,\n +properties?: Object,\n +message?: string,\n};\n\n/**\n */\nexport type RedirectObject = {\n +href: Href,\n +text?: RedirectTextObject,\n};\n\n/**\n * Error response model\n */\nexport default class ErrorResponse {\n _error: Object;\n _connectKey: ?string;\n\n /**\n * Construct ErrorResponse\n */\n constructor(data: Object, connectKey?: string) {\n this._error = data;\n this._connectKey = connectKey;\n }\n\n /**\n */\n set connectKey(key: string) {\n this._connectKey = key;\n }\n\n /**\n */\n get connectKey(): ?string {\n return this._connectKey;\n }\n\n /**\n * Return error information\n */\n get error(): Object {\n return this._error ?? {};\n }\n\n /**\n * Get request status code\n */\n get status(): number {\n const NO_RESPONSE_CODE = 0;\n const DECIMAL_RADIX = 10;\n return this.error.status\n ? parseInt(this.error.status, DECIMAL_RADIX)\n : NO_RESPONSE_CODE;\n }\n\n /**\n * Return error type information\n */\n get id(): string {\n if (this.isResourceNotFound && this.error.id !== \"Error.NotAuthorized\") {\n return \"Error.ResourceNotFound\";\n }\n\n return this.error.id || this.error.name || \"Error.GeneralError\";\n }\n\n /**\n */\n get message(): string {\n return this.error.message || this.id;\n }\n\n /**\n * Return response error message\n */\n get responseMessage(): string {\n return this.response.message || this.id;\n }\n\n /**\n * Return response error title\n */\n get title(): TitleObject {\n return this.response.title || null;\n }\n\n /**\n * Return response error title message\n */\n get titleMessage(): string {\n return this.response.title?.message || undefined;\n }\n\n /**\n * Return response error title Id\n */\n get titleId(): string {\n return this.response.title?.id || undefined;\n }\n\n /**\n * Return response error title properties\n */\n get titleProperties(): Object {\n return this.response.title?.properties || null;\n }\n\n /**\n * Return response error redirect\n */\n get redirect(): RedirectObject {\n return this.response.redirect || null;\n }\n /**\n * Return response error redirect text\n */\n get redirectText(): RedirectTextObject {\n return this.response.redirect?.text || null;\n }\n\n /**\n * Return response error redirect text id\n */\n get redirectTextID(): string {\n return this.response.redirect?.text?.id || undefined;\n }\n\n /**\n * Return response error redirect text properties\n */\n get redirectTextProperties(): Object {\n return this.response.redirect?.text?.properties || null;\n }\n\n /**\n * Return response error redirect text message\n */\n get redirectMessage(): string {\n return this.response.redirect?.text?.message || undefined;\n }\n\n /**\n * Return response error redirect href\n */\n get redirectHref(): Href {\n if (this.response.redirect?.href) {\n return new Href(this.response.redirect.href);\n }\n return new Href();\n }\n\n /**\n * Return error response layouthint\n */\n get layouthint(): LayoutHintCollection {\n return new LayoutHintCollection(this.response.layouthint);\n }\n\n /**\n */\n get response(): Object {\n return this.error.response.error || {};\n }\n\n /**\n */\n get properties(): Object {\n const { properties } = this.error;\n if (properties != null && typeof properties == \"object\") {\n return properties;\n }\n\n return {};\n }\n\n /**\n * Return error parameters\n */\n get parameters(): ?MessageParameters {\n return this.error.parameters || null;\n }\n\n /**\n */\n get isResourceNotFound(): boolean {\n const RESOURCE_NOT_FOUND_RESPONSE_CODE = 404;\n\n return this.status === RESOURCE_NOT_FOUND_RESPONSE_CODE;\n }\n\n /**\n */\n get isResourceNotFoundAfterReload(): boolean {\n return this.isResourceNotFound && this.error.isReload;\n }\n\n /**\n * Check if the error message is an authorization error\n */\n get isUnauthorized(): boolean {\n const UNAUTHORIZED_RESPONSE_CODE = 401;\n\n const hasUnauthorizedStatus = this.status === UNAUTHORIZED_RESPONSE_CODE;\n const hasUnauthorizedErrorId =\n this.id === \"Error.NotAuthorized\" ||\n this.id === \"Error.Authentication.Required\" ||\n this.id === \"Error.Authentication.InvalidUsername\" ||\n this.id === \"Error.Authentication.InvalidCredentials\";\n\n const hasLoginAction = this.error.action\n ? this.error.action.name === \"login\"\n : false;\n\n return hasUnauthorizedStatus || hasUnauthorizedErrorId || hasLoginAction;\n }\n\n /**\n */\n get isChangePassword(): boolean {\n return this.id === \"Error.ChangePasswordRequired\";\n }\n\n /**\n */\n get isConcurrentUser(): boolean {\n return this.id === \"Error.Authentication.ConcurrentUser\";\n }\n\n /**\n */\n get isConcurrentError(): boolean {\n return (\n this.id === \"Error.Case.ConcurrentModification\" ||\n this.id === \"Error.DataStore.ConcurrentModification\" ||\n this.id === \"Error.DataStore.RecordAlreadyExists\" ||\n this.id === \"Error.DataStore.RowCannotBeLocked\"\n );\n }\n\n /**\n */\n get isBlocked(): boolean {\n return this.id === \"Error.Authentication.BlockedUser\";\n }\n\n /**\n */\n get isInvalidUsername(): boolean {\n return this.id === \"Error.Authentication.InvalidUsername\";\n }\n\n /**\n */\n get isTimeoutError(): boolean {\n return this.id === \"Error.CodemapLookup.InvalidToken\";\n }\n\n /**\n * A RemoteServiceException occurs when an exception occurs connecting to an external system,\n * for example when using the service list panels\n */\n get isRemoteServiceException(): boolean {\n return this.id === \"Error.RemoteServiceException\";\n }\n\n /**\n * Get response url\n */\n get changePasswordHref(): ?Href {\n return this.properties.redirect ? new Href(this.properties.redirect) : null;\n }\n\n /**\n * When no action information is present in the unauthorized response, for now we assume it is Basic Authentication\n */\n get isBasicAuthentication(): boolean {\n const UNAUTHORIZED_RESPONSE_CODE = 401;\n return (\n this.isUnauthorized &&\n this.status === UNAUTHORIZED_RESPONSE_CODE &&\n this.response.error === \"No responseText\"\n );\n }\n\n /**\n * Retrieve a failed login attempt\n */\n get loginFailed(): boolean {\n return (\n this.id === \"Error.Authentication.Required\" ||\n this.id === \"Error.Authentication.InvalidCredentials\"\n );\n }\n\n /**\n */\n get shouldThrowOnServer(): boolean {\n return !this.isChangePassword && !this.isBlocked && !this.isConcurrentUser;\n }\n}\n"],"mappings":";;;;;;;;;;;AACA;;AAGA;;AAwBA;AACA;AACA;AACe,MAAMA,aAAN,CAAoB;EAIjC;AACF;AACA;EACEC,WAAW,CAACC,IAAD,EAAeC,UAAf,EAAoC;IAAA;IAAA;IAC7C,KAAKC,MAAL,GAAcF,IAAd;IACA,KAAKG,WAAL,GAAmBF,UAAnB;EACD;EAED;AACF;;;EACgB,IAAVA,UAAU,CAACG,GAAD,EAAc;IAC1B,KAAKD,WAAL,GAAmBC,GAAnB;EACD;EAED;AACF;;;EACgB,IAAVH,UAAU,GAAY;IACxB,OAAO,KAAKE,WAAZ;EACD;EAED;AACF;AACA;;;EACW,IAALE,KAAK,GAAW;IAAA;;IAClB,uBAAO,KAAKH,MAAZ,uDAAsB,EAAtB;EACD;EAED;AACF;AACA;;;EACY,IAANI,MAAM,GAAW;IACnB,MAAMC,gBAAgB,GAAG,CAAzB;IACA,MAAMC,aAAa,GAAG,EAAtB;IACA,OAAO,KAAKH,KAAL,CAAWC,MAAX,GACHG,QAAQ,CAAC,KAAKJ,KAAL,CAAWC,MAAZ,EAAoBE,aAApB,CADL,GAEHD,gBAFJ;EAGD;EAED;AACF;AACA;;;EACQ,IAAFG,EAAE,GAAW;IACf,IAAI,KAAKC,kBAAL,IAA2B,KAAKN,KAAL,CAAWK,EAAX,KAAkB,qBAAjD,EAAwE;MACtE,OAAO,wBAAP;IACD;;IAED,OAAO,KAAKL,KAAL,CAAWK,EAAX,IAAiB,KAAKL,KAAL,CAAWO,IAA5B,IAAoC,oBAA3C;EACD;EAED;AACF;;;EACa,IAAPC,OAAO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AA3B,GAAgE,IAAvE;EACD;EAED;AACF;AACA;;;EAC2B,IAArB6B,qBAAqB,GAAY;IACnC,MAAMb,0BAA0B,GAAG,GAAnC;IACA,OACE,KAAKD,cAAL,IACA,KAAK/B,MAAL,KAAgBgC,0BADhB,IAEA,KAAKvB,QAAL,CAAcV,KAAd,KAAwB,iBAH1B;EAKD;EAED;AACF;AACA;;;EACiB,IAAX+C,WAAW,GAAY;IACzB,OACE,KAAK1C,EAAL,KAAY,+BAAZ,IACA,KAAKA,EAAL,KAAY,yCAFd;EAID;EAED;AACF;;;EACyB,IAAnB2C,mBAAmB,GAAY;IACjC,OAAO,CAAC,KAAKV,gBAAN,IAA0B,CAAC,KAAKG,SAAhC,IAA6C,CAAC,KAAKF,gBAA1D;EACD;;AA7RgC"}
|
|
1
|
+
{"version":3,"file":"ErrorResponse.js","names":["ErrorResponse","constructor","data","connectKey","_error","_connectKey","key","error","status","NO_RESPONSE_CODE","DECIMAL_RADIX","parseInt","id","isResourceNotFound","name","message","responseMessage","response","title","titleMessage","undefined","titleId","titleProperties","properties","redirect","redirectText","text","redirectTextID","redirectTextProperties","redirectMessage","redirectHref","href","Href","layouthint","LayoutHintCollection","parameters","RESOURCE_NOT_FOUND_RESPONSE_CODE","isResourceNotFoundAfterReload","isReload","isUnauthorized","UNAUTHORIZED_RESPONSE_CODE","hasUnauthorizedStatus","hasUnauthorizedErrorId","hasLoginAction","action","isChangePassword","isConcurrentUser","isConcurrentError","isBlocked","isInvalidUsername","isTimeoutError","isRemoteServiceException","changePasswordHref","isBasicAuthentication","loginFailed","shouldThrowOnServer"],"sources":["../../../src/models/error/ErrorResponse.js"],"sourcesContent":["// @flow\nimport Href from \"../href/Href\";\n\nimport type { MessageParameters } from \"../../i18n/types\";\nimport LayoutHintCollection from \"../layouthint/LayoutHintCollection\";\n\n/**\n */\nexport type TitleObject = {\n +id: string,\n +properties?: Object,\n +message?: string,\n};\n/**\n */\nexport type RedirectTextObject = {\n +id: string,\n +properties?: Object,\n +message?: string,\n};\n\n/**\n */\nexport type RedirectObject = {\n +href: Href,\n +text?: RedirectTextObject,\n};\n\n/**\n * Error response model\n */\nexport default class ErrorResponse {\n _error: Object;\n _connectKey: ?string;\n\n /**\n * Construct ErrorResponse\n */\n constructor(data: Object, connectKey?: string) {\n this._error = data;\n this._connectKey = connectKey;\n }\n\n /**\n */\n set connectKey(key: string) {\n this._connectKey = key;\n }\n\n /**\n */\n get connectKey(): ?string {\n return this._connectKey;\n }\n\n /**\n * Return error information\n */\n get error(): Object {\n return this._error ?? {};\n }\n\n /**\n * Get request status code\n */\n get status(): number {\n const NO_RESPONSE_CODE = 0;\n const DECIMAL_RADIX = 10;\n return this.error.status\n ? parseInt(this.error.status, DECIMAL_RADIX)\n : NO_RESPONSE_CODE;\n }\n\n /**\n * Return error type information\n */\n get id(): string {\n if (this.isResourceNotFound && this.error.id !== \"Error.NotAuthorized\") {\n return \"Error.ResourceNotFound\";\n }\n\n return this.error.id || this.error.name || \"Error.GeneralError\";\n }\n\n /**\n */\n get message(): string {\n return this.error.message || this.id;\n }\n\n /**\n * Return response error message\n */\n get responseMessage(): string {\n return this.response.message || this.id;\n }\n\n /**\n * Return response error title\n */\n get title(): TitleObject {\n return this.response.title || null;\n }\n\n /**\n * Return response error title message\n */\n get titleMessage(): string {\n return this.response.title?.message || undefined;\n }\n\n /**\n * Return response error title Id\n */\n get titleId(): string {\n return this.response.title?.id || undefined;\n }\n\n /**\n * Return response error title properties\n */\n get titleProperties(): Object {\n return this.response.title?.properties || null;\n }\n\n /**\n * Return response error redirect\n */\n get redirect(): RedirectObject {\n return this.response.redirect || null;\n }\n /**\n * Return response error redirect text\n */\n get redirectText(): RedirectTextObject {\n return this.response?.redirect?.text || null;\n }\n\n /**\n * Return response error redirect text id\n */\n get redirectTextID(): string {\n return this.response.redirect?.text?.id || undefined;\n }\n\n /**\n * Return response error redirect text properties\n */\n get redirectTextProperties(): Object {\n return this.response.redirect?.text?.properties || null;\n }\n\n /**\n * Return response error redirect text message\n */\n get redirectMessage(): string {\n return this.response.redirect?.text?.message || undefined;\n }\n\n /**\n * Return response error redirect href\n */\n get redirectHref(): Href {\n if (this.response.redirect?.href) {\n return new Href(this.response.redirect?.href);\n }\n return new Href();\n }\n\n /**\n * Return error response layouthint\n */\n get layouthint(): LayoutHintCollection {\n return new LayoutHintCollection(this.response?.layouthint);\n }\n\n /**\n */\n get response(): Object {\n return this.error?.response?.error || {};\n }\n\n /**\n */\n get properties(): Object {\n const { properties } = this.error;\n if (properties != null && typeof properties == \"object\") {\n return properties;\n }\n\n return {};\n }\n\n /**\n * Return error parameters\n */\n get parameters(): ?MessageParameters {\n return this.error.parameters || null;\n }\n\n /**\n */\n get isResourceNotFound(): boolean {\n const RESOURCE_NOT_FOUND_RESPONSE_CODE = 404;\n\n return this.status === RESOURCE_NOT_FOUND_RESPONSE_CODE;\n }\n\n /**\n */\n get isResourceNotFoundAfterReload(): boolean {\n return this.isResourceNotFound && this.error.isReload;\n }\n\n /**\n * Check if the error message is an authorization error\n */\n get isUnauthorized(): boolean {\n const UNAUTHORIZED_RESPONSE_CODE = 401;\n\n const hasUnauthorizedStatus = this.status === UNAUTHORIZED_RESPONSE_CODE;\n const hasUnauthorizedErrorId =\n this.id === \"Error.NotAuthorized\" ||\n this.id === \"Error.Authentication.Required\" ||\n this.id === \"Error.Authentication.InvalidUsername\" ||\n this.id === \"Error.Authentication.InvalidCredentials\";\n\n const hasLoginAction = this.error.action\n ? this.error.action.name === \"login\"\n : false;\n\n return hasUnauthorizedStatus || hasUnauthorizedErrorId || hasLoginAction;\n }\n\n /**\n */\n get isChangePassword(): boolean {\n return this.id === \"Error.ChangePasswordRequired\";\n }\n\n /**\n */\n get isConcurrentUser(): boolean {\n return this.id === \"Error.Authentication.ConcurrentUser\";\n }\n\n /**\n */\n get isConcurrentError(): boolean {\n return (\n this.id === \"Error.Case.ConcurrentModification\" ||\n this.id === \"Error.DataStore.ConcurrentModification\" ||\n this.id === \"Error.DataStore.RecordAlreadyExists\" ||\n this.id === \"Error.DataStore.RowCannotBeLocked\"\n );\n }\n\n /**\n */\n get isBlocked(): boolean {\n return this.id === \"Error.Authentication.BlockedUser\";\n }\n\n /**\n */\n get isInvalidUsername(): boolean {\n return this.id === \"Error.Authentication.InvalidUsername\";\n }\n\n /**\n */\n get isTimeoutError(): boolean {\n return this.id === \"Error.CodemapLookup.InvalidToken\";\n }\n\n /**\n * A RemoteServiceException occurs when an exception occurs connecting to an external system,\n * for example when using the service list panels\n */\n get isRemoteServiceException(): boolean {\n return this.id === \"Error.RemoteServiceException\";\n }\n\n /**\n * Get response url\n */\n get changePasswordHref(): ?Href {\n return this.properties.redirect ? new Href(this.properties.redirect) : null;\n }\n\n /**\n * When no action information is present in the unauthorized response, for now we assume it is Basic Authentication\n */\n get isBasicAuthentication(): boolean {\n const UNAUTHORIZED_RESPONSE_CODE = 401;\n return (\n this.isUnauthorized &&\n this.status === UNAUTHORIZED_RESPONSE_CODE &&\n this.response.error === \"No responseText\"\n );\n }\n\n /**\n * Retrieve a failed login attempt\n */\n get loginFailed(): boolean {\n return (\n this.id === \"Error.Authentication.Required\" ||\n this.id === \"Error.Authentication.InvalidCredentials\"\n );\n }\n\n /**\n */\n get shouldThrowOnServer(): boolean {\n return !this.isChangePassword && !this.isBlocked && !this.isConcurrentUser;\n }\n}\n"],"mappings":";;;;;;;;;;;AACA;;AAGA;;AAwBA;AACA;AACA;AACe,MAAMA,aAAN,CAAoB;EAIjC;AACF;AACA;EACEC,WAAW,CAACC,IAAD,EAAeC,UAAf,EAAoC;IAAA;IAAA;IAC7C,KAAKC,MAAL,GAAcF,IAAd;IACA,KAAKG,WAAL,GAAmBF,UAAnB;EACD;EAED;AACF;;;EACgB,IAAVA,UAAU,CAACG,GAAD,EAAc;IAC1B,KAAKD,WAAL,GAAmBC,GAAnB;EACD;EAED;AACF;;;EACgB,IAAVH,UAAU,GAAY;IACxB,OAAO,KAAKE,WAAZ;EACD;EAED;AACF;AACA;;;EACW,IAAL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L,KAAY,mCAAZ,IACA,KAAKA,EAAL,KAAY,wCADZ,IAEA,KAAKA,EAAL,KAAY,qCAFZ,IAGA,KAAKA,EAAL,KAAY,mCAJd;EAMD;EAED;AACF;;;EACe,IAAToC,SAAS,GAAY;IACvB,OAAO,KAAKpC,EAAL,KAAY,kCAAnB;EACD;EAED;AACF;;;EACuB,IAAjBqC,iBAAiB,GAAY;IAC/B,OAAO,KAAKrC,EAAL,KAAY,sCAAnB;EACD;EAED;AACF;;;EACoB,IAAdsC,cAAc,GAAY;IAC5B,OAAO,KAAKtC,EAAL,KAAY,kCAAnB;EACD;EAED;AACF;AACA;AACA;;;EAC8B,IAAxBuC,wBAAwB,GAAY;IACtC,OAAO,KAAKvC,EAAL,KAAY,8BAAnB;EACD;EAED;AACF;AACA;;;EACwB,IAAlBwC,kBAAkB,GAAU;IAC9B,OAAO,KAAK7B,UAAL,CAAgBC,QAAhB,GAA2B,IAAIQ,aAAJ,CAAS,KAAKT,UAAL,CAAgBC,QAAzB,CAA3B,GAAgE,IAAvE;EACD;EAED;AACF;AACA;;;EAC2B,IAArB6B,qBAAqB,GAAY;IACnC,MAAMb,0BAA0B,GAAG,GAAnC;IACA,OACE,KAAKD,cAAL,IACA,KAAK/B,MAAL,KAAgBgC,0BADhB,IAEA,KAAKvB,QAAL,CAAcV,KAAd,KAAwB,iBAH1B;EAKD;EAED;AACF;AACA;;;EACiB,IAAX+C,WAAW,GAAY;IACzB,OACE,KAAK1C,EAAL,KAAY,+BAAZ,IACA,KAAKA,EAAL,KAAY,yCAFd;EAID;EAED;AACF;;;EACyB,IAAnB2C,mBAAmB,GAAY;IACjC,OAAO,CAAC,KAAKV,gBAAN,IAA0B,CAAC,KAAKG,SAAhC,IAA6C,CAAC,KAAKF,gBAA1D;EACD;;AA7RgC"}
|
|
@@ -49,6 +49,8 @@ var _Settings = require("../../constants/Settings");
|
|
|
49
49
|
|
|
50
50
|
var _LayoutHints = require("../../constants/LayoutHints");
|
|
51
51
|
|
|
52
|
+
var _LayoutHintCollection = _interopRequireDefault(require("../layouthint/LayoutHintCollection"));
|
|
53
|
+
|
|
52
54
|
/**
|
|
53
55
|
*/
|
|
54
56
|
class FormModel extends _ResourceModel.default {
|
|
@@ -549,9 +551,9 @@ class FormModel extends _ResourceModel.default {
|
|
|
549
551
|
|
|
550
552
|
addServerError(error) {
|
|
551
553
|
if (error.parameters) {
|
|
552
|
-
this.errorCollection.addServerError(error.id, error.message, error.parameters);
|
|
554
|
+
this.errorCollection.addServerError(error.id, error.message, error.parameters, error.layouthint);
|
|
553
555
|
} else {
|
|
554
|
-
this.errorCollection.addServerError(error.id, error.message);
|
|
556
|
+
this.errorCollection.addServerError(error.id, error.message, undefined, error.layouthint);
|
|
555
557
|
}
|
|
556
558
|
}
|
|
557
559
|
/**
|
|
@@ -1034,7 +1036,7 @@ class FormModel extends _ResourceModel.default {
|
|
|
1034
1036
|
if (error.anchor && this.currentFormObject && this.currentFormObject.key === error.anchor.objectid) {
|
|
1035
1037
|
this.currentFormObject.addServerError(error);
|
|
1036
1038
|
} else {
|
|
1037
|
-
this.errorCollection.addServerError(error.id, error.message, error.properties);
|
|
1039
|
+
this.errorCollection.addServerError(error.id, error.message, error.properties, new _LayoutHintCollection.default(error.layouthint));
|
|
1038
1040
|
}
|
|
1039
1041
|
});
|
|
1040
1042
|
}
|