@contrail/document-generation 2.0.40 → 2.0.42

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.
@@ -5,5 +5,4 @@ export declare class DocumentDynamicTextElementUtil {
5
5
  static isDynamicText(element: any): any;
6
6
  static handleDynamicText(element: DocumentElement, dataGroup: DataGroup): any;
7
7
  private static getPropertyValuesForElements;
8
- private static getTextValueFromFrameMembers;
9
8
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentDynamicTextElementUtil = void 0;
4
- const types_1 = require("@contrail/types");
4
+ const documents_1 = require("@contrail/documents");
5
5
  const util_1 = require("@contrail/util");
6
6
  const document_text_element_util_1 = require("./document-text-element-util");
7
7
  const HARD_CODED_PROPS = {
@@ -38,18 +38,18 @@ class DocumentDynamicTextElementUtil {
38
38
  }
39
39
  type = this.typeMap[entityType];
40
40
  property = type.typeProperties.find(p => p.slug === propertySlug);
41
- if (displayFunction === "label") {
41
+ if (displayFunction === documents_1.DynamicTextDisplayFunction.LABEL) {
42
42
  text = (property === null || property === void 0 ? void 0 : property.label) || HARD_CODED_PROPS[propertySlug] || `${type.label} name`;
43
43
  }
44
44
  else {
45
- let elementValues = this.getPropertyValuesForElements(dataGroup.data, propertyBindingsText);
46
- text = this.getTextValueFromFrameMembers(displayFunction, elementValues, property);
45
+ const elementValues = this.getPropertyValuesForElements(dataGroup.data, propertyBindingsText);
46
+ text = documents_1.DynamicTextUtil.getTextFromFrameMemberValues(displayFunction, property, elementValues);
47
47
  }
48
48
  }
49
49
  if (text === undefined || text === null) {
50
50
  text = 'n/a';
51
51
  }
52
- if (displayLabel && displayFunction !== "label") {
52
+ if (displayLabel && displayFunction !== documents_1.DynamicTextDisplayFunction.LABEL) {
53
53
  text = `${(property === null || property === void 0 ? void 0 : property.label) || `${type === null || type === void 0 ? void 0 : type.label} name` || HARD_CODED_PROPS[propertySlug]}: ${text}`;
54
54
  }
55
55
  }
@@ -67,36 +67,5 @@ class DocumentDynamicTextElementUtil {
67
67
  });
68
68
  return values;
69
69
  }
70
- static getTextValueFromFrameMembers(displayFunction, elementValues, property) {
71
- let text;
72
- const formatter = new types_1.PropertyValueFormatter();
73
- if (displayFunction === "average") {
74
- elementValues = elementValues.filter(e => e !== null);
75
- text = formatter.formatValue(elementValues.reduce((a, b) => a + b, 0) / elementValues.length, property.propertyType);
76
- }
77
- else if (displayFunction === "sum") {
78
- elementValues = elementValues.filter(e => e !== null);
79
- text = formatter.formatValue(elementValues.reduce((a, b) => a + b, 0), property.propertyType);
80
- }
81
- else if (displayFunction === "uniqueArray") {
82
- text = Array.from(new Set(elementValues.filter(e => e !== null))).join(', ');
83
- }
84
- else if (!displayFunction ||
85
- ["first", "value"].includes(displayFunction)) {
86
- text = elementValues[0];
87
- }
88
- else if (displayFunction === "last") {
89
- text = elementValues[elementValues.length - 1];
90
- }
91
- else if (displayFunction === "min") {
92
- elementValues = elementValues.filter(e => e !== null);
93
- text = formatter.formatValue(Math.min(...elementValues), property.propertyType);
94
- }
95
- else if (displayFunction === "max") {
96
- elementValues = elementValues.filter(e => e !== null);
97
- text = formatter.formatValue(Math.max(...elementValues), property.propertyType);
98
- }
99
- return text;
100
- }
101
70
  }
102
71
  exports.DocumentDynamicTextElementUtil = DocumentDynamicTextElementUtil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/document-generation",
3
- "version": "2.0.40",
3
+ "version": "2.0.42",
4
4
  "description": "Utilities for automatic generation of documents.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@contrail/data-grouping": "^1.0.24",
46
- "@contrail/documents": "^1.0.99",
46
+ "@contrail/documents": "^1.0.101",
47
47
  "@contrail/types": "^3.0.27",
48
48
  "@contrail/util": "^1.0.27"
49
49
  }