@beinformed/ui 1.25.1-beta.1 → 1.25.2

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 CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.25.2](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.25.1...v1.25.2) (2023-01-05)
6
+
7
+ ### Bug Fixes
8
+
9
+ - **mandatory:** handle missing validations on first repeat of unknown repeat ([c1187fb](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/commit/c1187fb996b97314229974dbdbe6bdb0e955a793))
10
+
11
+ ### [1.25.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.25.1-beta.1...v1.25.1) (2023-01-03)
12
+
5
13
  ### [1.25.1-beta.1](https://git.beinformed.com/public/nl.beinformed.bi.layout.lib.ui/compare/v1.25.1-beta.0...v1.25.1-beta.1) (2023-01-03)
6
14
 
7
15
  ### Bug Fixes
@@ -4,7 +4,10 @@ import clone from "lodash/clone";
4
4
  import cloneDeep from "lodash/cloneDeep";
5
5
  import LayoutHintCollection from "../layouthint/LayoutHintCollection";
6
6
  /**
7
- * Base model
7
+ * Base model, this is the foundation of a model,
8
+ * it contains data that is needed for all models like, data, contributions and layout hint
9
+ *
10
+ * Extend this for non modular ui resources, for modular ui resource start with the resourceModel
8
11
  */
9
12
  class BaseModel {
10
13
  /**
@@ -28,6 +31,7 @@ class BaseModel {
28
31
  }
29
32
 
30
33
  /**
34
+ * Retrieve property from the data object of the model, mostly used internal
31
35
  */
32
36
  getData(propName) {
33
37
  let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
@@ -42,6 +46,7 @@ class BaseModel {
42
46
  }
43
47
 
44
48
  /**
49
+ * Retrieve property from the contributions of the model, mostly used internal
45
50
  */
46
51
  getContribution(propName) {
47
52
  let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
@@ -70,18 +75,21 @@ class BaseModel {
70
75
  }
71
76
 
72
77
  /**
78
+ * Set the unique key for this model
73
79
  */
74
80
  set connectKey(key) {
75
81
  this._connectKey = key;
76
82
  }
77
83
 
78
84
  /**
85
+ * Get the unique key of this model
79
86
  */
80
87
  get connectKey() {
81
88
  return this._connectKey;
82
89
  }
83
90
 
84
91
  /**
92
+ * Dehydrate internal data, returns the information that is needed to recreate the model
85
93
  */
86
94
  dehydrate() {
87
95
  return {
@@ -92,13 +100,14 @@ class BaseModel {
92
100
  }
93
101
 
94
102
  /**
103
+ * Recreate the model with the given data
95
104
  */
96
105
  rehydrate(data) {
97
106
  this._connectKey = data.connectKey;
98
107
  }
99
108
 
100
109
  /**
101
- * Returns a clone of the model (this is not a deep copy)
110
+ * Returns a clone of the model
102
111
  */
103
112
  clone() {
104
113
  let deepcopy = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
@@ -1 +1 @@
1
- {"version":3,"file":"BaseModel.js","names":["clone","cloneDeep","LayoutHintCollection","BaseModel","constructor","data","contributions","_data","_contributions","_layouthint","getContribution","getData","propName","defaultValue","layouthint","hasData","length","connectKey","key","_connectKey","dehydrate","rehydrate","deepcopy"],"sources":["../../../src/models/base/BaseModel.js"],"sourcesContent":["// @flow\nimport clone from \"lodash/clone\";\nimport cloneDeep from \"lodash/cloneDeep\";\n\nimport LayoutHintCollection from \"../layouthint/LayoutHintCollection\";\n\nexport type BaseDehydrateData = {\n +data: Object,\n +contributions: Object,\n connectKey: string,\n ...\n};\n\n/**\n * Base model\n */\nclass BaseModel {\n _data: Object;\n _contributions: Object;\n _layouthint: LayoutHintCollection;\n _connectKey: string;\n\n /**\n * constructor\n */\n constructor(data: Object, contributions: Object) {\n this._data = data;\n this._contributions = contributions;\n this._layouthint = new LayoutHintCollection(\n this.getContribution(\"layouthint\", [])\n );\n }\n\n /**\n * Retrieve data\n */\n get data(): Object {\n return this._data || {};\n }\n\n /**\n */\n getData(propName: string, defaultValue: any = null): any {\n return this.data[propName] ?? defaultValue;\n }\n\n /**\n * Retrieve contributions\n */\n get contributions(): Object {\n return this._contributions || {};\n }\n\n /**\n */\n getContribution(propName: string, defaultValue: any = null): any {\n return this.contributions[propName] ?? defaultValue;\n }\n\n /**\n * Getting the layouthint\n */\n get layouthint(): LayoutHintCollection {\n return this._layouthint;\n }\n\n /**\n * Set the layouthint\n */\n set layouthint(layouthint: Array<string>) {\n this._layouthint = new LayoutHintCollection(layouthint);\n }\n\n /**\n * Indicates if the model has data\n */\n get hasData(): boolean {\n return Object.keys(this.data).length > 0;\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 */\n dehydrate(): BaseDehydrateData {\n return {\n data: this._data,\n contributions: this._contributions,\n connectKey: this._connectKey,\n };\n }\n\n /**\n */\n rehydrate(data: Object) {\n this._connectKey = data.connectKey;\n }\n\n /**\n * Returns a clone of the model (this is not a deep copy)\n */\n clone(deepcopy: boolean = false): any {\n // deepcopy can be expensive, use with care!\n if (deepcopy) {\n return cloneDeep(this);\n }\n\n return clone(this);\n }\n}\n\nexport default BaseModel;\n"],"mappings":";;AACA,OAAOA,KAAK,MAAM,cAAc;AAChC,OAAOC,SAAS,MAAM,kBAAkB;AAExC,OAAOC,oBAAoB,MAAM,oCAAoC;AASrE;AACA;AACA;AACA,MAAMC,SAAS,CAAC;EAMd;AACF;AACA;EACEC,WAAW,CAACC,IAAY,EAAEC,aAAqB,EAAE;IAAA;IAAA;IAAA;IAAA;IAC/C,IAAI,CAACC,KAAK,GAAGF,IAAI;IACjB,IAAI,CAACG,cAAc,GAAGF,aAAa;IACnC,IAAI,CAACG,WAAW,GAAG,IAAIP,oBAAoB,CACzC,IAAI,CAACQ,eAAe,CAAC,YAAY,EAAE,EAAE,CAAC,CACvC;EACH;;EAEA;AACF;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;AACA;EACEjB,KAAK,GAAiC;IAAA,IAAhCsB,QAAiB,uEAAG,KAAK;IAC7B;IACA,IAAIA,QAAQ,EAAE;MACZ,OAAOrB,SAAS,CAAC,IAAI,CAAC;IACxB;IAEA,OAAOD,KAAK,CAAC,IAAI,CAAC;EACpB;AACF;AAEA,eAAeG,SAAS"}
1
+ {"version":3,"file":"BaseModel.js","names":["clone","cloneDeep","LayoutHintCollection","BaseModel","constructor","data","contributions","_data","_contributions","_layouthint","getContribution","getData","propName","defaultValue","layouthint","hasData","length","connectKey","key","_connectKey","dehydrate","rehydrate","deepcopy"],"sources":["../../../src/models/base/BaseModel.js"],"sourcesContent":["// @flow\nimport clone from \"lodash/clone\";\nimport cloneDeep from \"lodash/cloneDeep\";\n\nimport LayoutHintCollection from \"../layouthint/LayoutHintCollection\";\n\nexport type BaseDehydrateData = {\n +data: Object,\n +contributions: Object,\n connectKey: string,\n ...\n};\n\n/**\n * Base model, this is the foundation of a model,\n * it contains data that is needed for all models like, data, contributions and layout hint\n *\n * Extend this for non modular ui resources, for modular ui resource start with the resourceModel\n */\nclass BaseModel {\n _data: Object;\n _contributions: Object;\n _layouthint: LayoutHintCollection;\n _connectKey: string;\n\n /**\n * constructor\n */\n constructor(data: Object, contributions: Object) {\n this._data = data;\n this._contributions = contributions;\n this._layouthint = new LayoutHintCollection(\n this.getContribution(\"layouthint\", [])\n );\n }\n\n /**\n * Retrieve data\n */\n get data(): Object {\n return this._data || {};\n }\n\n /**\n * Retrieve property from the data object of the model, mostly used internal\n */\n getData(propName: string, defaultValue: any = null): any {\n return this.data[propName] ?? defaultValue;\n }\n\n /**\n * Retrieve contributions\n */\n get contributions(): Object {\n return this._contributions || {};\n }\n\n /**\n * Retrieve property from the contributions of the model, mostly used internal\n */\n getContribution(propName: string, defaultValue: any = null): any {\n return this.contributions[propName] ?? defaultValue;\n }\n\n /**\n * Getting the layouthint\n */\n get layouthint(): LayoutHintCollection {\n return this._layouthint;\n }\n\n /**\n * Set the layouthint\n */\n set layouthint(layouthint: Array<string>) {\n this._layouthint = new LayoutHintCollection(layouthint);\n }\n\n /**\n * Indicates if the model has data\n */\n get hasData(): boolean {\n return Object.keys(this.data).length > 0;\n }\n\n /**\n * Set the unique key for this model\n */\n set connectKey(key: string) {\n this._connectKey = key;\n }\n\n /**\n * Get the unique key of this model\n */\n get connectKey(): string {\n return this._connectKey;\n }\n\n /**\n * Dehydrate internal data, returns the information that is needed to recreate the model\n */\n dehydrate(): BaseDehydrateData {\n return {\n data: this._data,\n contributions: this._contributions,\n connectKey: this._connectKey,\n };\n }\n\n /**\n * Recreate the model with the given data\n */\n rehydrate(data: BaseDehydrateData) {\n this._connectKey = data.connectKey;\n }\n\n /**\n * Returns a clone of the model\n */\n clone(deepcopy: boolean = false): any {\n // deepcopy can be expensive, use with care!\n if (deepcopy) {\n return cloneDeep(this);\n }\n\n return clone(this);\n }\n}\n\nexport default BaseModel;\n"],"mappings":";;AACA,OAAOA,KAAK,MAAM,cAAc;AAChC,OAAOC,SAAS,MAAM,kBAAkB;AAExC,OAAOC,oBAAoB,MAAM,oCAAoC;AASrE;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,SAAS,CAAC;EAMd;AACF;AACA;EACEC,WAAW,CAACC,IAAY,EAAEC,aAAqB,EAAE;IAAA;IAAA;IAAA;IAAA;IAC/C,IAAI,CAACC,KAAK,GAAGF,IAAI;IACjB,IAAI,CAACG,cAAc,GAAGF,aAAa;IACnC,IAAI,CAACG,WAAW,GAAG,IAAIP,oBAAoB,CACzC,IAAI,CAACQ,eAAe,CAAC,YAAY,EAAE,EAAE,CAAC,CACvC;EACH;;EAEA;AACF;AACA;EACE,IAAIL,IAAI,GAAW;IACjB,OAAO,IAAI,CAACE,KAAK,IAAI,CAAC,CAAC;EACzB;;EAEA;AACF;AACA;EACEI,OAAO,CAACC,QAAgB,EAAiC;IAAA,IAA/BC,YAAiB,uEAAG,IAAI;IAChD,OAAO,IAAI,CAACR,IAAI,CAACO,QAAQ,CA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AACF;AAEA,eAAeG,SAAS"}
@@ -6,7 +6,7 @@ import BaseModel from "./BaseModel";
6
6
  import LinkCollection from "../links/LinkCollection";
7
7
  import { IllegalArgumentException, IllegalStateException } from "../../exceptions";
8
8
  /**
9
- * Base model
9
+ * Base model, this the foundation for models that represent modular ui services, e.g. application, tab, caseview, etc
10
10
  */
11
11
  class ResourceModel extends BaseModel {
12
12
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"ResourceModel.js","names":["ModularUIResponse","BaseModel","LinkCollection","IllegalArgumentException","IllegalStateException","ResourceModel","constructor","modularuiResponse","data","contributions","_key","key","_locale","locale","_childModels","_lastServerUpdate","Date","now","isApplicableModel","Error","lastServerUpdate","type","resourcetype","getContribution","label","links","_links","Array","isArray","self","selflink","getLinkByKey","selfhref","href","getInitialChildModelLinks","childModels","addChildModels","models","flattenModels","setChildModels","dehydrate","childModel"],"sources":["../../../src/models/base/ResourceModel.js"],"sourcesContent":["// @flow\nimport ModularUIResponse from \"../../modularui/ModularUIResponse\";\n\nimport BaseModel from \"./BaseModel\";\nimport LinkCollection from \"../links/LinkCollection\";\n\nimport {\n IllegalArgumentException,\n IllegalStateException,\n} from \"../../exceptions\";\n\nimport type LinkModel from \"../links/LinkModel\";\nimport type Href from \"../href/Href\";\nimport type { ModularUIModel, IModelWithChildModels } from \"../types\";\n\n/**\n * Base model\n */\nclass ResourceModel extends BaseModel implements IModelWithChildModels {\n _key: string;\n _locale: string;\n _childModels: Array<ModularUIModel>;\n _links: LinkCollection;\n _lastServerUpdate: number;\n\n /**\n * constructor\n */\n constructor(modularuiResponse: ModularUIResponse = new ModularUIResponse()) {\n super(modularuiResponse.data, modularuiResponse.contributions);\n\n this._key = modularuiResponse.key;\n this._locale = modularuiResponse.locale;\n\n this._childModels = [];\n\n this._lastServerUpdate = Date.now();\n }\n\n /**\n * Returns true when the model is supported based on configuration found in contributions\n *\n * @abstract\n */\n static isApplicableModel(data: ModularUIResponse): boolean {\n if (!(data instanceof ModularUIResponse)) {\n throw new IllegalArgumentException(\n \"Given argument for isApplicableModel is not a ModularUIResponse\"\n );\n }\n\n throw new Error(\"No isApplicableModel condition set on resourcemodel\");\n }\n\n /**\n */\n get lastServerUpdate(): number {\n return this._lastServerUpdate;\n }\n\n /**\n */\n set lastServerUpdate(lastServerUpdate: number) {\n this._lastServerUpdate = lastServerUpdate;\n }\n\n /**\n */\n get locale(): string {\n return this._locale;\n }\n\n /**\n * Retrieve key\n */\n get key(): string {\n return this._key;\n }\n\n /**\n * Get type of model\n *\n * @abstract\n */\n get type(): string {\n throw new IllegalStateException(\n `No type set on the resource model with key ${this.key}`\n );\n }\n\n /**\n * Retrieve type of resource\n */\n get resourcetype(): string {\n return this.getContribution(\"resourcetype\", \"unknown\");\n }\n\n /**\n */\n get label(): string {\n return this.getContribution(\"label\", \"\");\n }\n\n /**\n * Getting the links of the resource\n */\n get links(): LinkCollection {\n if (!this._links) {\n this._links = new LinkCollection(\n Array.isArray(this.data._links)\n ? this.data._links[0]\n : this.data._links,\n {\n self: {\n resourcetype: this.resourcetype,\n },\n ...this.contributions._links,\n }\n );\n }\n return this._links;\n }\n\n /**\n */\n set links(links: LinkCollection) {\n this._links = links;\n }\n\n /**\n * Get self link of model\n */\n get selflink(): LinkModel {\n const selflink = this.links.getLinkByKey(\"self\");\n\n if (selflink === null) {\n throw new IllegalStateException(\n `Could not find self link for ${\n this.key === null ? \"unknown\" : this.key\n }`\n );\n }\n\n return selflink;\n }\n\n /**\n * Return default self link of resource\n */\n get selfhref(): Href {\n return this.selflink.href;\n }\n\n /**\n * Add links to expand on initialization of this model\n *\n * @abstract\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n return [];\n }\n\n /**\n * Retrieve links of expanded child models\n */\n get childModels(): Array<ModularUIModel> {\n return this._childModels;\n }\n\n /**\n * Add child models to this model\n */\n addChildModels(models: Array<ModularUIModel>): this {\n const flattenModels = [].concat(...models);\n\n this._childModels = flattenModels;\n\n this.setChildModels(flattenModels);\n\n return this;\n }\n\n /**\n * Template to set expanded child models\n * Use this hook to separate the retrieved child models into the correct models.\n *\n * @abstract\n * @example <caption>Put all models of instance List and GroupingPanel into the panels property</caption>\n */\n setChildModels(models: Array<ModularUIModel>): void {\n if (!models) {\n throw new IllegalArgumentException(\"No models send to setChildModels\");\n }\n }\n\n /**\n */\n dehydrate(): Object {\n return {\n ...super.dehydrate(),\n key: this._key,\n locale: this._locale,\n // $FlowFixMe[missing-type-arg]\n childModels: this._childModels.map<ModularUIModel>(\n (childModel: ModularUIModel) => childModel.dehydrate()\n ),\n };\n }\n}\n\nexport default ResourceModel;\n"],"mappings":";;;AACA,OAAOA,iBAAiB,MAAM,mCAAmC;AAEjE,OAAOC,SAAS,MAAM,aAAa;AACnC,OAAOC,cAAc,MAAM,yBAAyB;AAEpD,SACEC,wBAAwB,EACxBC,qBAAqB,QAChB,kBAAkB;AAMzB;AACA;AACA;AACA,MAAMC,aAAa,SAASJ,SAAS,CAAkC;EAOrE;AACF;AACA;EACEK,WAAW,GAAiE;IAAA,IAAhEC,iBAAoC,uEAAG,IAAIP,iBAAiB,EAAE;IACxE,KAAK,CAACO,iBAAiB,CAACC,IAAI,EAAED,iBAAiB,CAACE,aAAa,CAAC;IAAC;IAAA;IAAA;IAAA;IAAA;IAE/D,IAAI,CAACC,IAAI,GAAGH,iBAAiB,CAACI,GAAG;IACjC,IAAI,CAACC,OAAO,GAAGL,iBAAiB,CAACM,MAAM;IAEvC,IAAI,CAACC,YAAY,GAAG,EAAE;IAEtB,IAAI,CAACC,iBAAiB,GAAGC,IAAI,CAACC,GAAG,EAAE;EACrC;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAOC,iBAAiB,CAACV,IAAuB,EAAW;IACzD,IAAI,EAAEA,IAAI,YAAYR,iBAAiB,CAAC,EAAE;MACxC,MAAM,IAAIG,wBAAwB,CAChC,iEAAiE,CAClE;IACH;IAEA,MAAM,IAAIgB,KAAK,CAAC,qDAAqD,CAAC;EACxE;;EAEA;AACF;EACE,IA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["ModularUIResponse","BaseModel","LinkCollection","IllegalArgumentException","IllegalStateException","ResourceModel","constructor","modularuiResponse","data","contributions","_key","key","_locale","locale","_childModels","_lastServerUpdate","Date","now","isApplicableModel","Error","lastServerUpdate","type","resourcetype","getContribution","label","links","_links","Array","isArray","self","selflink","getLinkByKey","selfhref","href","getInitialChildModelLinks","childModels","addChildModels","models","flattenModels","setChildModels","dehydrate","childModel"],"sources":["../../../src/models/base/ResourceModel.js"],"sourcesContent":["// @flow\nimport ModularUIResponse from \"../../modularui/ModularUIResponse\";\n\nimport BaseModel from \"./BaseModel\";\nimport LinkCollection from \"../links/LinkCollection\";\n\nimport {\n IllegalArgumentException,\n IllegalStateException,\n} from \"../../exceptions\";\n\nimport type LinkModel from \"../links/LinkModel\";\nimport type Href from \"../href/Href\";\nimport type { ModularUIModel, IModelWithChildModels } from \"../types\";\n\n/**\n * Base model, this the foundation for models that represent modular ui services, e.g. application, tab, caseview, etc\n */\nclass ResourceModel extends BaseModel implements IModelWithChildModels {\n _key: string;\n _locale: string;\n _childModels: Array<ModularUIModel>;\n _links: LinkCollection;\n _lastServerUpdate: number;\n\n /**\n * constructor\n */\n constructor(modularuiResponse: ModularUIResponse = new ModularUIResponse()) {\n super(modularuiResponse.data, modularuiResponse.contributions);\n\n this._key = modularuiResponse.key;\n this._locale = modularuiResponse.locale;\n\n this._childModels = [];\n\n this._lastServerUpdate = Date.now();\n }\n\n /**\n * Returns true when the model is supported based on configuration found in contributions\n *\n * @abstract\n */\n static isApplicableModel(data: ModularUIResponse): boolean {\n if (!(data instanceof ModularUIResponse)) {\n throw new IllegalArgumentException(\n \"Given argument for isApplicableModel is not a ModularUIResponse\"\n );\n }\n\n throw new Error(\"No isApplicableModel condition set on resourcemodel\");\n }\n\n /**\n */\n get lastServerUpdate(): number {\n return this._lastServerUpdate;\n }\n\n /**\n */\n set lastServerUpdate(lastServerUpdate: number) {\n this._lastServerUpdate = lastServerUpdate;\n }\n\n /**\n */\n get locale(): string {\n return this._locale;\n }\n\n /**\n * Retrieve key\n */\n get key(): string {\n return this._key;\n }\n\n /**\n * Get type of model\n *\n * @abstract\n */\n get type(): string {\n throw new IllegalStateException(\n `No type set on the resource model with key ${this.key}`\n );\n }\n\n /**\n * Retrieve type of resource\n */\n get resourcetype(): string {\n return this.getContribution(\"resourcetype\", \"unknown\");\n }\n\n /**\n */\n get label(): string {\n return this.getContribution(\"label\", \"\");\n }\n\n /**\n * Getting the links of the resource\n */\n get links(): LinkCollection {\n if (!this._links) {\n this._links = new LinkCollection(\n Array.isArray(this.data._links)\n ? this.data._links[0]\n : this.data._links,\n {\n self: {\n resourcetype: this.resourcetype,\n },\n ...this.contributions._links,\n }\n );\n }\n return this._links;\n }\n\n /**\n */\n set links(links: LinkCollection) {\n this._links = links;\n }\n\n /**\n * Get self link of model\n */\n get selflink(): LinkModel {\n const selflink = this.links.getLinkByKey(\"self\");\n\n if (selflink === null) {\n throw new IllegalStateException(\n `Could not find self link for ${\n this.key === null ? \"unknown\" : this.key\n }`\n );\n }\n\n return selflink;\n }\n\n /**\n * Return default self link of resource\n */\n get selfhref(): Href {\n return this.selflink.href;\n }\n\n /**\n * Add links to expand on initialization of this model\n *\n * @abstract\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n return [];\n }\n\n /**\n * Retrieve links of expanded child models\n */\n get childModels(): Array<ModularUIModel> {\n return this._childModels;\n }\n\n /**\n * Add child models to this model\n */\n addChildModels(models: Array<ModularUIModel>): this {\n const flattenModels = [].concat(...models);\n\n this._childModels = flattenModels;\n\n this.setChildModels(flattenModels);\n\n return this;\n }\n\n /**\n * Template to set expanded child models\n * Use this hook to separate the retrieved child models into the correct models.\n *\n * @abstract\n * @example <caption>Put all models of instance List and GroupingPanel into the panels property</caption>\n */\n setChildModels(models: Array<ModularUIModel>): void {\n if (!models) {\n throw new IllegalArgumentException(\"No models send to setChildModels\");\n }\n }\n\n /**\n */\n dehydrate(): Object {\n return {\n ...super.dehydrate(),\n key: this._key,\n locale: this._locale,\n // $FlowFixMe[missing-type-arg]\n childModels: this._childModels.map<ModularUIModel>(\n (childModel: ModularUIModel) => childModel.dehydrate()\n ),\n };\n }\n}\n\nexport default ResourceModel;\n"],"mappings":";;;AACA,OAAOA,iBAAiB,MAAM,mCAAmC;AAEjE,OAAOC,SAAS,MAAM,aAAa;AACnC,OAAOC,cAAc,MAAM,yBAAyB;AAEpD,SACEC,wBAAwB,EACxBC,qBAAqB,QAChB,kBAAkB;AAMzB;AACA;AACA;AACA,MAAMC,aAAa,SAASJ,SAAS,CAAkC;EAOrE;AACF;AACA;EACEK,WAAW,GAAiE;IAAA,IAAhEC,iBAAoC,uEAAG,IAAIP,iBAAiB,EAAE;IACxE,KAAK,CAACO,iBAAiB,CAACC,IAAI,EAAED,iBAAiB,CAACE,aAAa,CAAC;IAAC;IAAA;IAAA;IAAA;IAAA;IAE/D,IAAI,CAACC,IAAI,GAAGH,iBAAiB,CAACI,GAAG;IACjC,IAAI,CAACC,OAAO,GAAGL,iBAAiB,CAACM,MAAM;IAEvC,IAAI,CAACC,YAAY,GAAG,EAAE;IAEtB,IAAI,CAACC,iBAAiB,GAAGC,IAAI,CAACC,GAAG,EAAE;EACrC;;EAEA;AACF;AACA;AACA;AACA;EACE,OAAOC,iBAAiB,CAACV,IAAuB,EAAW;IACzD,IAAI,EAAEA,IAAI,YAAYR,iBAAiB,CAAC,EAAE;MACxC,MAAM,IAAIG,wBAAwB,CAChC,iEAAiE,CAClE;IACH;IAEA,MAAM,IAAIgB,KAAK,CAAC,qDAAqD,CAAC;EACxE;;EAEA;AACF;EACE,IAAIC,gBAAgB,GAAW;IAC7B,OAAO,IAAI,CAACL,iBAAiB;EAC/B;;EAEA;AACF;EACE,IAAIK,gBAAgB,CAACA,gBAAwB,EAAE;IAC7C,IAAI,CAACL,iBAAiB,GAAGK,gBAAgB;EAC3C;;EAEA;AACF;EACE,IAAIP,MAAM,GAAW;IACnB,OAAO,IAAI,CAACD,OAAO;EACrB;;EAEA;AACF;AACA;E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,OAAOmB,QAAQ;EACjB;;EAEA;AACF;AACA;EACE,IAAIE,QAAQ,GAAS;IACnB,OAAO,IAAI,CAACF,QAAQ,CAACG,IAAI;EAC3B;;EAEA;AACF;AACA;AACA;AACA;EACEC,yBAAyB,GAAqB;IAC5C,OAAO,EAAE;EACX;;EAEA;AACF;AACA;EACE,IAAIC,WAAW,GAA0B;IACvC,OAAO,IAAI,CAACrB,YAAY;EAC1B;;EAEA;AACF;AACA;EACEsB,cAAc,CAACC,MAA6B,EAAQ;IAAA;IAClD,MAAMC,aAAa,GAAG,qCAAE,iBAAQ,GAAGD,MAAM,CAAC;IAE1C,IAAI,CAACvB,YAAY,GAAGwB,aAAa;IAEjC,IAAI,CAACC,cAAc,CAACD,aAAa,CAAC;IAElC,OAAO,IAAI;EACb;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,cAAc,CAACF,MAA6B,EAAQ;IAClD,IAAI,CAACA,MAAM,EAAE;MACX,MAAM,IAAIlC,wBAAwB,CAAC,kCAAkC,CAAC;IACxE;EACF;;EAEA;AACF;EACEqC,SAAS,GAAW;IAAA;IAClB,OAAO;MACL,GAAG,KAAK,CAACA,SAAS,EAAE;MACpB7B,GAAG,EAAE,IAAI,CAACD,IAAI;MACdG,MAAM,EAAE,IAAI,CAACD,OAAO;MACpB;MACAuB,WAAW,EAAE,qCAAI,CAACrB,YAAY,kBAC3B2B,UAA0B,IAAKA,UAAU,CAACD,SAAS,EAAE;IAE1D,CAAC;EACH;AACF;AAEA,eAAenC,aAAa"}
@@ -10,6 +10,7 @@ import CompositeAttributeModel from "../attributes/CompositeAttributeModel";
10
10
  import ContentConfiguration from "../contentconfiguration/ContentConfiguration";
11
11
  import ErrorCollection from "../error/ErrorCollection";
12
12
  import { IllegalArgumentException } from "../../exceptions";
13
+ import LayoutHintCollection from "../layouthint/LayoutHintCollection";
13
14
  /**
14
15
  * Form Object
15
16
  */
@@ -377,32 +378,60 @@ export default class FormObjectModel extends BaseModel {
377
378
  this._dynamicValidationsLoaded = dynamicValidationsLoaded;
378
379
  }
379
380
 
381
+ /**
382
+ * Convert error json from a form service to validation messages on the form object and attributes
383
+ */
384
+ handleErrorValidations(errors) {
385
+ const attributeErrors = [];
386
+ errors.forEach(error => {
387
+ if (error.anchor?.objectid === this.key) {
388
+ if (has(error.anchor, "elementid")) {
389
+ attributeErrors.push(error);
390
+ } else {
391
+ this.errorCollection.addServerError(error.id, error.message, error.properties, new LayoutHintCollection(error.layouthint));
392
+ }
393
+ }
394
+ });
395
+ this.attributeCollection.updateValidations(attributeErrors);
396
+ }
397
+
398
+ /**
399
+ * Convert missing json from a form service to mandatory validation constraints and messages
400
+ */
401
+ handleMissingValidations(missing) {
402
+ const attributeErrors = [];
403
+ for (const anchor of missing.anchors) {
404
+ if (Array.isArray(anchor.elements)) {
405
+ for (const element of anchor.elements) {
406
+ attributeErrors.push({
407
+ anchor: {
408
+ elementid: element.elementid
409
+ },
410
+ id: "Constraint.Mandatory"
411
+ });
412
+ }
413
+ } else {
414
+ attributeErrors.push({
415
+ anchor,
416
+ id: "Constraint.Mandatory"
417
+ });
418
+ }
419
+ }
420
+ this.attributeCollection.updateValidations(attributeErrors);
421
+ }
422
+
380
423
  /**
381
424
  */
382
425
  updateValidations(data) {
383
426
  this.resetErrors();
384
- const attributeErrors = [];
385
427
  if (Array.isArray(data.errors)) {
386
- data.errors.forEach(error => {
387
- if (error.anchor?.objectid === this.key) {
388
- if (has(error.anchor, "elementid")) {
389
- attributeErrors.push(error);
390
- } else {
391
- this.errorCollection.addServerError(error.id, error.message, error.properties, error.layouthint);
392
- }
393
- }
394
- });
428
+ this.handleErrorValidations(data.errors);
395
429
  }
396
430
 
397
431
  // missing attribute errors
398
432
  if (Array.isArray(data.missing?.anchors)) {
399
- var _context5;
400
- attributeErrors.push(..._mapInstanceProperty(_context5 = data.missing.anchors).call(_context5, anchor => ({
401
- anchor,
402
- id: "Constraint.Mandatory"
403
- })));
433
+ this.handleMissingValidations(data.missing);
404
434
  }
405
- this.attributeCollection.updateValidations(attributeErrors);
406
435
  this.dynamicValidationsLoaded = true;
407
436
  return this;
408
437
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FormObjectModel.js","names":["has","BaseModel","AttributeCollection","CompositeAttributeModel","ContentConfiguration","ErrorCollection","IllegalArgumentException","FormObjectModel","constructor","object","objectContributions","getElements","length","_attributeCollection","getApplicableAttributeContributions","_contentConfiguration","content","_errorCollection","data","attributeCollection","setReferenceDate","getData","indicateContentConfiguration","contentConfiguration","createEmpty","formObjectModel","contributions","equals","withRepeatIndex","key","objectContainsOneOfTheAttributes","all","attribute","isResult","some","hasAttributeByKey","hasSameRepeatIndex","repeatIndex","getAttributeByAttribute","getAttributeByKey","elements","push","results","dataResults","result","elementid","dataElementIds","element","getAttributesInData","attributes","isDynamic","attributeKey","mandatory","attributesContributions","attributeContributions","dataElementId","split","getInitialChildModelLinks","setChildModels","models","objectid","hasEndResultConfiguration","getContribution","hasDynamicValidations","isRepeatable","_repeatIndex","index","maxRepeats","hasFixedNrOfRepeats","isRepeatWithUnknownTotal","isLastRepeat","last","repeatIndexLabel","label","introText","text","message","assistent","buttonLabels","mergeObject","oldObject","forEach","mergeWithAttribute","mergeAttribute","updateAttribute","value","attributeToUpdate","Error","name","update","isChangedSince","timestamp","resetErrors","errorCollection","addServerError","error","anchor","id","properties","layouthint","hasServerErrors","hasItems","hasErrors","isValid","visible","every","dynamicValidationsLoaded","_dynamicValidationsLoaded","updateValidations","attributeErrors","Array","isArray","errors","missing","anchors","formdata","getFormData","validationData"],"sources":["../../../src/models/form/FormObjectModel.js"],"sourcesContent":["// @flow\nimport { has } from \"../../utils/helpers/objects\";\n\nimport BaseModel from \"../base/BaseModel\";\nimport AttributeCollection from \"../attributes/AttributeCollection\";\nimport CompositeAttributeModel from \"../attributes/CompositeAttributeModel\";\nimport ContentConfiguration from \"../contentconfiguration/ContentConfiguration\";\nimport ErrorCollection from \"../error/ErrorCollection\";\nimport { IllegalArgumentException } from \"../../exceptions\";\n\nimport type { AttributeType, ModularUIModel, FormErrorAnchor } from \"../types\";\nimport type LinkModel from \"../links/LinkModel\";\n\n/**\n * Form Object\n */\nexport default class FormObjectModel extends BaseModel {\n _attributeCollection: AttributeCollection;\n _contentConfiguration: ContentConfiguration;\n _errorCollection: ErrorCollection;\n _repeatIndex: number;\n _dynamicValidationsLoaded: boolean;\n\n /**\n * Construct FormObjectModel\n */\n constructor(object: Object, objectContributions: Object) {\n super(object, objectContributions);\n\n if (object && this.getElements().length > 0) {\n this._attributeCollection = new AttributeCollection(\n this.getElements(),\n this.getApplicableAttributeContributions()\n );\n } else {\n this._attributeCollection = new AttributeCollection();\n }\n\n this._contentConfiguration = new ContentConfiguration(\n objectContributions ? objectContributions.content : {}\n );\n\n this._errorCollection = new ErrorCollection(\"formobject\");\n\n if (has(this.data, \"referenceDate\")) {\n this.attributeCollection.setReferenceDate(this.getData(\"referenceDate\"));\n }\n\n this.attributeCollection.indicateContentConfiguration(\n this.contentConfiguration\n );\n }\n\n /**\n */\n static createEmpty(formObjectModel: FormObjectModel): FormObjectModel {\n if (!formObjectModel) {\n throw new IllegalArgumentException(\n \"createEmpty method needs a FormObjectModel as input argument to create a new version of the object\"\n );\n }\n return new FormObjectModel(\n formObjectModel.data,\n formObjectModel.contributions\n );\n }\n\n /**\n */\n equals(object: ?FormObjectModel, withRepeatIndex: boolean = true): boolean {\n if (!object || this.key !== object.key) {\n return false;\n }\n\n const objectContainsOneOfTheAttributes = this.attributeCollection.all\n .filter((attribute) => !attribute.isResult)\n .some(\n (attribute) =>\n object && object.attributeCollection.hasAttributeByKey(attribute.key)\n );\n\n const hasSameRepeatIndex = withRepeatIndex\n ? this.repeatIndex === object.repeatIndex\n : true;\n\n return hasSameRepeatIndex && objectContainsOneOfTheAttributes;\n }\n\n /**\n */\n getAttributeByAttribute(attribute: AttributeType): AttributeType | null {\n return this.attributeCollection.getAttributeByAttribute(attribute);\n }\n\n /**\n */\n getAttributeByKey(key: string): AttributeType | null {\n return this.attributeCollection.getAttributeByKey(key);\n }\n\n /**\n */\n hasAttributeByKey(key: string): boolean {\n return this.attributeCollection.hasAttributeByKey(key);\n }\n\n /**\n * Get elements from both the missing attributes and the result attributes\n */\n getElements(): Array<Object> {\n const elements = [];\n\n if (this.data.elements) {\n elements.push(...this.data.elements);\n }\n\n if (this.data.results) {\n const dataResults = this.data.results.map((result) => ({\n ...result,\n isResult: true,\n }));\n\n elements.push(...dataResults);\n }\n\n if (this.data.elementid) {\n elements.push({\n ...this.data,\n });\n }\n\n return elements;\n }\n\n /**\n * Map available contributions on the available data. Only use contributions that are needed for the data\n */\n getApplicableAttributeContributions(): Array<Object> {\n if (this.data && this.contributions) {\n const dataElementIds = this.getElements().map(\n (element) => element.elementid\n );\n\n const contributions = this.getAttributesInData(\n dataElementIds,\n this.contributions.attributes\n );\n\n // set all attribute mandatory for dynamic object\n if (this.isDynamic) {\n return contributions.map((attribute) => {\n const [attributeKey] = Object.keys(attribute);\n return {\n [attributeKey]: {\n ...attribute[attributeKey],\n mandatory: true,\n },\n };\n });\n }\n\n return contributions;\n }\n\n return [];\n }\n\n /**\n * Recursevily check if an attribute id occurs in the tree of attribute contributions.\n * The complete leaf of the tree is returned when an attribute id matches\n */\n getAttributesInData(\n dataElementIds: Array<string>,\n attributesContributions: Object\n ): Array<Object> {\n return attributesContributions.filter((attributeContributions) => {\n const [attributeKey] = Object.keys(attributeContributions);\n\n return dataElementIds.some(\n (dataElementId) => dataElementId.split(\".\")[0] === attributeKey\n );\n });\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n return this._attributeCollection.getInitialChildModelLinks();\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n this._attributeCollection.setChildModels(models);\n }\n\n /**\n * get key\n */\n get key(): string {\n return this.data.objectid;\n }\n\n /**\n * Get content configuration for form objects\n */\n get contentConfiguration(): ContentConfiguration {\n return this._contentConfiguration;\n }\n\n /**\n */\n get hasEndResultConfiguration(): boolean {\n return this.contributions.content?.results != null;\n }\n\n /**\n * Indicates if object is dynamic. A dynamic object should be submitted on each attribute change\n */\n get isDynamic(): boolean {\n return this.getContribution(\"dynamicObject\", false);\n }\n\n /**\n */\n get hasDynamicValidations(): boolean {\n return this.getContribution(\"dynamicValidations\", false);\n }\n\n /**\n * Indicates if object is repeatable\n */\n get isRepeatable(): boolean {\n return this.getContribution(\"repeatable\", false);\n }\n\n /**\n */\n get repeatIndex(): number {\n return this._repeatIndex ?? this.data.index ?? 1;\n }\n\n /**\n */\n set repeatIndex(repeatIndex: number) {\n this._repeatIndex = repeatIndex;\n }\n\n /**\n */\n get maxRepeats(): number {\n if (this.isRepeatable) {\n return this.getData(\"numberofrepeats\", -1);\n }\n\n return 1;\n }\n\n /**\n */\n get hasFixedNrOfRepeats(): boolean {\n return this.maxRepeats > -1;\n }\n\n /**\n */\n get isRepeatWithUnknownTotal(): boolean {\n return this.isRepeatable && this.maxRepeats === -1;\n }\n\n /**\n */\n get isLastRepeat(): boolean {\n if (this.isRepeatable) {\n return this.data.last || false;\n }\n\n return true;\n }\n\n /**\n */\n get repeatIndexLabel(): string | null {\n return this.data[\"index-identifier\"] || null;\n }\n\n /**\n * Get label of form object\n */\n get label(): string {\n return this.contributions.label;\n }\n\n /**\n * Get introText of form object\n */\n get introText(): string {\n if (this.data.content?.text) {\n return this.data.content.text.message;\n }\n\n if (this.contributions.text?.message) {\n return this.contributions.text.message;\n }\n\n return this.contributions.introText;\n }\n\n /**\n * Get assistent of form object\n */\n get assistent(): string {\n return this.contributions.assistent;\n }\n\n /**\n * Get button labels\n */\n get buttonLabels(): Object {\n return this.getContribution(\"buttonLabels\", {});\n }\n\n /**\n * get attribute collection\n */\n get attributeCollection(): AttributeCollection {\n return this._attributeCollection;\n }\n\n /**\n */\n set attributeCollection(attributeCollection: AttributeCollection) {\n this._attributeCollection = attributeCollection;\n }\n\n /**\n */\n mergeObject(oldObject: FormObjectModel) {\n this.attributeCollection.forEach((attribute) => {\n const mergeWithAttribute = oldObject.getAttributeByAttribute(attribute);\n if (mergeWithAttribute) {\n attribute.mergeAttribute(mergeWithAttribute);\n }\n });\n\n this.repeatIndex = oldObject.repeatIndex;\n }\n\n /**\n * Update attribute\n */\n updateAttribute(attribute: AttributeType, value: any): AttributeType {\n const attributeToUpdate =\n this.attributeCollection.getAttributeByAttribute(attribute);\n\n if (attributeToUpdate === null) {\n throw new Error(`Attribute with name: ${attribute.name} not found.`);\n }\n\n if (attributeToUpdate instanceof CompositeAttributeModel) {\n attributeToUpdate.update(value, attribute);\n } else {\n attributeToUpdate.update(value);\n }\n\n return attributeToUpdate;\n }\n\n /**\n * Inidicates if Form is changed since a given timestamp (Date.now)\n */\n isChangedSince(timestamp: number): boolean {\n return (\n this.attributeCollection.find((attribute) =>\n attribute.isChangedSince(timestamp)\n ) !== null\n );\n }\n\n /**\n * Reset all errors on Form Object\n */\n resetErrors() {\n this._errorCollection = new ErrorCollection(\"formobject\");\n this.attributeCollection.forEach((attribute) => attribute.resetErrors());\n }\n\n /**\n * Get error messages\n */\n get errorCollection(): ErrorCollection {\n return this._errorCollection;\n }\n\n /**\n * Registers an error that was received from a server response\n */\n addServerError(error: FormErrorAnchor) {\n if (error.anchor?.elementid != null) {\n this.attributeCollection.addServerError(error);\n } else {\n this._errorCollection.addServerError(\n error.id,\n error.message,\n error.properties,\n error.layouthint\n );\n }\n }\n\n /**\n */\n hasServerErrors(): boolean {\n return (\n this.errorCollection.hasItems ||\n this.attributeCollection.hasServerErrors()\n );\n }\n\n /**\n */\n hasErrors(): boolean {\n return (\n this.errorCollection.hasItems || this.attributeCollection.hasErrors()\n );\n }\n\n /**\n */\n get isValid(): boolean {\n return (\n this.attributeCollection.visible.every(\n (attribute) => attribute.isValid\n ) && !this.errorCollection.hasItems\n );\n }\n\n /**\n */\n get dynamicValidationsLoaded(): boolean {\n return this._dynamicValidationsLoaded;\n }\n\n /**\n */\n set dynamicValidationsLoaded(dynamicValidationsLoaded: boolean) {\n this._dynamicValidationsLoaded = dynamicValidationsLoaded;\n }\n\n /**\n */\n updateValidations(data: any): FormObjectModel {\n this.resetErrors();\n\n const attributeErrors = [];\n\n if (Array.isArray(data.errors)) {\n data.errors.forEach((error) => {\n if (error.anchor?.objectid === this.key) {\n if (has(error.anchor, \"elementid\")) {\n attributeErrors.push(error);\n } else {\n this.errorCollection.addServerError(\n error.id,\n error.message,\n error.properties,\n error.layouthint\n );\n }\n }\n });\n }\n\n // missing attribute errors\n if (Array.isArray(data.missing?.anchors)) {\n attributeErrors.push(\n ...data.missing.anchors.map((anchor) => ({\n anchor,\n id: \"Constraint.Mandatory\",\n }))\n );\n }\n\n this.attributeCollection.updateValidations(attributeErrors);\n\n this.dynamicValidationsLoaded = true;\n\n return this;\n }\n\n /**\n * Generate formdata object for current formobject based on formdata of attributes\n */\n get formdata(): { [string]: any } | null {\n return this.attributeCollection.formdata;\n }\n\n /**\n */\n getFormData(validationData: boolean = false): { [string]: any } | null {\n return this.attributeCollection.getFormData(validationData);\n }\n}\n"],"mappings":";;;;;AACA,SAASA,GAAG,QAAQ,6BAA6B;AAEjD,OAAOC,SAAS,MAAM,mBAAmB;AACzC,OAAOC,mBAAmB,MAAM,mCAAmC;AACnE,OAAOC,uBAAuB,MAAM,uCAAuC;AAC3E,OAAOC,oBAAoB,MAAM,8CAA8C;AAC/E,OAAOC,eAAe,MAAM,0BAA0B;AACtD,SAASC,wBAAwB,QAAQ,kBAAkB;AAK3D;AACA;AACA;AACA,eAAe,MAAMC,eAAe,SAASN,SAAS,CAAC;EAOrD;AACF;AACA;EACEO,WAAW,CAACC,MAAc,EAAEC,mBAA2B,EAAE;IACvD,KAAK,CAACD,MAAM,EAAEC,mBAAmB,CAAC;IAAC;IAAA;IAAA;IAAA;IAAA;IAEnC,IAAID,MAAM,IAAI,IAAI,CAACE,WAAW,EAAE,CAACC,MAAM,GAAG,CAAC,EAAE;MAC3C,IAAI,CAACC,oBAAoB,GAAG,IAAIX,mBAAmB,CACjD,IAAI,CAACS,WAAW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AAI,CAACF,eAAe,CAACC,cAAc,CACjCC,KAAK,CAACE,EAAE,EACRF,KAAK,CAACnB,OAAO,EACbmB,KAAK,CAACG,UAAU,EAChBH,KAAK,CAACI,UAAU,CACjB;UACH;QACF;MACF,CAAC,CAAC;IACJ;;IAEA;IACA,IAAIW,KAAK,CAACC,OAAO,CAAC7F,IAAI,CAAC+F,OAAO,EAAEC,OAAO,CAAC,EAAE;MAAA;MACxCL,eAAe,CAACpE,IAAI,CAClB,GAAG,iCAAAvB,IAAI,CAAC+F,OAAO,CAACC,OAAO,kBAAMlB,MAAM,KAAM;QACvCA,MAAM;QACNC,EAAE,EAAE;MACN,CAAC,CAAC,CAAC,CACJ;IACH;IAEA,IAAI,CAAC9E,mBAAmB,CAACyF,iBAAiB,CAACC,eAAe,CAAC;IAE3D,IAAI,CAACH,wBAAwB,GAAG,IAAI;IAEpC,OAAO,IAAI;EACb;;EAEA;AACF;AACA;EACE,IAAIS,QAAQ,GAA6B;IACvC,OAAO,IAAI,CAAChG,mBAAmB,CAACgG,QAAQ;EAC1C;;EAEA;AACF;EACEC,WAAW,GAA4D;IAAA,IAA3DC,cAAuB,uEAAG,KAAK;IACzC,OAAO,IAAI,CAAClG,mBAAmB,CAACiG,WAAW,CAACC,cAAc,CAAC;EAC7D;AACF"}
1
+ {"version":3,"file":"FormObjectModel.js","names":["has","BaseModel","AttributeCollection","CompositeAttributeModel","ContentConfiguration","ErrorCollection","IllegalArgumentException","LayoutHintCollection","FormObjectModel","constructor","object","objectContributions","getElements","length","_attributeCollection","getApplicableAttributeContributions","_contentConfiguration","content","_errorCollection","data","attributeCollection","setReferenceDate","getData","indicateContentConfiguration","contentConfiguration","createEmpty","formObjectModel","contributions","equals","withRepeatIndex","key","objectContainsOneOfTheAttributes","all","attribute","isResult","some","hasAttributeByKey","hasSameRepeatIndex","repeatIndex","getAttributeByAttribute","getAttributeByKey","elements","push","results","dataResults","result","elementid","dataElementIds","element","getAttributesInData","attributes","isDynamic","attributeKey","mandatory","attributesContributions","attributeContributions","dataElementId","split","getInitialChildModelLinks","setChildModels","models","objectid","hasEndResultConfiguration","getContribution","hasDynamicValidations","isRepeatable","_repeatIndex","index","maxRepeats","hasFixedNrOfRepeats","isRepeatWithUnknownTotal","isLastRepeat","last","repeatIndexLabel","label","introText","text","message","assistent","buttonLabels","mergeObject","oldObject","forEach","mergeWithAttribute","mergeAttribute","updateAttribute","value","attributeToUpdate","Error","name","update","isChangedSince","timestamp","resetErrors","errorCollection","addServerError","error","anchor","id","properties","layouthint","hasServerErrors","hasItems","hasErrors","isValid","visible","every","dynamicValidationsLoaded","_dynamicValidationsLoaded","handleErrorValidations","errors","attributeErrors","updateValidations","handleMissingValidations","missing","anchors","Array","isArray","formdata","getFormData","validationData"],"sources":["../../../src/models/form/FormObjectModel.js"],"sourcesContent":["// @flow\nimport { has } from \"../../utils/helpers/objects\";\n\nimport BaseModel from \"../base/BaseModel\";\nimport AttributeCollection from \"../attributes/AttributeCollection\";\nimport CompositeAttributeModel from \"../attributes/CompositeAttributeModel\";\nimport ContentConfiguration from \"../contentconfiguration/ContentConfiguration\";\nimport ErrorCollection from \"../error/ErrorCollection\";\nimport { IllegalArgumentException } from \"../../exceptions\";\n\nimport type { AttributeType, ModularUIModel, FormErrorAnchor } from \"../types\";\nimport type LinkModel from \"../links/LinkModel\";\nimport LayoutHintCollection from \"../layouthint/LayoutHintCollection\";\nimport type { MessageParameters } from \"../../i18n\";\n\n/**\n * Form Object\n */\nexport default class FormObjectModel extends BaseModel {\n _attributeCollection: AttributeCollection;\n _contentConfiguration: ContentConfiguration;\n _errorCollection: ErrorCollection;\n _repeatIndex: number;\n _dynamicValidationsLoaded: boolean;\n\n /**\n * Construct FormObjectModel\n */\n constructor(object: Object, objectContributions: Object) {\n super(object, objectContributions);\n\n if (object && this.getElements().length > 0) {\n this._attributeCollection = new AttributeCollection(\n this.getElements(),\n this.getApplicableAttributeContributions()\n );\n } else {\n this._attributeCollection = new AttributeCollection();\n }\n\n this._contentConfiguration = new ContentConfiguration(\n objectContributions ? objectContributions.content : {}\n );\n\n this._errorCollection = new ErrorCollection(\"formobject\");\n\n if (has(this.data, \"referenceDate\")) {\n this.attributeCollection.setReferenceDate(this.getData(\"referenceDate\"));\n }\n\n this.attributeCollection.indicateContentConfiguration(\n this.contentConfiguration\n );\n }\n\n /**\n */\n static createEmpty(formObjectModel: FormObjectModel): FormObjectModel {\n if (!formObjectModel) {\n throw new IllegalArgumentException(\n \"createEmpty method needs a FormObjectModel as input argument to create a new version of the object\"\n );\n }\n return new FormObjectModel(\n formObjectModel.data,\n formObjectModel.contributions\n );\n }\n\n /**\n */\n equals(object: ?FormObjectModel, withRepeatIndex: boolean = true): boolean {\n if (!object || this.key !== object.key) {\n return false;\n }\n\n const objectContainsOneOfTheAttributes = this.attributeCollection.all\n .filter((attribute) => !attribute.isResult)\n .some(\n (attribute) =>\n object && object.attributeCollection.hasAttributeByKey(attribute.key)\n );\n\n const hasSameRepeatIndex = withRepeatIndex\n ? this.repeatIndex === object.repeatIndex\n : true;\n\n return hasSameRepeatIndex && objectContainsOneOfTheAttributes;\n }\n\n /**\n */\n getAttributeByAttribute(attribute: AttributeType): AttributeType | null {\n return this.attributeCollection.getAttributeByAttribute(attribute);\n }\n\n /**\n */\n getAttributeByKey(key: string): AttributeType | null {\n return this.attributeCollection.getAttributeByKey(key);\n }\n\n /**\n */\n hasAttributeByKey(key: string): boolean {\n return this.attributeCollection.hasAttributeByKey(key);\n }\n\n /**\n * Get elements from both the missing attributes and the result attributes\n */\n getElements(): Array<Object> {\n const elements = [];\n\n if (this.data.elements) {\n elements.push(...this.data.elements);\n }\n\n if (this.data.results) {\n const dataResults = this.data.results.map((result) => ({\n ...result,\n isResult: true,\n }));\n\n elements.push(...dataResults);\n }\n\n if (this.data.elementid) {\n elements.push({\n ...this.data,\n });\n }\n\n return elements;\n }\n\n /**\n * Map available contributions on the available data. Only use contributions that are needed for the data\n */\n getApplicableAttributeContributions(): Array<Object> {\n if (this.data && this.contributions) {\n const dataElementIds = this.getElements().map(\n (element) => element.elementid\n );\n\n const contributions = this.getAttributesInData(\n dataElementIds,\n this.contributions.attributes\n );\n\n // set all attribute mandatory for dynamic object\n if (this.isDynamic) {\n return contributions.map((attribute) => {\n const [attributeKey] = Object.keys(attribute);\n return {\n [attributeKey]: {\n ...attribute[attributeKey],\n mandatory: true,\n },\n };\n });\n }\n\n return contributions;\n }\n\n return [];\n }\n\n /**\n * Recursevily check if an attribute id occurs in the tree of attribute contributions.\n * The complete leaf of the tree is returned when an attribute id matches\n */\n getAttributesInData(\n dataElementIds: Array<string>,\n attributesContributions: Object\n ): Array<Object> {\n return attributesContributions.filter((attributeContributions) => {\n const [attributeKey] = Object.keys(attributeContributions);\n\n return dataElementIds.some(\n (dataElementId) => dataElementId.split(\".\")[0] === attributeKey\n );\n });\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n return this._attributeCollection.getInitialChildModelLinks();\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n this._attributeCollection.setChildModels(models);\n }\n\n /**\n * get key\n */\n get key(): string {\n return this.data.objectid;\n }\n\n /**\n * Get content configuration for form objects\n */\n get contentConfiguration(): ContentConfiguration {\n return this._contentConfiguration;\n }\n\n /**\n */\n get hasEndResultConfiguration(): boolean {\n return this.contributions.content?.results != null;\n }\n\n /**\n * Indicates if object is dynamic. A dynamic object should be submitted on each attribute change\n */\n get isDynamic(): boolean {\n return this.getContribution(\"dynamicObject\", false);\n }\n\n /**\n */\n get hasDynamicValidations(): boolean {\n return this.getContribution(\"dynamicValidations\", false);\n }\n\n /**\n * Indicates if object is repeatable\n */\n get isRepeatable(): boolean {\n return this.getContribution(\"repeatable\", false);\n }\n\n /**\n */\n get repeatIndex(): number {\n return this._repeatIndex ?? this.data.index ?? 1;\n }\n\n /**\n */\n set repeatIndex(repeatIndex: number) {\n this._repeatIndex = repeatIndex;\n }\n\n /**\n */\n get maxRepeats(): number {\n if (this.isRepeatable) {\n return this.getData(\"numberofrepeats\", -1);\n }\n\n return 1;\n }\n\n /**\n */\n get hasFixedNrOfRepeats(): boolean {\n return this.maxRepeats > -1;\n }\n\n /**\n */\n get isRepeatWithUnknownTotal(): boolean {\n return this.isRepeatable && this.maxRepeats === -1;\n }\n\n /**\n */\n get isLastRepeat(): boolean {\n if (this.isRepeatable) {\n return this.data.last || false;\n }\n\n return true;\n }\n\n /**\n */\n get repeatIndexLabel(): string | null {\n return this.data[\"index-identifier\"] || null;\n }\n\n /**\n * Get label of form object\n */\n get label(): string {\n return this.contributions.label;\n }\n\n /**\n * Get introText of form object\n */\n get introText(): string {\n if (this.data.content?.text) {\n return this.data.content.text.message;\n }\n\n if (this.contributions.text?.message) {\n return this.contributions.text.message;\n }\n\n return this.contributions.introText;\n }\n\n /**\n * Get assistent of form object\n */\n get assistent(): string {\n return this.contributions.assistent;\n }\n\n /**\n * Get button labels\n */\n get buttonLabels(): Object {\n return this.getContribution(\"buttonLabels\", {});\n }\n\n /**\n * get attribute collection\n */\n get attributeCollection(): AttributeCollection {\n return this._attributeCollection;\n }\n\n /**\n */\n set attributeCollection(attributeCollection: AttributeCollection) {\n this._attributeCollection = attributeCollection;\n }\n\n /**\n */\n mergeObject(oldObject: FormObjectModel) {\n this.attributeCollection.forEach((attribute) => {\n const mergeWithAttribute = oldObject.getAttributeByAttribute(attribute);\n if (mergeWithAttribute) {\n attribute.mergeAttribute(mergeWithAttribute);\n }\n });\n\n this.repeatIndex = oldObject.repeatIndex;\n }\n\n /**\n * Update attribute\n */\n updateAttribute(attribute: AttributeType, value: any): AttributeType {\n const attributeToUpdate =\n this.attributeCollection.getAttributeByAttribute(attribute);\n\n if (attributeToUpdate === null) {\n throw new Error(`Attribute with name: ${attribute.name} not found.`);\n }\n\n if (attributeToUpdate instanceof CompositeAttributeModel) {\n attributeToUpdate.update(value, attribute);\n } else {\n attributeToUpdate.update(value);\n }\n\n return attributeToUpdate;\n }\n\n /**\n * Inidicates if Form is changed since a given timestamp (Date.now)\n */\n isChangedSince(timestamp: number): boolean {\n return (\n this.attributeCollection.find((attribute) =>\n attribute.isChangedSince(timestamp)\n ) !== null\n );\n }\n\n /**\n * Reset all errors on Form Object\n */\n resetErrors() {\n this._errorCollection = new ErrorCollection(\"formobject\");\n this.attributeCollection.forEach((attribute) => attribute.resetErrors());\n }\n\n /**\n * Get error messages\n */\n get errorCollection(): ErrorCollection {\n return this._errorCollection;\n }\n\n /**\n * Registers an error that was received from a server response\n */\n addServerError(error: FormErrorAnchor) {\n if (error.anchor?.elementid != null) {\n this.attributeCollection.addServerError(error);\n } else {\n this._errorCollection.addServerError(\n error.id,\n error.message,\n error.properties,\n error.layouthint\n );\n }\n }\n\n /**\n */\n hasServerErrors(): boolean {\n return (\n this.errorCollection.hasItems ||\n this.attributeCollection.hasServerErrors()\n );\n }\n\n /**\n */\n hasErrors(): boolean {\n return (\n this.errorCollection.hasItems || this.attributeCollection.hasErrors()\n );\n }\n\n /**\n */\n get isValid(): boolean {\n return (\n this.attributeCollection.visible.every(\n (attribute) => attribute.isValid\n ) && !this.errorCollection.hasItems\n );\n }\n\n /**\n */\n get dynamicValidationsLoaded(): boolean {\n return this._dynamicValidationsLoaded;\n }\n\n /**\n */\n set dynamicValidationsLoaded(dynamicValidationsLoaded: boolean) {\n this._dynamicValidationsLoaded = dynamicValidationsLoaded;\n }\n\n /**\n * Convert error json from a form service to validation messages on the form object and attributes\n */\n handleErrorValidations(\n errors: Array<{\n anchor: {\n objectid: string,\n elementid?: string,\n },\n id: string,\n message: string,\n properties: MessageParameters,\n layouthint: Array<string>,\n }>\n ) {\n const attributeErrors = [];\n\n errors.forEach((error) => {\n if (error.anchor?.objectid === this.key) {\n if (has(error.anchor, \"elementid\")) {\n attributeErrors.push(error);\n } else {\n this.errorCollection.addServerError(\n error.id,\n error.message,\n error.properties,\n new LayoutHintCollection(error.layouthint)\n );\n }\n }\n });\n\n this.attributeCollection.updateValidations(attributeErrors);\n }\n\n /**\n * Convert missing json from a form service to mandatory validation constraints and messages\n */\n handleMissingValidations(missing: {\n anchors: Array<\n | {\n elements: Array<{ elementid: string }>,\n }\n | { anchor: { elementid: string } }\n >,\n }) {\n const attributeErrors = [];\n\n for (const anchor of missing.anchors) {\n if (Array.isArray(anchor.elements)) {\n for (const element of anchor.elements) {\n attributeErrors.push({\n anchor: { elementid: element.elementid },\n id: \"Constraint.Mandatory\",\n });\n }\n } else {\n attributeErrors.push({\n anchor,\n id: \"Constraint.Mandatory\",\n });\n }\n }\n\n this.attributeCollection.updateValidations(attributeErrors);\n }\n\n /**\n */\n updateValidations(data: any): FormObjectModel {\n this.resetErrors();\n\n if (Array.isArray(data.errors)) {\n this.handleErrorValidations(data.errors);\n }\n\n // missing attribute errors\n if (Array.isArray(data.missing?.anchors)) {\n this.handleMissingValidations(data.missing);\n }\n\n this.dynamicValidationsLoaded = true;\n\n return this;\n }\n\n /**\n * Generate formdata object for current formobject based on formdata of attributes\n */\n get formdata(): { [string]: any } | null {\n return this.attributeCollection.formdata;\n }\n\n /**\n */\n getFormData(validationData: boolean = false): { [string]: any } | null {\n return this.attributeCollection.getFormData(validationData);\n }\n}\n"],"mappings":";;;;;AACA,SAASA,GAAG,QAAQ,6BAA6B;AAEjD,OAAOC,SAAS,MAAM,mBAAmB;AACzC,OAAOC,mBAAmB,MAAM,mCAAmC;AACnE,OAAOC,uBAAuB,MAAM,uCAAuC;AAC3E,OAAOC,oBAAoB,MAAM,8CAA8C;AAC/E,OAAOC,eAAe,MAAM,0BAA0B;AACtD,SAASC,wBAAwB,QAAQ,kBAAkB;AAI3D,OAAOC,oBAAoB,MAAM,oCAAoC;AAGrE;AACA;AACA;AACA,eAAe,MAAMC,eAAe,SAASP,SAAS,CAAC;EAOrD;AACF;AACA;EACEQ,WAAW,CAACC,MAAc,EAAEC,mBAA2B,EAAE;IACvD,KAAK,CAACD,MAAM,EAAEC,mBAAmB,CAAC;IAAC;IAAA;IAAA;IAAA;IAAA;IAEnC,IAAID,MAAM,IAAI,IAAI,C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IAEA,IAAI,CAACP,wBAAwB,GAAG,IAAI;IAEpC,OAAO,IAAI;EACb;;EAEA;AACF;AACA;EACE,IAAIW,QAAQ,GAA6B;IACvC,OAAO,IAAI,CAAClG,mBAAmB,CAACkG,QAAQ;EAC1C;;EAEA;AACF;EACEC,WAAW,GAA4D;IAAA,IAA3DC,cAAuB,uEAAG,KAAK;IACzC,OAAO,IAAI,CAACpG,mBAAmB,CAACmG,WAAW,CAACC,cAAc,CAAC;EAC7D;AACF"}
@@ -11,7 +11,10 @@ var _clone = _interopRequireDefault(require("lodash/clone"));
11
11
  var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
12
12
  var _LayoutHintCollection = _interopRequireDefault(require("../layouthint/LayoutHintCollection"));
13
13
  /**
14
- * Base model
14
+ * Base model, this is the foundation of a model,
15
+ * it contains data that is needed for all models like, data, contributions and layout hint
16
+ *
17
+ * Extend this for non modular ui resources, for modular ui resource start with the resourceModel
15
18
  */
16
19
  class BaseModel {
17
20
  /**
@@ -35,6 +38,7 @@ class BaseModel {
35
38
  }
36
39
 
37
40
  /**
41
+ * Retrieve property from the data object of the model, mostly used internal
38
42
  */
39
43
  getData(propName) {
40
44
  let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
@@ -49,6 +53,7 @@ class BaseModel {
49
53
  }
50
54
 
51
55
  /**
56
+ * Retrieve property from the contributions of the model, mostly used internal
52
57
  */
53
58
  getContribution(propName) {
54
59
  let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
@@ -77,18 +82,21 @@ class BaseModel {
77
82
  }
78
83
 
79
84
  /**
85
+ * Set the unique key for this model
80
86
  */
81
87
  set connectKey(key) {
82
88
  this._connectKey = key;
83
89
  }
84
90
 
85
91
  /**
92
+ * Get the unique key of this model
86
93
  */
87
94
  get connectKey() {
88
95
  return this._connectKey;
89
96
  }
90
97
 
91
98
  /**
99
+ * Dehydrate internal data, returns the information that is needed to recreate the model
92
100
  */
93
101
  dehydrate() {
94
102
  return {
@@ -99,13 +107,14 @@ class BaseModel {
99
107
  }
100
108
 
101
109
  /**
110
+ * Recreate the model with the given data
102
111
  */
103
112
  rehydrate(data) {
104
113
  this._connectKey = data.connectKey;
105
114
  }
106
115
 
107
116
  /**
108
- * Returns a clone of the model (this is not a deep copy)
117
+ * Returns a clone of the model
109
118
  */
110
119
  clone() {
111
120
  let deepcopy = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
@@ -12,7 +12,10 @@ export type BaseDehydrateData = {
12
12
  };
13
13
 
14
14
  /**
15
- * Base model
15
+ * Base model, this is the foundation of a model,
16
+ * it contains data that is needed for all models like, data, contributions and layout hint
17
+ *
18
+ * Extend this for non modular ui resources, for modular ui resource start with the resourceModel
16
19
  */
17
20
  class BaseModel {
18
21
  _data: Object;
@@ -39,6 +42,7 @@ class BaseModel {
39
42
  }
40
43
 
41
44
  /**
45
+ * Retrieve property from the data object of the model, mostly used internal
42
46
  */
43
47
  getData(propName: string, defaultValue: any = null): any {
44
48
  return this.data[propName] ?? defaultValue;
@@ -52,6 +56,7 @@ class BaseModel {
52
56
  }
53
57
 
54
58
  /**
59
+ * Retrieve property from the contributions of the model, mostly used internal
55
60
  */
56
61
  getContribution(propName: string, defaultValue: any = null): any {
57
62
  return this.contributions[propName] ?? defaultValue;
@@ -79,18 +84,21 @@ class BaseModel {
79
84
  }
80
85
 
81
86
  /**
87
+ * Set the unique key for this model
82
88
  */
83
89
  set connectKey(key: string) {
84
90
  this._connectKey = key;
85
91
  }
86
92
 
87
93
  /**
94
+ * Get the unique key of this model
88
95
  */
89
96
  get connectKey(): string {
90
97
  return this._connectKey;
91
98
  }
92
99
 
93
100
  /**
101
+ * Dehydrate internal data, returns the information that is needed to recreate the model
94
102
  */
95
103
  dehydrate(): BaseDehydrateData {
96
104
  return {
@@ -101,13 +109,14 @@ class BaseModel {
101
109
  }
102
110
 
103
111
  /**
112
+ * Recreate the model with the given data
104
113
  */
105
- rehydrate(data: Object) {
114
+ rehydrate(data: BaseDehydrateData) {
106
115
  this._connectKey = data.connectKey;
107
116
  }
108
117
 
109
118
  /**
110
- * Returns a clone of the model (this is not a deep copy)
119
+ * Returns a clone of the model
111
120
  */
112
121
  clone(deepcopy: boolean = false): any {
113
122
  // deepcopy can be expensive, use with care!
@@ -1 +1 @@
1
- {"version":3,"file":"BaseModel.js","names":["BaseModel","constructor","data","contributions","_data","_contributions","_layouthint","LayoutHintCollection","getContribution","getData","propName","defaultValue","layouthint","hasData","length","connectKey","key","_connectKey","dehydrate","rehydrate","clone","deepcopy","cloneDeep"],"sources":["../../../src/models/base/BaseModel.js"],"sourcesContent":["// @flow\nimport clone from \"lodash/clone\";\nimport cloneDeep from \"lodash/cloneDeep\";\n\nimport LayoutHintCollection from \"../layouthint/LayoutHintCollection\";\n\nexport type BaseDehydrateData = {\n +data: Object,\n +contributions: Object,\n connectKey: string,\n ...\n};\n\n/**\n * Base model\n */\nclass BaseModel {\n _data: Object;\n _contributions: Object;\n _layouthint: LayoutHintCollection;\n _connectKey: string;\n\n /**\n * constructor\n */\n constructor(data: Object, contributions: Object) {\n this._data = data;\n this._contributions = contributions;\n this._layouthint = new LayoutHintCollection(\n this.getContribution(\"layouthint\", [])\n );\n }\n\n /**\n * Retrieve data\n */\n get data(): Object {\n return this._data || {};\n }\n\n /**\n */\n getData(propName: string, defaultValue: any = null): any {\n return this.data[propName] ?? defaultValue;\n }\n\n /**\n * Retrieve contributions\n */\n get contributions(): Object {\n return this._contributions || {};\n }\n\n /**\n */\n getContribution(propName: string, defaultValue: any = null): any {\n return this.contributions[propName] ?? defaultValue;\n }\n\n /**\n * Getting the layouthint\n */\n get layouthint(): LayoutHintCollection {\n return this._layouthint;\n }\n\n /**\n * Set the layouthint\n */\n set layouthint(layouthint: Array<string>) {\n this._layouthint = new LayoutHintCollection(layouthint);\n }\n\n /**\n * Indicates if the model has data\n */\n get hasData(): boolean {\n return Object.keys(this.data).length > 0;\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 */\n dehydrate(): BaseDehydrateData {\n return {\n data: this._data,\n contributions: this._contributions,\n connectKey: this._connectKey,\n };\n }\n\n /**\n */\n rehydrate(data: Object) {\n this._connectKey = data.connectKey;\n }\n\n /**\n * Returns a clone of the model (this is not a deep copy)\n */\n clone(deepcopy: boolean = false): any {\n // deepcopy can be expensive, use with care!\n if (deepcopy) {\n return cloneDeep(this);\n }\n\n return clone(this);\n }\n}\n\nexport default BaseModel;\n"],"mappings":";;;;;;;;;AACA;AACA;AAEA;AASA;AACA;AACA;AACA,MAAMA,SAAS,CAAC;EAMd;AACF;AACA;EACEC,WAAW,CAACC,IAAY,EAAEC,aAAqB,EAAE;IAAA;IAAA;IAAA;IAAA;IAC/C,IAAI,CAACC,KAAK,GAAGF,IAAI;IACjB,IAAI,CAACG,cAAc,GAAGF,aAAa;IACnC,IAAI,CAACG,WAAW,GAAG,IAAIC,6BAAoB,CACzC,IAAI,CAACC,eAAe,CAAC,YAAY,EAAE,EAAE,CAAC,CACvC;EACH;;EAEA;AACF;AACA;EACE,IAAIN,IAAI,GAAW;IACjB,OAAO,IAAI,CAACE,KAAK,IAAI,CAAC,CAAC;EACzB;;EAEA;AACF;EACEK,OAAO,CAACC,QAAgB,EAAiC;IAAA,IAA/BC,YAAiB,uEAAG,IAAI;IAChD,OAAO,IAAI,CAACT,IAAI,CAACQ,QAAQ,CAAC,IAAIC,YAAY;EAC5C;;EAEA;AACF;AACA;EACE,IAAIR,aAAa,GAAW;IAC1B,OAAO,IAAI,CAACE,cAAc,IAAI,CAAC,CAAC;EAClC;;EAEA;AACF;EACEG,eAAe,CAACE,QAAgB,EAAiC;IAAA,IAA/BC,YAAiB,uEAAG,IAAI;IACxD,OAAO,IAAI,CAACR,aAAa,CAACO,QAAQ,CAAC,IAAIC,YAAY;EACrD;;EAEA;AACF;AACA;EACE,IAAIC,UAAU,GAAyB;IACrC,OAAO,IAAI,CAACN,WAAW;EACzB;;EAEA;AACF;AACA;EACE,IAAIM,UAAU,CAACA,UAAyB,EAAE;IACxC,IAAI,CAACN,WAAW,GAAG,IAAIC,6BAAoB,CAACK,UAAU,CAAC;EACzD;;EAEA;AACF;AACA;EACE,IAAIC,OAAO,GAAY;IACrB,OAAO,mBAAY,IAAI,CAACX,IAAI,CAAC,CAACY,MAAM,GAAG,CAAC;EAC1C;;EAEA;AACF;EACE,IAAIC,UAAU,CAACC,GAAW,EAAE;IAC1B,IAAI,CAACC,WAAW,GAAGD,GAAG;EACxB;;EAEA;AACF;EACE,IAAID,UAAU,GAAW;IACvB,OAAO,IAAI,CAACE,WAAW;EACzB;;EAEA;AACF;EACEC,SAAS,GAAsB;IAC7B,OAAO;MACLhB,IAAI,EAAE,IAAI,CAACE,KAAK;MAChBD,aAAa,EAAE,IAAI,CAACE,cAAc;MAClCU,UAAU,EAAE,IAAI,CAACE;IACnB,CAAC;EACH;;EAEA;AACF;EACEE,SAAS,CAACjB,IAAY,EAAE;IACtB,IAAI,CAACe,WAAW,GAAGf,IAAI,CAACa,UAAU;EACpC;;EAEA;AACF;AACA;EACEK,KAAK,GAAiC;IAAA,IAAhCC,QAAiB,uEAAG,KAAK;IAC7B;IACA,IAAIA,QAAQ,EAAE;MACZ,OAAO,IAAAC,kBAAS,EAAC,IAAI,CAAC;IACxB;IAEA,OAAO,IAAAF,cAAK,EAAC,IAAI,CAAC;EACpB;AACF;AAAC,eAEcpB,SAAS;AAAA"}
1
+ {"version":3,"file":"BaseModel.js","names":["BaseModel","constructor","data","contributions","_data","_contributions","_layouthint","LayoutHintCollection","getContribution","getData","propName","defaultValue","layouthint","hasData","length","connectKey","key","_connectKey","dehydrate","rehydrate","clone","deepcopy","cloneDeep"],"sources":["../../../src/models/base/BaseModel.js"],"sourcesContent":["// @flow\nimport clone from \"lodash/clone\";\nimport cloneDeep from \"lodash/cloneDeep\";\n\nimport LayoutHintCollection from \"../layouthint/LayoutHintCollection\";\n\nexport type BaseDehydrateData = {\n +data: Object,\n +contributions: Object,\n connectKey: string,\n ...\n};\n\n/**\n * Base model, this is the foundation of a model,\n * it contains data that is needed for all models like, data, contributions and layout hint\n *\n * Extend this for non modular ui resources, for modular ui resource start with the resourceModel\n */\nclass BaseModel {\n _data: Object;\n _contributions: Object;\n _layouthint: LayoutHintCollection;\n _connectKey: string;\n\n /**\n * constructor\n */\n constructor(data: Object, contributions: Object) {\n this._data = data;\n this._contributions = contributions;\n this._layouthint = new LayoutHintCollection(\n this.getContribution(\"layouthint\", [])\n );\n }\n\n /**\n * Retrieve data\n */\n get data(): Object {\n return this._data || {};\n }\n\n /**\n * Retrieve property from the data object of the model, mostly used internal\n */\n getData(propName: string, defaultValue: any = null): any {\n return this.data[propName] ?? defaultValue;\n }\n\n /**\n * Retrieve contributions\n */\n get contributions(): Object {\n return this._contributions || {};\n }\n\n /**\n * Retrieve property from the contributions of the model, mostly used internal\n */\n getContribution(propName: string, defaultValue: any = null): any {\n return this.contributions[propName] ?? defaultValue;\n }\n\n /**\n * Getting the layouthint\n */\n get layouthint(): LayoutHintCollection {\n return this._layouthint;\n }\n\n /**\n * Set the layouthint\n */\n set layouthint(layouthint: Array<string>) {\n this._layouthint = new LayoutHintCollection(layouthint);\n }\n\n /**\n * Indicates if the model has data\n */\n get hasData(): boolean {\n return Object.keys(this.data).length > 0;\n }\n\n /**\n * Set the unique key for this model\n */\n set connectKey(key: string) {\n this._connectKey = key;\n }\n\n /**\n * Get the unique key of this model\n */\n get connectKey(): string {\n return this._connectKey;\n }\n\n /**\n * Dehydrate internal data, returns the information that is needed to recreate the model\n */\n dehydrate(): BaseDehydrateData {\n return {\n data: this._data,\n contributions: this._contributions,\n connectKey: this._connectKey,\n };\n }\n\n /**\n * Recreate the model with the given data\n */\n rehydrate(data: BaseDehydrateData) {\n this._connectKey = data.connectKey;\n }\n\n /**\n * Returns a clone of the model\n */\n clone(deepcopy: boolean = false): any {\n // deepcopy can be expensive, use with care!\n if (deepcopy) {\n return cloneDeep(this);\n }\n\n return clone(this);\n }\n}\n\nexport default BaseModel;\n"],"mappings":";;;;;;;;;AACA;AACA;AAEA;AASA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,SAAS,CAAC;EAMd;AACF;AACA;EACEC,WAAW,CAACC,IAAY,EAAEC,aAAqB,EAAE;IAAA;IAAA;IAAA;IAAA;IAC/C,IAAI,CAACC,KAAK,GAAGF,IAAI;IACjB,IAAI,CAACG,cAAc,GAAGF,aAAa;IACnC,IAAI,CAACG,WAAW,GAAG,IAAIC,6BAAoB,CACzC,IAAI,CAACC,eAAe,CAAC,YAAY,EAAE,EAAE,CAAC,CACvC;EACH;;EAEA;AACF;AACA;EACE,IAAIN,IAAI,GAAW;IACjB,OAAO,IAAI,CAACE,KAAK,IAAI,CAAC,CAAC;EACzB;;EAEA;AACF;AACA;EACEK,OAAO,CAACC,QAAgB,EAAiC;IAAA,IAA/BC,YAAiB,uEAAG,IAAI;IAChD,OAAO,IAAI,CAACT,IAAI,CAACQ,QAAQ,CAAC,IAAIC,YAAY;EAC5C;;EAEA;AACF;AACA;EACE,IAAIR,aAAa,GAAW;IAC1B,OAAO,IAAI,CAACE,cAAc,IAAI,CAAC,CAAC;EAClC;;EAEA;AACF;AACA;EACEG,eAAe,CAACE,QAAgB,EAAiC;IAAA,IAA/BC,YAAiB,uEAAG,IAAI;IACxD,OAAO,IAAI,CAACR,aAAa,CAACO,QAAQ,CAAC,IAAIC,YAAY;EACrD;;EAEA;AACF;AACA;EACE,IAAIC,UAAU,GAAyB;IACrC,OAAO,IAAI,CAACN,WAAW;EACzB;;EAEA;AACF;AACA;EACE,IAAIM,UAAU,CAACA,UAAyB,EAAE;IACxC,IAAI,CAACN,WAAW,GAAG,IAAIC,6BAAoB,CAACK,UAAU,CAAC;EACzD;;EAEA;AACF;AACA;EACE,IAAIC,OAAO,GAAY;IACrB,OAAO,mBAAY,IAAI,CAACX,IAAI,CAAC,CAACY,MAAM,GAAG,CAAC;EAC1C;;EAEA;AACF;AACA;EACE,IAAIC,UAAU,CAACC,GAAW,EAAE;IAC1B,IAAI,CAACC,WAAW,GAAGD,GAAG;EACxB;;EAEA;AACF;AACA;EACE,IAAID,UAAU,GAAW;IACvB,OAAO,IAAI,CAACE,WAAW;EACzB;;EAEA;AACF;AACA;EACEC,SAAS,GAAsB;IAC7B,OAAO;MACLhB,IAAI,EAAE,IAAI,CAACE,KAAK;MAChBD,aAAa,EAAE,IAAI,CAACE,cAAc;MAClCU,UAAU,EAAE,IAAI,CAACE;IACnB,CAAC;EACH;;EAEA;AACF;AACA;EACEE,SAAS,CAACjB,IAAuB,EAAE;IACjC,IAAI,CAACe,WAAW,GAAGf,IAAI,CAACa,UAAU;EACpC;;EAEA;AACF;AACA;EACEK,KAAK,GAAiC;IAAA,IAAhCC,QAAiB,uEAAG,KAAK;IAC7B;IACA,IAAIA,QAAQ,EAAE;MACZ,OAAO,IAAAC,kBAAS,EAAC,IAAI,CAAC;IACxB;IAEA,OAAO,IAAAF,cAAK,EAAC,IAAI,CAAC;EACpB;AACF;AAAC,eAEcpB,SAAS;AAAA"}
@@ -13,7 +13,7 @@ var _BaseModel = _interopRequireDefault(require("./BaseModel"));
13
13
  var _LinkCollection = _interopRequireDefault(require("../links/LinkCollection"));
14
14
  var _exceptions = require("../../exceptions");
15
15
  /**
16
- * Base model
16
+ * Base model, this the foundation for models that represent modular ui services, e.g. application, tab, caseview, etc
17
17
  */
18
18
  class ResourceModel extends _BaseModel.default {
19
19
  /**
@@ -14,7 +14,7 @@ import type Href from "../href/Href";
14
14
  import type { ModularUIModel, IModelWithChildModels } from "../types";
15
15
 
16
16
  /**
17
- * Base model
17
+ * Base model, this the foundation for models that represent modular ui services, e.g. application, tab, caseview, etc
18
18
  */
19
19
  class ResourceModel extends BaseModel implements IModelWithChildModels {
20
20
  _key: string;
@@ -1 +1 @@
1
- {"version":3,"file":"ResourceModel.js","names":["ResourceModel","BaseModel","constructor","modularuiResponse","ModularUIResponse","data","contributions","_key","key","_locale","locale","_childModels","_lastServerUpdate","Date","now","isApplicableModel","IllegalArgumentException","Error","lastServerUpdate","type","IllegalStateException","resourcetype","getContribution","label","links","_links","LinkCollection","Array","isArray","self","selflink","getLinkByKey","selfhref","href","getInitialChildModelLinks","childModels","addChildModels","models","flattenModels","setChildModels","dehydrate","childModel"],"sources":["../../../src/models/base/ResourceModel.js"],"sourcesContent":["// @flow\nimport ModularUIResponse from \"../../modularui/ModularUIResponse\";\n\nimport BaseModel from \"./BaseModel\";\nimport LinkCollection from \"../links/LinkCollection\";\n\nimport {\n IllegalArgumentException,\n IllegalStateException,\n} from \"../../exceptions\";\n\nimport type LinkModel from \"../links/LinkModel\";\nimport type Href from \"../href/Href\";\nimport type { ModularUIModel, IModelWithChildModels } from \"../types\";\n\n/**\n * Base model\n */\nclass ResourceModel extends BaseModel implements IModelWithChildModels {\n _key: string;\n _locale: string;\n _childModels: Array<ModularUIModel>;\n _links: LinkCollection;\n _lastServerUpdate: number;\n\n /**\n * constructor\n */\n constructor(modularuiResponse: ModularUIResponse = new ModularUIResponse()) {\n super(modularuiResponse.data, modularuiResponse.contributions);\n\n this._key = modularuiResponse.key;\n this._locale = modularuiResponse.locale;\n\n this._childModels = [];\n\n this._lastServerUpdate = Date.now();\n }\n\n /**\n * Returns true when the model is supported based on configuration found in contributions\n *\n * @abstract\n */\n static isApplicableModel(data: ModularUIResponse): boolean {\n if (!(data instanceof ModularUIResponse)) {\n throw new IllegalArgumentException(\n \"Given argument for isApplicableModel is not a ModularUIResponse\"\n );\n }\n\n throw new Error(\"No isApplicableModel condition set on resourcemodel\");\n }\n\n /**\n */\n get lastServerUpdate(): number {\n return this._lastServerUpdate;\n }\n\n /**\n */\n set lastServerUpdate(lastServerUpdate: number) {\n this._lastServerUpdate = lastServerUpdate;\n }\n\n /**\n */\n get locale(): string {\n return this._locale;\n }\n\n /**\n * Retrieve key\n */\n get key(): string {\n return this._key;\n }\n\n /**\n * Get type of model\n *\n * @abstract\n */\n get type(): string {\n throw new IllegalStateException(\n `No type set on the resource model with key ${this.key}`\n );\n }\n\n /**\n * Retrieve type of resource\n */\n get resourcetype(): string {\n return this.getContribution(\"resourcetype\", \"unknown\");\n }\n\n /**\n */\n get label(): string {\n return this.getContribution(\"label\", \"\");\n }\n\n /**\n * Getting the links of the resource\n */\n get links(): LinkCollection {\n if (!this._links) {\n this._links = new LinkCollection(\n Array.isArray(this.data._links)\n ? this.data._links[0]\n : this.data._links,\n {\n self: {\n resourcetype: this.resourcetype,\n },\n ...this.contributions._links,\n }\n );\n }\n return this._links;\n }\n\n /**\n */\n set links(links: LinkCollection) {\n this._links = links;\n }\n\n /**\n * Get self link of model\n */\n get selflink(): LinkModel {\n const selflink = this.links.getLinkByKey(\"self\");\n\n if (selflink === null) {\n throw new IllegalStateException(\n `Could not find self link for ${\n this.key === null ? \"unknown\" : this.key\n }`\n );\n }\n\n return selflink;\n }\n\n /**\n * Return default self link of resource\n */\n get selfhref(): Href {\n return this.selflink.href;\n }\n\n /**\n * Add links to expand on initialization of this model\n *\n * @abstract\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n return [];\n }\n\n /**\n * Retrieve links of expanded child models\n */\n get childModels(): Array<ModularUIModel> {\n return this._childModels;\n }\n\n /**\n * Add child models to this model\n */\n addChildModels(models: Array<ModularUIModel>): this {\n const flattenModels = [].concat(...models);\n\n this._childModels = flattenModels;\n\n this.setChildModels(flattenModels);\n\n return this;\n }\n\n /**\n * Template to set expanded child models\n * Use this hook to separate the retrieved child models into the correct models.\n *\n * @abstract\n * @example <caption>Put all models of instance List and GroupingPanel into the panels property</caption>\n */\n setChildModels(models: Array<ModularUIModel>): void {\n if (!models) {\n throw new IllegalArgumentException(\"No models send to setChildModels\");\n }\n }\n\n /**\n */\n dehydrate(): Object {\n return {\n ...super.dehydrate(),\n key: this._key,\n locale: this._locale,\n // $FlowFixMe[missing-type-arg]\n childModels: this._childModels.map<ModularUIModel>(\n (childModel: ModularUIModel) => childModel.dehydrate()\n ),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IC,WAAW,GAA0B;IACvC,OAAO,IAAI,CAACxB,YAAY;EAC1B;;EAEA;AACF;AACA;EACEyB,cAAc,CAACC,MAA6B,EAAQ;IAAA;IAClD,MAAMC,aAAa,GAAG,kCAAE,iBAAQ,GAAGD,MAAM,CAAC;IAE1C,IAAI,CAAC1B,YAAY,GAAG2B,aAAa;IAEjC,IAAI,CAACC,cAAc,CAACD,aAAa,CAAC;IAElC,OAAO,IAAI;EACb;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;EACEC,cAAc,CAACF,MAA6B,EAAQ;IAClD,IAAI,CAACA,MAAM,EAAE;MACX,MAAM,IAAIrB,oCAAwB,CAAC,kCAAkC,CAAC;IACxE;EACF;;EAEA;AACF;EACEwB,SAAS,GAAW;IAAA;IAClB,OAAO;MACL,GAAG,KAAK,CAACA,SAAS,EAAE;MACpBhC,GAAG,EAAE,IAAI,CAACD,IAAI;MACdG,MAAM,EAAE,IAAI,CAACD,OAAO;MACpB;MACA0B,WAAW,EAAE,kCAAI,CAACxB,YAAY,kBAC3B8B,UAA0B,IAAKA,UAAU,CAACD,SAAS,EAAE;IAE1D,CAAC;EACH;AACF;AAAC,eAEcxC,aAAa;AAAA"}
1
+ {"version":3,"file":"ResourceModel.js","names":["ResourceModel","BaseModel","constructor","modularuiResponse","ModularUIResponse","data","contributions","_key","key","_locale","locale","_childModels","_lastServerUpdate","Date","now","isApplicableModel","IllegalArgumentException","Error","lastServerUpdate","type","IllegalStateException","resourcetype","getContribution","label","links","_links","LinkCollection","Array","isArray","self","selflink","getLinkByKey","selfhref","href","getInitialChildModelLinks","childModels","addChildModels","models","flattenModels","setChildModels","dehydrate","childModel"],"sources":["../../../src/models/base/ResourceModel.js"],"sourcesContent":["// @flow\nimport ModularUIResponse from \"../../modularui/ModularUIResponse\";\n\nimport BaseModel from \"./BaseModel\";\nimport LinkCollection from \"../links/LinkCollection\";\n\nimport {\n IllegalArgumentException,\n IllegalStateException,\n} from \"../../exceptions\";\n\nimport type LinkModel from \"../links/LinkModel\";\nimport type Href from \"../href/Href\";\nimport type { ModularUIModel, IModelWithChildModels } from \"../types\";\n\n/**\n * Base model, this the foundation for models that represent modular ui services, e.g. application, tab, caseview, etc\n */\nclass ResourceModel extends BaseModel implements IModelWithChildModels {\n _key: string;\n _locale: string;\n _childModels: Array<ModularUIModel>;\n _links: LinkCollection;\n _lastServerUpdate: number;\n\n /**\n * constructor\n */\n constructor(modularuiResponse: ModularUIResponse = new ModularUIResponse()) {\n super(modularuiResponse.data, modularuiResponse.contributions);\n\n this._key = modularuiResponse.key;\n this._locale = modularuiResponse.locale;\n\n this._childModels = [];\n\n this._lastServerUpdate = Date.now();\n }\n\n /**\n * Returns true when the model is supported based on configuration found in contributions\n *\n * @abstract\n */\n static isApplicableModel(data: ModularUIResponse): boolean {\n if (!(data instanceof ModularUIResponse)) {\n throw new IllegalArgumentException(\n \"Given argument for isApplicableModel is not a ModularUIResponse\"\n );\n }\n\n throw new Error(\"No isApplicableModel condition set on resourcemodel\");\n }\n\n /**\n */\n get lastServerUpdate(): number {\n return this._lastServerUpdate;\n }\n\n /**\n */\n set lastServerUpdate(lastServerUpdate: number) {\n this._lastServerUpdate = lastServerUpdate;\n }\n\n /**\n */\n get locale(): string {\n return this._locale;\n }\n\n /**\n * Retrieve key\n */\n get key(): string {\n return this._key;\n }\n\n /**\n * Get type of model\n *\n * @abstract\n */\n get type(): string {\n throw new IllegalStateException(\n `No type set on the resource model with key ${this.key}`\n );\n }\n\n /**\n * Retrieve type of resource\n */\n get resourcetype(): string {\n return this.getContribution(\"resourcetype\", \"unknown\");\n }\n\n /**\n */\n get label(): string {\n return this.getContribution(\"label\", \"\");\n }\n\n /**\n * Getting the links of the resource\n */\n get links(): LinkCollection {\n if (!this._links) {\n this._links = new LinkCollection(\n Array.isArray(this.data._links)\n ? this.data._links[0]\n : this.data._links,\n {\n self: {\n resourcetype: this.resourcetype,\n },\n ...this.contributions._links,\n }\n );\n }\n return this._links;\n }\n\n /**\n */\n set links(links: LinkCollection) {\n this._links = links;\n }\n\n /**\n * Get self link of model\n */\n get selflink(): LinkModel {\n const selflink = this.links.getLinkByKey(\"self\");\n\n if (selflink === null) {\n throw new IllegalStateException(\n `Could not find self link for ${\n this.key === null ? \"unknown\" : this.key\n }`\n );\n }\n\n return selflink;\n }\n\n /**\n * Return default self link of resource\n */\n get selfhref(): Href {\n return this.selflink.href;\n }\n\n /**\n * Add links to expand on initialization of this model\n *\n * @abstract\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n return [];\n }\n\n /**\n * Retrieve links of expanded child models\n */\n get childModels(): Array<ModularUIModel> {\n return this._childModels;\n }\n\n /**\n * Add child models to this model\n */\n addChildModels(models: Array<ModularUIModel>): this {\n const flattenModels = [].concat(...models);\n\n this._childModels = flattenModels;\n\n this.setChildModels(flattenModels);\n\n return this;\n }\n\n /**\n * Template to set expanded child models\n * Use this hook to separate the retrieved child models into the correct models.\n *\n * @abstract\n * @example <caption>Put all models of instance List and GroupingPanel into the panels property</caption>\n */\n setChildModels(models: Array<ModularUIModel>): void {\n if (!models) {\n throw new IllegalArgumentException(\"No models send to setChildModels\");\n }\n }\n\n /**\n */\n dehydrate(): Object {\n return {\n ...super.dehydrate(),\n key: this._key,\n locale: this._locale,\n // $FlowFixMe[missing-type-arg]\n childModels: this._childModels.map<ModularUIModel>(\n (childModel: ModularUIModel) => childModel.dehydrate()\n ),\n };\n }\n}\n\nexport default ResourceModel;\n"],"mappings":";;;;;;;;;;AACA;AAEA;AACA;AAEA;AASA;AACA;AACA;AACA,MAAMA,aAAa,SAASC,kBAAS,CAAkC;EAOrE;AACF;AACA;EACEC,WAAW,GAAiE;IAAA,IAAhEC,iBAAoC,uEAAG,IAAIC,0BAAiB,EAAE;IACxE,KAAK,CAACD,iBAAiB,CAACE,IAAI,EAAEF,iBAAiB,CAACG,aAAa,CAAC;IAAC;IAAA;IAAA;IAAA;IAAA;IAE/D,IAAI,CAACC,IAAI,GAAGJ,iBAAiB,CAACK,GAAG;I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M,EAAE;MACX,MAAM,IAAIrB,oCAAwB,CAAC,kCAAkC,CAAC;IACxE;EACF;;EAEA;AACF;EACEwB,SAAS,GAAW;IAAA;IAClB,OAAO;MACL,GAAG,KAAK,CAACA,SAAS,EAAE;MACpBhC,GAAG,EAAE,IAAI,CAACD,IAAI;MACdG,MAAM,EAAE,IAAI,CAACD,OAAO;MACpB;MACA0B,WAAW,EAAE,kCAAI,CAACxB,YAAY,kBAC3B8B,UAA0B,IAAKA,UAAU,CAACD,SAAS,EAAE;IAE1D,CAAC;EACH;AACF;AAAC,eAEcxC,aAAa;AAAA"}
@@ -17,6 +17,7 @@ var _CompositeAttributeModel = _interopRequireDefault(require("../attributes/Com
17
17
  var _ContentConfiguration = _interopRequireDefault(require("../contentconfiguration/ContentConfiguration"));
18
18
  var _ErrorCollection = _interopRequireDefault(require("../error/ErrorCollection"));
19
19
  var _exceptions = require("../../exceptions");
20
+ var _LayoutHintCollection = _interopRequireDefault(require("../layouthint/LayoutHintCollection"));
20
21
  /**
21
22
  * Form Object
22
23
  */
@@ -384,32 +385,60 @@ class FormObjectModel extends _BaseModel.default {
384
385
  this._dynamicValidationsLoaded = dynamicValidationsLoaded;
385
386
  }
386
387
 
388
+ /**
389
+ * Convert error json from a form service to validation messages on the form object and attributes
390
+ */
391
+ handleErrorValidations(errors) {
392
+ const attributeErrors = [];
393
+ errors.forEach(error => {
394
+ if (error.anchor?.objectid === this.key) {
395
+ if ((0, _objects.has)(error.anchor, "elementid")) {
396
+ attributeErrors.push(error);
397
+ } else {
398
+ this.errorCollection.addServerError(error.id, error.message, error.properties, new _LayoutHintCollection.default(error.layouthint));
399
+ }
400
+ }
401
+ });
402
+ this.attributeCollection.updateValidations(attributeErrors);
403
+ }
404
+
405
+ /**
406
+ * Convert missing json from a form service to mandatory validation constraints and messages
407
+ */
408
+ handleMissingValidations(missing) {
409
+ const attributeErrors = [];
410
+ for (const anchor of missing.anchors) {
411
+ if (Array.isArray(anchor.elements)) {
412
+ for (const element of anchor.elements) {
413
+ attributeErrors.push({
414
+ anchor: {
415
+ elementid: element.elementid
416
+ },
417
+ id: "Constraint.Mandatory"
418
+ });
419
+ }
420
+ } else {
421
+ attributeErrors.push({
422
+ anchor,
423
+ id: "Constraint.Mandatory"
424
+ });
425
+ }
426
+ }
427
+ this.attributeCollection.updateValidations(attributeErrors);
428
+ }
429
+
387
430
  /**
388
431
  */
389
432
  updateValidations(data) {
390
433
  this.resetErrors();
391
- const attributeErrors = [];
392
434
  if (Array.isArray(data.errors)) {
393
- data.errors.forEach(error => {
394
- if (error.anchor?.objectid === this.key) {
395
- if ((0, _objects.has)(error.anchor, "elementid")) {
396
- attributeErrors.push(error);
397
- } else {
398
- this.errorCollection.addServerError(error.id, error.message, error.properties, error.layouthint);
399
- }
400
- }
401
- });
435
+ this.handleErrorValidations(data.errors);
402
436
  }
403
437
 
404
438
  // missing attribute errors
405
439
  if (Array.isArray(data.missing?.anchors)) {
406
- var _context5;
407
- attributeErrors.push(...(0, _map.default)(_context5 = data.missing.anchors).call(_context5, anchor => ({
408
- anchor,
409
- id: "Constraint.Mandatory"
410
- })));
440
+ this.handleMissingValidations(data.missing);
411
441
  }
412
- this.attributeCollection.updateValidations(attributeErrors);
413
442
  this.dynamicValidationsLoaded = true;
414
443
  return this;
415
444
  }
@@ -10,6 +10,8 @@ import { IllegalArgumentException } from "../../exceptions";
10
10
 
11
11
  import type { AttributeType, ModularUIModel, FormErrorAnchor } from "../types";
12
12
  import type LinkModel from "../links/LinkModel";
13
+ import LayoutHintCollection from "../layouthint/LayoutHintCollection";
14
+ import type { MessageParameters } from "../../i18n";
13
15
 
14
16
  /**
15
17
  * Form Object
@@ -448,40 +450,85 @@ export default class FormObjectModel extends BaseModel {
448
450
  }
449
451
 
450
452
  /**
453
+ * Convert error json from a form service to validation messages on the form object and attributes
451
454
  */
452
- updateValidations(data: any): FormObjectModel {
453
- this.resetErrors();
454
-
455
+ handleErrorValidations(
456
+ errors: Array<{
457
+ anchor: {
458
+ objectid: string,
459
+ elementid?: string,
460
+ },
461
+ id: string,
462
+ message: string,
463
+ properties: MessageParameters,
464
+ layouthint: Array<string>,
465
+ }>
466
+ ) {
455
467
  const attributeErrors = [];
456
468
 
457
- if (Array.isArray(data.errors)) {
458
- data.errors.forEach((error) => {
459
- if (error.anchor?.objectid === this.key) {
460
- if (has(error.anchor, "elementid")) {
461
- attributeErrors.push(error);
462
- } else {
463
- this.errorCollection.addServerError(
464
- error.id,
465
- error.message,
466
- error.properties,
467
- error.layouthint
468
- );
469
- }
469
+ errors.forEach((error) => {
470
+ if (error.anchor?.objectid === this.key) {
471
+ if (has(error.anchor, "elementid")) {
472
+ attributeErrors.push(error);
473
+ } else {
474
+ this.errorCollection.addServerError(
475
+ error.id,
476
+ error.message,
477
+ error.properties,
478
+ new LayoutHintCollection(error.layouthint)
479
+ );
470
480
  }
471
- });
472
- }
481
+ }
482
+ });
473
483
 
474
- // missing attribute errors
475
- if (Array.isArray(data.missing?.anchors)) {
476
- attributeErrors.push(
477
- ...data.missing.anchors.map((anchor) => ({
484
+ this.attributeCollection.updateValidations(attributeErrors);
485
+ }
486
+
487
+ /**
488
+ * Convert missing json from a form service to mandatory validation constraints and messages
489
+ */
490
+ handleMissingValidations(missing: {
491
+ anchors: Array<
492
+ | {
493
+ elements: Array<{ elementid: string }>,
494
+ }
495
+ | { anchor: { elementid: string } }
496
+ >,
497
+ }) {
498
+ const attributeErrors = [];
499
+
500
+ for (const anchor of missing.anchors) {
501
+ if (Array.isArray(anchor.elements)) {
502
+ for (const element of anchor.elements) {
503
+ attributeErrors.push({
504
+ anchor: { elementid: element.elementid },
505
+ id: "Constraint.Mandatory",
506
+ });
507
+ }
508
+ } else {
509
+ attributeErrors.push({
478
510
  anchor,
479
511
  id: "Constraint.Mandatory",
480
- }))
481
- );
512
+ });
513
+ }
482
514
  }
483
515
 
484
516
  this.attributeCollection.updateValidations(attributeErrors);
517
+ }
518
+
519
+ /**
520
+ */
521
+ updateValidations(data: any): FormObjectModel {
522
+ this.resetErrors();
523
+
524
+ if (Array.isArray(data.errors)) {
525
+ this.handleErrorValidations(data.errors);
526
+ }
527
+
528
+ // missing attribute errors
529
+ if (Array.isArray(data.missing?.anchors)) {
530
+ this.handleMissingValidations(data.missing);
531
+ }
485
532
 
486
533
  this.dynamicValidationsLoaded = true;
487
534
 
@@ -1 +1 @@
1
- {"version":3,"file":"FormObjectModel.js","names":["FormObjectModel","BaseModel","constructor","object","objectContributions","getElements","length","_attributeCollection","AttributeCollection","getApplicableAttributeContributions","_contentConfiguration","ContentConfiguration","content","_errorCollection","ErrorCollection","has","data","attributeCollection","setReferenceDate","getData","indicateContentConfiguration","contentConfiguration","createEmpty","formObjectModel","IllegalArgumentException","contributions","equals","withRepeatIndex","key","objectContainsOneOfTheAttributes","all","attribute","isResult","some","hasAttributeByKey","hasSameRepeatIndex","repeatIndex","getAttributeByAttribute","getAttributeByKey","elements","push","results","dataResults","result","elementid","dataElementIds","element","getAttributesInData","attributes","isDynamic","attributeKey","mandatory","attributesContributions","attributeContributions","dataElementId","split","getInitialChildModelLinks","setChildModels","models","objectid","hasEndResultConfiguration","getContribution","hasDynamicValidations","isRepeatable","_repeatIndex","index","maxRepeats","hasFixedNrOfRepeats","isRepeatWithUnknownTotal","isLastRepeat","last","repeatIndexLabel","label","introText","text","message","assistent","buttonLabels","mergeObject","oldObject","forEach","mergeWithAttribute","mergeAttribute","updateAttribute","value","attributeToUpdate","Error","name","CompositeAttributeModel","update","isChangedSince","timestamp","resetErrors","errorCollection","addServerError","error","anchor","id","properties","layouthint","hasServerErrors","hasItems","hasErrors","isValid","visible","every","dynamicValidationsLoaded","_dynamicValidationsLoaded","updateValidations","attributeErrors","Array","isArray","errors","missing","anchors","formdata","getFormData","validationData"],"sources":["../../../src/models/form/FormObjectModel.js"],"sourcesContent":["// @flow\nimport { has } from \"../../utils/helpers/objects\";\n\nimport BaseModel from \"../base/BaseModel\";\nimport AttributeCollection from \"../attributes/AttributeCollection\";\nimport CompositeAttributeModel from \"../attributes/CompositeAttributeModel\";\nimport ContentConfiguration from \"../contentconfiguration/ContentConfiguration\";\nimport ErrorCollection from \"../error/ErrorCollection\";\nimport { IllegalArgumentException } from \"../../exceptions\";\n\nimport type { AttributeType, ModularUIModel, FormErrorAnchor } from \"../types\";\nimport type LinkModel from \"../links/LinkModel\";\n\n/**\n * Form Object\n */\nexport default class FormObjectModel extends BaseModel {\n _attributeCollection: AttributeCollection;\n _contentConfiguration: ContentConfiguration;\n _errorCollection: ErrorCollection;\n _repeatIndex: number;\n _dynamicValidationsLoaded: boolean;\n\n /**\n * Construct FormObjectModel\n */\n constructor(object: Object, objectContributions: Object) {\n super(object, objectContributions);\n\n if (object && this.getElements().length > 0) {\n this._attributeCollection = new AttributeCollection(\n this.getElements(),\n this.getApplicableAttributeContributions()\n );\n } else {\n this._attributeCollection = new AttributeCollection();\n }\n\n this._contentConfiguration = new ContentConfiguration(\n objectContributions ? objectContributions.content : {}\n );\n\n this._errorCollection = new ErrorCollection(\"formobject\");\n\n if (has(this.data, \"referenceDate\")) {\n this.attributeCollection.setReferenceDate(this.getData(\"referenceDate\"));\n }\n\n this.attributeCollection.indicateContentConfiguration(\n this.contentConfiguration\n );\n }\n\n /**\n */\n static createEmpty(formObjectModel: FormObjectModel): FormObjectModel {\n if (!formObjectModel) {\n throw new IllegalArgumentException(\n \"createEmpty method needs a FormObjectModel as input argument to create a new version of the object\"\n );\n }\n return new FormObjectModel(\n formObjectModel.data,\n formObjectModel.contributions\n );\n }\n\n /**\n */\n equals(object: ?FormObjectModel, withRepeatIndex: boolean = true): boolean {\n if (!object || this.key !== object.key) {\n return false;\n }\n\n const objectContainsOneOfTheAttributes = this.attributeCollection.all\n .filter((attribute) => !attribute.isResult)\n .some(\n (attribute) =>\n object && object.attributeCollection.hasAttributeByKey(attribute.key)\n );\n\n const hasSameRepeatIndex = withRepeatIndex\n ? this.repeatIndex === object.repeatIndex\n : true;\n\n return hasSameRepeatIndex && objectContainsOneOfTheAttributes;\n }\n\n /**\n */\n getAttributeByAttribute(attribute: AttributeType): AttributeType | null {\n return this.attributeCollection.getAttributeByAttribute(attribute);\n }\n\n /**\n */\n getAttributeByKey(key: string): AttributeType | null {\n return this.attributeCollection.getAttributeByKey(key);\n }\n\n /**\n */\n hasAttributeByKey(key: string): boolean {\n return this.attributeCollection.hasAttributeByKey(key);\n }\n\n /**\n * Get elements from both the missing attributes and the result attributes\n */\n getElements(): Array<Object> {\n const elements = [];\n\n if (this.data.elements) {\n elements.push(...this.data.elements);\n }\n\n if (this.data.results) {\n const dataResults = this.data.results.map((result) => ({\n ...result,\n isResult: true,\n }));\n\n elements.push(...dataResults);\n }\n\n if (this.data.elementid) {\n elements.push({\n ...this.data,\n });\n }\n\n return elements;\n }\n\n /**\n * Map available contributions on the available data. Only use contributions that are needed for the data\n */\n getApplicableAttributeContributions(): Array<Object> {\n if (this.data && this.contributions) {\n const dataElementIds = this.getElements().map(\n (element) => element.elementid\n );\n\n const contributions = this.getAttributesInData(\n dataElementIds,\n this.contributions.attributes\n );\n\n // set all attribute mandatory for dynamic object\n if (this.isDynamic) {\n return contributions.map((attribute) => {\n const [attributeKey] = Object.keys(attribute);\n return {\n [attributeKey]: {\n ...attribute[attributeKey],\n mandatory: true,\n },\n };\n });\n }\n\n return contributions;\n }\n\n return [];\n }\n\n /**\n * Recursevily check if an attribute id occurs in the tree of attribute contributions.\n * The complete leaf of the tree is returned when an attribute id matches\n */\n getAttributesInData(\n dataElementIds: Array<string>,\n attributesContributions: Object\n ): Array<Object> {\n return attributesContributions.filter((attributeContributions) => {\n const [attributeKey] = Object.keys(attributeContributions);\n\n return dataElementIds.some(\n (dataElementId) => dataElementId.split(\".\")[0] === attributeKey\n );\n });\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n return this._attributeCollection.getInitialChildModelLinks();\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n this._attributeCollection.setChildModels(models);\n }\n\n /**\n * get key\n */\n get key(): string {\n return this.data.objectid;\n }\n\n /**\n * Get content configuration for form objects\n */\n get contentConfiguration(): ContentConfiguration {\n return this._contentConfiguration;\n }\n\n /**\n */\n get hasEndResultConfiguration(): boolean {\n return this.contributions.content?.results != null;\n }\n\n /**\n * Indicates if object is dynamic. A dynamic object should be submitted on each attribute change\n */\n get isDynamic(): boolean {\n return this.getContribution(\"dynamicObject\", false);\n }\n\n /**\n */\n get hasDynamicValidations(): boolean {\n return this.getContribution(\"dynamicValidations\", false);\n }\n\n /**\n * Indicates if object is repeatable\n */\n get isRepeatable(): boolean {\n return this.getContribution(\"repeatable\", false);\n }\n\n /**\n */\n get repeatIndex(): number {\n return this._repeatIndex ?? this.data.index ?? 1;\n }\n\n /**\n */\n set repeatIndex(repeatIndex: number) {\n this._repeatIndex = repeatIndex;\n }\n\n /**\n */\n get maxRepeats(): number {\n if (this.isRepeatable) {\n return this.getData(\"numberofrepeats\", -1);\n }\n\n return 1;\n }\n\n /**\n */\n get hasFixedNrOfRepeats(): boolean {\n return this.maxRepeats > -1;\n }\n\n /**\n */\n get isRepeatWithUnknownTotal(): boolean {\n return this.isRepeatable && this.maxRepeats === -1;\n }\n\n /**\n */\n get isLastRepeat(): boolean {\n if (this.isRepeatable) {\n return this.data.last || false;\n }\n\n return true;\n }\n\n /**\n */\n get repeatIndexLabel(): string | null {\n return this.data[\"index-identifier\"] || null;\n }\n\n /**\n * Get label of form object\n */\n get label(): string {\n return this.contributions.label;\n }\n\n /**\n * Get introText of form object\n */\n get introText(): string {\n if (this.data.content?.text) {\n return this.data.content.text.message;\n }\n\n if (this.contributions.text?.message) {\n return this.contributions.text.message;\n }\n\n return this.contributions.introText;\n }\n\n /**\n * Get assistent of form object\n */\n get assistent(): string {\n return this.contributions.assistent;\n }\n\n /**\n * Get button labels\n */\n get buttonLabels(): Object {\n return this.getContribution(\"buttonLabels\", {});\n }\n\n /**\n * get attribute collection\n */\n get attributeCollection(): AttributeCollection {\n return this._attributeCollection;\n }\n\n /**\n */\n set attributeCollection(attributeCollection: AttributeCollection) {\n this._attributeCollection = attributeCollection;\n }\n\n /**\n */\n mergeObject(oldObject: FormObjectModel) {\n this.attributeCollection.forEach((attribute) => {\n const mergeWithAttribute = oldObject.getAttributeByAttribute(attribute);\n if (mergeWithAttribute) {\n attribute.mergeAttribute(mergeWithAttribute);\n }\n });\n\n this.repeatIndex = oldObject.repeatIndex;\n }\n\n /**\n * Update attribute\n */\n updateAttribute(attribute: AttributeType, value: any): AttributeType {\n const attributeToUpdate =\n this.attributeCollection.getAttributeByAttribute(attribute);\n\n if (attributeToUpdate === null) {\n throw new Error(`Attribute with name: ${attribute.name} not found.`);\n }\n\n if (attributeToUpdate instanceof CompositeAttributeModel) {\n attributeToUpdate.update(value, attribute);\n } else {\n attributeToUpdate.update(value);\n }\n\n return attributeToUpdate;\n }\n\n /**\n * Inidicates if Form is changed since a given timestamp (Date.now)\n */\n isChangedSince(timestamp: number): boolean {\n return (\n this.attributeCollection.find((attribute) =>\n attribute.isChangedSince(timestamp)\n ) !== null\n );\n }\n\n /**\n * Reset all errors on Form Object\n */\n resetErrors() {\n this._errorCollection = new ErrorCollection(\"formobject\");\n this.attributeCollection.forEach((attribute) => attribute.resetErrors());\n }\n\n /**\n * Get error messages\n */\n get errorCollection(): ErrorCollection {\n return this._errorCollection;\n }\n\n /**\n * Registers an error that was received from a server response\n */\n addServerError(error: FormErrorAnchor) {\n if (error.anchor?.elementid != null) {\n this.attributeCollection.addServerError(error);\n } else {\n this._errorCollection.addServerError(\n error.id,\n error.message,\n error.properties,\n error.layouthint\n );\n }\n }\n\n /**\n */\n hasServerErrors(): boolean {\n return (\n this.errorCollection.hasItems ||\n this.attributeCollection.hasServerErrors()\n );\n }\n\n /**\n */\n hasErrors(): boolean {\n return (\n this.errorCollection.hasItems || this.attributeCollection.hasErrors()\n );\n }\n\n /**\n */\n get isValid(): boolean {\n return (\n this.attributeCollection.visible.every(\n (attribute) => attribute.isValid\n ) && !this.errorCollection.hasItems\n );\n }\n\n /**\n */\n get dynamicValidationsLoaded(): boolean {\n return this._dynamicValidationsLoaded;\n }\n\n /**\n */\n set dynamicValidationsLoaded(dynamicValidationsLoaded: boolean) {\n this._dynamicValidationsLoaded = dynamicValidationsLoaded;\n }\n\n /**\n */\n updateValidations(data: any): FormObjectModel {\n this.resetErrors();\n\n const attributeErrors = [];\n\n if (Array.isArray(data.errors)) {\n data.errors.forEach((error) => {\n if (error.anchor?.objectid === this.key) {\n if (has(error.anchor, \"elementid\")) {\n attributeErrors.push(error);\n } else {\n this.errorCollection.addServerError(\n error.id,\n error.message,\n error.properties,\n error.layouthint\n );\n }\n }\n });\n }\n\n // missing attribute errors\n if (Array.isArray(data.missing?.anchors)) {\n attributeErrors.push(\n ...data.missing.anchors.map((anchor) => ({\n anchor,\n id: \"Constraint.Mandatory\",\n }))\n );\n }\n\n this.attributeCollection.updateValidations(attributeErrors);\n\n this.dynamicValidationsLoaded = true;\n\n return this;\n }\n\n /**\n * Generate formdata object for current formobject based on formdata of attributes\n */\n get formdata(): { [string]: any } | null {\n return this.attributeCollection.formdata;\n }\n\n /**\n */\n getFormData(validationData: boolean = false): { [string]: any } | null {\n return this.attributeCollection.getFormData(validationData);\n }\n}\n"],"mappings":";;;;;;;;;;;;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAKA;AACA;AACA;AACe,MAAMA,eAAe,SAASC,kBAAS,CAAC;EAOrD;AACF;AACA;EACEC,WAAW,CAACC,MAAc,EAAEC,mBAA2B,EAAE;IACvD,KAAK,CAACD,MAAM,EAAEC,mBAAmB,CAAC;IAAC;IAAA;IAAA;IAAA;IAAA;IAEnC,IAAID,MAAM,IAAI,IAAI,CAACE,WAAW,EAAE,CAACC,MAAM,GAAG,CAAC,EAAE;MAC3C,IAAI,CAACC,oBAAoB,GAAG,IAAIC,4BAAmB,CACjD,IAAI,CAACH,WAAW,EAAE,EAClB,IAAI,CAACI,mCAAmC,EAAE,CAC3C;IACH,CAAC,MAAM;MACL,IAAI,CAACF,o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boB,KAAK,CAACG,UAAU,EAChBH,KAAK,CAACI,UAAU,CACjB;UACH;QACF;MACF,CAAC,CAAC;IACJ;;IAEA;IACA,IAAIW,KAAK,CAACC,OAAO,CAAC/F,IAAI,CAACiG,OAAO,EAAEC,OAAO,CAAC,EAAE;MAAA;MACxCL,eAAe,CAACrE,IAAI,CAClB,GAAG,8BAAAxB,IAAI,CAACiG,OAAO,CAACC,OAAO,kBAAMlB,MAAM,KAAM;QACvCA,MAAM;QACNC,EAAE,EAAE;MACN,CAAC,CAAC,CAAC,CACJ;IACH;IAEA,IAAI,CAAChF,mBAAmB,CAAC2F,iBAAiB,CAACC,eAAe,CAAC;IAE3D,IAAI,CAACH,wBAAwB,GAAG,IAAI;IAEpC,OAAO,IAAI;EACb;;EAEA;AACF;AACA;EACE,IAAIS,QAAQ,GAA6B;IACvC,OAAO,IAAI,CAAClG,mBAAmB,CAACkG,QAAQ;EAC1C;;EAEA;AACF;EACEC,WAAW,GAA4D;IAAA,IAA3DC,cAAuB,uEAAG,KAAK;IACzC,OAAO,IAAI,CAACpG,mBAAmB,CAACmG,WAAW,CAACC,cAAc,CAAC;EAC7D;AACF;AAAC"}
1
+ {"version":3,"file":"FormObjectModel.js","names":["FormObjectModel","BaseModel","constructor","object","objectContributions","getElements","length","_attributeCollection","AttributeCollection","getApplicableAttributeContributions","_contentConfiguration","ContentConfiguration","content","_errorCollection","ErrorCollection","has","data","attributeCollection","setReferenceDate","getData","indicateContentConfiguration","contentConfiguration","createEmpty","formObjectModel","IllegalArgumentException","contributions","equals","withRepeatIndex","key","objectContainsOneOfTheAttributes","all","attribute","isResult","some","hasAttributeByKey","hasSameRepeatIndex","repeatIndex","getAttributeByAttribute","getAttributeByKey","elements","push","results","dataResults","result","elementid","dataElementIds","element","getAttributesInData","attributes","isDynamic","attributeKey","mandatory","attributesContributions","attributeContributions","dataElementId","split","getInitialChildModelLinks","setChildModels","models","objectid","hasEndResultConfiguration","getContribution","hasDynamicValidations","isRepeatable","_repeatIndex","index","maxRepeats","hasFixedNrOfRepeats","isRepeatWithUnknownTotal","isLastRepeat","last","repeatIndexLabel","label","introText","text","message","assistent","buttonLabels","mergeObject","oldObject","forEach","mergeWithAttribute","mergeAttribute","updateAttribute","value","attributeToUpdate","Error","name","CompositeAttributeModel","update","isChangedSince","timestamp","resetErrors","errorCollection","addServerError","error","anchor","id","properties","layouthint","hasServerErrors","hasItems","hasErrors","isValid","visible","every","dynamicValidationsLoaded","_dynamicValidationsLoaded","handleErrorValidations","errors","attributeErrors","LayoutHintCollection","updateValidations","handleMissingValidations","missing","anchors","Array","isArray","formdata","getFormData","validationData"],"sources":["../../../src/models/form/FormObjectModel.js"],"sourcesContent":["// @flow\nimport { has } from \"../../utils/helpers/objects\";\n\nimport BaseModel from \"../base/BaseModel\";\nimport AttributeCollection from \"../attributes/AttributeCollection\";\nimport CompositeAttributeModel from \"../attributes/CompositeAttributeModel\";\nimport ContentConfiguration from \"../contentconfiguration/ContentConfiguration\";\nimport ErrorCollection from \"../error/ErrorCollection\";\nimport { IllegalArgumentException } from \"../../exceptions\";\n\nimport type { AttributeType, ModularUIModel, FormErrorAnchor } from \"../types\";\nimport type LinkModel from \"../links/LinkModel\";\nimport LayoutHintCollection from \"../layouthint/LayoutHintCollection\";\nimport type { MessageParameters } from \"../../i18n\";\n\n/**\n * Form Object\n */\nexport default class FormObjectModel extends BaseModel {\n _attributeCollection: AttributeCollection;\n _contentConfiguration: ContentConfiguration;\n _errorCollection: ErrorCollection;\n _repeatIndex: number;\n _dynamicValidationsLoaded: boolean;\n\n /**\n * Construct FormObjectModel\n */\n constructor(object: Object, objectContributions: Object) {\n super(object, objectContributions);\n\n if (object && this.getElements().length > 0) {\n this._attributeCollection = new AttributeCollection(\n this.getElements(),\n this.getApplicableAttributeContributions()\n );\n } else {\n this._attributeCollection = new AttributeCollection();\n }\n\n this._contentConfiguration = new ContentConfiguration(\n objectContributions ? objectContributions.content : {}\n );\n\n this._errorCollection = new ErrorCollection(\"formobject\");\n\n if (has(this.data, \"referenceDate\")) {\n this.attributeCollection.setReferenceDate(this.getData(\"referenceDate\"));\n }\n\n this.attributeCollection.indicateContentConfiguration(\n this.contentConfiguration\n );\n }\n\n /**\n */\n static createEmpty(formObjectModel: FormObjectModel): FormObjectModel {\n if (!formObjectModel) {\n throw new IllegalArgumentException(\n \"createEmpty method needs a FormObjectModel as input argument to create a new version of the object\"\n );\n }\n return new FormObjectModel(\n formObjectModel.data,\n formObjectModel.contributions\n );\n }\n\n /**\n */\n equals(object: ?FormObjectModel, withRepeatIndex: boolean = true): boolean {\n if (!object || this.key !== object.key) {\n return false;\n }\n\n const objectContainsOneOfTheAttributes = this.attributeCollection.all\n .filter((attribute) => !attribute.isResult)\n .some(\n (attribute) =>\n object && object.attributeCollection.hasAttributeByKey(attribute.key)\n );\n\n const hasSameRepeatIndex = withRepeatIndex\n ? this.repeatIndex === object.repeatIndex\n : true;\n\n return hasSameRepeatIndex && objectContainsOneOfTheAttributes;\n }\n\n /**\n */\n getAttributeByAttribute(attribute: AttributeType): AttributeType | null {\n return this.attributeCollection.getAttributeByAttribute(attribute);\n }\n\n /**\n */\n getAttributeByKey(key: string): AttributeType | null {\n return this.attributeCollection.getAttributeByKey(key);\n }\n\n /**\n */\n hasAttributeByKey(key: string): boolean {\n return this.attributeCollection.hasAttributeByKey(key);\n }\n\n /**\n * Get elements from both the missing attributes and the result attributes\n */\n getElements(): Array<Object> {\n const elements = [];\n\n if (this.data.elements) {\n elements.push(...this.data.elements);\n }\n\n if (this.data.results) {\n const dataResults = this.data.results.map((result) => ({\n ...result,\n isResult: true,\n }));\n\n elements.push(...dataResults);\n }\n\n if (this.data.elementid) {\n elements.push({\n ...this.data,\n });\n }\n\n return elements;\n }\n\n /**\n * Map available contributions on the available data. Only use contributions that are needed for the data\n */\n getApplicableAttributeContributions(): Array<Object> {\n if (this.data && this.contributions) {\n const dataElementIds = this.getElements().map(\n (element) => element.elementid\n );\n\n const contributions = this.getAttributesInData(\n dataElementIds,\n this.contributions.attributes\n );\n\n // set all attribute mandatory for dynamic object\n if (this.isDynamic) {\n return contributions.map((attribute) => {\n const [attributeKey] = Object.keys(attribute);\n return {\n [attributeKey]: {\n ...attribute[attributeKey],\n mandatory: true,\n },\n };\n });\n }\n\n return contributions;\n }\n\n return [];\n }\n\n /**\n * Recursevily check if an attribute id occurs in the tree of attribute contributions.\n * The complete leaf of the tree is returned when an attribute id matches\n */\n getAttributesInData(\n dataElementIds: Array<string>,\n attributesContributions: Object\n ): Array<Object> {\n return attributesContributions.filter((attributeContributions) => {\n const [attributeKey] = Object.keys(attributeContributions);\n\n return dataElementIds.some(\n (dataElementId) => dataElementId.split(\".\")[0] === attributeKey\n );\n });\n }\n\n /**\n */\n getInitialChildModelLinks(): Array<LinkModel> {\n return this._attributeCollection.getInitialChildModelLinks();\n }\n\n /**\n */\n setChildModels(models: Array<ModularUIModel>) {\n this._attributeCollection.setChildModels(models);\n }\n\n /**\n * get key\n */\n get key(): string {\n return this.data.objectid;\n }\n\n /**\n * Get content configuration for form objects\n */\n get contentConfiguration(): ContentConfiguration {\n return this._contentConfiguration;\n }\n\n /**\n */\n get hasEndResultConfiguration(): boolean {\n return this.contributions.content?.results != null;\n }\n\n /**\n * Indicates if object is dynamic. A dynamic object should be submitted on each attribute change\n */\n get isDynamic(): boolean {\n return this.getContribution(\"dynamicObject\", false);\n }\n\n /**\n */\n get hasDynamicValidations(): boolean {\n return this.getContribution(\"dynamicValidations\", false);\n }\n\n /**\n * Indicates if object is repeatable\n */\n get isRepeatable(): boolean {\n return this.getContribution(\"repeatable\", false);\n }\n\n /**\n */\n get repeatIndex(): number {\n return this._repeatIndex ?? this.data.index ?? 1;\n }\n\n /**\n */\n set repeatIndex(repeatIndex: number) {\n this._repeatIndex = repeatIndex;\n }\n\n /**\n */\n get maxRepeats(): number {\n if (this.isRepeatable) {\n return this.getData(\"numberofrepeats\", -1);\n }\n\n return 1;\n }\n\n /**\n */\n get hasFixedNrOfRepeats(): boolean {\n return this.maxRepeats > -1;\n }\n\n /**\n */\n get isRepeatWithUnknownTotal(): boolean {\n return this.isRepeatable && this.maxRepeats === -1;\n }\n\n /**\n */\n get isLastRepeat(): boolean {\n if (this.isRepeatable) {\n return this.data.last || false;\n }\n\n return true;\n }\n\n /**\n */\n get repeatIndexLabel(): string | null {\n return this.data[\"index-identifier\"] || null;\n }\n\n /**\n * Get label of form object\n */\n get label(): string {\n return this.contributions.label;\n }\n\n /**\n * Get introText of form object\n */\n get introText(): string {\n if (this.data.content?.text) {\n return this.data.content.text.message;\n }\n\n if (this.contributions.text?.message) {\n return this.contributions.text.message;\n }\n\n return this.contributions.introText;\n }\n\n /**\n * Get assistent of form object\n */\n get assistent(): string {\n return this.contributions.assistent;\n }\n\n /**\n * Get button labels\n */\n get buttonLabels(): Object {\n return this.getContribution(\"buttonLabels\", {});\n }\n\n /**\n * get attribute collection\n */\n get attributeCollection(): AttributeCollection {\n return this._attributeCollection;\n }\n\n /**\n */\n set attributeCollection(attributeCollection: AttributeCollection) {\n this._attributeCollection = attributeCollection;\n }\n\n /**\n */\n mergeObject(oldObject: FormObjectModel) {\n this.attributeCollection.forEach((attribute) => {\n const mergeWithAttribute = oldObject.getAttributeByAttribute(attribute);\n if (mergeWithAttribute) {\n attribute.mergeAttribute(mergeWithAttribute);\n }\n });\n\n this.repeatIndex = oldObject.repeatIndex;\n }\n\n /**\n * Update attribute\n */\n updateAttribute(attribute: AttributeType, value: any): AttributeType {\n const attributeToUpdate =\n this.attributeCollection.getAttributeByAttribute(attribute);\n\n if (attributeToUpdate === null) {\n throw new Error(`Attribute with name: ${attribute.name} not found.`);\n }\n\n if (attributeToUpdate instanceof CompositeAttributeModel) {\n attributeToUpdate.update(value, attribute);\n } else {\n attributeToUpdate.update(value);\n }\n\n return attributeToUpdate;\n }\n\n /**\n * Inidicates if Form is changed since a given timestamp (Date.now)\n */\n isChangedSince(timestamp: number): boolean {\n return (\n this.attributeCollection.find((attribute) =>\n attribute.isChangedSince(timestamp)\n ) !== null\n );\n }\n\n /**\n * Reset all errors on Form Object\n */\n resetErrors() {\n this._errorCollection = new ErrorCollection(\"formobject\");\n this.attributeCollection.forEach((attribute) => attribute.resetErrors());\n }\n\n /**\n * Get error messages\n */\n get errorCollection(): ErrorCollection {\n return this._errorCollection;\n }\n\n /**\n * Registers an error that was received from a server response\n */\n addServerError(error: FormErrorAnchor) {\n if (error.anchor?.elementid != null) {\n this.attributeCollection.addServerError(error);\n } else {\n this._errorCollection.addServerError(\n error.id,\n error.message,\n error.properties,\n error.layouthint\n );\n }\n }\n\n /**\n */\n hasServerErrors(): boolean {\n return (\n this.errorCollection.hasItems ||\n this.attributeCollection.hasServerErrors()\n );\n }\n\n /**\n */\n hasErrors(): boolean {\n return (\n this.errorCollection.hasItems || this.attributeCollection.hasErrors()\n );\n }\n\n /**\n */\n get isValid(): boolean {\n return (\n this.attributeCollection.visible.every(\n (attribute) => attribute.isValid\n ) && !this.errorCollection.hasItems\n );\n }\n\n /**\n */\n get dynamicValidationsLoaded(): boolean {\n return this._dynamicValidationsLoaded;\n }\n\n /**\n */\n set dynamicValidationsLoaded(dynamicValidationsLoaded: boolean) {\n this._dynamicValidationsLoaded = dynamicValidationsLoaded;\n }\n\n /**\n * Convert error json from a form service to validation messages on the form object and attributes\n */\n handleErrorValidations(\n errors: Array<{\n anchor: {\n objectid: string,\n elementid?: string,\n },\n id: string,\n message: string,\n properties: MessageParameters,\n layouthint: Array<string>,\n }>\n ) {\n const attributeErrors = [];\n\n errors.forEach((error) => {\n if (error.anchor?.objectid === this.key) {\n if (has(error.anchor, \"elementid\")) {\n attributeErrors.push(error);\n } else {\n this.errorCollection.addServerError(\n error.id,\n error.message,\n error.properties,\n new LayoutHintCollection(error.layouthint)\n );\n }\n }\n });\n\n this.attributeCollection.updateValidations(attributeErrors);\n }\n\n /**\n * Convert missing json from a form service to mandatory validation constraints and messages\n */\n handleMissingValidations(missing: {\n anchors: Array<\n | {\n elements: Array<{ elementid: string }>,\n }\n | { anchor: { elementid: string } }\n >,\n }) {\n const attributeErrors = [];\n\n for (const anchor of missing.anchors) {\n if (Array.isArray(anchor.elements)) {\n for (const element of anchor.elements) {\n attributeErrors.push({\n anchor: { elementid: element.elementid },\n id: \"Constraint.Mandatory\",\n });\n }\n } else {\n attributeErrors.push({\n anchor,\n id: \"Constraint.Mandatory\",\n });\n }\n }\n\n this.attributeCollection.updateValidations(attributeErrors);\n }\n\n /**\n */\n updateValidations(data: any): FormObjectModel {\n this.resetErrors();\n\n if (Array.isArray(data.errors)) {\n this.handleErrorValidations(data.errors);\n }\n\n // missing attribute errors\n if (Array.isArray(data.missing?.anchors)) {\n this.handleMissingValidations(data.missing);\n }\n\n this.dynamicValidationsLoaded = true;\n\n return this;\n }\n\n /**\n * Generate formdata object for current formobject based on formdata of attributes\n */\n get formdata(): { [string]: any } | null {\n return this.attributeCollection.formdata;\n }\n\n /**\n */\n getFormData(validationData: boolean = false): { [string]: any } | null {\n return this.attributeCollection.getFormData(validationData);\n }\n}\n"],"mappings":";;;;;;;;;;;;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAIA;AAGA;AACA;AACA;AACe,MAAMA,eAAe,SAASC,kBAAS,CAAC;EAOrD;AACF;AACA;EACEC,WAAW,CAACC,MAAc,EAAEC,mBAA2B,EAAE;IACvD,KAAK,CAACD,MAAM,EAAEC,mBAAmB,CAAC;IAAC;IAAA;IAAA;IAAA;IAAA;IAEnC,IAAID,MAAM,IAAI,IAAI,CAACE,WAAW,EAAE,CAACC,MAAM,GAAG,CAAC,EAAE;MAC3C,IAAI,CAACC,oBAAoB,GAAG,IAAIC,4BAAmB,CACjD,IAAI,CAACH,WAAW,EAAE,EAClB,IAAI,CAACI,mCAAmC,EAAE,CAC3C;IACH,CAAC,MAAM;MACL,IAAI,CAACF,oBAAoB,GAAG,IAAIC,4BAAmB,EAAE;IACvD;IAEA,IAAI,CAACE,qBAAqB,GAAG,IAAIC,6BAAoB,CACnDP,mBAAmB,GAAGA,mBAAmB,C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 @@ describe("formModel repeating objects", () => {
35
35
  expect(form.allObjects).toHaveLength(1);
36
36
  expect(form.currentFormObject.repeatIndex).toBe(1);
37
37
 
38
+ expect(form.currentFormObject.getAttributeByKey("Name").mandatory).toBe(
39
+ true
40
+ );
41
+
38
42
  form.addEmptyFormObject(form.currentFormObject);
39
43
  expect(form.allObjects).toHaveLength(2);
40
44
  expect(form.currentFormObject.repeatIndex).toBe(2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beinformed/ui",
3
- "version": "1.25.1-beta.1",
3
+ "version": "1.25.2",
4
4
  "description": "Toolbox for be informed javascript layouts",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "bugs": "http://support.beinformed.com",
@@ -12,7 +12,10 @@ export type BaseDehydrateData = {
12
12
  };
13
13
 
14
14
  /**
15
- * Base model
15
+ * Base model, this is the foundation of a model,
16
+ * it contains data that is needed for all models like, data, contributions and layout hint
17
+ *
18
+ * Extend this for non modular ui resources, for modular ui resource start with the resourceModel
16
19
  */
17
20
  class BaseModel {
18
21
  _data: Object;
@@ -39,6 +42,7 @@ class BaseModel {
39
42
  }
40
43
 
41
44
  /**
45
+ * Retrieve property from the data object of the model, mostly used internal
42
46
  */
43
47
  getData(propName: string, defaultValue: any = null): any {
44
48
  return this.data[propName] ?? defaultValue;
@@ -52,6 +56,7 @@ class BaseModel {
52
56
  }
53
57
 
54
58
  /**
59
+ * Retrieve property from the contributions of the model, mostly used internal
55
60
  */
56
61
  getContribution(propName: string, defaultValue: any = null): any {
57
62
  return this.contributions[propName] ?? defaultValue;
@@ -79,18 +84,21 @@ class BaseModel {
79
84
  }
80
85
 
81
86
  /**
87
+ * Set the unique key for this model
82
88
  */
83
89
  set connectKey(key: string) {
84
90
  this._connectKey = key;
85
91
  }
86
92
 
87
93
  /**
94
+ * Get the unique key of this model
88
95
  */
89
96
  get connectKey(): string {
90
97
  return this._connectKey;
91
98
  }
92
99
 
93
100
  /**
101
+ * Dehydrate internal data, returns the information that is needed to recreate the model
94
102
  */
95
103
  dehydrate(): BaseDehydrateData {
96
104
  return {
@@ -101,13 +109,14 @@ class BaseModel {
101
109
  }
102
110
 
103
111
  /**
112
+ * Recreate the model with the given data
104
113
  */
105
- rehydrate(data: Object) {
114
+ rehydrate(data: BaseDehydrateData) {
106
115
  this._connectKey = data.connectKey;
107
116
  }
108
117
 
109
118
  /**
110
- * Returns a clone of the model (this is not a deep copy)
119
+ * Returns a clone of the model
111
120
  */
112
121
  clone(deepcopy: boolean = false): any {
113
122
  // deepcopy can be expensive, use with care!
@@ -14,7 +14,7 @@ import type Href from "../href/Href";
14
14
  import type { ModularUIModel, IModelWithChildModels } from "../types";
15
15
 
16
16
  /**
17
- * Base model
17
+ * Base model, this the foundation for models that represent modular ui services, e.g. application, tab, caseview, etc
18
18
  */
19
19
  class ResourceModel extends BaseModel implements IModelWithChildModels {
20
20
  _key: string;
@@ -10,6 +10,8 @@ import { IllegalArgumentException } from "../../exceptions";
10
10
 
11
11
  import type { AttributeType, ModularUIModel, FormErrorAnchor } from "../types";
12
12
  import type LinkModel from "../links/LinkModel";
13
+ import LayoutHintCollection from "../layouthint/LayoutHintCollection";
14
+ import type { MessageParameters } from "../../i18n";
13
15
 
14
16
  /**
15
17
  * Form Object
@@ -448,40 +450,85 @@ export default class FormObjectModel extends BaseModel {
448
450
  }
449
451
 
450
452
  /**
453
+ * Convert error json from a form service to validation messages on the form object and attributes
451
454
  */
452
- updateValidations(data: any): FormObjectModel {
453
- this.resetErrors();
454
-
455
+ handleErrorValidations(
456
+ errors: Array<{
457
+ anchor: {
458
+ objectid: string,
459
+ elementid?: string,
460
+ },
461
+ id: string,
462
+ message: string,
463
+ properties: MessageParameters,
464
+ layouthint: Array<string>,
465
+ }>
466
+ ) {
455
467
  const attributeErrors = [];
456
468
 
457
- if (Array.isArray(data.errors)) {
458
- data.errors.forEach((error) => {
459
- if (error.anchor?.objectid === this.key) {
460
- if (has(error.anchor, "elementid")) {
461
- attributeErrors.push(error);
462
- } else {
463
- this.errorCollection.addServerError(
464
- error.id,
465
- error.message,
466
- error.properties,
467
- error.layouthint
468
- );
469
- }
469
+ errors.forEach((error) => {
470
+ if (error.anchor?.objectid === this.key) {
471
+ if (has(error.anchor, "elementid")) {
472
+ attributeErrors.push(error);
473
+ } else {
474
+ this.errorCollection.addServerError(
475
+ error.id,
476
+ error.message,
477
+ error.properties,
478
+ new LayoutHintCollection(error.layouthint)
479
+ );
470
480
  }
471
- });
472
- }
481
+ }
482
+ });
473
483
 
474
- // missing attribute errors
475
- if (Array.isArray(data.missing?.anchors)) {
476
- attributeErrors.push(
477
- ...data.missing.anchors.map((anchor) => ({
484
+ this.attributeCollection.updateValidations(attributeErrors);
485
+ }
486
+
487
+ /**
488
+ * Convert missing json from a form service to mandatory validation constraints and messages
489
+ */
490
+ handleMissingValidations(missing: {
491
+ anchors: Array<
492
+ | {
493
+ elements: Array<{ elementid: string }>,
494
+ }
495
+ | { anchor: { elementid: string } }
496
+ >,
497
+ }) {
498
+ const attributeErrors = [];
499
+
500
+ for (const anchor of missing.anchors) {
501
+ if (Array.isArray(anchor.elements)) {
502
+ for (const element of anchor.elements) {
503
+ attributeErrors.push({
504
+ anchor: { elementid: element.elementid },
505
+ id: "Constraint.Mandatory",
506
+ });
507
+ }
508
+ } else {
509
+ attributeErrors.push({
478
510
  anchor,
479
511
  id: "Constraint.Mandatory",
480
- }))
481
- );
512
+ });
513
+ }
482
514
  }
483
515
 
484
516
  this.attributeCollection.updateValidations(attributeErrors);
517
+ }
518
+
519
+ /**
520
+ */
521
+ updateValidations(data: any): FormObjectModel {
522
+ this.resetErrors();
523
+
524
+ if (Array.isArray(data.errors)) {
525
+ this.handleErrorValidations(data.errors);
526
+ }
527
+
528
+ // missing attribute errors
529
+ if (Array.isArray(data.missing?.anchors)) {
530
+ this.handleMissingValidations(data.missing);
531
+ }
485
532
 
486
533
  this.dynamicValidationsLoaded = true;
487
534
 
@@ -35,6 +35,10 @@ describe("formModel repeating objects", () => {
35
35
  expect(form.allObjects).toHaveLength(1);
36
36
  expect(form.currentFormObject.repeatIndex).toBe(1);
37
37
 
38
+ expect(form.currentFormObject.getAttributeByKey("Name").mandatory).toBe(
39
+ true
40
+ );
41
+
38
42
  form.addEmptyFormObject(form.currentFormObject);
39
43
  expect(form.allObjects).toHaveLength(2);
40
44
  expect(form.currentFormObject.repeatIndex).toBe(2);
@@ -1,7 +1,10 @@
1
1
  type BaseDehydrateData = {};
2
2
  export default BaseModel;
3
3
  /**
4
- * Base model
4
+ * Base model, this is the foundation of a model,
5
+ * it contains data that is needed for all models like, data, contributions and layout hint
6
+ *
7
+ * Extend this for non modular ui resources, for modular ui resource start with the resourceModel
5
8
  */
6
9
  declare class BaseModel {
7
10
  /**
@@ -17,6 +20,7 @@ declare class BaseModel {
17
20
  */
18
21
  get data(): Object;
19
22
  /**
23
+ * Retrieve property from the data object of the model, mostly used internal
20
24
  */
21
25
  getData(propName: string, defaultValue?: any): any;
22
26
  /**
@@ -24,6 +28,7 @@ declare class BaseModel {
24
28
  */
25
29
  get contributions(): Object;
26
30
  /**
31
+ * Retrieve property from the contributions of the model, mostly used internal
27
32
  */
28
33
  getContribution(propName: string, defaultValue?: any): any;
29
34
  /**
@@ -39,19 +44,23 @@ declare class BaseModel {
39
44
  */
40
45
  get hasData(): boolean;
41
46
  /**
47
+ * Set the unique key for this model
42
48
  */
43
49
  set connectKey(arg: string);
44
50
  /**
51
+ * Get the unique key of this model
45
52
  */
46
53
  get connectKey(): string;
47
54
  /**
55
+ * Dehydrate internal data, returns the information that is needed to recreate the model
48
56
  */
49
57
  dehydrate(): BaseDehydrateData;
50
58
  /**
59
+ * Recreate the model with the given data
51
60
  */
52
- rehydrate(data: Object): void;
61
+ rehydrate(data: BaseDehydrateData): void;
53
62
  /**
54
- * Returns a clone of the model (this is not a deep copy)
63
+ * Returns a clone of the model
55
64
  */
56
65
  clone(deepcopy?: boolean): any;
57
66
  }
@@ -1,6 +1,6 @@
1
1
  export default ResourceModel;
2
2
  /**
3
- * Base model
3
+ * Base model, this the foundation for models that represent modular ui services, e.g. application, tab, caseview, etc
4
4
  */
5
5
  declare class ResourceModel extends BaseModel {
6
6
  /**
@@ -145,6 +145,8 @@ export default class FormObjectModel extends BaseModel {
145
145
  /**
146
146
  */
147
147
  get dynamicValidationsLoaded(): boolean;
148
+ handleErrorValidations(errors: any): void;
149
+ handleMissingValidations(missing: any): void;
148
150
  /**
149
151
  */
150
152
  updateValidations(data: any): FormObjectModel;