@contrail/document-generation 1.0.5 → 1.0.6
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/component-generator.d.ts +9 -0
- package/lib/component-generator.js +21 -0
- package/lib/component-grid-generator.d.ts +5 -0
- package/lib/component-grid-generator.js +48 -0
- package/lib/document-generator.d.ts +11 -0
- package/lib/document-generator.js +108 -0
- package/lib/frame-generator.d.ts +8 -0
- package/lib/frame-generator.js +44 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +18 -0
- package/lib/interfaces.d.ts +32 -0
- package/lib/interfaces.js +8 -0
- package/lib/scripts/test.d.ts +1 -0
- package/lib/scripts/test.js +125 -0
- package/lib/test-data.d.ts +74 -0
- package/lib/test-data.js +212 -0
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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;
|
|
@@ -0,0 +1,5 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DocumentElement, PositionDefinition } from "@contrail/documents";
|
|
2
|
+
import { DocumentGenerationOptions, DocumentTemplate } from "./interfaces";
|
|
3
|
+
import { DataGroup } from "@contrail/data-grouping";
|
|
4
|
+
export declare class DocumentGenerator {
|
|
5
|
+
constructor();
|
|
6
|
+
static generateDocumentElements(options: DocumentGenerationOptions): Array<DocumentElement>;
|
|
7
|
+
static generateGroup(group: DataGroup, template: any, startingPosition: any, totalDepth: any, currentDepth: any): any[];
|
|
8
|
+
static getGroupSpan(group: DataGroup, totalDepth: any, currentDepth: any): number;
|
|
9
|
+
static generateFrameGroup(dataGroup: DataGroup, template: DocumentTemplate, position: PositionDefinition): Array<DocumentElement>;
|
|
10
|
+
static generateGroupHeading(dataGroup: DataGroup, template: DocumentTemplate, position: PositionDefinition, span: any): any[];
|
|
11
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DocumentGenerator = void 0;
|
|
4
|
+
const documents_1 = require("@contrail/documents");
|
|
5
|
+
const interfaces_1 = require("./interfaces");
|
|
6
|
+
const util_1 = require("@contrail/util");
|
|
7
|
+
const frame_generator_1 = require("./frame-generator");
|
|
8
|
+
class DocumentGenerator {
|
|
9
|
+
constructor() {
|
|
10
|
+
}
|
|
11
|
+
static generateDocumentElements(options) {
|
|
12
|
+
const elements = [];
|
|
13
|
+
const structure = options.data.dataGroup;
|
|
14
|
+
const template = options.documentTemplateDefinition;
|
|
15
|
+
console.log("generateDocumentElements: ", structure.depth, structure.groupingProperties.length);
|
|
16
|
+
let position = options.startingCoordinates || { x: 0, y: 0 };
|
|
17
|
+
const group = structure.rootGroup;
|
|
18
|
+
elements.push(...this.generateGroup(group, template, position, structure.depth, 0));
|
|
19
|
+
return elements;
|
|
20
|
+
}
|
|
21
|
+
static generateGroup(group, template, startingPosition, totalDepth, currentDepth) {
|
|
22
|
+
const elements = [];
|
|
23
|
+
let position = util_1.ObjectUtil.cloneDeep(startingPosition);
|
|
24
|
+
if (currentDepth > 0) {
|
|
25
|
+
let groupHeaderPosition = { x: position.x + template.framePadding, y: position.y + template.framePadding };
|
|
26
|
+
let span = this.getGroupSpan(group, totalDepth, currentDepth);
|
|
27
|
+
elements.push(...this.generateGroupHeading(group, template, groupHeaderPosition, span));
|
|
28
|
+
let groupHeaderDimensions = { width: template.frameSize.width, height: template.frameGroupHeaderTemplate.size.height };
|
|
29
|
+
if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
|
|
30
|
+
position = { x: position.x + groupHeaderDimensions.height + template.framePadding, y: position.y };
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
position = { x: position.x, y: position.y + groupHeaderDimensions.height + template.framePadding };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (currentDepth === totalDepth) {
|
|
37
|
+
elements.push(...this.generateFrameGroup(group, template, position));
|
|
38
|
+
}
|
|
39
|
+
if (currentDepth < totalDepth) {
|
|
40
|
+
for (let subGroup of group.subGroups) {
|
|
41
|
+
elements.push(...this.generateGroup(subGroup, template, position, totalDepth, currentDepth + 1));
|
|
42
|
+
let frameSetMultiple = this.getGroupSpan(subGroup, totalDepth, currentDepth + 1);
|
|
43
|
+
let paddingMultiple = 1;
|
|
44
|
+
if (currentDepth < totalDepth) {
|
|
45
|
+
paddingMultiple = frameSetMultiple;
|
|
46
|
+
}
|
|
47
|
+
if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
|
|
48
|
+
position = { x: position.x, y: position.y + (template.frameSize.height * frameSetMultiple) + (template.framePadding * paddingMultiple) };
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
position = { x: position.x + (template.frameSize.width * frameSetMultiple) + (template.framePadding * paddingMultiple), y: position.y };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return elements;
|
|
56
|
+
}
|
|
57
|
+
static getGroupSpan(group, totalDepth, currentDepth) {
|
|
58
|
+
let span = 1;
|
|
59
|
+
if (currentDepth !== totalDepth) {
|
|
60
|
+
span = group.subGroups.length;
|
|
61
|
+
}
|
|
62
|
+
return span;
|
|
63
|
+
}
|
|
64
|
+
static generateFrameGroup(dataGroup, template, position) {
|
|
65
|
+
const elements = [];
|
|
66
|
+
let framePosition = { x: position.x + template.framePadding, y: position.y + template.framePadding };
|
|
67
|
+
for (let group of dataGroup.subGroups) {
|
|
68
|
+
elements.push(...frame_generator_1.FrameGenerator.generateFrameForDataGroup(group, framePosition, template));
|
|
69
|
+
if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
|
|
70
|
+
framePosition.x = framePosition.x + template.frameSize.width + template.framePadding || 10;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
framePosition.y = framePosition.y + template.frameSize.height + template.framePadding || 10;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return elements;
|
|
77
|
+
}
|
|
78
|
+
static generateGroupHeading(dataGroup, template, position, span) {
|
|
79
|
+
console.log("generateGroupHeading: ", dataGroup.name, span);
|
|
80
|
+
const elements = [];
|
|
81
|
+
const heading = documents_1.DocumentElementFactory.createTextElement("Placeholder", {});
|
|
82
|
+
console.log("template.frameGroupHeaderTemplate.size.height: ", template.frameGroupHeaderTemplate.size.height);
|
|
83
|
+
heading.style = { border: { width: 1, color: "rgba(0,0,0,0)" }, color: "#000000", backgroundColor: template.frameGroupHeaderTemplate.style.backgroundColor || 'black' };
|
|
84
|
+
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
|
+
heading.position = position;
|
|
86
|
+
if (template.frameOrientation === interfaces_1.Orientation.HORIZONTAL) {
|
|
87
|
+
let sizeDim = template.frameSize.height * span;
|
|
88
|
+
if (span > 1) {
|
|
89
|
+
sizeDim += (span - 1) * template.framePadding;
|
|
90
|
+
}
|
|
91
|
+
heading.size = { width: sizeDim, height: template.frameGroupHeaderTemplate.size.height };
|
|
92
|
+
heading.rotate = { angle: 270 };
|
|
93
|
+
heading.position.x = heading.position.x - (heading.size.width / 2) + (heading.size.height / 2);
|
|
94
|
+
heading.position.y = heading.position.y + (heading.size.width / 2) - (heading.size.height / 2);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
let sizeDim = template.frameSize.width * span;
|
|
98
|
+
if (span > 1) {
|
|
99
|
+
sizeDim += (span - 1) * template.framePadding;
|
|
100
|
+
}
|
|
101
|
+
heading.rotate = { angle: 0 };
|
|
102
|
+
heading.size = { width: sizeDim, height: template.frameGroupHeaderTemplate.size.height };
|
|
103
|
+
}
|
|
104
|
+
elements.push(heading);
|
|
105
|
+
return elements;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.DocumentGenerator = DocumentGenerator;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DocumentElement, PositionDefinition, SizeDefinition } from "@contrail/documents";
|
|
2
|
+
import { DataGroup } from "@contrail/data-grouping";
|
|
3
|
+
import { DocumentTemplate } from "./interfaces";
|
|
4
|
+
export declare class FrameGenerator {
|
|
5
|
+
static generateFrameForDataGroup(dataGroup: DataGroup, framePosition: PositionDefinition, template: DocumentTemplate): any[];
|
|
6
|
+
static generateFrameHeaderForDataGroup(dataGroup: DataGroup, position: PositionDefinition, template: DocumentTemplate, headerSize: SizeDefinition): DocumentElement[];
|
|
7
|
+
static generateFrame(options: DocumentElement): DocumentElement;
|
|
8
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FrameGenerator = void 0;
|
|
4
|
+
const documents_1 = require("@contrail/documents");
|
|
5
|
+
const component_grid_generator_1 = require("./component-grid-generator");
|
|
6
|
+
const util_1 = require("@contrail/util");
|
|
7
|
+
class FrameGenerator {
|
|
8
|
+
static generateFrameForDataGroup(dataGroup, framePosition, template) {
|
|
9
|
+
const elements = [];
|
|
10
|
+
const frame = this.generateFrame({
|
|
11
|
+
position: util_1.ObjectUtil.cloneDeep(framePosition),
|
|
12
|
+
size: template.frameSize,
|
|
13
|
+
style: { backgroundColor: "#fff", border: { width: 1, color: "#616161" } }
|
|
14
|
+
});
|
|
15
|
+
frame.name = dataGroup.name;
|
|
16
|
+
const FRAME_PADDING = 20;
|
|
17
|
+
const headerPosition = util_1.ObjectUtil.cloneDeep(framePosition);
|
|
18
|
+
headerPosition.y = headerPosition.y + FRAME_PADDING;
|
|
19
|
+
headerPosition.x = headerPosition.x + FRAME_PADDING;
|
|
20
|
+
const frameHeaderDimensions = { height: 50, width: template.frameSize.width - 50 };
|
|
21
|
+
const HEADER_MARGIN = 20;
|
|
22
|
+
const gridPosition = util_1.ObjectUtil.cloneDeep(headerPosition);
|
|
23
|
+
gridPosition.y = gridPosition.y + frameHeaderDimensions.height + HEADER_MARGIN;
|
|
24
|
+
const componentGridPosition = util_1.ObjectUtil.cloneDeep(gridPosition);
|
|
25
|
+
const componentGridSize = template.frameSize;
|
|
26
|
+
elements.push(util_1.ObjectUtil.cloneDeep(frame));
|
|
27
|
+
elements.push(...this.generateFrameHeaderForDataGroup(dataGroup, headerPosition, template, frameHeaderDimensions));
|
|
28
|
+
elements.push(...component_grid_generator_1.ComponentGridGenerator.generateComponentGrid(dataGroup.data, componentGridPosition, template.componentGridTemplate, componentGridSize));
|
|
29
|
+
return elements;
|
|
30
|
+
}
|
|
31
|
+
static generateFrameHeaderForDataGroup(dataGroup, position, template, headerSize) {
|
|
32
|
+
const heading = documents_1.DocumentElementFactory.createTextElement(dataGroup.name, template.frameHeaderTemplate);
|
|
33
|
+
heading.style = { border: { width: 1, color: "rgba(0,0,0,0)" }, color: "#000000", backgroundColor: template.frameHeaderTemplate.style.backgroundColor || 'black' };
|
|
34
|
+
heading.text = `<p><span style=\"font-size: ${template.frameHeaderTemplate.style.font.size}pt;\"><strong><span style=\"color: ${template.frameHeaderTemplate.style.color};\">${dataGroup.name}</span></strong></span></p>`;
|
|
35
|
+
heading.size = util_1.ObjectUtil.cloneDeep(headerSize);
|
|
36
|
+
heading.position = util_1.ObjectUtil.cloneDeep(position);
|
|
37
|
+
return [heading];
|
|
38
|
+
}
|
|
39
|
+
static generateFrame(options) {
|
|
40
|
+
const frame = documents_1.DocumentElementFactory.createFrameElement(options);
|
|
41
|
+
return frame;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.FrameGenerator = FrameGenerator;
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./document-generator"), exports);
|
|
18
|
+
__exportStar(require("./interfaces"), exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DataGroupStructure } from "@contrail/data-grouping";
|
|
2
|
+
import { PositionDefinition, SizeDefinition, Document, DocumentElement } from "@contrail/documents";
|
|
3
|
+
export declare enum Orientation {
|
|
4
|
+
HORIZONTAL = "horizontal",
|
|
5
|
+
VERTICAL = "vertical"
|
|
6
|
+
}
|
|
7
|
+
export interface DocumentGenerationDataDefinition {
|
|
8
|
+
dataGroup: DataGroupStructure;
|
|
9
|
+
}
|
|
10
|
+
export interface DocumentGenerationOptions {
|
|
11
|
+
startingCoordinates: PositionDefinition;
|
|
12
|
+
data: DocumentGenerationDataDefinition;
|
|
13
|
+
documentTemplateDefinition: DocumentTemplate;
|
|
14
|
+
}
|
|
15
|
+
export interface DocumentTemplate {
|
|
16
|
+
frameOrientation: Orientation;
|
|
17
|
+
frameSize: SizeDefinition;
|
|
18
|
+
framePadding?: number;
|
|
19
|
+
frameGroupHeaderTemplate: DocumentElement;
|
|
20
|
+
frameHeaderTemplate: DocumentElement;
|
|
21
|
+
componentGridTemplate: ComponentGridTemplate;
|
|
22
|
+
}
|
|
23
|
+
export interface ComponentGridTemplate {
|
|
24
|
+
componentTemplate: ComponentTemplate;
|
|
25
|
+
gridDimensions: {
|
|
26
|
+
rows: number;
|
|
27
|
+
cols: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface ComponentTemplate {
|
|
31
|
+
templateDocument: Document;
|
|
32
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Orientation = void 0;
|
|
4
|
+
var Orientation;
|
|
5
|
+
(function (Orientation) {
|
|
6
|
+
Orientation["HORIZONTAL"] = "horizontal";
|
|
7
|
+
Orientation["VERTICAL"] = "vertical";
|
|
8
|
+
})(Orientation = exports.Orientation || (exports.Orientation = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
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 test_data_1 = require("../test-data");
|
|
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 generator = new document_generator_1.DocumentGenerator();
|
|
21
|
+
const orgSlug = 'new-balance-prod';
|
|
22
|
+
yield loginSDK(orgSlug);
|
|
23
|
+
const assortmentId = 'OBZc68qwHM0Xsw4k';
|
|
24
|
+
const documentTemplateDefinition = test_data_1.VERTICAL_DOCUMENT_TEMPLATE;
|
|
25
|
+
const itemType = yield new sdk_1.Types().getType({ path: 'item' });
|
|
26
|
+
const groupingProperties = [
|
|
27
|
+
{
|
|
28
|
+
property: itemType.typeProperties.find(p => p.slug === 'modelSeries'),
|
|
29
|
+
scope: 'item',
|
|
30
|
+
sort: sdk_1.SortOrderOptions.ASC,
|
|
31
|
+
values: null,
|
|
32
|
+
}, {
|
|
33
|
+
property: itemType.typeProperties.find(p => p.slug === 'gender'),
|
|
34
|
+
scope: 'item',
|
|
35
|
+
sort: sdk_1.SortOrderOptions.ASC,
|
|
36
|
+
values: null,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
const dataGroup = yield getDataGroupStructure(assortmentId, groupingProperties, documentTemplateDefinition);
|
|
40
|
+
const params = {
|
|
41
|
+
startingCoordinates: { x: 500, y: 500 },
|
|
42
|
+
data: {
|
|
43
|
+
dataGroup
|
|
44
|
+
},
|
|
45
|
+
documentTemplateDefinition,
|
|
46
|
+
};
|
|
47
|
+
const elements = document_generator_1.DocumentGenerator.generateDocumentElements(params);
|
|
48
|
+
const documentId = (0, nanoid_1.nanoid)(16);
|
|
49
|
+
elements.forEach(el => {
|
|
50
|
+
el.id = (0, nanoid_1.nanoid)(16);
|
|
51
|
+
});
|
|
52
|
+
const document = {
|
|
53
|
+
size: { width: 1600, height: 900 },
|
|
54
|
+
elements,
|
|
55
|
+
id: documentId,
|
|
56
|
+
};
|
|
57
|
+
yield uploadAndOpen(orgSlug, document);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function loginSDK(orgSlug) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
yield (0, sdk_1.login)({
|
|
63
|
+
email: 'brian@vibeiq.com',
|
|
64
|
+
password: process.env.CONTRAIL_PW,
|
|
65
|
+
orgSlug: orgSlug,
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function getAssortmentItems(assortmentId) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const assortment = yield new sdk_1.Entities().get({
|
|
72
|
+
entityName: 'assortment',
|
|
73
|
+
id: assortmentId,
|
|
74
|
+
relations: ['assortmentItems', 'assortmentItems.item', 'assortmentItems.projectItem']
|
|
75
|
+
});
|
|
76
|
+
let assortmentItems = assortment.assortmentItems;
|
|
77
|
+
if (assortment.itemsDownloadURL) {
|
|
78
|
+
const response = yield fetch(assortment.itemsDownloadURL);
|
|
79
|
+
assortmentItems = yield response.json();
|
|
80
|
+
}
|
|
81
|
+
return assortmentItems;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function getDataGroupStructure(assortmentId, groupingProperties, template) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const assortmentItems = yield getAssortmentItems(assortmentId);
|
|
87
|
+
const data = fromAssortmentModelToItemModel(assortmentItems);
|
|
88
|
+
const leafNodeDataCount = template.componentGridTemplate.gridDimensions.cols * template.componentGridTemplate.gridDimensions.rows;
|
|
89
|
+
return data_grouping_1.DataGroupGenerator.buildDataGroupStructure(data, groupingProperties, leafNodeDataCount);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function fromAssortmentModelToItemModel(data) {
|
|
93
|
+
const results = [];
|
|
94
|
+
data.forEach(ai => {
|
|
95
|
+
results.push({
|
|
96
|
+
item: ai.item,
|
|
97
|
+
projectItem: ai.projectItem,
|
|
98
|
+
viewable: ai.item,
|
|
99
|
+
assortmentItem: ai,
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
return results;
|
|
103
|
+
}
|
|
104
|
+
function uploadAndOpen(orgSlug, document) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
let config = (0, sdk_1.getConfig)();
|
|
107
|
+
var writeStream = fs.createWriteStream("testdocument.json");
|
|
108
|
+
writeStream.write(JSON.stringify(document));
|
|
109
|
+
writeStream.end();
|
|
110
|
+
const file = fs.createReadStream("testdocument.json");
|
|
111
|
+
const fileEntity = yield new sdk_1.Files().createAndUploadFileFromBuffer(file, 'application/json', 'testdocument.json', null, 300);
|
|
112
|
+
const domain = "http://preview.vibeiq.com";
|
|
113
|
+
const authToken = config.apiUserToken;
|
|
114
|
+
const documentType = 'board';
|
|
115
|
+
let url = domain +
|
|
116
|
+
'?url=' + encodeURIComponent(fileEntity.downloadUrl) +
|
|
117
|
+
'&orgSlug=' + encodeURIComponent(orgSlug) +
|
|
118
|
+
'&apiToken=' + encodeURIComponent(authToken) +
|
|
119
|
+
'&documentType=' + encodeURIComponent(documentType);
|
|
120
|
+
var start = (process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open');
|
|
121
|
+
const encodedUrl = url.replace(/&/g, '^&');
|
|
122
|
+
require('child_process').exec(start + ' ' + encodedUrl);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
run();
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { DataGroupStructure } from "@contrail/data-grouping";
|
|
2
|
+
import { ComponentGridTemplate, DocumentTemplate } from "./interfaces";
|
|
3
|
+
import { Document } from '@contrail/documents';
|
|
4
|
+
export declare const TEST_ITEM_MODEL: {
|
|
5
|
+
item: {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
optionName: string;
|
|
9
|
+
gender: string;
|
|
10
|
+
mediumViewableDownloadUrl: string;
|
|
11
|
+
};
|
|
12
|
+
projectItem: {
|
|
13
|
+
id: string;
|
|
14
|
+
retailPrice: number;
|
|
15
|
+
};
|
|
16
|
+
assortmentItem: {
|
|
17
|
+
id: string;
|
|
18
|
+
targetVolume: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare const TEST_GROUP: {
|
|
22
|
+
name: string;
|
|
23
|
+
data: {
|
|
24
|
+
item: {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
optionName: string;
|
|
28
|
+
gender: string;
|
|
29
|
+
mediumViewableDownloadUrl: string;
|
|
30
|
+
};
|
|
31
|
+
projectItem: {
|
|
32
|
+
id: string;
|
|
33
|
+
retailPrice: number;
|
|
34
|
+
};
|
|
35
|
+
assortmentItem: {
|
|
36
|
+
id: string;
|
|
37
|
+
targetVolume: number;
|
|
38
|
+
};
|
|
39
|
+
}[];
|
|
40
|
+
properties: {
|
|
41
|
+
gender: string;
|
|
42
|
+
};
|
|
43
|
+
subGroups: any[];
|
|
44
|
+
};
|
|
45
|
+
export declare const TEST_GROUP_2: {
|
|
46
|
+
name: string;
|
|
47
|
+
data: {
|
|
48
|
+
item: {
|
|
49
|
+
id: string;
|
|
50
|
+
name: string;
|
|
51
|
+
optionName: string;
|
|
52
|
+
gender: string;
|
|
53
|
+
mediumViewableDownloadUrl: string;
|
|
54
|
+
};
|
|
55
|
+
projectItem: {
|
|
56
|
+
id: string;
|
|
57
|
+
retailPrice: number;
|
|
58
|
+
};
|
|
59
|
+
assortmentItem: {
|
|
60
|
+
id: string;
|
|
61
|
+
targetVolume: number;
|
|
62
|
+
};
|
|
63
|
+
}[];
|
|
64
|
+
properties: {
|
|
65
|
+
gender: string;
|
|
66
|
+
};
|
|
67
|
+
subGroups: any[];
|
|
68
|
+
};
|
|
69
|
+
export declare const TEST_ROOT_GROUP: DataGroupStructure;
|
|
70
|
+
export declare const TEST_TWO_LEVEL_ROOT_GROUP: DataGroupStructure;
|
|
71
|
+
export declare const ITEM_COMPONENT_TEMPLATE: Document;
|
|
72
|
+
export declare const COMPONENT_GRID_TEMPLATE: ComponentGridTemplate;
|
|
73
|
+
export declare const HORIZONTAL_DOCUMENT_TEMPLATE: DocumentTemplate;
|
|
74
|
+
export declare const VERTICAL_DOCUMENT_TEMPLATE: DocumentTemplate;
|
package/lib/test-data.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VERTICAL_DOCUMENT_TEMPLATE = exports.HORIZONTAL_DOCUMENT_TEMPLATE = exports.COMPONENT_GRID_TEMPLATE = exports.ITEM_COMPONENT_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
|
+
properties: {
|
|
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
|
+
properties: {
|
|
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
|
+
properties: {},
|
|
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
|
+
properties: {
|
|
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
|
+
properties: {
|
|
99
|
+
gender: 'mens'
|
|
100
|
+
},
|
|
101
|
+
data: [],
|
|
102
|
+
}],
|
|
103
|
+
name: "Root",
|
|
104
|
+
properties: {},
|
|
105
|
+
}
|
|
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
|
+
exports.COMPONENT_GRID_TEMPLATE = {
|
|
148
|
+
gridDimensions: { cols: 7, rows: 3 },
|
|
149
|
+
componentTemplate: {
|
|
150
|
+
templateDocument: exports.ITEM_COMPONENT_TEMPLATE
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
exports.HORIZONTAL_DOCUMENT_TEMPLATE = {
|
|
154
|
+
frameOrientation: interfaces_1.Orientation.HORIZONTAL,
|
|
155
|
+
frameSize: { width: 1200, height: 675 },
|
|
156
|
+
framePadding: 30,
|
|
157
|
+
frameHeaderTemplate: {
|
|
158
|
+
style: {
|
|
159
|
+
color: '#000000',
|
|
160
|
+
font: {
|
|
161
|
+
size: 20
|
|
162
|
+
},
|
|
163
|
+
backgroundColor: '#FFFFFF',
|
|
164
|
+
},
|
|
165
|
+
size: {
|
|
166
|
+
height: 60,
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
frameGroupHeaderTemplate: {
|
|
170
|
+
style: {
|
|
171
|
+
color: '#ffffff',
|
|
172
|
+
font: {
|
|
173
|
+
size: 20
|
|
174
|
+
},
|
|
175
|
+
backgroundColor: 'black',
|
|
176
|
+
},
|
|
177
|
+
size: {
|
|
178
|
+
height: 60,
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
componentGridTemplate: exports.COMPONENT_GRID_TEMPLATE,
|
|
182
|
+
};
|
|
183
|
+
exports.VERTICAL_DOCUMENT_TEMPLATE = {
|
|
184
|
+
frameOrientation: interfaces_1.Orientation.VERTICAL,
|
|
185
|
+
frameSize: { width: 1200, height: 675 },
|
|
186
|
+
framePadding: 30,
|
|
187
|
+
frameHeaderTemplate: {
|
|
188
|
+
style: {
|
|
189
|
+
color: '#000000',
|
|
190
|
+
font: {
|
|
191
|
+
size: 20
|
|
192
|
+
},
|
|
193
|
+
backgroundColor: '#FFFFFF',
|
|
194
|
+
},
|
|
195
|
+
size: {
|
|
196
|
+
height: 60,
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
frameGroupHeaderTemplate: {
|
|
200
|
+
style: {
|
|
201
|
+
color: '#ffffff',
|
|
202
|
+
font: {
|
|
203
|
+
size: 20
|
|
204
|
+
},
|
|
205
|
+
backgroundColor: 'black',
|
|
206
|
+
},
|
|
207
|
+
size: {
|
|
208
|
+
height: 60,
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
componentGridTemplate: exports.COMPONENT_GRID_TEMPLATE,
|
|
212
|
+
};
|