@contrail/documents 1.1.23 → 1.2.1
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TypeProperty } from '@contrail/types';
|
|
1
|
+
import { PropertyLevel, TypeProperty } from '@contrail/types';
|
|
2
2
|
import { DocumentElement } from '../../types/document-element';
|
|
3
3
|
export declare enum DYNAMIC_TEXT_DATA_SOURCE {
|
|
4
4
|
PROJECT = "project",
|
|
@@ -36,7 +36,7 @@ export declare const HARD_CODED_TEXT: {
|
|
|
36
36
|
'frame.colorCount': string;
|
|
37
37
|
};
|
|
38
38
|
export declare class DynamicTextUtil {
|
|
39
|
-
static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, frame: {
|
|
39
|
+
static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, propertyLevel: PropertyLevel, frame: {
|
|
40
40
|
name: string;
|
|
41
41
|
id?: string;
|
|
42
42
|
}, componentModels: any[], ownerReferenceModel?: any): string;
|
|
@@ -49,7 +49,7 @@ const frameProperties = [
|
|
|
49
49
|
'frame.colorCount',
|
|
50
50
|
];
|
|
51
51
|
class DynamicTextUtil {
|
|
52
|
-
static getDynamicTextValue(dynamicTextElement, property, frame, componentModels, ownerReferenceModel = null) {
|
|
52
|
+
static getDynamicTextValue(dynamicTextElement, property, propertyLevel, frame, componentModels, ownerReferenceModel = null) {
|
|
53
53
|
var _a, _b, _c, _d;
|
|
54
54
|
if (!dynamicTextElement.propertyBindings || !dynamicTextElement.propertyBindings.text) {
|
|
55
55
|
return exports.CLICK_TO_CONFIGURE;
|
|
@@ -98,6 +98,11 @@ class DynamicTextUtil {
|
|
|
98
98
|
property = null;
|
|
99
99
|
}
|
|
100
100
|
const frameMemberValues = [];
|
|
101
|
+
if (propertyLevel) {
|
|
102
|
+
componentModels = Array.from(new Map(componentModels
|
|
103
|
+
.filter((model) => { var _a, _b; return (_b = (_a = model[entityType]) === null || _a === void 0 ? void 0 : _a.roles) === null || _b === void 0 ? void 0 : _b.includes(propertyLevel); })
|
|
104
|
+
.map((model) => { var _a; return [(_a = model[entityType]) === null || _a === void 0 ? void 0 : _a.id, model]; })).values());
|
|
105
|
+
}
|
|
101
106
|
componentModels.forEach((elementModel) => {
|
|
102
107
|
frameMemberValues.push(util_1.ObjectUtil.getByPath(elementModel, bindingProperty));
|
|
103
108
|
});
|
|
@@ -167,8 +172,8 @@ class DynamicTextUtil {
|
|
|
167
172
|
}
|
|
168
173
|
const formatter = new types_1.PropertyValueFormatter();
|
|
169
174
|
if (displayFunction === DynamicTextDisplayFunction.AVERAGE) {
|
|
170
|
-
|
|
171
|
-
text = formatter.formatValueForProperty(
|
|
175
|
+
const memberNumValues = memberValues.filter(Number);
|
|
176
|
+
text = formatter.formatValueForProperty(memberNumValues.reduce((a, b) => a + b, 0) / memberValues.length, property);
|
|
172
177
|
}
|
|
173
178
|
else if (displayFunction === DynamicTextDisplayFunction.SUM) {
|
|
174
179
|
memberValues = memberValues.filter(Number);
|
|
@@ -190,8 +195,13 @@ class DynamicTextUtil {
|
|
|
190
195
|
text = formatter.formatValueForProperty(memberValues[memberValues.length - 1], property);
|
|
191
196
|
}
|
|
192
197
|
else if (displayFunction === DynamicTextDisplayFunction.MIN) {
|
|
193
|
-
|
|
194
|
-
|
|
198
|
+
const minValue = Math.min(...memberValues.filter((e) => e !== null && e !== undefined));
|
|
199
|
+
if (minValue > 0 && (memberValues.includes(null) || memberValues.includes(undefined))) {
|
|
200
|
+
text = '';
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
text = formatter.formatValueForProperty(minValue, property);
|
|
204
|
+
}
|
|
195
205
|
}
|
|
196
206
|
else if (displayFunction === DynamicTextDisplayFunction.MAX) {
|
|
197
207
|
memberValues = memberValues.filter((e) => e !== null && e !== undefined);
|