@contrail/document-generation 2.1.11 → 2.1.12
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.
|
@@ -3,6 +3,5 @@ import { DocumentElement } from '@contrail/documents';
|
|
|
3
3
|
export declare class DocumentDynamicTextElementUtil {
|
|
4
4
|
static typeMap: any;
|
|
5
5
|
static isDynamicText(element: any): any;
|
|
6
|
-
static handleDynamicText(element: DocumentElement, dataGroup: DataGroup, frameTitle?: any):
|
|
7
|
-
private static getPropertyValuesForElements;
|
|
6
|
+
static handleDynamicText(element: DocumentElement, dataGroup: DataGroup, frameTitle?: any): void;
|
|
8
7
|
}
|
|
@@ -2,76 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DocumentDynamicTextElementUtil = void 0;
|
|
4
4
|
const documents_1 = require("@contrail/documents");
|
|
5
|
-
const util_1 = require("@contrail/util");
|
|
6
5
|
const document_text_element_util_1 = require("./document-text-element-util");
|
|
7
|
-
const HARD_CODED_PROPS = {
|
|
8
|
-
createdBy: 'Created by',
|
|
9
|
-
updatedBy: 'Updated by',
|
|
10
|
-
'frame.count': 'Count',
|
|
11
|
-
'frame.name': 'Frame name',
|
|
12
|
-
};
|
|
13
6
|
class DocumentDynamicTextElementUtil {
|
|
14
7
|
static isDynamicText(element) {
|
|
15
8
|
return element.type === 'text' && element.propertyBindings && element.propertyBindingsMetaData;
|
|
16
9
|
}
|
|
17
10
|
static handleDynamicText(element, dataGroup, frameTitle = null) {
|
|
18
11
|
var _a;
|
|
19
|
-
const displayFunction = element.propertyBindingsMetaData.displayFunction;
|
|
20
|
-
const displayLabel = element.propertyBindingsMetaData.displayLabel;
|
|
21
12
|
const propertyBindingsText = element.propertyBindings.text;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
const frame = {
|
|
14
|
+
name: frameTitle || dataGroup.name,
|
|
15
|
+
};
|
|
16
|
+
const [entityType, propertySlug] = propertyBindingsText.split('.');
|
|
25
17
|
let property;
|
|
26
18
|
let type;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
text = HARD_CODED_PROPS[propertyBindingsText];
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
if (propertySlug === 'count') {
|
|
34
|
-
text = dataGroup.data.length;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
text = frameTitle || dataGroup.name;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
if (dataGroup.data.length === 0) {
|
|
43
|
-
return propertyBindingsText;
|
|
44
|
-
}
|
|
45
|
-
type = this.typeMap[entityType];
|
|
46
|
-
property = type.typeProperties.find((p) => p.slug === propertySlug);
|
|
47
|
-
if (displayFunction === documents_1.DynamicTextDisplayFunction.LABEL) {
|
|
48
|
-
text = (property === null || property === void 0 ? void 0 : property.label) || HARD_CODED_PROPS[propertySlug] || `${type.label} name`;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
const elementValues = this.getPropertyValuesForElements(dataGroup.data, propertyBindingsText);
|
|
52
|
-
text = documents_1.DynamicTextUtil.getTextFromFrameMemberValues(displayFunction, property, elementValues);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (text === undefined || text === null || text === '') {
|
|
56
|
-
text = 'n/a';
|
|
57
|
-
}
|
|
58
|
-
if (displayLabel && displayFunction !== documents_1.DynamicTextDisplayFunction.LABEL) {
|
|
59
|
-
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}`;
|
|
60
|
-
}
|
|
19
|
+
type = this.typeMap[entityType];
|
|
20
|
+
if (type) {
|
|
21
|
+
property = type.typeProperties.find(p => p.slug === propertySlug);
|
|
61
22
|
}
|
|
23
|
+
let text = documents_1.DynamicTextUtil.getDynamicTextValue(element, property, frame, dataGroup.data);
|
|
62
24
|
if (((_a = element.text) === null || _a === void 0 ? void 0 : _a.toString().indexOf('</')) > -1) {
|
|
63
25
|
const styleDefinition = document_text_element_util_1.DocumentTextElementUtil.extractStyleFromInline(element.text);
|
|
64
26
|
text = document_text_element_util_1.DocumentTextElementUtil.applyInLineStyling(text, styleDefinition);
|
|
65
27
|
}
|
|
66
28
|
element.text = text;
|
|
67
29
|
}
|
|
68
|
-
static getPropertyValuesForElements(elements, propertyKey) {
|
|
69
|
-
const values = [];
|
|
70
|
-
elements.forEach((el) => {
|
|
71
|
-
const propertyValue = util_1.ObjectUtil.getByPath(el, propertyKey);
|
|
72
|
-
values.push(propertyValue);
|
|
73
|
-
});
|
|
74
|
-
return values;
|
|
75
|
-
}
|
|
76
30
|
}
|
|
77
31
|
exports.DocumentDynamicTextElementUtil = DocumentDynamicTextElementUtil;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/document-generation",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.12",
|
|
4
4
|
"description": "Utilities for automatic generation of documents.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@contrail/data-grouping": "^1.0.24",
|
|
46
46
|
"@contrail/document-table": "^1.0.4",
|
|
47
|
-
"@contrail/documents": "^1.
|
|
47
|
+
"@contrail/documents": "^1.1.17",
|
|
48
48
|
"@contrail/types": "^3.0.95",
|
|
49
49
|
"@contrail/util": "^1.1.0"
|
|
50
50
|
}
|