@beinformed/ui 1.28.7 → 1.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,6 +27,7 @@ import type { ModularUIResponse } from "../../modularui";
27
27
  import type ErrorResponse from "../error/ErrorResponse";
28
28
  import type LinkModel from "../links/LinkModel";
29
29
  import LayoutHintCollection from "../layouthint/LayoutHintCollection";
30
+ import AttributeSetModel from "../attributes/AttributeSetModel";
30
31
 
31
32
  /**
32
33
  */
@@ -611,11 +612,36 @@ class FormModel extends ResourceModel {
611
612
  }
612
613
 
613
614
  /**
615
+ * Get the result data as plain json object
614
616
  */
615
617
  getSuccessData(): ?Object {
616
618
  return this.data.success?.data;
617
619
  }
618
620
 
621
+ /**
622
+ * Retrieve an object where each property is a result data attribute set
623
+ */
624
+ getResultData(): ?{
625
+ [key: string]: AttributeSetModel,
626
+ } {
627
+ const resultDataKeys = Object.keys(this.contributions.resultdata) ?? [];
628
+ const successData = this.getSuccessData() ?? {};
629
+
630
+ const resultdata: {
631
+ [key: string]: AttributeSetModel,
632
+ } = {};
633
+
634
+ for (const resultDataKey of resultDataKeys) {
635
+ resultdata[resultDataKey] = new AttributeSetModel(
636
+ resultDataKey,
637
+ successData[resultDataKey],
638
+ this.contributions.resultdata[resultDataKey]
639
+ );
640
+ }
641
+
642
+ return resultdata;
643
+ }
644
+
619
645
  /**
620
646
  */
621
647
  get resultData(): ?Object {
@@ -0,0 +1,86 @@
1
+ import ModularUIResponse from "../../../modularui/ModularUIResponse";
2
+ import FormModel from "../FormModel";
3
+
4
+ describe("formModel with result data", () => {
5
+ it("should be able to create a FormModel with result data", () => {
6
+ const data = ModularUIResponse.create({
7
+ data: {
8
+ formresponse: {
9
+ _links: {
10
+ self: { href: "/rebuild-db/database-actions/rebuild-db-server" },
11
+ api_doc: {
12
+ href: "/api-docs/v3/rebuild-db/database-actions/rebuild-db-server",
13
+ },
14
+ contributions: {
15
+ href: "/contributions/rebuild-db/database-actions/rebuild-db-server",
16
+ },
17
+ },
18
+ success: { redirect: "/", data: { out: { money: 10 } } },
19
+ },
20
+ },
21
+ contributions: {
22
+ RebuildDBServer: {
23
+ label: "Rebuild DB server",
24
+ resourcetype: "Form",
25
+ actiontype: "form",
26
+ objects: {
27
+ AttributeSet: {
28
+ dynamicObject: false,
29
+ repeatable: false,
30
+ dynamicValidations: false,
31
+ label: "Rebuild DB",
32
+ mandatory: false,
33
+ attributes: [
34
+ {
35
+ Dummy: {
36
+ type: "string",
37
+ label: "Dummy (not visible)",
38
+ mandatory: false,
39
+ readonly: true,
40
+ layouthint: ["label"],
41
+ },
42
+ },
43
+ ],
44
+ },
45
+ },
46
+ resultdata: {
47
+ out: {
48
+ repeatable: false,
49
+ label: "Result data",
50
+ introText: {
51
+ id: "out.Introtext",
52
+ message: "<p>uit</p>",
53
+ },
54
+ attributes: [
55
+ {
56
+ money: {
57
+ type: "number",
58
+ label: "Money",
59
+ mandatory: false,
60
+ decimalSeparator: ",",
61
+ layouthint: ["money"],
62
+ format: "#,##0.00",
63
+ groupingSeparator: ".",
64
+ currencySymbol: "€",
65
+ },
66
+ },
67
+ ],
68
+ },
69
+ },
70
+ },
71
+ },
72
+ });
73
+
74
+ const form = new FormModel(data);
75
+
76
+ const resultData = form.getResultData();
77
+ expect(resultData.out.key).toBe("out");
78
+ expect(resultData.out.label).toBe("Result data");
79
+ expect(resultData.out.attributeCollection.size).toBe(1);
80
+ expect(resultData.out.attributeCollection.first.label).toBe("Money");
81
+ expect(resultData.out.attributeCollection.first.readonlyvalue).toBe(
82
+ "10,00"
83
+ );
84
+ expect(resultData.out.attributeCollection.first.currencySymbol).toBe("€");
85
+ });
86
+ });
@@ -41,6 +41,8 @@ export { default as BaseLayoutHintRule } from "./attributes/layouthint-rules/Bas
41
41
  export { default as DependentAttribute } from "./attributes/layouthint-rules/DependentAttribute";
42
42
  export { default as RemainingTotalUploadSize } from "./attributes/layouthint-rules/RemainingTotalUploadSize";
43
43
 
44
+ import { default as LayoutHintCollection } from "./layouthint/LayoutHintCollection";
45
+
44
46
  import { default as CaseViewModel } from "./caseview/CaseViewModel";
45
47
 
46
48
  import { default as BusinessScenarioModel } from "./concepts/BusinessScenarioModel";
@@ -168,6 +170,7 @@ export {
168
170
  FilterModel,
169
171
  RangeFilterModel,
170
172
  ConceptIndexFilterModel,
173
+ LayoutHintCollection,
171
174
  };
172
175
 
173
176
  export type * from "./types";
@@ -181,8 +181,15 @@ declare class FormModel extends ResourceModel {
181
181
  */
182
182
  get redirectLocation(): Href;
183
183
  /**
184
+ * Get the result data as plain json object
184
185
  */
185
186
  getSuccessData(): Object | null;
187
+ /**
188
+ * Retrieve an object where each property is a result data attribute set
189
+ */
190
+ getResultData(): {
191
+ [key: string]: AttributeSetModel;
192
+ };
186
193
  /**
187
194
  */
188
195
  get resultData(): Object;
@@ -307,6 +314,7 @@ import ErrorCollection from "../error/ErrorCollection";
307
314
  import Href from "../href/Href";
308
315
  import Parameter from "../parameter/Parameter";
309
316
  import ErrorResponse from "../error/ErrorResponse";
317
+ import AttributeSetModel from "../attributes/AttributeSetModel";
310
318
  import { ModularUIResponse } from "../../modularui";
311
319
  import { ModularUIModel } from "../types";
312
320
  import { AttributeType } from "../types";