@contrail/document-generation 2.0.37 → 2.0.39
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/board-document-generator.d.ts +23 -0
- package/lib/board-document-generator.js +227 -0
- package/lib/components/component-generator.d.ts +6 -0
- package/lib/components/component-generator.js +55 -0
- package/lib/components/component-grid-generator.d.ts +7 -0
- package/lib/components/component-grid-generator.js +84 -0
- package/lib/components/component-util.d.ts +5 -0
- package/lib/components/component-util.js +43 -0
- package/lib/document-generator.d.ts +6 -0
- package/lib/document-generator.js +11 -0
- package/lib/frames/frame-generator.d.ts +12 -0
- package/lib/frames/frame-generator.js +135 -0
- package/lib/frames/frame.d.ts +16 -0
- package/lib/frames/frame.js +67 -0
- package/lib/frames/index.d.ts +2 -0
- package/lib/frames/index.js +18 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +22 -0
- package/lib/info-panel/info-panel-generator.d.ts +6 -0
- package/lib/info-panel/info-panel-generator.js +52 -0
- package/lib/interfaces.d.ts +72 -0
- package/lib/interfaces.js +8 -0
- package/lib/scripts/test-board.d.ts +1 -0
- package/lib/scripts/test-board.js +230 -0
- package/lib/scripts/test-showcase.d.ts +1 -0
- package/lib/scripts/test-showcase.js +257 -0
- package/lib/showcase-frame-generator.d.ts +8 -0
- package/lib/showcase-frame-generator.js +44 -0
- package/lib/test-data.d.ts +72 -0
- package/lib/test-data.js +187 -0
- package/lib/util/document-dynamic-text-element-util.d.ts +9 -0
- package/lib/util/document-dynamic-text-element-util.js +99 -0
- package/lib/util/document-property-util.d.ts +9 -0
- package/lib/util/document-property-util.js +101 -0
- package/lib/util/document-text-element-util.d.ts +10 -0
- package/lib/util/document-text-element-util.js +124 -0
- package/lib/util/document-util.d.ts +8 -0
- package/lib/util/document-util.js +22 -0
- package/lib/util/index.d.ts +2 -0
- package/lib/util/index.js +18 -0
- package/lib/util/text-util.d.ts +4 -0
- package/lib/util/text-util.js +28 -0
- package/package.json +2 -2
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BoardFrame = exports.ShowcaseFrame = exports.DocumentFrame = void 0;
|
|
4
|
+
const documents_1 = require("@contrail/documents");
|
|
5
|
+
const util_1 = require("@contrail/util");
|
|
6
|
+
class DocumentFrame {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.frameContentElements = [];
|
|
9
|
+
}
|
|
10
|
+
addDocumentElements(elements) {
|
|
11
|
+
this.frameContentElements.push(...elements);
|
|
12
|
+
}
|
|
13
|
+
toDocumentElements() {
|
|
14
|
+
const elements = [];
|
|
15
|
+
elements.push(...this.frameContentElements);
|
|
16
|
+
return elements;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.DocumentFrame = DocumentFrame;
|
|
20
|
+
class ShowcaseFrame extends DocumentFrame {
|
|
21
|
+
}
|
|
22
|
+
exports.ShowcaseFrame = ShowcaseFrame;
|
|
23
|
+
class BoardFrame extends DocumentFrame {
|
|
24
|
+
constructor(name, position, size, style, clipContent = false) {
|
|
25
|
+
super();
|
|
26
|
+
if (!position) {
|
|
27
|
+
position = { x: 0, y: 0 };
|
|
28
|
+
}
|
|
29
|
+
if (!size) {
|
|
30
|
+
size = { width: 1200, height: 675 };
|
|
31
|
+
}
|
|
32
|
+
if (!style) {
|
|
33
|
+
style = {};
|
|
34
|
+
}
|
|
35
|
+
this.frameElement = documents_1.DocumentElementFactory.createFrameElement({ size, position, style, clipContent });
|
|
36
|
+
this.frameElement.name = name;
|
|
37
|
+
}
|
|
38
|
+
toDocumentElements() {
|
|
39
|
+
const elements = [];
|
|
40
|
+
elements.push(this.frameElement);
|
|
41
|
+
const repositionedElements = [];
|
|
42
|
+
for (let element of util_1.ObjectUtil.cloneDeep(this.frameContentElements)) {
|
|
43
|
+
if (this.frameElement.position.x !== 0) {
|
|
44
|
+
if (element.type === 'line') {
|
|
45
|
+
element.lineDefinition.x1 += this.frameElement.position.x;
|
|
46
|
+
element.lineDefinition.x2 += this.frameElement.position.x;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
element.position.x += this.frameElement.position.x;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (this.frameElement.position.y !== 0) {
|
|
53
|
+
if (element.type === 'line') {
|
|
54
|
+
element.lineDefinition.y1 += this.frameElement.position.y;
|
|
55
|
+
element.lineDefinition.y2 += this.frameElement.position.y;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
element.position.y += this.frameElement.position.y;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
repositionedElements.push(element);
|
|
62
|
+
}
|
|
63
|
+
elements.push(...repositionedElements);
|
|
64
|
+
return elements;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.BoardFrame = BoardFrame;
|
|
@@ -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("./frame"), exports);
|
|
18
|
+
__exportStar(require("./frame-generator"), exports);
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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("./board-document-generator"), exports);
|
|
19
|
+
__exportStar(require("./showcase-frame-generator"), exports);
|
|
20
|
+
__exportStar(require("./interfaces"), exports);
|
|
21
|
+
__exportStar(require("./frames"), exports);
|
|
22
|
+
__exportStar(require("./util"), exports);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DocumentElement, PositionDefinition, SizeDefinition } from '@contrail/documents';
|
|
2
|
+
import { FrameInfoPanelTemplate } from '../interfaces';
|
|
3
|
+
export declare class InfoPanelGenerator {
|
|
4
|
+
static generatedModelBindings(data: any): any;
|
|
5
|
+
static generatePanelFromTemplate(data: any, template: FrameInfoPanelTemplate, position: PositionDefinition, panelSize: SizeDefinition): Array<DocumentElement>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 generatedModelBindings(data) {
|
|
9
|
+
const model = {};
|
|
10
|
+
if (data.item) {
|
|
11
|
+
model.item = `item:${data.item.id}`;
|
|
12
|
+
}
|
|
13
|
+
if (data.projectItem) {
|
|
14
|
+
model.projectItem = `project-item:${data.projectItem.id}`;
|
|
15
|
+
}
|
|
16
|
+
if (data.assortmentItem) {
|
|
17
|
+
model.assortmentItem = `assortment-item:${data.assortmentItem.id}`;
|
|
18
|
+
}
|
|
19
|
+
if (data.assortment) {
|
|
20
|
+
model.assortment = `assortment:${data.assortment.id}`;
|
|
21
|
+
}
|
|
22
|
+
return model;
|
|
23
|
+
}
|
|
24
|
+
static generatePanelFromTemplate(data, template, position, panelSize) {
|
|
25
|
+
var _a;
|
|
26
|
+
if (!template.propertyTemplate) {
|
|
27
|
+
throw Error('No panel property template defined');
|
|
28
|
+
}
|
|
29
|
+
const elements = [];
|
|
30
|
+
const panel = documents_1.DocumentElementFactory.createShapeElement('rectangle', {});
|
|
31
|
+
panel.style = ((_a = template.panelDocumentTemplate) === null || _a === void 0 ? void 0 : _a.style) || {};
|
|
32
|
+
panel.size = util_1.ObjectUtil.cloneDeep(panelSize) || {};
|
|
33
|
+
panel.position = util_1.ObjectUtil.cloneDeep(position);
|
|
34
|
+
elements.push(panel);
|
|
35
|
+
const modelBindings = this.generatedModelBindings(data);
|
|
36
|
+
const textOptions = {
|
|
37
|
+
style: {
|
|
38
|
+
text: {
|
|
39
|
+
align: template.propertyTemplate.textHorizontalAlignment,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
size: {
|
|
43
|
+
width: panelSize.width - 10,
|
|
44
|
+
},
|
|
45
|
+
modelBindings,
|
|
46
|
+
};
|
|
47
|
+
const textElements = document_property_util_1.DocumentPropertyUtil.generatePropertyElements(data, template.propertyTemplate.properties, textOptions, { x: panel.position.x, y: panel.position.y }, {}, false);
|
|
48
|
+
elements.push(...textElements);
|
|
49
|
+
return elements;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.InfoPanelGenerator = InfoPanelGenerator;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { DataGroupStructure } from '@contrail/data-grouping';
|
|
2
|
+
import { PositionDefinition, SizeDefinition, Document, DocumentElement, StyleDefinition } from '@contrail/documents';
|
|
3
|
+
import { TypeProperty } from '@contrail/types';
|
|
4
|
+
export declare enum Orientation {
|
|
5
|
+
HORIZONTAL = "horizontal",
|
|
6
|
+
VERTICAL = "vertical"
|
|
7
|
+
}
|
|
8
|
+
export interface DocumentGenerationDataDefinition {
|
|
9
|
+
dataGroup: DataGroupStructure;
|
|
10
|
+
}
|
|
11
|
+
export interface DocumentGenerationOptions {
|
|
12
|
+
startingCoordinates: PositionDefinition;
|
|
13
|
+
data: DocumentGenerationDataDefinition;
|
|
14
|
+
documentTemplateDefinition: DocumentTemplate;
|
|
15
|
+
frameTemplate?: FrameDocumentTemplate;
|
|
16
|
+
}
|
|
17
|
+
export interface DocumentTemplate {
|
|
18
|
+
frameOrientation: Orientation;
|
|
19
|
+
frameSize: SizeDefinition;
|
|
20
|
+
framePadding?: number;
|
|
21
|
+
frameGroupHeaderTemplate: DocumentElement;
|
|
22
|
+
secondaryFrameGroupHeaderTemplate?: DocumentElement;
|
|
23
|
+
frameHeaderTemplate?: DocumentElement;
|
|
24
|
+
frameInfoPanelTemplate?: FrameInfoPanelTemplate;
|
|
25
|
+
componentGridTemplate: ComponentGridTemplate;
|
|
26
|
+
}
|
|
27
|
+
export interface GridSpaceDefinition {
|
|
28
|
+
size: SizeDefinition;
|
|
29
|
+
position: PositionDefinition;
|
|
30
|
+
}
|
|
31
|
+
export interface FrameDocumentTemplate {
|
|
32
|
+
id: string;
|
|
33
|
+
templateType: 'FRAME' | 'BOARD';
|
|
34
|
+
document: Document;
|
|
35
|
+
gridSpaceDefinition: GridSpaceDefinition;
|
|
36
|
+
name: string;
|
|
37
|
+
clipContent: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface FrameInfoPanelTemplate {
|
|
40
|
+
panelDocumentTemplate: DocumentElement;
|
|
41
|
+
propertyTemplate: PanelPropertyTemplate;
|
|
42
|
+
}
|
|
43
|
+
export interface PanelPropertyTemplate {
|
|
44
|
+
textHorizontalAlignment?: 'center' | 'right' | 'left';
|
|
45
|
+
properties: Array<DocumentPropertyDefinition>;
|
|
46
|
+
}
|
|
47
|
+
export interface ComponentGridTemplate {
|
|
48
|
+
componentTemplate: ComponentTemplate;
|
|
49
|
+
componentPadding?: number;
|
|
50
|
+
gridDimensions: {
|
|
51
|
+
rows: number;
|
|
52
|
+
cols: number;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export interface ComponentTemplate {
|
|
56
|
+
propertyTemplate?: ComponentPropertyTemplate;
|
|
57
|
+
}
|
|
58
|
+
export interface ComponentPropertyTemplate {
|
|
59
|
+
imageDimension?: SizeDefinition;
|
|
60
|
+
imageLocation?: 'top' | 'right' | 'left' | 'bottom';
|
|
61
|
+
textHorizontalAlignment?: 'center' | 'right' | 'left';
|
|
62
|
+
properties: Array<DocumentPropertyDefinition>;
|
|
63
|
+
}
|
|
64
|
+
export interface DocumentPropertyDefinition {
|
|
65
|
+
style?: StyleDefinition;
|
|
66
|
+
propertyDefinition: TypeProperty;
|
|
67
|
+
slug: string;
|
|
68
|
+
typeRootSlug: string;
|
|
69
|
+
includeLabel?: boolean;
|
|
70
|
+
isHidden?: boolean;
|
|
71
|
+
size?: SizeDefinition;
|
|
72
|
+
}
|
|
@@ -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,230 @@
|
|
|
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 = 'nb-legacy-prod';
|
|
21
|
+
yield loginSDK(orgSlug);
|
|
22
|
+
const assortmentId = 'ejNEwWTgDPAtPoSY';
|
|
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 assortmentItemType = yield new sdk_1.Types().getType({ path: 'assortment-item' });
|
|
26
|
+
const PROPERTY_COMPONENT_TEMPLATE = {
|
|
27
|
+
imageDimension: { width: 600 },
|
|
28
|
+
imageLocation: 'top',
|
|
29
|
+
textHorizontalAlignment: 'center',
|
|
30
|
+
properties: [
|
|
31
|
+
{
|
|
32
|
+
propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'name'),
|
|
33
|
+
typeRootSlug: 'item',
|
|
34
|
+
slug: 'name',
|
|
35
|
+
style: {
|
|
36
|
+
font: {
|
|
37
|
+
size: 14,
|
|
38
|
+
weight: 'bold',
|
|
39
|
+
},
|
|
40
|
+
color: 'rgba(0,0,0,.5)',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'optionName'),
|
|
45
|
+
typeRootSlug: 'item',
|
|
46
|
+
slug: 'optionName',
|
|
47
|
+
style: {
|
|
48
|
+
font: {
|
|
49
|
+
size: 10,
|
|
50
|
+
weight: 'bold',
|
|
51
|
+
},
|
|
52
|
+
color: 'green',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
propertyDefinition: assortmentItemType.typeProperties.find((p) => p.slug === 'targetVolume'),
|
|
57
|
+
slug: 'targetVolume',
|
|
58
|
+
typeRootSlug: 'assortment-item',
|
|
59
|
+
includeLabel: true,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
const PANEL_PROPERTY_TEMPLATE = {
|
|
64
|
+
properties: [
|
|
65
|
+
{
|
|
66
|
+
propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'name'),
|
|
67
|
+
typeRootSlug: 'item',
|
|
68
|
+
slug: 'name',
|
|
69
|
+
includeLabel: false,
|
|
70
|
+
style: {
|
|
71
|
+
font: {
|
|
72
|
+
size: 25,
|
|
73
|
+
weight: 'bold',
|
|
74
|
+
},
|
|
75
|
+
color: 'white',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
const documentTemplateDefinition = {
|
|
81
|
+
frameOrientation: interfaces_1.Orientation.HORIZONTAL,
|
|
82
|
+
frameSize: { width: 1200, height: 675 },
|
|
83
|
+
framePadding: 30,
|
|
84
|
+
frameGroupHeaderTemplate: {
|
|
85
|
+
style: {
|
|
86
|
+
color: '#ffffff',
|
|
87
|
+
font: {
|
|
88
|
+
size: 20,
|
|
89
|
+
},
|
|
90
|
+
backgroundColor: 'rgba(0, 0, 0, 0.8)',
|
|
91
|
+
},
|
|
92
|
+
size: {
|
|
93
|
+
height: 60,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
frameInfoPanelTemplate: {
|
|
97
|
+
panelDocumentTemplate: {
|
|
98
|
+
style: {
|
|
99
|
+
color: '#ffffff',
|
|
100
|
+
font: {
|
|
101
|
+
size: 20,
|
|
102
|
+
},
|
|
103
|
+
backgroundColor: 'rgba(0, 0, 0, 0.8)',
|
|
104
|
+
border: {
|
|
105
|
+
radius: 4,
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
size: {
|
|
109
|
+
width: 250,
|
|
110
|
+
height: 400,
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
propertyTemplate: PANEL_PROPERTY_TEMPLATE,
|
|
114
|
+
},
|
|
115
|
+
componentGridTemplate: {
|
|
116
|
+
gridDimensions: { cols: 3, rows: 1 },
|
|
117
|
+
componentPadding: 5,
|
|
118
|
+
componentTemplate: {
|
|
119
|
+
propertyTemplate: PROPERTY_COMPONENT_TEMPLATE,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
const groupingProperties = [
|
|
124
|
+
{
|
|
125
|
+
propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'category'),
|
|
126
|
+
typeRootSlug: 'item',
|
|
127
|
+
sort: sdk_1.SortOrderOptions.ASC,
|
|
128
|
+
values: null,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
propertyDefinition: itemType.typeProperties.find((p) => p.slug === 'name'),
|
|
132
|
+
typeRootSlug: 'item',
|
|
133
|
+
sort: sdk_1.SortOrderOptions.ASC,
|
|
134
|
+
values: null,
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
documentTemplateDefinition.componentGridTemplate.componentTemplate.propertyTemplate = PROPERTY_COMPONENT_TEMPLATE;
|
|
138
|
+
const dataGroup = yield getDataGroupStructure(assortmentId, groupingProperties, documentTemplateDefinition);
|
|
139
|
+
const params = {
|
|
140
|
+
startingCoordinates: { x: 500, y: 500 },
|
|
141
|
+
data: {
|
|
142
|
+
dataGroup,
|
|
143
|
+
},
|
|
144
|
+
documentTemplateDefinition,
|
|
145
|
+
};
|
|
146
|
+
const elements = document_generator_1.DocumentGenerator.generateDocumentElements(params, {});
|
|
147
|
+
const documentId = (0, nanoid_1.nanoid)(16);
|
|
148
|
+
elements.forEach((el) => {
|
|
149
|
+
el.id = (0, nanoid_1.nanoid)(16);
|
|
150
|
+
});
|
|
151
|
+
const document = {
|
|
152
|
+
size: { width: 1600, height: 900 },
|
|
153
|
+
elements,
|
|
154
|
+
id: documentId,
|
|
155
|
+
};
|
|
156
|
+
yield uploadAndOpen(orgSlug, document);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function loginSDK(orgSlug) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
const config = {
|
|
162
|
+
email: 'brian@vibeiq.com',
|
|
163
|
+
password: process.env.CONTRAIL_PW,
|
|
164
|
+
orgSlug: orgSlug,
|
|
165
|
+
};
|
|
166
|
+
yield (0, sdk_1.login)(config);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function getAssortmentItems(assortmentId) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
const assortment = yield new sdk_1.Entities().get({
|
|
172
|
+
entityName: 'assortment',
|
|
173
|
+
id: assortmentId,
|
|
174
|
+
relations: ['assortmentItems', 'assortmentItems.item', 'assortmentItems.projectItem'],
|
|
175
|
+
});
|
|
176
|
+
let assortmentItems = assortment.assortmentItems;
|
|
177
|
+
if (assortment.itemsDownloadURL) {
|
|
178
|
+
const response = yield fetch(assortment.itemsDownloadURL);
|
|
179
|
+
assortmentItems = yield response.json();
|
|
180
|
+
}
|
|
181
|
+
return assortmentItems;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function getDataGroupStructure(assortmentId, groupingProperties, template) {
|
|
185
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
+
const assortmentItems = yield getAssortmentItems(assortmentId);
|
|
187
|
+
const data = fromAssortmentModelToItemModel(assortmentItems);
|
|
188
|
+
const leafNodeDataCount = template.componentGridTemplate.gridDimensions.cols * template.componentGridTemplate.gridDimensions.rows;
|
|
189
|
+
return data_grouping_1.DataGroupGenerator.buildDataGroupStructure(data, groupingProperties, leafNodeDataCount);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function fromAssortmentModelToItemModel(data) {
|
|
193
|
+
const results = [];
|
|
194
|
+
data.forEach((ai) => {
|
|
195
|
+
results.push({
|
|
196
|
+
item: ai.item,
|
|
197
|
+
projectItem: ai.projectItem,
|
|
198
|
+
viewable: ai.item,
|
|
199
|
+
assortmentItem: ai,
|
|
200
|
+
assortment: { id: ai.assortmentId },
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
return results;
|
|
204
|
+
}
|
|
205
|
+
function uploadAndOpen(orgSlug, document) {
|
|
206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
let config = (0, sdk_1.getConfig)();
|
|
208
|
+
var writeStream = fs.createWriteStream('testdocument.json');
|
|
209
|
+
writeStream.write(JSON.stringify(document));
|
|
210
|
+
writeStream.end();
|
|
211
|
+
const file = fs.createReadStream('testdocument.json');
|
|
212
|
+
const fileEntity = yield new sdk_1.Files().createAndUploadFileFromBuffer(file, 'application/json', 'testdocument.json', null, 300);
|
|
213
|
+
const domain = 'http://preview.vibeiq.com';
|
|
214
|
+
const authToken = config.apiUserToken;
|
|
215
|
+
const documentType = 'board';
|
|
216
|
+
let url = domain +
|
|
217
|
+
'?url=' +
|
|
218
|
+
encodeURIComponent(fileEntity.downloadUrl) +
|
|
219
|
+
'&orgSlug=' +
|
|
220
|
+
encodeURIComponent(orgSlug) +
|
|
221
|
+
'&apiToken=' +
|
|
222
|
+
encodeURIComponent(authToken) +
|
|
223
|
+
'&documentType=' +
|
|
224
|
+
encodeURIComponent(documentType);
|
|
225
|
+
var start = process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open';
|
|
226
|
+
const encodedUrl = url.replace(/&/g, '^&');
|
|
227
|
+
require('child_process').exec(start + ' ' + encodedUrl);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
run();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|