@contrail/documents 1.1.13 → 1.1.14
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.
|
@@ -4,7 +4,7 @@ exports.DocumentElementSortOrderService = void 0;
|
|
|
4
4
|
class DocumentElementSortOrderService {
|
|
5
5
|
static removeSortIdsFromSortOrder(sortOrder, sortIds) {
|
|
6
6
|
const sortIdsSet = new Set(sortIds);
|
|
7
|
-
return sortOrder.filter(id => !sortIdsSet.has(id));
|
|
7
|
+
return sortOrder.filter((id) => !sortIdsSet.has(id));
|
|
8
8
|
}
|
|
9
9
|
static updateSortOrder(sortOrder, { sortIds, targetSortIndex, addAfterElementId }) {
|
|
10
10
|
let newSortOrder = [...sortOrder];
|
|
@@ -30,13 +30,13 @@ class DocumentElementSortOrderService {
|
|
|
30
30
|
else {
|
|
31
31
|
sortIds = sortIds;
|
|
32
32
|
const sortedMoves = [...sortIds].sort((a, b) => a.index - b.index);
|
|
33
|
-
sortedMoves.forEach(sortId => {
|
|
33
|
+
sortedMoves.forEach((sortId) => {
|
|
34
34
|
const currentIndex = newSortOrder.indexOf(sortId.id);
|
|
35
35
|
if (currentIndex > -1) {
|
|
36
36
|
newSortOrder.splice(currentIndex, 1);
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
|
-
sortedMoves.forEach(sortId => {
|
|
39
|
+
sortedMoves.forEach((sortId) => {
|
|
40
40
|
if (sortId.index <= newSortOrder.length) {
|
|
41
41
|
newSortOrder.splice(sortId.index, 0, sortId.id);
|
|
42
42
|
}
|
|
@@ -58,10 +58,10 @@ class DocumentElementSortOrderService {
|
|
|
58
58
|
return elements;
|
|
59
59
|
let newSortOrder = [];
|
|
60
60
|
if ((sorts === null || sorts === void 0 ? void 0 : sorts.length) > 0) {
|
|
61
|
-
newSortOrder = this.updateSortOrderByArray(elements.map(element => element.id), sorts);
|
|
61
|
+
newSortOrder = this.updateSortOrderByArray(elements.map((element) => element.id), sorts);
|
|
62
62
|
}
|
|
63
63
|
else if (sort) {
|
|
64
|
-
newSortOrder = this.updateSortOrder(elements.map(element => element.id), sort);
|
|
64
|
+
newSortOrder = this.updateSortOrder(elements.map((element) => element.id), sort);
|
|
65
65
|
}
|
|
66
66
|
const newSortOrderIndexMap = new Map(newSortOrder.map((id, index) => [id, index]));
|
|
67
67
|
const lastIndex = elements.length;
|
|
@@ -82,13 +82,13 @@ class DocumentElementSortOrderService {
|
|
|
82
82
|
var _a;
|
|
83
83
|
let sortIds = sort.sortIds;
|
|
84
84
|
if ((elements === null || elements === void 0 ? void 0 : elements.length) > 0 && (frames === null || frames === void 0 ? void 0 : frames.size) > 0) {
|
|
85
|
-
const elementsMap = new Map(elements.map(element => [element.id, element]));
|
|
85
|
+
const elementsMap = new Map(elements.map((element) => [element.id, element]));
|
|
86
86
|
if (sort.targetSortIndex != null || sort.addAfterElementId != null) {
|
|
87
|
-
const frameIds = sortIds.filter(id => { var _a; return ((_a = elementsMap.get(id)) === null || _a === void 0 ? void 0 : _a.type) === 'frame'; });
|
|
87
|
+
const frameIds = sortIds.filter((id) => { var _a; return ((_a = elementsMap.get(id)) === null || _a === void 0 ? void 0 : _a.type) === 'frame'; });
|
|
88
88
|
if ((frameIds === null || frameIds === void 0 ? void 0 : frameIds.length) > 0) {
|
|
89
89
|
for (const frameId of frameIds) {
|
|
90
90
|
const frame = frames.get(frameId);
|
|
91
|
-
const frameMemberIds = (_a = frame === null || frame === void 0 ? void 0 : frame.elements) === null || _a === void 0 ? void 0 : _a.map(e => e.id);
|
|
91
|
+
const frameMemberIds = (_a = frame === null || frame === void 0 ? void 0 : frame.elements) === null || _a === void 0 ? void 0 : _a.map((e) => e.id);
|
|
92
92
|
if (frame && (frameMemberIds === null || frameMemberIds === void 0 ? void 0 : frameMemberIds.length) > 0) {
|
|
93
93
|
sortIds = this.removeSortIdsFromSortOrder(sortIds, frameMemberIds);
|
|
94
94
|
sortIds.splice(sortIds.indexOf(frameId) + 1, 0, ...frameMemberIds);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DocumentElement } from '../../types/document-element';
|
|
1
2
|
export declare enum DynamicTextDisplayFunction {
|
|
2
3
|
VALUE = "value",
|
|
3
4
|
LABEL = "label",
|
|
@@ -9,6 +10,26 @@ export declare enum DynamicTextDisplayFunction {
|
|
|
9
10
|
AVERAGE = "average",
|
|
10
11
|
SUM = "sum"
|
|
11
12
|
}
|
|
13
|
+
export declare const MOVE_TO_FRAME_TEXT = "Move to a frame";
|
|
14
|
+
export declare const CLICK_TO_CONFIGURE = "Click to configure";
|
|
15
|
+
export declare const HARD_CODED_TEXT: {
|
|
16
|
+
'project.name': string;
|
|
17
|
+
'project.createdBy.email': string;
|
|
18
|
+
'project.updatedBy.email': string;
|
|
19
|
+
'board.name': string;
|
|
20
|
+
'board.createdBy.email': string;
|
|
21
|
+
'board.updatedBy.email': string;
|
|
22
|
+
'showcase.name': string;
|
|
23
|
+
'showcase.createdBy.email': string;
|
|
24
|
+
'showcase.updatedBy.email': string;
|
|
25
|
+
'frame.name': string;
|
|
26
|
+
'frame.count': string;
|
|
27
|
+
'frame.itemFamilyCount': string;
|
|
28
|
+
'frame.itemOptionCount': string;
|
|
29
|
+
'frame.colorCount': string;
|
|
30
|
+
};
|
|
12
31
|
export declare class DynamicTextUtil {
|
|
32
|
+
static getDynamicTextValue(dynamicTextElement: DocumentElement, property: any, frame: any, componentModels: any[], ownerReferenceModel?: any): string;
|
|
13
33
|
static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
|
|
34
|
+
private static getItemCount;
|
|
14
35
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DynamicTextUtil = exports.DynamicTextDisplayFunction = void 0;
|
|
3
|
+
exports.DynamicTextUtil = exports.HARD_CODED_TEXT = exports.CLICK_TO_CONFIGURE = exports.MOVE_TO_FRAME_TEXT = exports.DynamicTextDisplayFunction = void 0;
|
|
4
4
|
const types_1 = require("@contrail/types");
|
|
5
|
+
const util_1 = require("@contrail/util");
|
|
5
6
|
var DynamicTextDisplayFunction;
|
|
6
7
|
(function (DynamicTextDisplayFunction) {
|
|
7
8
|
DynamicTextDisplayFunction["VALUE"] = "value";
|
|
@@ -14,7 +15,111 @@ var DynamicTextDisplayFunction;
|
|
|
14
15
|
DynamicTextDisplayFunction["AVERAGE"] = "average";
|
|
15
16
|
DynamicTextDisplayFunction["SUM"] = "sum";
|
|
16
17
|
})(DynamicTextDisplayFunction = exports.DynamicTextDisplayFunction || (exports.DynamicTextDisplayFunction = {}));
|
|
18
|
+
exports.MOVE_TO_FRAME_TEXT = 'Move to a frame';
|
|
19
|
+
exports.CLICK_TO_CONFIGURE = 'Click to configure';
|
|
20
|
+
exports.HARD_CODED_TEXT = {
|
|
21
|
+
'project.name': 'Project name',
|
|
22
|
+
'project.createdBy.email': 'Project created by',
|
|
23
|
+
'project.updatedBy.email': 'Project updated by',
|
|
24
|
+
'board.name': 'Board name',
|
|
25
|
+
'board.createdBy.email': 'Board created by',
|
|
26
|
+
'board.updatedBy.email': 'Board updated by',
|
|
27
|
+
'showcase.name': 'Showcase name',
|
|
28
|
+
'showcase.createdBy.email': 'Showcase created by',
|
|
29
|
+
'showcase.updatedBy.email': 'Showcase updated by',
|
|
30
|
+
'frame.name': 'Frame name',
|
|
31
|
+
'frame.count': 'Total count',
|
|
32
|
+
'frame.itemFamilyCount': 'Item family count',
|
|
33
|
+
'frame.itemOptionCount': 'Item option count',
|
|
34
|
+
'frame.colorCount': 'Color count',
|
|
35
|
+
};
|
|
36
|
+
const frameProperties = [
|
|
37
|
+
'frame.name',
|
|
38
|
+
'frame.count',
|
|
39
|
+
'frame.itemFamilyCount',
|
|
40
|
+
'frame.itemOptionCount',
|
|
41
|
+
'frame.colorCount',
|
|
42
|
+
];
|
|
17
43
|
class DynamicTextUtil {
|
|
44
|
+
static getDynamicTextValue(dynamicTextElement, property, frame, componentModels, ownerReferenceModel = null) {
|
|
45
|
+
var _a, _b, _c, _d;
|
|
46
|
+
if (!dynamicTextElement.propertyBindings || !dynamicTextElement.propertyBindings.text) {
|
|
47
|
+
return exports.CLICK_TO_CONFIGURE;
|
|
48
|
+
}
|
|
49
|
+
const formatter = new types_1.PropertyValueFormatter();
|
|
50
|
+
const isSpecRelated = (_b = (_a = dynamicTextElement.propertyBindings) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b.startsWith('specification');
|
|
51
|
+
const displayFunction = ((_c = dynamicTextElement.propertyBindingsMetaData) === null || _c === void 0 ? void 0 : _c.displayFunction) || DynamicTextDisplayFunction.VALUE;
|
|
52
|
+
const displayLabel = (_d = dynamicTextElement.propertyBindingsMetaData) === null || _d === void 0 ? void 0 : _d.displayLabel;
|
|
53
|
+
const bindingProperty = dynamicTextElement.propertyBindings.text;
|
|
54
|
+
const entityType = bindingProperty === null || bindingProperty === void 0 ? void 0 : bindingProperty.split('.')[0];
|
|
55
|
+
const propertySlug = bindingProperty === null || bindingProperty === void 0 ? void 0 : bindingProperty.split('.')[1];
|
|
56
|
+
let text = '';
|
|
57
|
+
if (['showcase', 'board', 'project'].includes(entityType)) {
|
|
58
|
+
if (!ownerReferenceModel) {
|
|
59
|
+
return '';
|
|
60
|
+
}
|
|
61
|
+
text = util_1.ObjectUtil.getByPath(ownerReferenceModel, bindingProperty);
|
|
62
|
+
text = formatter.formatValue(text, (property === null || property === void 0 ? void 0 : property.propertyType) || types_1.PropertyType.String);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
if (!frame && !isSpecRelated) {
|
|
66
|
+
text = exports.MOVE_TO_FRAME_TEXT;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
if (entityType === 'frame') {
|
|
70
|
+
if (propertySlug === 'count') {
|
|
71
|
+
text = componentModels.length.toString();
|
|
72
|
+
}
|
|
73
|
+
else if (['itemFamilyCount', 'itemOptionCount', 'colorCount'].includes(propertySlug)) {
|
|
74
|
+
text = this.getItemCount(propertySlug, componentModels);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
text = frame === null || frame === void 0 ? void 0 : frame.name;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
if (frameProperties.includes(bindingProperty)) {
|
|
82
|
+
property = null;
|
|
83
|
+
}
|
|
84
|
+
else if (['projectItem.project.name', 'specificationProjectItem.project.name'].includes(bindingProperty)) {
|
|
85
|
+
property = {
|
|
86
|
+
slug: 'name',
|
|
87
|
+
label: 'Project name',
|
|
88
|
+
propertyType: types_1.PropertyType.String,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const frameMemberValues = [];
|
|
92
|
+
componentModels.forEach((elementModel) => {
|
|
93
|
+
frameMemberValues.push(util_1.ObjectUtil.getByPath(elementModel, bindingProperty));
|
|
94
|
+
});
|
|
95
|
+
if (frameMemberValues.length > 0) {
|
|
96
|
+
text = this.getTextFromFrameMemberValues(displayFunction, property, frameMemberValues);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (displayFunction === DynamicTextDisplayFunction.LABEL) {
|
|
102
|
+
if (['showcase', 'board', 'project', 'frame'].includes(entityType)) {
|
|
103
|
+
text = exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label);
|
|
104
|
+
}
|
|
105
|
+
else if (!frame) {
|
|
106
|
+
text = exports.MOVE_TO_FRAME_TEXT;
|
|
107
|
+
}
|
|
108
|
+
else if (frame) {
|
|
109
|
+
text = property === null || property === void 0 ? void 0 : property.label;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (text === undefined || text === null || text === '') {
|
|
113
|
+
text = 'n/a';
|
|
114
|
+
}
|
|
115
|
+
if (displayLabel &&
|
|
116
|
+
![exports.MOVE_TO_FRAME_TEXT, exports.CLICK_TO_CONFIGURE].includes(text) &&
|
|
117
|
+
displayFunction !== DynamicTextDisplayFunction.LABEL &&
|
|
118
|
+
text !== bindingProperty) {
|
|
119
|
+
text = `${exports.HARD_CODED_TEXT[bindingProperty] || (property === null || property === void 0 ? void 0 : property.label) || ''}: ${text}`;
|
|
120
|
+
}
|
|
121
|
+
return text;
|
|
122
|
+
}
|
|
18
123
|
static getTextFromFrameMemberValues(displayFunction, property, memberValues) {
|
|
19
124
|
let text = '';
|
|
20
125
|
if (memberValues.length === 0) {
|
|
@@ -54,5 +159,24 @@ class DynamicTextUtil {
|
|
|
54
159
|
}
|
|
55
160
|
return text;
|
|
56
161
|
}
|
|
162
|
+
static getItemCount(countType, componentModels) {
|
|
163
|
+
const elementModels = componentModels.map((elementModel) => {
|
|
164
|
+
return elementModel.item || elementModel.color;
|
|
165
|
+
});
|
|
166
|
+
let count = 0;
|
|
167
|
+
if (countType === 'itemFamilyCount') {
|
|
168
|
+
count = new Set(elementModels.filter((model) => model.entityType === 'item').map((model) => model === null || model === void 0 ? void 0 : model.itemFamilyId))
|
|
169
|
+
.size;
|
|
170
|
+
}
|
|
171
|
+
else if (countType === 'itemOptionCount') {
|
|
172
|
+
count = new Set(elementModels
|
|
173
|
+
.filter((model) => model.entityType === 'item' && model.roles.includes('option'))
|
|
174
|
+
.map((model) => model === null || model === void 0 ? void 0 : model.id)).size;
|
|
175
|
+
}
|
|
176
|
+
else if (countType === 'colorCount') {
|
|
177
|
+
count = new Set(elementModels.filter((model) => model.entityType === 'color').map((model) => model === null || model === void 0 ? void 0 : model.id)).size;
|
|
178
|
+
}
|
|
179
|
+
return count.toString();
|
|
180
|
+
}
|
|
57
181
|
}
|
|
58
182
|
exports.DynamicTextUtil = DynamicTextUtil;
|