@contrail/document-generation 1.0.6 → 1.0.8
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 +14 -0
- package/lib/components/component-generator.js +101 -0
- package/lib/components/component-grid-generator.d.ts +7 -0
- package/lib/components/component-grid-generator.js +82 -0
- package/lib/components/component-util.d.ts +4 -0
- package/lib/components/component-util.js +26 -0
- package/lib/document-generator.js +0 -2
- package/lib/frame-generator.js +9 -4
- package/lib/interfaces.d.ts +17 -2
- package/lib/scripts/test.js +105 -6
- package/lib/test-data.d.ts +0 -2
- package/lib/test-data.js +7 -43
- package/lib/util/document-util.d.ts +7 -0
- package/lib/util/document-util.js +13 -0
- package/package.json +3 -3
- package/lib/component-generator.d.ts +0 -9
- package/lib/component-generator.js +0 -21
- package/lib/component-grid-generator.d.ts +0 -5
- package/lib/component-grid-generator.js +0 -48
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DocumentElement } from "@contrail/documents";
|
|
2
|
+
import { ComponentPropertyDefinition, ComponentPropertyTemplate, ComponentTemplate } from "../interfaces";
|
|
3
|
+
import { PropertyValueFormatter } from "@contrail/types";
|
|
4
|
+
export declare class ComponentGenerator {
|
|
5
|
+
static generateComponent(data: any, options: DocumentElement, template: ComponentTemplate): any;
|
|
6
|
+
static generatedModelBindings(data: any): {
|
|
7
|
+
item: string;
|
|
8
|
+
projectItem: string;
|
|
9
|
+
viewable: string;
|
|
10
|
+
};
|
|
11
|
+
static generateComponentFromPropertyTemplate(data: any, options: DocumentElement, template: ComponentPropertyTemplate): DocumentElement;
|
|
12
|
+
static generatePropertyTextElements(data: any, properties: Array<ComponentPropertyDefinition>, options: DocumentElement): Array<DocumentElement>;
|
|
13
|
+
static generatePropertyTextElement(data: any, property: ComponentPropertyDefinition, options: DocumentElement, formatter: PropertyValueFormatter): DocumentElement;
|
|
14
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentGenerator = void 0;
|
|
4
|
+
const documents_1 = require("@contrail/documents");
|
|
5
|
+
const nanoid_1 = require("nanoid");
|
|
6
|
+
const types_1 = require("@contrail/types");
|
|
7
|
+
const util_1 = require("@contrail/util");
|
|
8
|
+
class ComponentGenerator {
|
|
9
|
+
static generateComponent(data, options, template) {
|
|
10
|
+
let component;
|
|
11
|
+
if (template.propertyTemplate) {
|
|
12
|
+
component = this.generateComponentFromPropertyTemplate(data, options, template.propertyTemplate);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
throw Error("No component property template defined");
|
|
16
|
+
}
|
|
17
|
+
return component;
|
|
18
|
+
}
|
|
19
|
+
static generatedModelBindings(data) {
|
|
20
|
+
return {
|
|
21
|
+
item: `item:${data.item.id}`,
|
|
22
|
+
projectItem: `project-item:${data.projectItem.id}`,
|
|
23
|
+
viewable: `item:${data.item.id}`,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
static generateComponentFromPropertyTemplate(data, options, template) {
|
|
27
|
+
var _a;
|
|
28
|
+
let componentElement = documents_1.DocumentElementFactory.initNewElement('component');
|
|
29
|
+
if (options) {
|
|
30
|
+
componentElement = Object.assign(componentElement, options);
|
|
31
|
+
}
|
|
32
|
+
let yPosition = 0;
|
|
33
|
+
const imageDimension = template.imageDimension || {};
|
|
34
|
+
const imageHeight = imageDimension.height || imageDimension.width || 125;
|
|
35
|
+
const imageWidth = imageDimension.width || 125;
|
|
36
|
+
const imageUrl = util_1.ObjectUtil.getByPath(data, `viewable.mediumViewableDownloadUrl`);
|
|
37
|
+
const elements = [{
|
|
38
|
+
type: "image",
|
|
39
|
+
size: { width: imageWidth, height: imageHeight },
|
|
40
|
+
propertyBindings: { url: 'viewable.mediumViewableDownloadUrl' },
|
|
41
|
+
url: imageUrl,
|
|
42
|
+
}];
|
|
43
|
+
yPosition += imageHeight;
|
|
44
|
+
const textOptions = {
|
|
45
|
+
style: {
|
|
46
|
+
text: {
|
|
47
|
+
align: template.textHorizontalAlignment
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
size: {
|
|
51
|
+
width: imageWidth
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
elements.push(...this.generatePropertyTextElements(data, template.properties, textOptions));
|
|
55
|
+
const modelBindings = this.generatedModelBindings(data);
|
|
56
|
+
componentElement.elements = elements;
|
|
57
|
+
componentElement.modelBindings = modelBindings;
|
|
58
|
+
if (((_a = componentElement === null || componentElement === void 0 ? void 0 : componentElement.elements) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
59
|
+
componentElement.elements = componentElement.elements.map((e) => {
|
|
60
|
+
e.id = (0, nanoid_1.nanoid)(16);
|
|
61
|
+
return e;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return componentElement;
|
|
65
|
+
}
|
|
66
|
+
static generatePropertyTextElements(data, properties, options) {
|
|
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);
|
|
71
|
+
elements.push(element);
|
|
72
|
+
}
|
|
73
|
+
return elements;
|
|
74
|
+
}
|
|
75
|
+
static generatePropertyTextElement(data, property, options, formatter) {
|
|
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: 0 },
|
|
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
|
+
}
|
|
101
|
+
exports.ComponentGenerator = ComponentGenerator;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DocumentElement, PositionDefinition, SizeDefinition } from "@contrail/documents";
|
|
2
|
+
import { ComponentGridTemplate } from "../interfaces";
|
|
3
|
+
export declare class ComponentGridGenerator {
|
|
4
|
+
static generateComponentGrid(data: any, startingPosition: PositionDefinition, template: ComponentGridTemplate, idealSize: SizeDefinition): Array<DocumentElement>;
|
|
5
|
+
private static getComponentSize;
|
|
6
|
+
private static adjustComponentTemplate;
|
|
7
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentGridGenerator = void 0;
|
|
4
|
+
const util_1 = require("@contrail/util");
|
|
5
|
+
const component_generator_1 = require("./component-generator");
|
|
6
|
+
const component_util_1 = require("./component-util");
|
|
7
|
+
class ComponentGridGenerator {
|
|
8
|
+
static generateComponentGrid(data, startingPosition = { x: 0, y: 0 }, template, idealSize) {
|
|
9
|
+
if (!data) {
|
|
10
|
+
console.warn("WARN: data null in generateComponentGrid");
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
if (!template) {
|
|
14
|
+
console.warn("WARN: template null in generateComponentGrid");
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
if (!template.componentTemplate) {
|
|
18
|
+
console.warn("WARN: component template is null generateComponentGrid");
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
const elements = [];
|
|
22
|
+
let dataIndex = 0;
|
|
23
|
+
let gridTemplate = template;
|
|
24
|
+
const optimizeTemplate = true;
|
|
25
|
+
if (optimizeTemplate) {
|
|
26
|
+
gridTemplate = this.adjustComponentTemplate(data, idealSize, template);
|
|
27
|
+
}
|
|
28
|
+
const componentTemplate = gridTemplate.componentTemplate;
|
|
29
|
+
const componentPosition = util_1.ObjectUtil.cloneDeep(startingPosition);
|
|
30
|
+
const componentSize = this.getComponentSize(data, gridTemplate);
|
|
31
|
+
if (componentSize.width < 120) {
|
|
32
|
+
componentSize.width = 120;
|
|
33
|
+
}
|
|
34
|
+
const componentPadding = gridTemplate.componentPadding || 20;
|
|
35
|
+
componentPosition.x += componentPadding;
|
|
36
|
+
componentPosition.y += componentPadding;
|
|
37
|
+
for (let row = 0; row < gridTemplate.gridDimensions.rows; row++) {
|
|
38
|
+
for (let col = 0; col < gridTemplate.gridDimensions.cols; col++) {
|
|
39
|
+
if (dataIndex >= data.length) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
let dataObj = data[dataIndex];
|
|
43
|
+
dataObj.viewable = dataObj.item;
|
|
44
|
+
const position = util_1.ObjectUtil.cloneDeep(componentPosition);
|
|
45
|
+
let component = component_generator_1.ComponentGenerator.generateComponent(dataObj, { position }, componentTemplate);
|
|
46
|
+
elements.push(component);
|
|
47
|
+
dataIndex++;
|
|
48
|
+
componentPosition.x += componentSize.width + (componentPadding * 2);
|
|
49
|
+
}
|
|
50
|
+
componentPosition.y += componentSize.height + (componentPadding * 2);
|
|
51
|
+
componentPosition.x = startingPosition.x + componentPadding;
|
|
52
|
+
}
|
|
53
|
+
return elements;
|
|
54
|
+
}
|
|
55
|
+
static getComponentSize(data, template) {
|
|
56
|
+
if (!(data === null || data === void 0 ? void 0 : data.length)) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const firstData = data[0];
|
|
60
|
+
const element = component_generator_1.ComponentGenerator.generateComponent(firstData, {}, template.componentTemplate);
|
|
61
|
+
return component_util_1.ComponentUtil.getComponentSize(element);
|
|
62
|
+
}
|
|
63
|
+
static adjustComponentTemplate(data, idealSize, template) {
|
|
64
|
+
const componentSize = this.getComponentSize(data, template);
|
|
65
|
+
const adjustedTemplate = util_1.ObjectUtil.cloneDeep(template);
|
|
66
|
+
const requiredSize = {
|
|
67
|
+
width: componentSize.width * template.gridDimensions.cols + ((template.gridDimensions.cols * 2) * template.componentPadding || 20),
|
|
68
|
+
height: componentSize.height * template.gridDimensions.rows + ((template.gridDimensions.rows * 2) * template.componentPadding || 20)
|
|
69
|
+
};
|
|
70
|
+
const requiredHeightAdjustment = (idealSize.height - requiredSize.height) / template.gridDimensions.rows;
|
|
71
|
+
const requiredWidthAdjustment = (idealSize.width - requiredSize.width) / template.gridDimensions.cols;
|
|
72
|
+
console.log("requiredHeightAdjustment: ", requiredHeightAdjustment, " requiredWidthAdjustment: ", requiredWidthAdjustment);
|
|
73
|
+
if (requiredHeightAdjustment < 0 && requiredHeightAdjustment < requiredWidthAdjustment) {
|
|
74
|
+
adjustedTemplate.componentTemplate.propertyTemplate.imageDimension.width += requiredHeightAdjustment;
|
|
75
|
+
}
|
|
76
|
+
if (requiredWidthAdjustment < 0 && requiredWidthAdjustment < requiredHeightAdjustment) {
|
|
77
|
+
adjustedTemplate.componentTemplate.propertyTemplate.imageDimension.width += requiredWidthAdjustment;
|
|
78
|
+
}
|
|
79
|
+
return adjustedTemplate;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.ComponentGridGenerator = ComponentGridGenerator;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentUtil = void 0;
|
|
4
|
+
class ComponentUtil {
|
|
5
|
+
static getComponentSize(element) {
|
|
6
|
+
var _a, _b, _c, _d, _e;
|
|
7
|
+
const sizeDefinition = {
|
|
8
|
+
width: 0,
|
|
9
|
+
height: 0,
|
|
10
|
+
};
|
|
11
|
+
const imageElement = ((_a = element.elements) === null || _a === void 0 ? void 0 : _a.find(el => el.type === 'image')) || {};
|
|
12
|
+
sizeDefinition.width = (_b = imageElement.size) === null || _b === void 0 ? void 0 : _b.width;
|
|
13
|
+
const LINE_PADDING = 8;
|
|
14
|
+
const textElements = (_c = element.elements) === null || _c === void 0 ? void 0 : _c.filter(el => el.type === 'text');
|
|
15
|
+
let textHeight = 0;
|
|
16
|
+
textElements.forEach(el => {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
let fontSize = ((_b = (_a = el.style) === null || _a === void 0 ? void 0 : _a.font) === null || _b === void 0 ? void 0 : _b.size) || 12;
|
|
19
|
+
textHeight += fontSize + LINE_PADDING;
|
|
20
|
+
});
|
|
21
|
+
const imageHeight = (((_d = imageElement.size) === null || _d === void 0 ? void 0 : _d.height) || ((_e = imageElement.size) === null || _e === void 0 ? void 0 : _e.width) || 150);
|
|
22
|
+
sizeDefinition.height = imageHeight + textHeight;
|
|
23
|
+
return sizeDefinition;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.ComponentUtil = ComponentUtil;
|
|
@@ -76,10 +76,8 @@ class DocumentGenerator {
|
|
|
76
76
|
return elements;
|
|
77
77
|
}
|
|
78
78
|
static generateGroupHeading(dataGroup, template, position, span) {
|
|
79
|
-
console.log("generateGroupHeading: ", dataGroup.name, span);
|
|
80
79
|
const elements = [];
|
|
81
80
|
const heading = documents_1.DocumentElementFactory.createTextElement("Placeholder", {});
|
|
82
|
-
console.log("template.frameGroupHeaderTemplate.size.height: ", template.frameGroupHeaderTemplate.size.height);
|
|
83
81
|
heading.style = { border: { width: 1, color: "rgba(0,0,0,0)" }, color: "#000000", backgroundColor: template.frameGroupHeaderTemplate.style.backgroundColor || 'black' };
|
|
84
82
|
heading.text = `<p><span style=\"font-size: ${template.frameGroupHeaderTemplate.style.font.size}pt;\"><strong><span style=\"color: ${template.frameGroupHeaderTemplate.style.color};\">${dataGroup.name}</span></strong></span></p>`;
|
|
85
83
|
heading.position = position;
|
package/lib/frame-generator.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FrameGenerator = void 0;
|
|
4
4
|
const documents_1 = require("@contrail/documents");
|
|
5
|
-
const component_grid_generator_1 = require("./component-grid-generator");
|
|
5
|
+
const component_grid_generator_1 = require("./components/component-grid-generator");
|
|
6
6
|
const util_1 = require("@contrail/util");
|
|
7
|
+
const document_util_1 = require("./util/document-util");
|
|
7
8
|
class FrameGenerator {
|
|
8
9
|
static generateFrameForDataGroup(dataGroup, framePosition, template) {
|
|
9
10
|
const elements = [];
|
|
@@ -21,11 +22,15 @@ class FrameGenerator {
|
|
|
21
22
|
const HEADER_MARGIN = 20;
|
|
22
23
|
const gridPosition = util_1.ObjectUtil.cloneDeep(headerPosition);
|
|
23
24
|
gridPosition.y = gridPosition.y + frameHeaderDimensions.height + HEADER_MARGIN;
|
|
24
|
-
const
|
|
25
|
-
const
|
|
25
|
+
const relativeGridPosition = document_util_1.DocumentUtil.getRelativePosition(framePosition, gridPosition);
|
|
26
|
+
const frameSize = template.frameSize;
|
|
27
|
+
const idealGridSize = {
|
|
28
|
+
width: frameSize.width - relativeGridPosition.x - FRAME_PADDING,
|
|
29
|
+
height: frameSize.height - relativeGridPosition.y - FRAME_PADDING
|
|
30
|
+
};
|
|
26
31
|
elements.push(util_1.ObjectUtil.cloneDeep(frame));
|
|
27
32
|
elements.push(...this.generateFrameHeaderForDataGroup(dataGroup, headerPosition, template, frameHeaderDimensions));
|
|
28
|
-
elements.push(...component_grid_generator_1.ComponentGridGenerator.generateComponentGrid(dataGroup.data,
|
|
33
|
+
elements.push(...component_grid_generator_1.ComponentGridGenerator.generateComponentGrid(dataGroup.data, gridPosition, template.componentGridTemplate, idealGridSize));
|
|
29
34
|
return elements;
|
|
30
35
|
}
|
|
31
36
|
static generateFrameHeaderForDataGroup(dataGroup, position, template, headerSize) {
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DataGroupStructure } from "@contrail/data-grouping";
|
|
2
|
-
import { PositionDefinition, SizeDefinition,
|
|
2
|
+
import { PositionDefinition, SizeDefinition, DocumentElement, StyleDefinition } from "@contrail/documents";
|
|
3
|
+
import { TypeProperty } from "@contrail/types";
|
|
3
4
|
export declare enum Orientation {
|
|
4
5
|
HORIZONTAL = "horizontal",
|
|
5
6
|
VERTICAL = "vertical"
|
|
@@ -22,11 +23,25 @@ export interface DocumentTemplate {
|
|
|
22
23
|
}
|
|
23
24
|
export interface ComponentGridTemplate {
|
|
24
25
|
componentTemplate: ComponentTemplate;
|
|
26
|
+
componentPadding?: number;
|
|
25
27
|
gridDimensions: {
|
|
26
28
|
rows: number;
|
|
27
29
|
cols: number;
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
32
|
export interface ComponentTemplate {
|
|
31
|
-
|
|
33
|
+
propertyTemplate?: ComponentPropertyTemplate;
|
|
34
|
+
}
|
|
35
|
+
export interface ComponentPropertyTemplate {
|
|
36
|
+
imageDimension?: SizeDefinition;
|
|
37
|
+
imageLocation?: 'top' | 'right' | 'left' | 'bottom';
|
|
38
|
+
textHorizontalAlignment?: 'center' | 'right' | 'left';
|
|
39
|
+
properties: Array<ComponentPropertyDefinition>;
|
|
40
|
+
}
|
|
41
|
+
export interface ComponentPropertyDefinition {
|
|
42
|
+
style?: StyleDefinition;
|
|
43
|
+
propertyDefinition: TypeProperty;
|
|
44
|
+
slug: string;
|
|
45
|
+
typeRootSlug: string;
|
|
46
|
+
includeLabel?: boolean;
|
|
32
47
|
}
|
package/lib/scripts/test.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const document_generator_1 = require("../document-generator");
|
|
13
|
-
const
|
|
13
|
+
const interfaces_1 = require("../interfaces");
|
|
14
14
|
const sdk_1 = require("@contrail/sdk");
|
|
15
15
|
const fs = require("fs");
|
|
16
16
|
const nanoid_1 = require("nanoid");
|
|
@@ -18,24 +18,123 @@ const data_grouping_1 = require("@contrail/data-grouping");
|
|
|
18
18
|
function run() {
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
const generator = new document_generator_1.DocumentGenerator();
|
|
21
|
-
const orgSlug = '
|
|
21
|
+
const orgSlug = 'converse-prod';
|
|
22
22
|
yield loginSDK(orgSlug);
|
|
23
|
-
const assortmentId = '
|
|
24
|
-
const documentTemplateDefinition = test_data_1.VERTICAL_DOCUMENT_TEMPLATE;
|
|
23
|
+
const assortmentId = 'Z7nTOauGtuuiU9UC';
|
|
25
24
|
const itemType = yield new sdk_1.Types().getType({ path: 'item' });
|
|
25
|
+
const projectItemType = yield new sdk_1.Types().getType({ path: 'project-item' });
|
|
26
|
+
const PROPERTY_COMPONENT_TEMPLATE = {
|
|
27
|
+
imageDimension: { width: 600 },
|
|
28
|
+
imageLocation: 'top',
|
|
29
|
+
textHorizontalAlignment: 'center',
|
|
30
|
+
properties: [{
|
|
31
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'name'),
|
|
32
|
+
typeRootSlug: 'item',
|
|
33
|
+
slug: "name",
|
|
34
|
+
style: {
|
|
35
|
+
font: {
|
|
36
|
+
size: 14,
|
|
37
|
+
weight: 'bold',
|
|
38
|
+
},
|
|
39
|
+
color: 'rgba(0,0,0,.5)',
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'optionName'),
|
|
43
|
+
typeRootSlug: 'item',
|
|
44
|
+
slug: "optionName",
|
|
45
|
+
style: {
|
|
46
|
+
font: {
|
|
47
|
+
size: 10,
|
|
48
|
+
weight: 'bold',
|
|
49
|
+
},
|
|
50
|
+
color: 'green',
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'category'),
|
|
54
|
+
typeRootSlug: 'item',
|
|
55
|
+
slug: "category",
|
|
56
|
+
includeLabel: true,
|
|
57
|
+
}, {
|
|
58
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'designTheme'),
|
|
59
|
+
typeRootSlug: 'item',
|
|
60
|
+
slug: "designTheme",
|
|
61
|
+
includeLabel: true,
|
|
62
|
+
}, {
|
|
63
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'baseStyleNumber'),
|
|
64
|
+
typeRootSlug: 'item',
|
|
65
|
+
slug: "baseStyleNumber",
|
|
66
|
+
}, {
|
|
67
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'closureType'),
|
|
68
|
+
typeRootSlug: 'item',
|
|
69
|
+
slug: "closureType",
|
|
70
|
+
includeLabel: true,
|
|
71
|
+
}, {
|
|
72
|
+
propertyDefinition: itemType.typeProperties.find(p => p.slug === 'colorFamily'),
|
|
73
|
+
typeRootSlug: 'item',
|
|
74
|
+
slug: "colorFamily",
|
|
75
|
+
includeLabel: true,
|
|
76
|
+
}, {
|
|
77
|
+
propertyDefinition: projectItemType.typeProperties.find(p => p.slug === 'colorwayStatus'),
|
|
78
|
+
slug: "colorwayStatus",
|
|
79
|
+
typeRootSlug: 'project-item',
|
|
80
|
+
includeLabel: true,
|
|
81
|
+
}]
|
|
82
|
+
};
|
|
83
|
+
const documentTemplateDefinition = {
|
|
84
|
+
frameOrientation: interfaces_1.Orientation.VERTICAL,
|
|
85
|
+
frameSize: { width: 1200, height: 675 },
|
|
86
|
+
framePadding: 30,
|
|
87
|
+
frameHeaderTemplate: {
|
|
88
|
+
style: {
|
|
89
|
+
color: '#000000',
|
|
90
|
+
font: {
|
|
91
|
+
size: 20
|
|
92
|
+
},
|
|
93
|
+
backgroundColor: '#FFFFFF',
|
|
94
|
+
},
|
|
95
|
+
size: {
|
|
96
|
+
height: 60,
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
frameGroupHeaderTemplate: {
|
|
100
|
+
style: {
|
|
101
|
+
color: '#ffffff',
|
|
102
|
+
font: {
|
|
103
|
+
size: 20
|
|
104
|
+
},
|
|
105
|
+
backgroundColor: 'black',
|
|
106
|
+
},
|
|
107
|
+
size: {
|
|
108
|
+
height: 60,
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
componentGridTemplate: {
|
|
112
|
+
gridDimensions: { cols: 8, rows: 2 },
|
|
113
|
+
componentPadding: 5,
|
|
114
|
+
componentTemplate: {
|
|
115
|
+
propertyTemplate: PROPERTY_COMPONENT_TEMPLATE
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
26
119
|
const groupingProperties = [
|
|
27
120
|
{
|
|
28
|
-
property: itemType.typeProperties.find(p => p.slug === '
|
|
121
|
+
property: itemType.typeProperties.find(p => p.slug === 'designPack'),
|
|
122
|
+
scope: 'item',
|
|
123
|
+
sort: sdk_1.SortOrderOptions.ASC,
|
|
124
|
+
values: null,
|
|
125
|
+
}, {
|
|
126
|
+
property: itemType.typeProperties.find(p => p.slug === 'category'),
|
|
29
127
|
scope: 'item',
|
|
30
128
|
sort: sdk_1.SortOrderOptions.ASC,
|
|
31
129
|
values: null,
|
|
32
130
|
}, {
|
|
33
|
-
property: itemType.typeProperties.find(p => p.slug === '
|
|
131
|
+
property: itemType.typeProperties.find(p => p.slug === 'class'),
|
|
34
132
|
scope: 'item',
|
|
35
133
|
sort: sdk_1.SortOrderOptions.ASC,
|
|
36
134
|
values: null,
|
|
37
135
|
},
|
|
38
136
|
];
|
|
137
|
+
documentTemplateDefinition.componentGridTemplate.componentTemplate.propertyTemplate = PROPERTY_COMPONENT_TEMPLATE;
|
|
39
138
|
const dataGroup = yield getDataGroupStructure(assortmentId, groupingProperties, documentTemplateDefinition);
|
|
40
139
|
const params = {
|
|
41
140
|
startingCoordinates: { x: 500, y: 500 },
|
package/lib/test-data.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DataGroupStructure } from "@contrail/data-grouping";
|
|
2
2
|
import { ComponentGridTemplate, DocumentTemplate } from "./interfaces";
|
|
3
|
-
import { Document } from '@contrail/documents';
|
|
4
3
|
export declare const TEST_ITEM_MODEL: {
|
|
5
4
|
item: {
|
|
6
5
|
id: string;
|
|
@@ -68,7 +67,6 @@ export declare const TEST_GROUP_2: {
|
|
|
68
67
|
};
|
|
69
68
|
export declare const TEST_ROOT_GROUP: DataGroupStructure;
|
|
70
69
|
export declare const TEST_TWO_LEVEL_ROOT_GROUP: DataGroupStructure;
|
|
71
|
-
export declare const ITEM_COMPONENT_TEMPLATE: Document;
|
|
72
70
|
export declare const COMPONENT_GRID_TEMPLATE: ComponentGridTemplate;
|
|
73
71
|
export declare const HORIZONTAL_DOCUMENT_TEMPLATE: DocumentTemplate;
|
|
74
72
|
export declare const VERTICAL_DOCUMENT_TEMPLATE: DocumentTemplate;
|
package/lib/test-data.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VERTICAL_DOCUMENT_TEMPLATE = exports.HORIZONTAL_DOCUMENT_TEMPLATE = exports.COMPONENT_GRID_TEMPLATE = exports.
|
|
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
4
|
const types_1 = require("@contrail/types");
|
|
5
5
|
const interfaces_1 = require("./interfaces");
|
|
6
6
|
const sdk_1 = require("@contrail/sdk");
|
|
@@ -104,51 +104,15 @@ exports.TEST_TWO_LEVEL_ROOT_GROUP = {
|
|
|
104
104
|
properties: {},
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
|
-
exports.ITEM_COMPONENT_TEMPLATE = {
|
|
108
|
-
elements: [{
|
|
109
|
-
type: "image",
|
|
110
|
-
size: { width: 125, height: 125 },
|
|
111
|
-
propertyBindings: { url: 'viewable.mediumViewableDownloadUrl' }
|
|
112
|
-
}, {
|
|
113
|
-
type: "text",
|
|
114
|
-
position: { x: 0, y: 126 },
|
|
115
|
-
size: { height: 25, width: 125 },
|
|
116
|
-
style: {
|
|
117
|
-
font: {
|
|
118
|
-
size: 8,
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
propertyBindings: { text: 'item.name' }
|
|
122
|
-
}, {
|
|
123
|
-
type: "text",
|
|
124
|
-
position: { x: 0, y: 151 },
|
|
125
|
-
size: { height: 25, width: 125 },
|
|
126
|
-
style: {
|
|
127
|
-
font: {
|
|
128
|
-
size: 8,
|
|
129
|
-
},
|
|
130
|
-
color: 'rgba(0,0,0,.5)',
|
|
131
|
-
},
|
|
132
|
-
propertyBindings: { text: 'item.optionName' }
|
|
133
|
-
}, {
|
|
134
|
-
type: "text",
|
|
135
|
-
position: { x: 0, y: 151 },
|
|
136
|
-
size: { height: 25, width: 125 },
|
|
137
|
-
style: {
|
|
138
|
-
font: {
|
|
139
|
-
size: 8,
|
|
140
|
-
},
|
|
141
|
-
color: 'rgba(0,0,0,.5)',
|
|
142
|
-
},
|
|
143
|
-
propertyBindings: { text: 'item.gender' }
|
|
144
|
-
},
|
|
145
|
-
]
|
|
146
|
-
};
|
|
147
107
|
exports.COMPONENT_GRID_TEMPLATE = {
|
|
148
108
|
gridDimensions: { cols: 7, rows: 3 },
|
|
149
109
|
componentTemplate: {
|
|
150
|
-
|
|
151
|
-
|
|
110
|
+
propertyTemplate: {
|
|
111
|
+
properties: [],
|
|
112
|
+
imageLocation: 'top',
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
componentPadding: 20
|
|
152
116
|
};
|
|
153
117
|
exports.HORIZONTAL_DOCUMENT_TEMPLATE = {
|
|
154
118
|
frameOrientation: interfaces_1.Orientation.HORIZONTAL,
|
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrail/document-generation",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Utilities for automatic generation of documents.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"testEnvironment": "node"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@contrail/data-grouping": "^1.0.
|
|
45
|
+
"@contrail/data-grouping": "^1.0.15",
|
|
46
46
|
"@contrail/documents": "^1.0.44",
|
|
47
47
|
"@contrail/types": "^3.0.27",
|
|
48
|
-
"@contrail/util": "^1.0.
|
|
48
|
+
"@contrail/util": "^1.0.27"
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { DocumentElement } from "@contrail/documents";
|
|
2
|
-
import { ComponentTemplate } from "./interfaces";
|
|
3
|
-
export declare class ComponentGenerator {
|
|
4
|
-
static generateComponent(data: any, options: DocumentElement, template: ComponentTemplate): DocumentElement;
|
|
5
|
-
static generatedModelBindings(data: any): {
|
|
6
|
-
item: string;
|
|
7
|
-
viewable: string;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ComponentGenerator = void 0;
|
|
4
|
-
const documents_1 = require("@contrail/documents");
|
|
5
|
-
class ComponentGenerator {
|
|
6
|
-
static generateComponent(data, options, template) {
|
|
7
|
-
const componentDefinition = {
|
|
8
|
-
defaultTemplate: template.templateDocument,
|
|
9
|
-
};
|
|
10
|
-
const modelBindings = this.generatedModelBindings(data);
|
|
11
|
-
const component = documents_1.DocumentElementFactory.createComponentFromComponentDefinition(componentDefinition, data, modelBindings, options);
|
|
12
|
-
return component;
|
|
13
|
-
}
|
|
14
|
-
static generatedModelBindings(data) {
|
|
15
|
-
return {
|
|
16
|
-
item: `item:${data.item.id}`,
|
|
17
|
-
viewable: `item:${data.item.id}`,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.ComponentGenerator = ComponentGenerator;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { DocumentElement, PositionDefinition, SizeDefinition } from "@contrail/documents";
|
|
2
|
-
import { ComponentGridTemplate } from "./interfaces";
|
|
3
|
-
export declare class ComponentGridGenerator {
|
|
4
|
-
static generateComponentGrid(data: any, startingPosition: PositionDefinition, template: ComponentGridTemplate, documentSize: SizeDefinition): Array<DocumentElement>;
|
|
5
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ComponentGridGenerator = void 0;
|
|
4
|
-
const util_1 = require("@contrail/util");
|
|
5
|
-
const component_generator_1 = require("./component-generator");
|
|
6
|
-
class ComponentGridGenerator {
|
|
7
|
-
static generateComponentGrid(data, startingPosition = { x: 0, y: 0 }, template, documentSize) {
|
|
8
|
-
if (!data) {
|
|
9
|
-
console.warn("WARN: data null in generateComponentGrid");
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
if (!template) {
|
|
13
|
-
console.warn("WARN: template null in generateComponentGrid");
|
|
14
|
-
return [];
|
|
15
|
-
}
|
|
16
|
-
if (!template.componentTemplate) {
|
|
17
|
-
console.warn("WARN: component template is null generateComponentGrid");
|
|
18
|
-
return [];
|
|
19
|
-
}
|
|
20
|
-
const elements = [];
|
|
21
|
-
let dataIndex = 0;
|
|
22
|
-
const componentTemplate = template.componentTemplate;
|
|
23
|
-
const componentPosition = util_1.ObjectUtil.cloneDeep(startingPosition);
|
|
24
|
-
const COMPONENT_WIDTH = 150;
|
|
25
|
-
const COMPONENT_HEIGHT = 180;
|
|
26
|
-
const COMPONENT_PADDING = 20;
|
|
27
|
-
componentPosition.x += COMPONENT_PADDING;
|
|
28
|
-
componentPosition.y += COMPONENT_PADDING;
|
|
29
|
-
for (let row = 0; row < template.gridDimensions.rows; row++) {
|
|
30
|
-
for (let col = 0; col < template.gridDimensions.cols; col++) {
|
|
31
|
-
if (dataIndex >= data.length) {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
let dataObj = data[dataIndex];
|
|
35
|
-
dataObj.viewable = dataObj.item;
|
|
36
|
-
const position = util_1.ObjectUtil.cloneDeep(componentPosition);
|
|
37
|
-
let component = component_generator_1.ComponentGenerator.generateComponent(dataObj, { position }, componentTemplate);
|
|
38
|
-
elements.push(component);
|
|
39
|
-
dataIndex++;
|
|
40
|
-
componentPosition.x += COMPONENT_WIDTH + COMPONENT_PADDING;
|
|
41
|
-
}
|
|
42
|
-
componentPosition.y += COMPONENT_HEIGHT + COMPONENT_PADDING;
|
|
43
|
-
componentPosition.x = startingPosition.x + COMPONENT_PADDING;
|
|
44
|
-
}
|
|
45
|
-
return elements;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.ComponentGridGenerator = ComponentGridGenerator;
|