@contrail/documents 1.1.12 → 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.
@@ -3,37 +3,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentElementSortOrderService = void 0;
4
4
  class DocumentElementSortOrderService {
5
5
  static removeSortIdsFromSortOrder(sortOrder, sortIds) {
6
- sortIds.forEach((id) => {
7
- const sourceSortIndex = sortOrder.indexOf(id);
8
- if (sourceSortIndex > -1) {
9
- sortOrder.splice(sourceSortIndex, 1);
10
- }
11
- });
6
+ const sortIdsSet = new Set(sortIds);
7
+ return sortOrder.filter((id) => !sortIdsSet.has(id));
12
8
  }
13
9
  static updateSortOrder(sortOrder, { sortIds, targetSortIndex, addAfterElementId }) {
10
+ let newSortOrder = [...sortOrder];
14
11
  if (addAfterElementId) {
15
12
  sortIds = sortIds;
16
- this.removeSortIdsFromSortOrder(sortOrder, sortIds);
17
- const lastIndex = sortOrder.lastIndexOf(addAfterElementId);
13
+ newSortOrder = this.removeSortIdsFromSortOrder(newSortOrder, sortIds);
14
+ const lastIndex = newSortOrder.lastIndexOf(addAfterElementId);
18
15
  if (lastIndex > -1) {
19
- sortOrder.splice(lastIndex + 1, 0, ...sortIds);
16
+ newSortOrder.splice(lastIndex + 1, 0, ...sortIds);
20
17
  }
21
18
  else {
22
- sortOrder.push(...sortIds);
19
+ newSortOrder.push(...sortIds);
23
20
  }
24
21
  }
25
22
  else if (targetSortIndex != null && targetSortIndex >= 0) {
26
23
  sortIds = sortIds;
27
- this.removeSortIdsFromSortOrder(sortOrder, sortIds);
28
- sortOrder.splice(targetSortIndex, 0, ...sortIds);
24
+ newSortOrder = this.removeSortIdsFromSortOrder(newSortOrder, sortIds);
25
+ newSortOrder.splice(targetSortIndex, 0, ...sortIds);
29
26
  }
30
27
  else if (targetSortIndex === -1) {
31
- this.removeSortIdsFromSortOrder(sortOrder, sortIds);
28
+ newSortOrder = this.removeSortIdsFromSortOrder(newSortOrder, sortIds);
32
29
  }
33
30
  else {
34
31
  sortIds = sortIds;
35
32
  const sortedMoves = [...sortIds].sort((a, b) => a.index - b.index);
36
- const newSortOrder = [...sortOrder];
37
33
  sortedMoves.forEach((sortId) => {
38
34
  const currentIndex = newSortOrder.indexOf(sortId.id);
39
35
  if (currentIndex > -1) {
@@ -48,9 +44,8 @@ class DocumentElementSortOrderService {
48
44
  newSortOrder.push(sortId.id);
49
45
  }
50
46
  });
51
- sortOrder = newSortOrder;
52
47
  }
53
- return sortOrder;
48
+ return newSortOrder;
54
49
  }
55
50
  static updateSortOrderByArray(sortOrder, sorts) {
56
51
  for (const sort of sorts) {
@@ -85,7 +80,7 @@ class DocumentElementSortOrderService {
85
80
  }
86
81
  static addFrameMembersToSort(elements, frames, sort) {
87
82
  var _a;
88
- const sortIds = sort.sortIds;
83
+ let sortIds = sort.sortIds;
89
84
  if ((elements === null || elements === void 0 ? void 0 : elements.length) > 0 && (frames === null || frames === void 0 ? void 0 : frames.size) > 0) {
90
85
  const elementsMap = new Map(elements.map((element) => [element.id, element]));
91
86
  if (sort.targetSortIndex != null || sort.addAfterElementId != null) {
@@ -95,7 +90,7 @@ class DocumentElementSortOrderService {
95
90
  const frame = frames.get(frameId);
96
91
  const frameMemberIds = (_a = frame === null || frame === void 0 ? void 0 : frame.elements) === null || _a === void 0 ? void 0 : _a.map((e) => e.id);
97
92
  if (frame && (frameMemberIds === null || frameMemberIds === void 0 ? void 0 : frameMemberIds.length) > 0) {
98
- this.removeSortIdsFromSortOrder(sortIds, frameMemberIds);
93
+ sortIds = this.removeSortIdsFromSortOrder(sortIds, frameMemberIds);
99
94
  sortIds.splice(sortIds.indexOf(frameId) + 1, 0, ...frameMemberIds);
100
95
  }
101
96
  }
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",