@contrail/document-generation 1.0.15 → 1.0.17
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.
- package/lib/components/component-generator.d.ts +11 -0
- package/lib/components/component-generator.js +67 -0
- package/lib/components/component-grid-generator.d.ts +7 -0
- package/lib/components/component-grid-generator.js +81 -0
- package/lib/components/component-util.d.ts +4 -0
- package/lib/components/component-util.js +26 -0
- package/lib/document-generator.d.ts +11 -0
- package/lib/document-generator.js +106 -0
- package/lib/frame-generator.d.ts +9 -0
- package/lib/frame-generator.js +77 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +18 -0
- package/lib/info-panel/info-panel-generator.d.ts +5 -0
- package/lib/info-panel/info-panel-generator.js +34 -0
- package/lib/interfaces.d.ts +56 -0
- package/lib/interfaces.js +8 -0
- package/lib/scripts/test.d.ts +1 -0
- package/lib/scripts/test.js +270 -0
- package/lib/test-data.d.ts +72 -0
- package/lib/test-data.js +176 -0
- package/lib/util/document-property-util.d.ts +7 -0
- package/lib/util/document-property-util.js +44 -0
- package/lib/util/document-text-element-util.d.ts +6 -0
- package/lib/util/document-text-element-util.js +52 -0
- package/lib/util/document-util.d.ts +7 -0
- package/lib/util/document-util.js +13 -0
- package/package.json +1 -1
- package/testdocument.json +1 -1
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const document_generator_1 = require("../document-generator");
|
|
13
|
+
const interfaces_1 = require("../interfaces");
|
|
14
|
+
const sdk_1 = require("@contrail/sdk");
|
|
15
|
+
const fs = require("fs");
|
|
16
|
+
const nanoid_1 = require("nanoid");
|
|
17
|
+
const data_grouping_1 = require("@contrail/data-grouping");
|
|
18
|
+
function run() {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const orgSlug = 'converse-prod';
|
|
21
|
+
yield loginSDK(orgSlug);
|
|
22
|
+
const assortmentId = 'Z7nTOauGtuuiU9UC';
|
|
23
|
+
const itemType = yield new sdk_1.Types().getType({ path: 'item' });
|
|
24
|
+
const projectItemType = yield new sdk_1.Types().getType({ path: 'project-item' });
|
|
25
|
+
const PROPERTY_COMPONENT_TEMPLATE = {
|
|
26
|
+
imageDimension: { width: 600 },
|
|
27
|
+
imageLocation: 'top',
|
|
28
|
+
textHorizontalAlignment: 'center',
|
|
29
|
+
properties: [{
|
|
30
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'name'),
|
|
31
|
+
typeRootSlug: 'item',
|
|
32
|
+
slug: "name",
|
|
33
|
+
style: {
|
|
34
|
+
font: {
|
|
35
|
+
size: 14,
|
|
36
|
+
weight: 'bold',
|
|
37
|
+
},
|
|
38
|
+
color: 'rgba(0,0,0,.5)',
|
|
39
|
+
}
|
|
40
|
+
}, {
|
|
41
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'optionName'),
|
|
42
|
+
typeRootSlug: 'item',
|
|
43
|
+
slug: "optionName",
|
|
44
|
+
style: {
|
|
45
|
+
font: {
|
|
46
|
+
size: 10,
|
|
47
|
+
weight: 'bold',
|
|
48
|
+
},
|
|
49
|
+
color: 'green',
|
|
50
|
+
}
|
|
51
|
+
}, {
|
|
52
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'category'),
|
|
53
|
+
typeRootSlug: 'item',
|
|
54
|
+
slug: "category",
|
|
55
|
+
includeLabel: true,
|
|
56
|
+
}, {
|
|
57
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'designTheme'),
|
|
58
|
+
typeRootSlug: 'item',
|
|
59
|
+
slug: "designTheme",
|
|
60
|
+
includeLabel: true,
|
|
61
|
+
}, {
|
|
62
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'baseStyleNumber'),
|
|
63
|
+
typeRootSlug: 'item',
|
|
64
|
+
slug: "baseStyleNumber",
|
|
65
|
+
}]
|
|
66
|
+
};
|
|
67
|
+
const PANEL_PROPERTY_TEMPLATE = {
|
|
68
|
+
properties: [{
|
|
69
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'name'),
|
|
70
|
+
typeRootSlug: 'item',
|
|
71
|
+
slug: "name",
|
|
72
|
+
includeLabel: false,
|
|
73
|
+
style: {
|
|
74
|
+
font: {
|
|
75
|
+
size: 25,
|
|
76
|
+
weight: 'bold'
|
|
77
|
+
},
|
|
78
|
+
color: 'white',
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'segment'),
|
|
82
|
+
typeRootSlug: 'item',
|
|
83
|
+
slug: "segment",
|
|
84
|
+
includeLabel: true,
|
|
85
|
+
style: {
|
|
86
|
+
font: {
|
|
87
|
+
size: 14,
|
|
88
|
+
},
|
|
89
|
+
color: 'white',
|
|
90
|
+
}
|
|
91
|
+
}, {
|
|
92
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'familyName'),
|
|
93
|
+
typeRootSlug: 'item',
|
|
94
|
+
slug: "familyName",
|
|
95
|
+
includeLabel: true,
|
|
96
|
+
style: {
|
|
97
|
+
font: {
|
|
98
|
+
size: 14,
|
|
99
|
+
},
|
|
100
|
+
color: 'white',
|
|
101
|
+
}
|
|
102
|
+
}, {
|
|
103
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'ageGroup'),
|
|
104
|
+
typeRootSlug: 'item',
|
|
105
|
+
slug: "ageGroup",
|
|
106
|
+
includeLabel: true,
|
|
107
|
+
style: {
|
|
108
|
+
font: {
|
|
109
|
+
size: 14,
|
|
110
|
+
},
|
|
111
|
+
color: 'white',
|
|
112
|
+
}
|
|
113
|
+
}, {
|
|
114
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'planningLevel1'),
|
|
115
|
+
typeRootSlug: 'item',
|
|
116
|
+
slug: "planningLevel1",
|
|
117
|
+
includeLabel: true,
|
|
118
|
+
style: {
|
|
119
|
+
font: {
|
|
120
|
+
size: 14,
|
|
121
|
+
},
|
|
122
|
+
color: 'white',
|
|
123
|
+
}
|
|
124
|
+
}]
|
|
125
|
+
};
|
|
126
|
+
const documentTemplateDefinition = {
|
|
127
|
+
frameOrientation: interfaces_1.Orientation.VERTICAL,
|
|
128
|
+
frameSize: { width: 1200, height: 675 },
|
|
129
|
+
framePadding: 30,
|
|
130
|
+
frameGroupHeaderTemplate: {
|
|
131
|
+
style: {
|
|
132
|
+
color: '#ffffff',
|
|
133
|
+
font: {
|
|
134
|
+
size: 20
|
|
135
|
+
},
|
|
136
|
+
backgroundColor: 'rgba(0, 0, 0, 0.8)',
|
|
137
|
+
},
|
|
138
|
+
size: {
|
|
139
|
+
height: 60,
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
frameInfoPanelTemplate: {
|
|
143
|
+
panelDocumentTemplate: {
|
|
144
|
+
style: {
|
|
145
|
+
color: '#ffffff',
|
|
146
|
+
font: {
|
|
147
|
+
size: 20
|
|
148
|
+
},
|
|
149
|
+
backgroundColor: 'rgba(0, 0, 0, 0.8)',
|
|
150
|
+
border: {
|
|
151
|
+
radius: 4,
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
size: {
|
|
155
|
+
width: 250,
|
|
156
|
+
height: 400,
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
propertyTemplate: PANEL_PROPERTY_TEMPLATE
|
|
160
|
+
},
|
|
161
|
+
componentGridTemplate: {
|
|
162
|
+
gridDimensions: { cols: 4, rows: 2 },
|
|
163
|
+
componentPadding: 5,
|
|
164
|
+
componentTemplate: {
|
|
165
|
+
propertyTemplate: PROPERTY_COMPONENT_TEMPLATE
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const groupingProperties = [
|
|
170
|
+
{
|
|
171
|
+
property: itemType.typeProperties.find(p => p.slug === 'category'),
|
|
172
|
+
scope: 'item',
|
|
173
|
+
sort: sdk_1.SortOrderOptions.ASC,
|
|
174
|
+
values: null,
|
|
175
|
+
}, {
|
|
176
|
+
property: itemType.typeProperties.find(p => p.slug === 'name'),
|
|
177
|
+
scope: 'item',
|
|
178
|
+
sort: sdk_1.SortOrderOptions.ASC,
|
|
179
|
+
values: null,
|
|
180
|
+
},
|
|
181
|
+
];
|
|
182
|
+
documentTemplateDefinition.componentGridTemplate.componentTemplate.propertyTemplate = PROPERTY_COMPONENT_TEMPLATE;
|
|
183
|
+
const dataGroup = yield getDataGroupStructure(assortmentId, groupingProperties, documentTemplateDefinition);
|
|
184
|
+
const params = {
|
|
185
|
+
startingCoordinates: { x: 500, y: 500 },
|
|
186
|
+
data: {
|
|
187
|
+
dataGroup
|
|
188
|
+
},
|
|
189
|
+
documentTemplateDefinition,
|
|
190
|
+
};
|
|
191
|
+
const elements = document_generator_1.DocumentGenerator.generateDocumentElements(params);
|
|
192
|
+
const documentId = (0, nanoid_1.nanoid)(16);
|
|
193
|
+
elements.forEach(el => {
|
|
194
|
+
el.id = (0, nanoid_1.nanoid)(16);
|
|
195
|
+
});
|
|
196
|
+
const document = {
|
|
197
|
+
size: { width: 1600, height: 900 },
|
|
198
|
+
elements,
|
|
199
|
+
id: documentId,
|
|
200
|
+
};
|
|
201
|
+
yield uploadAndOpen(orgSlug, document);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
function loginSDK(orgSlug) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
const config = {
|
|
207
|
+
email: 'brian@vibeiq.com',
|
|
208
|
+
password: process.env.CONTRAIL_PW,
|
|
209
|
+
orgSlug: orgSlug,
|
|
210
|
+
};
|
|
211
|
+
yield (0, sdk_1.login)(config);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function getAssortmentItems(assortmentId) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
+
const assortment = yield new sdk_1.Entities().get({
|
|
217
|
+
entityName: 'assortment',
|
|
218
|
+
id: assortmentId,
|
|
219
|
+
relations: ['assortmentItems', 'assortmentItems.item', 'assortmentItems.projectItem']
|
|
220
|
+
});
|
|
221
|
+
let assortmentItems = assortment.assortmentItems;
|
|
222
|
+
if (assortment.itemsDownloadURL) {
|
|
223
|
+
const response = yield fetch(assortment.itemsDownloadURL);
|
|
224
|
+
assortmentItems = yield response.json();
|
|
225
|
+
}
|
|
226
|
+
return assortmentItems;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
function getDataGroupStructure(assortmentId, groupingProperties, template) {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
const assortmentItems = yield getAssortmentItems(assortmentId);
|
|
232
|
+
const data = fromAssortmentModelToItemModel(assortmentItems);
|
|
233
|
+
const leafNodeDataCount = template.componentGridTemplate.gridDimensions.cols * template.componentGridTemplate.gridDimensions.rows;
|
|
234
|
+
return data_grouping_1.DataGroupGenerator.buildDataGroupStructure(data, groupingProperties, leafNodeDataCount);
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
function fromAssortmentModelToItemModel(data) {
|
|
238
|
+
const results = [];
|
|
239
|
+
data.forEach(ai => {
|
|
240
|
+
results.push({
|
|
241
|
+
item: ai.item,
|
|
242
|
+
projectItem: ai.projectItem,
|
|
243
|
+
viewable: ai.item,
|
|
244
|
+
assortmentItem: ai,
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
return results;
|
|
248
|
+
}
|
|
249
|
+
function uploadAndOpen(orgSlug, document) {
|
|
250
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
+
let config = (0, sdk_1.getConfig)();
|
|
252
|
+
var writeStream = fs.createWriteStream("testdocument.json");
|
|
253
|
+
writeStream.write(JSON.stringify(document));
|
|
254
|
+
writeStream.end();
|
|
255
|
+
const file = fs.createReadStream("testdocument.json");
|
|
256
|
+
const fileEntity = yield new sdk_1.Files().createAndUploadFileFromBuffer(file, 'application/json', 'testdocument.json', null, 300);
|
|
257
|
+
const domain = "http://preview.vibeiq.com";
|
|
258
|
+
const authToken = config.apiUserToken;
|
|
259
|
+
const documentType = 'board';
|
|
260
|
+
let url = domain +
|
|
261
|
+
'?url=' + encodeURIComponent(fileEntity.downloadUrl) +
|
|
262
|
+
'&orgSlug=' + encodeURIComponent(orgSlug) +
|
|
263
|
+
'&apiToken=' + encodeURIComponent(authToken) +
|
|
264
|
+
'&documentType=' + encodeURIComponent(documentType);
|
|
265
|
+
var start = (process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open');
|
|
266
|
+
const encodedUrl = url.replace(/&/g, '^&');
|
|
267
|
+
require('child_process').exec(start + ' ' + encodedUrl);
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
run();
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { DataGroupStructure } from "@contrail/data-grouping";
|
|
2
|
+
import { ComponentGridTemplate, DocumentTemplate } from "./interfaces";
|
|
3
|
+
export declare const TEST_ITEM_MODEL: {
|
|
4
|
+
item: {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
optionName: string;
|
|
8
|
+
gender: string;
|
|
9
|
+
mediumViewableDownloadUrl: string;
|
|
10
|
+
};
|
|
11
|
+
projectItem: {
|
|
12
|
+
id: string;
|
|
13
|
+
retailPrice: number;
|
|
14
|
+
};
|
|
15
|
+
assortmentItem: {
|
|
16
|
+
id: string;
|
|
17
|
+
targetVolume: number;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export declare const TEST_GROUP: {
|
|
21
|
+
name: string;
|
|
22
|
+
data: {
|
|
23
|
+
item: {
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
optionName: string;
|
|
27
|
+
gender: string;
|
|
28
|
+
mediumViewableDownloadUrl: string;
|
|
29
|
+
};
|
|
30
|
+
projectItem: {
|
|
31
|
+
id: string;
|
|
32
|
+
retailPrice: number;
|
|
33
|
+
};
|
|
34
|
+
assortmentItem: {
|
|
35
|
+
id: string;
|
|
36
|
+
targetVolume: number;
|
|
37
|
+
};
|
|
38
|
+
}[];
|
|
39
|
+
propertyValues: {
|
|
40
|
+
gender: string;
|
|
41
|
+
};
|
|
42
|
+
subGroups: any[];
|
|
43
|
+
};
|
|
44
|
+
export declare const TEST_GROUP_2: {
|
|
45
|
+
name: string;
|
|
46
|
+
data: {
|
|
47
|
+
item: {
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
optionName: string;
|
|
51
|
+
gender: string;
|
|
52
|
+
mediumViewableDownloadUrl: string;
|
|
53
|
+
};
|
|
54
|
+
projectItem: {
|
|
55
|
+
id: string;
|
|
56
|
+
retailPrice: number;
|
|
57
|
+
};
|
|
58
|
+
assortmentItem: {
|
|
59
|
+
id: string;
|
|
60
|
+
targetVolume: number;
|
|
61
|
+
};
|
|
62
|
+
}[];
|
|
63
|
+
propertyValues: {
|
|
64
|
+
gender: string;
|
|
65
|
+
};
|
|
66
|
+
subGroups: any[];
|
|
67
|
+
};
|
|
68
|
+
export declare const TEST_ROOT_GROUP: DataGroupStructure;
|
|
69
|
+
export declare const TEST_TWO_LEVEL_ROOT_GROUP: DataGroupStructure;
|
|
70
|
+
export declare const COMPONENT_GRID_TEMPLATE: ComponentGridTemplate;
|
|
71
|
+
export declare const HORIZONTAL_DOCUMENT_TEMPLATE: DocumentTemplate;
|
|
72
|
+
export declare const VERTICAL_DOCUMENT_TEMPLATE: DocumentTemplate;
|
package/lib/test-data.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VERTICAL_DOCUMENT_TEMPLATE = exports.HORIZONTAL_DOCUMENT_TEMPLATE = exports.COMPONENT_GRID_TEMPLATE = exports.TEST_TWO_LEVEL_ROOT_GROUP = exports.TEST_ROOT_GROUP = exports.TEST_GROUP_2 = exports.TEST_GROUP = exports.TEST_ITEM_MODEL = void 0;
|
|
4
|
+
const types_1 = require("@contrail/types");
|
|
5
|
+
const interfaces_1 = require("./interfaces");
|
|
6
|
+
const sdk_1 = require("@contrail/sdk");
|
|
7
|
+
exports.TEST_ITEM_MODEL = {
|
|
8
|
+
item: {
|
|
9
|
+
id: 'item-1001',
|
|
10
|
+
name: 'Shirt 1',
|
|
11
|
+
optionName: 'Red',
|
|
12
|
+
gender: 'mens',
|
|
13
|
+
mediumViewableDownloadUrl: 'https://api.vibeiq.com/dev/api/files/downloadUrl/-VMrLJrt3clDKPi0%2Fcontent:m3Bd4u-QLci1XiOl%2F2b72d48a-6b19-4ba8-9d54-813745fb8dd4.png',
|
|
14
|
+
},
|
|
15
|
+
projectItem: {
|
|
16
|
+
id: 'projectItem-1001',
|
|
17
|
+
retailPrice: 45.00
|
|
18
|
+
},
|
|
19
|
+
assortmentItem: {
|
|
20
|
+
id: 'assortmentItem-1001',
|
|
21
|
+
targetVolume: 1000
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
exports.TEST_GROUP = {
|
|
25
|
+
name: "Mens",
|
|
26
|
+
data: [exports.TEST_ITEM_MODEL,
|
|
27
|
+
exports.TEST_ITEM_MODEL,
|
|
28
|
+
exports.TEST_ITEM_MODEL,
|
|
29
|
+
exports.TEST_ITEM_MODEL,
|
|
30
|
+
exports.TEST_ITEM_MODEL,
|
|
31
|
+
exports.TEST_ITEM_MODEL,
|
|
32
|
+
exports.TEST_ITEM_MODEL,
|
|
33
|
+
exports.TEST_ITEM_MODEL,
|
|
34
|
+
exports.TEST_ITEM_MODEL,
|
|
35
|
+
exports.TEST_ITEM_MODEL],
|
|
36
|
+
propertyValues: {
|
|
37
|
+
gender: 'mens'
|
|
38
|
+
},
|
|
39
|
+
subGroups: [],
|
|
40
|
+
};
|
|
41
|
+
exports.TEST_GROUP_2 = {
|
|
42
|
+
name: "Womens",
|
|
43
|
+
data: [exports.TEST_ITEM_MODEL,
|
|
44
|
+
exports.TEST_ITEM_MODEL,
|
|
45
|
+
exports.TEST_ITEM_MODEL,
|
|
46
|
+
exports.TEST_ITEM_MODEL,
|
|
47
|
+
exports.TEST_ITEM_MODEL,
|
|
48
|
+
exports.TEST_ITEM_MODEL,
|
|
49
|
+
exports.TEST_ITEM_MODEL],
|
|
50
|
+
propertyValues: {
|
|
51
|
+
gender: 'womens'
|
|
52
|
+
},
|
|
53
|
+
subGroups: [],
|
|
54
|
+
};
|
|
55
|
+
exports.TEST_ROOT_GROUP = {
|
|
56
|
+
depth: 1,
|
|
57
|
+
groupingProperties: [{
|
|
58
|
+
property: {
|
|
59
|
+
slug: 'gender',
|
|
60
|
+
propertyType: types_1.PropertyType.SingleSelect,
|
|
61
|
+
label: "Gender",
|
|
62
|
+
},
|
|
63
|
+
sort: sdk_1.SortOrderOptions.ASC,
|
|
64
|
+
scope: 'item',
|
|
65
|
+
values: null,
|
|
66
|
+
}],
|
|
67
|
+
rootGroup: {
|
|
68
|
+
data: [],
|
|
69
|
+
subGroups: [exports.TEST_GROUP, exports.TEST_GROUP, exports.TEST_GROUP],
|
|
70
|
+
name: "Root",
|
|
71
|
+
propertyValues: {},
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
exports.TEST_TWO_LEVEL_ROOT_GROUP = {
|
|
75
|
+
depth: 2,
|
|
76
|
+
groupingProperties: [{
|
|
77
|
+
property: {
|
|
78
|
+
slug: 'gender',
|
|
79
|
+
propertyType: types_1.PropertyType.SingleSelect,
|
|
80
|
+
label: "Gender",
|
|
81
|
+
},
|
|
82
|
+
sort: sdk_1.SortOrderOptions.ASC,
|
|
83
|
+
scope: 'item',
|
|
84
|
+
values: null,
|
|
85
|
+
}],
|
|
86
|
+
rootGroup: {
|
|
87
|
+
data: [],
|
|
88
|
+
subGroups: [{
|
|
89
|
+
name: 'Mens',
|
|
90
|
+
subGroups: [exports.TEST_GROUP, exports.TEST_GROUP],
|
|
91
|
+
propertyValues: {
|
|
92
|
+
gender: 'mens'
|
|
93
|
+
},
|
|
94
|
+
data: [],
|
|
95
|
+
}, {
|
|
96
|
+
name: 'Womens',
|
|
97
|
+
subGroups: [exports.TEST_GROUP_2, exports.TEST_GROUP_2, exports.TEST_GROUP_2, exports.TEST_GROUP_2],
|
|
98
|
+
propertyValues: {
|
|
99
|
+
gender: 'mens'
|
|
100
|
+
},
|
|
101
|
+
data: [],
|
|
102
|
+
}],
|
|
103
|
+
name: "Root",
|
|
104
|
+
propertyValues: {},
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
exports.COMPONENT_GRID_TEMPLATE = {
|
|
108
|
+
gridDimensions: { cols: 7, rows: 3 },
|
|
109
|
+
componentTemplate: {
|
|
110
|
+
propertyTemplate: {
|
|
111
|
+
properties: [],
|
|
112
|
+
imageLocation: 'top',
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
componentPadding: 20
|
|
116
|
+
};
|
|
117
|
+
exports.HORIZONTAL_DOCUMENT_TEMPLATE = {
|
|
118
|
+
frameOrientation: interfaces_1.Orientation.HORIZONTAL,
|
|
119
|
+
frameSize: { width: 1200, height: 675 },
|
|
120
|
+
framePadding: 30,
|
|
121
|
+
frameHeaderTemplate: {
|
|
122
|
+
style: {
|
|
123
|
+
color: '#000000',
|
|
124
|
+
font: {
|
|
125
|
+
size: 20
|
|
126
|
+
},
|
|
127
|
+
backgroundColor: '#FFFFFF',
|
|
128
|
+
},
|
|
129
|
+
size: {
|
|
130
|
+
height: 60,
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
frameGroupHeaderTemplate: {
|
|
134
|
+
style: {
|
|
135
|
+
color: '#ffffff',
|
|
136
|
+
font: {
|
|
137
|
+
size: 20
|
|
138
|
+
},
|
|
139
|
+
backgroundColor: 'black',
|
|
140
|
+
},
|
|
141
|
+
size: {
|
|
142
|
+
height: 60,
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
componentGridTemplate: exports.COMPONENT_GRID_TEMPLATE,
|
|
146
|
+
};
|
|
147
|
+
exports.VERTICAL_DOCUMENT_TEMPLATE = {
|
|
148
|
+
frameOrientation: interfaces_1.Orientation.VERTICAL,
|
|
149
|
+
frameSize: { width: 1200, height: 675 },
|
|
150
|
+
framePadding: 30,
|
|
151
|
+
frameHeaderTemplate: {
|
|
152
|
+
style: {
|
|
153
|
+
color: '#000000',
|
|
154
|
+
font: {
|
|
155
|
+
size: 20
|
|
156
|
+
},
|
|
157
|
+
backgroundColor: '#FFFFFF',
|
|
158
|
+
},
|
|
159
|
+
size: {
|
|
160
|
+
height: 60,
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
frameGroupHeaderTemplate: {
|
|
164
|
+
style: {
|
|
165
|
+
color: '#ffffff',
|
|
166
|
+
font: {
|
|
167
|
+
size: 20
|
|
168
|
+
},
|
|
169
|
+
backgroundColor: 'black',
|
|
170
|
+
},
|
|
171
|
+
size: {
|
|
172
|
+
height: 60,
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
componentGridTemplate: exports.COMPONENT_GRID_TEMPLATE,
|
|
176
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DocumentPropertyDefinition } from "../interfaces";
|
|
2
|
+
import { DocumentElement, PositionDefinition } from "@contrail/documents";
|
|
3
|
+
import { PropertyValueFormatter } from "@contrail/types";
|
|
4
|
+
export declare class DocumentPropertyUtil {
|
|
5
|
+
static generatePropertyTextElements(data: any, properties: Array<DocumentPropertyDefinition>, options: DocumentElement, startingPosition: PositionDefinition, isComponent?: boolean): Array<DocumentElement>;
|
|
6
|
+
static generatePropertyTextElement(model: any, property: DocumentPropertyDefinition, options: DocumentElement, formatter: PropertyValueFormatter, position: PositionDefinition, isComponent?: boolean): DocumentElement;
|
|
7
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentPropertyUtil = void 0;
|
|
4
|
+
const util_1 = require("@contrail/util");
|
|
5
|
+
const types_1 = require("@contrail/types");
|
|
6
|
+
const document_text_element_util_1 = require("./document-text-element-util");
|
|
7
|
+
class DocumentPropertyUtil {
|
|
8
|
+
static generatePropertyTextElements(data, properties, options, startingPosition, isComponent = false) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
let yPosition = startingPosition.y || 0;
|
|
11
|
+
const xPosition = startingPosition.x || 0;
|
|
12
|
+
const elements = [];
|
|
13
|
+
const formatter = new types_1.PropertyValueFormatter();
|
|
14
|
+
for (let property of properties) {
|
|
15
|
+
const fontSize = ((_b = (_a = property.style) === null || _a === void 0 ? void 0 : _a.font) === null || _b === void 0 ? void 0 : _b.size) || 12;
|
|
16
|
+
let height = fontSize + 12;
|
|
17
|
+
options.size = options.size || {};
|
|
18
|
+
options.size.height = height;
|
|
19
|
+
let element = DocumentPropertyUtil.generatePropertyTextElement(data, property, options, formatter, { x: xPosition, y: yPosition }, isComponent);
|
|
20
|
+
yPosition += height;
|
|
21
|
+
elements.push(element);
|
|
22
|
+
}
|
|
23
|
+
return elements;
|
|
24
|
+
}
|
|
25
|
+
static generatePropertyTextElement(model, property, options, formatter, position, isComponent = false) {
|
|
26
|
+
var _a;
|
|
27
|
+
const modelKey = `${util_1.StringUtil.convertToCamelCase(property.typeRootSlug)}.${property.propertyDefinition.slug}`;
|
|
28
|
+
const value = util_1.ObjectUtil.getByPath(model, modelKey);
|
|
29
|
+
let display = formatter.formatValueForProperty(value, property.propertyDefinition);
|
|
30
|
+
if (!isComponent && property.includeLabel) {
|
|
31
|
+
display = property.propertyDefinition.label + ': ' + display;
|
|
32
|
+
}
|
|
33
|
+
const mergedOptions = util_1.ObjectUtil.mergeDeep(util_1.ObjectUtil.cloneDeep(options), { style: property.style || {} });
|
|
34
|
+
mergedOptions.position = position;
|
|
35
|
+
const useInlineFormatting = isComponent === false;
|
|
36
|
+
let element = document_text_element_util_1.DocumentTextElementUtil.generateTextElement(display, mergedOptions, useInlineFormatting);
|
|
37
|
+
if (isComponent && property.includeLabel) {
|
|
38
|
+
element.label = (_a = property.propertyDefinition) === null || _a === void 0 ? void 0 : _a.label;
|
|
39
|
+
}
|
|
40
|
+
element.propertyBindings = { text: modelKey };
|
|
41
|
+
return element;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.DocumentPropertyUtil = DocumentPropertyUtil;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DocumentElement, StyleDefinition } from "@contrail/documents";
|
|
2
|
+
export declare class DocumentTextElementUtil {
|
|
3
|
+
static generateTextElement(textValue: any, options: any, applyInlineFormatting?: boolean): DocumentElement;
|
|
4
|
+
static applyInLineStyling(text: any, style: StyleDefinition): any;
|
|
5
|
+
static applyBold(text: any): void;
|
|
6
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentTextElementUtil = void 0;
|
|
4
|
+
const documents_1 = require("@contrail/documents");
|
|
5
|
+
const util_1 = require("@contrail/util");
|
|
6
|
+
class DocumentTextElementUtil {
|
|
7
|
+
static generateTextElement(textValue, options, applyInlineFormatting = true) {
|
|
8
|
+
var _a;
|
|
9
|
+
const defaultStyle = {
|
|
10
|
+
font: {
|
|
11
|
+
size: 8,
|
|
12
|
+
},
|
|
13
|
+
color: 'rgba(0,0,0,.5)',
|
|
14
|
+
};
|
|
15
|
+
let style = util_1.ObjectUtil.mergeDeep(defaultStyle, options.style || {});
|
|
16
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.style) === null || _a === void 0 ? void 0 : _a.text) {
|
|
17
|
+
style.text = options.style.text;
|
|
18
|
+
}
|
|
19
|
+
let position = options.position || { y: 0, x: 0 };
|
|
20
|
+
position.x = position.x || 0;
|
|
21
|
+
position.y = position.y || 0;
|
|
22
|
+
let size = options.size || { height: 25, width: 125 };
|
|
23
|
+
size.height = size.height || 25;
|
|
24
|
+
size.width = size.width || 125;
|
|
25
|
+
const defaultedOptions = util_1.ObjectUtil.mergeDeep(util_1.ObjectUtil.cloneDeep(options), { position, size, style });
|
|
26
|
+
let element = documents_1.DocumentElementFactory.createTextElement(textValue);
|
|
27
|
+
element = Object.assign(element, defaultedOptions);
|
|
28
|
+
if (applyInlineFormatting) {
|
|
29
|
+
element.text = this.applyInLineStyling(element.text, element.style);
|
|
30
|
+
}
|
|
31
|
+
return element;
|
|
32
|
+
}
|
|
33
|
+
static applyInLineStyling(text, style) {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
let formattedText = text;
|
|
36
|
+
if ((style === null || style === void 0 ? void 0 : style.font.weight) === 'bold') {
|
|
37
|
+
formattedText = `<strong>${formattedText}</strong>`;
|
|
38
|
+
}
|
|
39
|
+
if (((_a = style === null || style === void 0 ? void 0 : style.text) === null || _a === void 0 ? void 0 : _a.decoration) === 'underline') {
|
|
40
|
+
formattedText = `<span style="text-decoration: underline;">${formattedText}</span>`;
|
|
41
|
+
}
|
|
42
|
+
if ((_b = style === null || style === void 0 ? void 0 : style.font) === null || _b === void 0 ? void 0 : _b.size) {
|
|
43
|
+
formattedText = `<span style="font-size: ${style.font.size}pt;">${formattedText}</span>`;
|
|
44
|
+
}
|
|
45
|
+
formattedText = `<p>${formattedText}</p>`;
|
|
46
|
+
return formattedText;
|
|
47
|
+
}
|
|
48
|
+
static applyBold(text) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.DocumentTextElementUtil = DocumentTextElementUtil;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentUtil = void 0;
|
|
4
|
+
class DocumentUtil {
|
|
5
|
+
static getRelativePosition(position1, position2) {
|
|
6
|
+
const relativePosition = {
|
|
7
|
+
x: position2.x - position1.x,
|
|
8
|
+
y: position2.y - position1.y,
|
|
9
|
+
};
|
|
10
|
+
return relativePosition;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.DocumentUtil = DocumentUtil;
|