@contrail/document-generation 1.0.10 → 1.0.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.
- package/lib/components/component-generator.d.ts +1 -4
- package/lib/components/component-generator.js +2 -36
- package/lib/components/component-grid-generator.js +0 -1
- package/lib/frame-generator.d.ts +1 -0
- package/lib/frame-generator.js +34 -6
- 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 +12 -3
- package/lib/scripts/test.js +75 -29
- package/lib/util/document-property-util.d.ts +8 -0
- package/lib/util/document-property-util.js +67 -0
- package/package.json +2 -2
- package/testdocument.json +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DocumentElement } from "@contrail/documents";
|
|
2
|
-
import {
|
|
3
|
-
import { PropertyValueFormatter } from "@contrail/types";
|
|
2
|
+
import { ComponentPropertyTemplate, ComponentTemplate } from "../interfaces";
|
|
4
3
|
export declare class ComponentGenerator {
|
|
5
4
|
static generateComponent(data: any, options: DocumentElement, template: ComponentTemplate): any;
|
|
6
5
|
static generatedModelBindings(data: any): {
|
|
@@ -9,6 +8,4 @@ export declare class ComponentGenerator {
|
|
|
9
8
|
viewable: string;
|
|
10
9
|
};
|
|
11
10
|
static generateComponentFromPropertyTemplate(data: any, options: DocumentElement, template: ComponentPropertyTemplate): DocumentElement;
|
|
12
|
-
static generatePropertyTextElements(data: any, properties: Array<ComponentPropertyDefinition>, options: DocumentElement, yPosition: number): Array<DocumentElement>;
|
|
13
|
-
static generatePropertyTextElement(data: any, property: ComponentPropertyDefinition, options: DocumentElement, formatter: PropertyValueFormatter, yPosition: number): DocumentElement;
|
|
14
11
|
}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ComponentGenerator = void 0;
|
|
4
4
|
const documents_1 = require("@contrail/documents");
|
|
5
5
|
const nanoid_1 = require("nanoid");
|
|
6
|
-
const types_1 = require("@contrail/types");
|
|
7
6
|
const util_1 = require("@contrail/util");
|
|
7
|
+
const document_property_util_1 = require("../util/document-property-util");
|
|
8
8
|
class ComponentGenerator {
|
|
9
9
|
static generateComponent(data, options, template) {
|
|
10
10
|
let component;
|
|
@@ -51,7 +51,7 @@ class ComponentGenerator {
|
|
|
51
51
|
width: imageWidth
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
|
-
elements.push(...
|
|
54
|
+
elements.push(...document_property_util_1.DocumentPropertyUtil.generatePropertyTextElements(data, template.properties, textOptions, { y: yPosition }, true));
|
|
55
55
|
const modelBindings = this.generatedModelBindings(data);
|
|
56
56
|
componentElement.elements = elements;
|
|
57
57
|
componentElement.modelBindings = modelBindings;
|
|
@@ -63,39 +63,5 @@ class ComponentGenerator {
|
|
|
63
63
|
}
|
|
64
64
|
return componentElement;
|
|
65
65
|
}
|
|
66
|
-
static generatePropertyTextElements(data, properties, options, yPosition) {
|
|
67
|
-
const elements = [];
|
|
68
|
-
const formatter = new types_1.PropertyValueFormatter();
|
|
69
|
-
for (let property of properties) {
|
|
70
|
-
let element = this.generatePropertyTextElement(data, property, options, formatter, yPosition);
|
|
71
|
-
elements.push(element);
|
|
72
|
-
}
|
|
73
|
-
return elements;
|
|
74
|
-
}
|
|
75
|
-
static generatePropertyTextElement(data, property, options, formatter, yPosition) {
|
|
76
|
-
var _a, _b, _c;
|
|
77
|
-
const key = `${util_1.StringUtil.convertToCamelCase(property.typeRootSlug)}.${property.propertyDefinition.slug}`;
|
|
78
|
-
let style = property.style || {
|
|
79
|
-
font: {
|
|
80
|
-
size: 8,
|
|
81
|
-
},
|
|
82
|
-
color: 'rgba(0,0,0,.5)',
|
|
83
|
-
};
|
|
84
|
-
if ((_a = options === null || options === void 0 ? void 0 : options.style) === null || _a === void 0 ? void 0 : _a.text) {
|
|
85
|
-
style.text = options.style.text;
|
|
86
|
-
}
|
|
87
|
-
let element = Object.assign({
|
|
88
|
-
label: property.includeLabel ? (_b = property.propertyDefinition) === null || _b === void 0 ? void 0 : _b.label : null,
|
|
89
|
-
type: "text",
|
|
90
|
-
position: { x: 0, y: yPosition },
|
|
91
|
-
size: { height: 25, width: ((_c = options === null || options === void 0 ? void 0 : options.size) === null || _c === void 0 ? void 0 : _c.width) || 125 },
|
|
92
|
-
style,
|
|
93
|
-
propertyBindings: { text: key }
|
|
94
|
-
});
|
|
95
|
-
const value = util_1.ObjectUtil.getByPath(data, key);
|
|
96
|
-
const display = formatter.formatValueForProperty(value, property.propertyDefinition);
|
|
97
|
-
element.text = display;
|
|
98
|
-
return element;
|
|
99
|
-
}
|
|
100
66
|
}
|
|
101
67
|
exports.ComponentGenerator = ComponentGenerator;
|
|
@@ -69,7 +69,6 @@ class ComponentGridGenerator {
|
|
|
69
69
|
};
|
|
70
70
|
const requiredHeightAdjustment = (idealSize.height - requiredSize.height) / template.gridDimensions.rows;
|
|
71
71
|
const requiredWidthAdjustment = (idealSize.width - requiredSize.width) / template.gridDimensions.cols;
|
|
72
|
-
console.log("requiredHeightAdjustment: ", requiredHeightAdjustment, " requiredWidthAdjustment: ", requiredWidthAdjustment);
|
|
73
72
|
if (requiredHeightAdjustment < 0 && requiredHeightAdjustment < requiredWidthAdjustment) {
|
|
74
73
|
adjustedTemplate.componentTemplate.propertyTemplate.imageDimension.width += requiredHeightAdjustment;
|
|
75
74
|
}
|
package/lib/frame-generator.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ import { DocumentTemplate } from "./interfaces";
|
|
|
4
4
|
export declare class FrameGenerator {
|
|
5
5
|
static generateFrameForDataGroup(dataGroup: DataGroup, framePosition: PositionDefinition, template: DocumentTemplate): any[];
|
|
6
6
|
static generateFrameHeaderForDataGroup(dataGroup: DataGroup, position: PositionDefinition, template: DocumentTemplate, headerSize: SizeDefinition): DocumentElement[];
|
|
7
|
+
static generateFrameInfoPanelForDataGroup(dataGroup: DataGroup, position: PositionDefinition, template: DocumentTemplate, panelSize: SizeDefinition): DocumentElement[];
|
|
7
8
|
static generateFrame(options: DocumentElement): DocumentElement;
|
|
8
9
|
}
|
package/lib/frame-generator.js
CHANGED
|
@@ -5,8 +5,10 @@ const documents_1 = require("@contrail/documents");
|
|
|
5
5
|
const component_grid_generator_1 = require("./components/component-grid-generator");
|
|
6
6
|
const util_1 = require("@contrail/util");
|
|
7
7
|
const document_util_1 = require("./util/document-util");
|
|
8
|
+
const info_panel_generator_1 = require("./info-panel/info-panel-generator");
|
|
8
9
|
class FrameGenerator {
|
|
9
10
|
static generateFrameForDataGroup(dataGroup, framePosition, template) {
|
|
11
|
+
var _a, _b;
|
|
10
12
|
const elements = [];
|
|
11
13
|
const frame = this.generateFrame({
|
|
12
14
|
position: util_1.ObjectUtil.cloneDeep(framePosition),
|
|
@@ -18,18 +20,41 @@ class FrameGenerator {
|
|
|
18
20
|
const headerPosition = util_1.ObjectUtil.cloneDeep(framePosition);
|
|
19
21
|
headerPosition.y = headerPosition.y + FRAME_PADDING;
|
|
20
22
|
headerPosition.x = headerPosition.x + FRAME_PADDING;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const panelPosition = util_1.ObjectUtil.cloneDeep(framePosition);
|
|
24
|
+
panelPosition.y = panelPosition.y + FRAME_PADDING;
|
|
25
|
+
panelPosition.x = panelPosition.x + FRAME_PADDING;
|
|
26
|
+
let frameHeaderDimensions = { height: 0, width: 0 };
|
|
27
|
+
let framePanelDimensions = { height: 0, width: 0 };
|
|
28
|
+
let hasPanel = false;
|
|
29
|
+
let hasHeader = false;
|
|
30
|
+
elements.push(util_1.ObjectUtil.cloneDeep(frame));
|
|
31
|
+
if (template.frameHeaderTemplate) {
|
|
32
|
+
hasHeader = true;
|
|
33
|
+
frameHeaderDimensions = { height: 50, width: template.frameSize.width - 50 };
|
|
34
|
+
elements.push(...this.generateFrameHeaderForDataGroup(dataGroup, headerPosition, template, frameHeaderDimensions));
|
|
35
|
+
}
|
|
36
|
+
if (template.frameInfoPanelTemplate) {
|
|
37
|
+
hasPanel = true;
|
|
38
|
+
framePanelDimensions = { width: ((_b = (_a = template.frameInfoPanelTemplate.panelDocumentTemplate) === null || _a === void 0 ? void 0 : _a.size) === null || _b === void 0 ? void 0 : _b.width) || 300 };
|
|
39
|
+
framePanelDimensions.height = template.frameSize.height - (2 * FRAME_PADDING);
|
|
40
|
+
elements.push(...this.generateFrameInfoPanelForDataGroup(dataGroup, panelPosition, template, framePanelDimensions));
|
|
41
|
+
}
|
|
42
|
+
const GRID_MARGIN = 20;
|
|
43
|
+
let gridPosition = util_1.ObjectUtil.cloneDeep(framePosition);
|
|
44
|
+
if (hasHeader) {
|
|
45
|
+
gridPosition = util_1.ObjectUtil.cloneDeep(headerPosition);
|
|
46
|
+
gridPosition.y = gridPosition.y + frameHeaderDimensions.height + GRID_MARGIN;
|
|
47
|
+
}
|
|
48
|
+
if (hasPanel) {
|
|
49
|
+
gridPosition = util_1.ObjectUtil.cloneDeep(panelPosition);
|
|
50
|
+
gridPosition.x = gridPosition.x + framePanelDimensions.width + GRID_MARGIN;
|
|
51
|
+
}
|
|
25
52
|
const relativeGridPosition = document_util_1.DocumentUtil.getRelativePosition(framePosition, gridPosition);
|
|
26
53
|
const frameSize = template.frameSize;
|
|
27
54
|
const idealGridSize = {
|
|
28
55
|
width: frameSize.width - relativeGridPosition.x - FRAME_PADDING,
|
|
29
56
|
height: frameSize.height - relativeGridPosition.y - FRAME_PADDING
|
|
30
57
|
};
|
|
31
|
-
elements.push(util_1.ObjectUtil.cloneDeep(frame));
|
|
32
|
-
elements.push(...this.generateFrameHeaderForDataGroup(dataGroup, headerPosition, template, frameHeaderDimensions));
|
|
33
58
|
elements.push(...component_grid_generator_1.ComponentGridGenerator.generateComponentGrid(dataGroup.data, gridPosition, template.componentGridTemplate, idealGridSize));
|
|
34
59
|
return elements;
|
|
35
60
|
}
|
|
@@ -41,6 +66,9 @@ class FrameGenerator {
|
|
|
41
66
|
heading.position = util_1.ObjectUtil.cloneDeep(position);
|
|
42
67
|
return [heading];
|
|
43
68
|
}
|
|
69
|
+
static generateFrameInfoPanelForDataGroup(dataGroup, position, template, panelSize) {
|
|
70
|
+
return info_panel_generator_1.InfoPanelGenerator.generatePanelFromTemplate(dataGroup.propertyValues, template.frameInfoPanelTemplate, position, panelSize);
|
|
71
|
+
}
|
|
44
72
|
static generateFrame(options) {
|
|
45
73
|
const frame = documents_1.DocumentElementFactory.createFrameElement(options);
|
|
46
74
|
return frame;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DocumentElement, PositionDefinition, SizeDefinition } from "@contrail/documents";
|
|
2
|
+
import { FrameInfoPanelTemplate } from "../interfaces";
|
|
3
|
+
export declare class InfoPanelGenerator {
|
|
4
|
+
static generatePanelFromTemplate(data: any, template: FrameInfoPanelTemplate, position: PositionDefinition, panelSize: SizeDefinition): Array<DocumentElement>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InfoPanelGenerator = void 0;
|
|
4
|
+
const documents_1 = require("@contrail/documents");
|
|
5
|
+
const util_1 = require("@contrail/util");
|
|
6
|
+
const document_property_util_1 = require("../util/document-property-util");
|
|
7
|
+
class InfoPanelGenerator {
|
|
8
|
+
static generatePanelFromTemplate(data, template, position, panelSize) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (!template.propertyTemplate) {
|
|
11
|
+
throw Error("No panel property template defined");
|
|
12
|
+
}
|
|
13
|
+
const elements = [];
|
|
14
|
+
const panel = documents_1.DocumentElementFactory.createShapeElement('rectangle', {});
|
|
15
|
+
panel.style = ((_a = template.panelDocumentTemplate) === null || _a === void 0 ? void 0 : _a.style) || {};
|
|
16
|
+
panel.size = util_1.ObjectUtil.cloneDeep(panelSize) || {};
|
|
17
|
+
panel.position = util_1.ObjectUtil.cloneDeep(position);
|
|
18
|
+
elements.push(panel);
|
|
19
|
+
const textOptions = {
|
|
20
|
+
style: {
|
|
21
|
+
text: {
|
|
22
|
+
align: template.propertyTemplate.textHorizontalAlignment
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
size: {
|
|
26
|
+
width: panelSize.width - 10
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const textElements = document_property_util_1.DocumentPropertyUtil.generatePropertyTextElements(data, template.propertyTemplate.properties, textOptions, { x: panel.position.x, y: panel.position.y }, false);
|
|
30
|
+
elements.push(...textElements);
|
|
31
|
+
return elements;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.InfoPanelGenerator = InfoPanelGenerator;
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -18,9 +18,18 @@ export interface DocumentTemplate {
|
|
|
18
18
|
frameSize: SizeDefinition;
|
|
19
19
|
framePadding?: number;
|
|
20
20
|
frameGroupHeaderTemplate: DocumentElement;
|
|
21
|
-
frameHeaderTemplate
|
|
21
|
+
frameHeaderTemplate?: DocumentElement;
|
|
22
|
+
frameInfoPanelTemplate?: FrameInfoPanelTemplate;
|
|
22
23
|
componentGridTemplate: ComponentGridTemplate;
|
|
23
24
|
}
|
|
25
|
+
export interface FrameInfoPanelTemplate {
|
|
26
|
+
panelDocumentTemplate: DocumentElement;
|
|
27
|
+
propertyTemplate: PanelPropertyTemplate;
|
|
28
|
+
}
|
|
29
|
+
export interface PanelPropertyTemplate {
|
|
30
|
+
textHorizontalAlignment?: 'center' | 'right' | 'left';
|
|
31
|
+
properties: Array<DocumentPropertyDefinition>;
|
|
32
|
+
}
|
|
24
33
|
export interface ComponentGridTemplate {
|
|
25
34
|
componentTemplate: ComponentTemplate;
|
|
26
35
|
componentPadding?: number;
|
|
@@ -36,9 +45,9 @@ export interface ComponentPropertyTemplate {
|
|
|
36
45
|
imageDimension?: SizeDefinition;
|
|
37
46
|
imageLocation?: 'top' | 'right' | 'left' | 'bottom';
|
|
38
47
|
textHorizontalAlignment?: 'center' | 'right' | 'left';
|
|
39
|
-
properties: Array<
|
|
48
|
+
properties: Array<DocumentPropertyDefinition>;
|
|
40
49
|
}
|
|
41
|
-
export interface
|
|
50
|
+
export interface DocumentPropertyDefinition {
|
|
42
51
|
style?: StyleDefinition;
|
|
43
52
|
propertyDefinition: TypeProperty;
|
|
44
53
|
slug: string;
|
package/lib/scripts/test.js
CHANGED
|
@@ -17,7 +17,6 @@ const nanoid_1 = require("nanoid");
|
|
|
17
17
|
const data_grouping_1 = require("@contrail/data-grouping");
|
|
18
18
|
function run() {
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
const generator = new document_generator_1.DocumentGenerator();
|
|
21
20
|
const orgSlug = 'converse-prod';
|
|
22
21
|
yield loginSDK(orgSlug);
|
|
23
22
|
const assortmentId = 'Z7nTOauGtuuiU9UC';
|
|
@@ -63,53 +62,104 @@ function run() {
|
|
|
63
62
|
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'baseStyleNumber'),
|
|
64
63
|
typeRootSlug: 'item',
|
|
65
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
|
+
}
|
|
66
80
|
}, {
|
|
67
|
-
propertyDefinition: itemType.typeProperties.find(p => p.slug === '
|
|
81
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'segment'),
|
|
68
82
|
typeRootSlug: 'item',
|
|
69
|
-
slug: "
|
|
83
|
+
slug: "segment",
|
|
70
84
|
includeLabel: true,
|
|
85
|
+
style: {
|
|
86
|
+
font: {
|
|
87
|
+
size: 14,
|
|
88
|
+
},
|
|
89
|
+
color: 'white',
|
|
90
|
+
}
|
|
71
91
|
}, {
|
|
72
|
-
propertyDefinition: itemType.typeProperties.find(p => p.slug === '
|
|
92
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'familyName'),
|
|
73
93
|
typeRootSlug: 'item',
|
|
74
|
-
slug: "
|
|
94
|
+
slug: "familyName",
|
|
75
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
|
+
}
|
|
76
113
|
}, {
|
|
77
|
-
propertyDefinition:
|
|
78
|
-
|
|
79
|
-
|
|
114
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'planningLevel1'),
|
|
115
|
+
typeRootSlug: 'item',
|
|
116
|
+
slug: "planningLevel1",
|
|
80
117
|
includeLabel: true,
|
|
118
|
+
style: {
|
|
119
|
+
font: {
|
|
120
|
+
size: 14,
|
|
121
|
+
},
|
|
122
|
+
color: 'white',
|
|
123
|
+
}
|
|
81
124
|
}]
|
|
82
125
|
};
|
|
83
126
|
const documentTemplateDefinition = {
|
|
84
127
|
frameOrientation: interfaces_1.Orientation.VERTICAL,
|
|
85
128
|
frameSize: { width: 1200, height: 675 },
|
|
86
129
|
framePadding: 30,
|
|
87
|
-
|
|
130
|
+
frameGroupHeaderTemplate: {
|
|
88
131
|
style: {
|
|
89
|
-
color: '#
|
|
132
|
+
color: '#ffffff',
|
|
90
133
|
font: {
|
|
91
134
|
size: 20
|
|
92
135
|
},
|
|
93
|
-
backgroundColor: '
|
|
136
|
+
backgroundColor: 'rgba(0, 0, 0, 0.8)',
|
|
94
137
|
},
|
|
95
138
|
size: {
|
|
96
139
|
height: 60,
|
|
97
140
|
}
|
|
98
141
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
}
|
|
104
153
|
},
|
|
105
|
-
|
|
154
|
+
size: {
|
|
155
|
+
width: 250,
|
|
156
|
+
height: 400,
|
|
157
|
+
}
|
|
106
158
|
},
|
|
107
|
-
|
|
108
|
-
height: 60,
|
|
109
|
-
}
|
|
159
|
+
propertyTemplate: PANEL_PROPERTY_TEMPLATE
|
|
110
160
|
},
|
|
111
161
|
componentGridTemplate: {
|
|
112
|
-
gridDimensions: { cols:
|
|
162
|
+
gridDimensions: { cols: 4, rows: 2 },
|
|
113
163
|
componentPadding: 5,
|
|
114
164
|
componentTemplate: {
|
|
115
165
|
propertyTemplate: PROPERTY_COMPONENT_TEMPLATE
|
|
@@ -118,17 +168,12 @@ function run() {
|
|
|
118
168
|
};
|
|
119
169
|
const groupingProperties = [
|
|
120
170
|
{
|
|
121
|
-
property: itemType.typeProperties.find(p => p.slug === 'designPack'),
|
|
122
|
-
scope: 'item',
|
|
123
|
-
sort: sdk_1.SortOrderOptions.ASC,
|
|
124
|
-
values: null,
|
|
125
|
-
}, {
|
|
126
171
|
property: itemType.typeProperties.find(p => p.slug === 'category'),
|
|
127
172
|
scope: 'item',
|
|
128
173
|
sort: sdk_1.SortOrderOptions.ASC,
|
|
129
174
|
values: null,
|
|
130
175
|
}, {
|
|
131
|
-
property: itemType.typeProperties.find(p => p.slug === '
|
|
176
|
+
property: itemType.typeProperties.find(p => p.slug === 'name'),
|
|
132
177
|
scope: 'item',
|
|
133
178
|
sort: sdk_1.SortOrderOptions.ASC,
|
|
134
179
|
values: null,
|
|
@@ -158,11 +203,12 @@ function run() {
|
|
|
158
203
|
}
|
|
159
204
|
function loginSDK(orgSlug) {
|
|
160
205
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
-
|
|
206
|
+
const config = {
|
|
162
207
|
email: 'brian@vibeiq.com',
|
|
163
208
|
password: process.env.CONTRAIL_PW,
|
|
164
209
|
orgSlug: orgSlug,
|
|
165
|
-
}
|
|
210
|
+
};
|
|
211
|
+
yield (0, sdk_1.login)(config);
|
|
166
212
|
});
|
|
167
213
|
}
|
|
168
214
|
function getAssortmentItems(assortmentId) {
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
private static generateTextElement;
|
|
8
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentPropertyUtil = void 0;
|
|
4
|
+
const util_1 = require("@contrail/util");
|
|
5
|
+
const documents_1 = require("@contrail/documents");
|
|
6
|
+
const types_1 = require("@contrail/types");
|
|
7
|
+
class DocumentPropertyUtil {
|
|
8
|
+
static generatePropertyTextElements(data, properties, options, startingPosition, isComponent) {
|
|
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) {
|
|
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
|
+
const mergedOptions = util_1.ObjectUtil.mergeDeep(util_1.ObjectUtil.cloneDeep(options), { style: property.style || {} });
|
|
31
|
+
let element = this.generateTextElement(display, mergedOptions, position);
|
|
32
|
+
if (isComponent && property.includeLabel) {
|
|
33
|
+
element.label = (_a = property.propertyDefinition) === null || _a === void 0 ? void 0 : _a.label;
|
|
34
|
+
}
|
|
35
|
+
else if (!isComponent && property.includeLabel) {
|
|
36
|
+
display = property.propertyDefinition.label + ': ' + display;
|
|
37
|
+
}
|
|
38
|
+
element.text = display;
|
|
39
|
+
element.propertyBindings = { text: modelKey };
|
|
40
|
+
return element;
|
|
41
|
+
}
|
|
42
|
+
static generateTextElement(textValue, options, position) {
|
|
43
|
+
var _a, _b, _c;
|
|
44
|
+
const yPosition = position.y || 0;
|
|
45
|
+
const xPosition = position.x || 0;
|
|
46
|
+
const defaultStyle = {
|
|
47
|
+
font: {
|
|
48
|
+
size: 8,
|
|
49
|
+
},
|
|
50
|
+
color: 'rgba(0,0,0,.5)',
|
|
51
|
+
};
|
|
52
|
+
let style = options.style || defaultStyle;
|
|
53
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.style) === null || _a === void 0 ? void 0 : _a.text) {
|
|
54
|
+
style.text = options.style.text;
|
|
55
|
+
}
|
|
56
|
+
let element = documents_1.DocumentElementFactory.createTextElement(textValue);
|
|
57
|
+
const height = ((_b = options.size) === null || _b === void 0 ? void 0 : _b.height) || 25;
|
|
58
|
+
const width = ((_c = options === null || options === void 0 ? void 0 : options.size) === null || _c === void 0 ? void 0 : _c.width) || 125;
|
|
59
|
+
element = Object.assign(element, {
|
|
60
|
+
position: { x: xPosition, y: yPosition },
|
|
61
|
+
size: { height, width },
|
|
62
|
+
style,
|
|
63
|
+
});
|
|
64
|
+
return element;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.DocumentPropertyUtil = DocumentPropertyUtil;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/document-generation",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"description": "Utilities for automatic generation of documents.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"testEnvironment": "node"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@contrail/data-grouping": "^1.0.
|
|
45
|
+
"@contrail/data-grouping": "^1.0.18",
|
|
46
46
|
"@contrail/documents": "^1.0.44",
|
|
47
47
|
"@contrail/types": "^3.0.27",
|
|
48
48
|
"@contrail/util": "^1.0.27"
|