@elisra-devops/docgen-skins 0.3.4 → 0.4.0
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/.github/sonar-project.properties +4 -4
- package/.github/workflows/ci.yml +23 -18
- package/.github/workflows/release.yml +47 -45
- package/Readme.md +6 -6
- package/bin/index.d.ts +15 -0
- package/bin/index.js +277 -0
- package/bin/index.js.map +1 -0
- package/bin/models/json/JSONRun.d.ts +7 -0
- package/bin/models/json/JSONRun.js +84 -0
- package/bin/models/json/JSONRun.js.map +1 -0
- package/bin/models/json/default.d.ts +3 -0
- package/bin/models/json/default.js +25 -0
- package/bin/models/json/default.js.map +1 -0
- package/bin/models/json/html/JSONHtml.d.ts +6 -0
- package/bin/models/json/html/JSONHtml.js +13 -0
- package/bin/models/json/html/JSONHtml.js.map +1 -0
- package/bin/models/json/paragraph/JSONParagraph.d.ts +9 -0
- package/bin/models/json/paragraph/JSONParagraph.js +62 -0
- package/bin/models/json/paragraph/JSONParagraph.js.map +1 -0
- package/bin/models/json/paragraph/JSONRichTextParagraph.d.ts +9 -0
- package/bin/models/json/paragraph/JSONRichTextParagraph.js +72 -0
- package/bin/models/json/paragraph/JSONRichTextParagraph.js.map +1 -0
- package/bin/models/json/paragraph/JSONTestSuiteHeaderParagraph.d.ts +10 -0
- package/bin/models/json/paragraph/JSONTestSuiteHeaderParagraph.js +76 -0
- package/bin/models/json/paragraph/JSONTestSuiteHeaderParagraph.js.map +1 -0
- package/bin/models/json/table/JSONTable.d.ts +9 -0
- package/bin/models/json/table/JSONTable.js +60 -0
- package/bin/models/json/table/JSONTable.js.map +1 -0
- package/bin/models/json/table/JSONTableCell.d.ts +8 -0
- package/bin/models/json/table/JSONTableCell.js +105 -0
- package/bin/models/json/table/JSONTableCell.js.map +1 -0
- package/bin/models/json/table/JSONTableRow.d.ts +7 -0
- package/bin/models/json/table/JSONTableRow.js +27 -0
- package/bin/models/json/table/JSONTableRow.js.map +1 -0
- package/bin/models/json/wordJsonModels.d.ts +97 -0
- package/bin/models/json/wordJsonModels.js +3 -0
- package/bin/models/json/wordJsonModels.js.map +1 -0
- package/bin/services/logger.d.ts +3 -0
- package/bin/services/logger.js +46 -0
- package/bin/services/logger.js.map +1 -0
- package/bin/snippets/free-runs.d.ts +1 -0
- package/bin/snippets/free-runs.js +58 -0
- package/bin/snippets/free-runs.js.map +1 -0
- package/bin/test/skins.test.d.ts +1 -0
- package/bin/test/skins.test.js +116 -0
- package/bin/test/skins.test.js.map +1 -0
- package/package.json +46 -46
- package/samples/document-skins-examples/document-attchament-table.json +25 -25
- package/samples/document-skins-examples/documentExample.json +66 -66
- package/samples/document-skins-examples/paragraphExample.json +16 -16
- package/samples/document-skins-examples/tableExample.json +29 -29
- package/src/index.ts +338 -401
- package/src/models/json/JSONRun.ts +80 -80
- package/src/models/json/default.ts +23 -23
- package/src/models/json/html/JSONHtml.ts +13 -13
- package/src/models/json/paragraph/JSONParagraph.ts +76 -76
- package/src/models/json/paragraph/JSONRichTextParagraph.ts +84 -84
- package/src/models/json/paragraph/JSONTestSuiteHeaderParagraph.ts +94 -94
- package/src/models/json/table/JSONTable.ts +74 -74
- package/src/models/json/table/JSONTableCell.ts +117 -117
- package/src/models/json/table/JSONTableRow.ts +34 -34
- package/src/models/json/wordJsonModels.ts +97 -97
- package/src/services/logger.ts +26 -26
- package/src/snippets/free-runs.ts +53 -53
- package/src/test/skins.test.ts +171 -171
- package/tsconfig.json +61 -61
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Paragraph,
|
|
3
|
-
Run,
|
|
4
|
-
WIData,
|
|
5
|
-
WIProperty,
|
|
6
|
-
StyleOptions,
|
|
7
|
-
} from "../wordJsonModels";
|
|
8
|
-
import JSONRun from "../JSONRun";
|
|
9
|
-
|
|
10
|
-
export default class JSONTestSuiteHeaderParagraph {
|
|
11
|
-
paragraphStyles: StyleOptions;
|
|
12
|
-
paragraphTemplate: Paragraph;
|
|
13
|
-
wiId: number;
|
|
14
|
-
|
|
15
|
-
constructor(
|
|
16
|
-
fields: WIProperty[],
|
|
17
|
-
paragraphStyles: StyleOptions,
|
|
18
|
-
wiId: number,
|
|
19
|
-
headingLevel: number
|
|
20
|
-
) {
|
|
21
|
-
this.paragraphStyles = paragraphStyles;
|
|
22
|
-
this.wiId = wiId;
|
|
23
|
-
this.paragraphTemplate = {
|
|
24
|
-
type: "paragraph",
|
|
25
|
-
runs: this.generateJsonParagraphHeaderRuns(fields, this.paragraphStyles),
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
if (headingLevel) {
|
|
29
|
-
this.paragraphTemplate.headingLevel = headingLevel;
|
|
30
|
-
} else {
|
|
31
|
-
this.paragraphTemplate.headingLevel = 0;
|
|
32
|
-
}
|
|
33
|
-
} //constructor
|
|
34
|
-
|
|
35
|
-
generateJsonParagraphHeaderRuns(fields, paragraphStyles) {
|
|
36
|
-
let runs: any = [];
|
|
37
|
-
fields.forEach((field) => {
|
|
38
|
-
runs = [
|
|
39
|
-
...runs,
|
|
40
|
-
...this.generateJsonParagraphRun(field, this.paragraphStyles),
|
|
41
|
-
];
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
return runs;
|
|
45
|
-
}
|
|
46
|
-
generateJsonParagraphRun(field: WIProperty, paragraphStyles): Run[] {
|
|
47
|
-
let jsonRun: JSONRun;
|
|
48
|
-
let runs: Run[] = [];
|
|
49
|
-
let titleStyle = JSON.parse(JSON.stringify(paragraphStyles));
|
|
50
|
-
|
|
51
|
-
titleStyle.isBold = false;
|
|
52
|
-
titleStyle.IsUnderline = true;
|
|
53
|
-
titleStyle.InsertSpace = true;
|
|
54
|
-
titleStyle.InsertLineBreak = false;
|
|
55
|
-
//adds ':' to field titles
|
|
56
|
-
if (field.name !== "") {
|
|
57
|
-
field.name += ": ";
|
|
58
|
-
}
|
|
59
|
-
//exclude titles for fields that only show values
|
|
60
|
-
if (
|
|
61
|
-
field.name !== "Title: " &&
|
|
62
|
-
field.name !== "ID: " &&
|
|
63
|
-
field.name !== "Description: "
|
|
64
|
-
) {
|
|
65
|
-
paragraphStyles.Uri = field.url;
|
|
66
|
-
jsonRun = new JSONRun(field.name, titleStyle);
|
|
67
|
-
runs = [...runs, ...jsonRun.runs];
|
|
68
|
-
|
|
69
|
-
paragraphStyles.InsertLineBreak = false;
|
|
70
|
-
} //end if
|
|
71
|
-
|
|
72
|
-
if (field.name === "ID: ") {
|
|
73
|
-
field.value = `${field.value}`;
|
|
74
|
-
paragraphStyles.Uri = field.url;
|
|
75
|
-
paragraphStyles.InsertLineBreak = false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (field.name === "Title: ") {
|
|
79
|
-
let fieldtype = "SuiteHeaderParagraphTitle";
|
|
80
|
-
paragraphStyles.InsertLineBreak = false;
|
|
81
|
-
paragraphStyles.Uri = field.url;
|
|
82
|
-
jsonRun = new JSONRun(field.value, paragraphStyles, fieldtype);
|
|
83
|
-
runs = [...runs, ...jsonRun.runs];
|
|
84
|
-
} else {
|
|
85
|
-
jsonRun = new JSONRun(field.value, paragraphStyles);
|
|
86
|
-
runs = [...runs, ...jsonRun.runs];
|
|
87
|
-
}
|
|
88
|
-
return runs;
|
|
89
|
-
} //generateJsonParagraph
|
|
90
|
-
|
|
91
|
-
getJSONParagraph(): Paragraph {
|
|
92
|
-
return this.paragraphTemplate;
|
|
93
|
-
} //getJSONTable
|
|
94
|
-
} //class
|
|
1
|
+
import {
|
|
2
|
+
Paragraph,
|
|
3
|
+
Run,
|
|
4
|
+
WIData,
|
|
5
|
+
WIProperty,
|
|
6
|
+
StyleOptions,
|
|
7
|
+
} from "../wordJsonModels";
|
|
8
|
+
import JSONRun from "../JSONRun";
|
|
9
|
+
|
|
10
|
+
export default class JSONTestSuiteHeaderParagraph {
|
|
11
|
+
paragraphStyles: StyleOptions;
|
|
12
|
+
paragraphTemplate: Paragraph;
|
|
13
|
+
wiId: number;
|
|
14
|
+
|
|
15
|
+
constructor(
|
|
16
|
+
fields: WIProperty[],
|
|
17
|
+
paragraphStyles: StyleOptions,
|
|
18
|
+
wiId: number,
|
|
19
|
+
headingLevel: number
|
|
20
|
+
) {
|
|
21
|
+
this.paragraphStyles = paragraphStyles;
|
|
22
|
+
this.wiId = wiId;
|
|
23
|
+
this.paragraphTemplate = {
|
|
24
|
+
type: "paragraph",
|
|
25
|
+
runs: this.generateJsonParagraphHeaderRuns(fields, this.paragraphStyles),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if (headingLevel) {
|
|
29
|
+
this.paragraphTemplate.headingLevel = headingLevel;
|
|
30
|
+
} else {
|
|
31
|
+
this.paragraphTemplate.headingLevel = 0;
|
|
32
|
+
}
|
|
33
|
+
} //constructor
|
|
34
|
+
|
|
35
|
+
generateJsonParagraphHeaderRuns(fields, paragraphStyles) {
|
|
36
|
+
let runs: any = [];
|
|
37
|
+
fields.forEach((field) => {
|
|
38
|
+
runs = [
|
|
39
|
+
...runs,
|
|
40
|
+
...this.generateJsonParagraphRun(field, this.paragraphStyles),
|
|
41
|
+
];
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return runs;
|
|
45
|
+
}
|
|
46
|
+
generateJsonParagraphRun(field: WIProperty, paragraphStyles): Run[] {
|
|
47
|
+
let jsonRun: JSONRun;
|
|
48
|
+
let runs: Run[] = [];
|
|
49
|
+
let titleStyle = JSON.parse(JSON.stringify(paragraphStyles));
|
|
50
|
+
|
|
51
|
+
titleStyle.isBold = false;
|
|
52
|
+
titleStyle.IsUnderline = true;
|
|
53
|
+
titleStyle.InsertSpace = true;
|
|
54
|
+
titleStyle.InsertLineBreak = false;
|
|
55
|
+
//adds ':' to field titles
|
|
56
|
+
if (field.name !== "") {
|
|
57
|
+
field.name += ": ";
|
|
58
|
+
}
|
|
59
|
+
//exclude titles for fields that only show values
|
|
60
|
+
if (
|
|
61
|
+
field.name !== "Title: " &&
|
|
62
|
+
field.name !== "ID: " &&
|
|
63
|
+
field.name !== "Description: "
|
|
64
|
+
) {
|
|
65
|
+
paragraphStyles.Uri = field.url;
|
|
66
|
+
jsonRun = new JSONRun(field.name, titleStyle);
|
|
67
|
+
runs = [...runs, ...jsonRun.runs];
|
|
68
|
+
|
|
69
|
+
paragraphStyles.InsertLineBreak = false;
|
|
70
|
+
} //end if
|
|
71
|
+
|
|
72
|
+
if (field.name === "ID: ") {
|
|
73
|
+
field.value = `${field.value}`;
|
|
74
|
+
paragraphStyles.Uri = field.url;
|
|
75
|
+
paragraphStyles.InsertLineBreak = false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (field.name === "Title: ") {
|
|
79
|
+
let fieldtype = "SuiteHeaderParagraphTitle";
|
|
80
|
+
paragraphStyles.InsertLineBreak = false;
|
|
81
|
+
paragraphStyles.Uri = field.url;
|
|
82
|
+
jsonRun = new JSONRun(field.value, paragraphStyles, fieldtype);
|
|
83
|
+
runs = [...runs, ...jsonRun.runs];
|
|
84
|
+
} else {
|
|
85
|
+
jsonRun = new JSONRun(field.value, paragraphStyles);
|
|
86
|
+
runs = [...runs, ...jsonRun.runs];
|
|
87
|
+
}
|
|
88
|
+
return runs;
|
|
89
|
+
} //generateJsonParagraph
|
|
90
|
+
|
|
91
|
+
getJSONParagraph(): Paragraph {
|
|
92
|
+
return this.paragraphTemplate;
|
|
93
|
+
} //getJSONTable
|
|
94
|
+
} //class
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import logger from "../../../services/logger";
|
|
2
|
-
import {
|
|
3
|
-
Table,
|
|
4
|
-
TableRow,
|
|
5
|
-
WIQueryResults,
|
|
6
|
-
WIData,
|
|
7
|
-
WIProperty,
|
|
8
|
-
StyleOptions,
|
|
9
|
-
} from "../wordJsonModels";
|
|
10
|
-
import JSONTableRow from "./JSONTableRow";
|
|
11
|
-
export default class JSONTable {
|
|
12
|
-
tableTemplate: Table;
|
|
13
|
-
tableStyles: StyleOptions;
|
|
14
|
-
|
|
15
|
-
constructor(
|
|
16
|
-
data: WIQueryResults,
|
|
17
|
-
tableStyles: StyleOptions,
|
|
18
|
-
headingLvl: number
|
|
19
|
-
) {
|
|
20
|
-
this.tableStyles = tableStyles;
|
|
21
|
-
this.tableTemplate = {
|
|
22
|
-
type: "table",
|
|
23
|
-
headingLevel: headingLvl,
|
|
24
|
-
Rows: this.generateJsonRows(data, this.tableStyles),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
generateJsonRows(data: any, tableStyles: StyleOptions): TableRow[] {
|
|
29
|
-
let rows: TableRow[] = [];
|
|
30
|
-
let headersRowData: WIData = this.headersRowAdapter(data[0]);
|
|
31
|
-
|
|
32
|
-
let style2 = {
|
|
33
|
-
isBold: true,
|
|
34
|
-
IsItalic: false,
|
|
35
|
-
IsUnderline: false,
|
|
36
|
-
Size: 12,
|
|
37
|
-
Uri: null,
|
|
38
|
-
Font: "Arial",
|
|
39
|
-
InsertLineBreak: false,
|
|
40
|
-
InsertSpace: false,
|
|
41
|
-
};
|
|
42
|
-
let headersRow = new JSONTableRow(headersRowData, style2);
|
|
43
|
-
|
|
44
|
-
rows.push(headersRow.getRow());
|
|
45
|
-
|
|
46
|
-
data.forEach((rowData: WIData) => {
|
|
47
|
-
let row = new JSONTableRow(rowData, tableStyles);
|
|
48
|
-
rows.push(row.getRow());
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
return rows;
|
|
52
|
-
} //generateJsonRows
|
|
53
|
-
|
|
54
|
-
headersRowAdapter(data: WIData): WIData {
|
|
55
|
-
let headerValuesWi;
|
|
56
|
-
try {
|
|
57
|
-
headerValuesWi = data.fields.map((field: WIProperty) => {
|
|
58
|
-
return { name: "header", value: field.name };
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
} catch (error) {
|
|
62
|
-
logger.error(`no fields to append`);
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
url: "",
|
|
66
|
-
fields: headerValuesWi,
|
|
67
|
-
Source: 999999999999,
|
|
68
|
-
level: data.level,
|
|
69
|
-
};
|
|
70
|
-
} //headersRowAdapter
|
|
71
|
-
|
|
72
|
-
getJSONTable(): Table {
|
|
73
|
-
return this.tableTemplate;
|
|
74
|
-
} //getJSONTable
|
|
1
|
+
import logger from "../../../services/logger";
|
|
2
|
+
import {
|
|
3
|
+
Table,
|
|
4
|
+
TableRow,
|
|
5
|
+
WIQueryResults,
|
|
6
|
+
WIData,
|
|
7
|
+
WIProperty,
|
|
8
|
+
StyleOptions,
|
|
9
|
+
} from "../wordJsonModels";
|
|
10
|
+
import JSONTableRow from "./JSONTableRow";
|
|
11
|
+
export default class JSONTable {
|
|
12
|
+
tableTemplate: Table;
|
|
13
|
+
tableStyles: StyleOptions;
|
|
14
|
+
|
|
15
|
+
constructor(
|
|
16
|
+
data: WIQueryResults,
|
|
17
|
+
tableStyles: StyleOptions,
|
|
18
|
+
headingLvl: number
|
|
19
|
+
) {
|
|
20
|
+
this.tableStyles = tableStyles;
|
|
21
|
+
this.tableTemplate = {
|
|
22
|
+
type: "table",
|
|
23
|
+
headingLevel: headingLvl,
|
|
24
|
+
Rows: this.generateJsonRows(data, this.tableStyles),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
generateJsonRows(data: any, tableStyles: StyleOptions): TableRow[] {
|
|
29
|
+
let rows: TableRow[] = [];
|
|
30
|
+
let headersRowData: WIData = this.headersRowAdapter(data[0]);
|
|
31
|
+
|
|
32
|
+
let style2 = {
|
|
33
|
+
isBold: true,
|
|
34
|
+
IsItalic: false,
|
|
35
|
+
IsUnderline: false,
|
|
36
|
+
Size: 12,
|
|
37
|
+
Uri: null,
|
|
38
|
+
Font: "Arial",
|
|
39
|
+
InsertLineBreak: false,
|
|
40
|
+
InsertSpace: false,
|
|
41
|
+
};
|
|
42
|
+
let headersRow = new JSONTableRow(headersRowData, style2);
|
|
43
|
+
|
|
44
|
+
rows.push(headersRow.getRow());
|
|
45
|
+
|
|
46
|
+
data.forEach((rowData: WIData) => {
|
|
47
|
+
let row = new JSONTableRow(rowData, tableStyles);
|
|
48
|
+
rows.push(row.getRow());
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return rows;
|
|
52
|
+
} //generateJsonRows
|
|
53
|
+
|
|
54
|
+
headersRowAdapter(data: WIData): WIData {
|
|
55
|
+
let headerValuesWi;
|
|
56
|
+
try {
|
|
57
|
+
headerValuesWi = data.fields.map((field: WIProperty) => {
|
|
58
|
+
return { name: "header", value: field.name };
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
} catch (error) {
|
|
62
|
+
logger.error(`no fields to append`);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
url: "",
|
|
66
|
+
fields: headerValuesWi,
|
|
67
|
+
Source: 999999999999,
|
|
68
|
+
level: data.level,
|
|
69
|
+
};
|
|
70
|
+
} //headersRowAdapter
|
|
71
|
+
|
|
72
|
+
getJSONTable(): Table {
|
|
73
|
+
return this.tableTemplate;
|
|
74
|
+
} //getJSONTable
|
|
75
75
|
} //class
|
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
import { extname } from "path";
|
|
2
|
-
import {
|
|
3
|
-
TableCell,
|
|
4
|
-
Run,
|
|
5
|
-
Attachment,
|
|
6
|
-
WIProperty,
|
|
7
|
-
MultipeValuesWIProperty,
|
|
8
|
-
StyleOptions,
|
|
9
|
-
JsonHtml,
|
|
10
|
-
} from "../wordJsonModels";
|
|
11
|
-
import JSONRun from "../JSONRun";
|
|
12
|
-
import logger from "../../../services/logger";
|
|
13
|
-
|
|
14
|
-
export default class JSONTableCell {
|
|
15
|
-
cell: TableCell;
|
|
16
|
-
constructor(data: WIProperty, tableStyles: StyleOptions) {
|
|
17
|
-
this.cell = this.generateJsonCell(data, tableStyles);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
generateJsonCell(
|
|
21
|
-
data: WIProperty | MultipeValuesWIProperty,
|
|
22
|
-
styles
|
|
23
|
-
): TableCell {
|
|
24
|
-
let runs: Run[] = [];
|
|
25
|
-
let attachments: Attachment[] = [];
|
|
26
|
-
let HtmlData: string = ""
|
|
27
|
-
|
|
28
|
-
//multiple values
|
|
29
|
-
if (
|
|
30
|
-
typeof data.value !== "string" &&
|
|
31
|
-
typeof data.value !== "number" &&
|
|
32
|
-
data.value
|
|
33
|
-
) {
|
|
34
|
-
data.value.forEach((runData) => {
|
|
35
|
-
//check if photo type
|
|
36
|
-
if (this.isPictureUri(runData.tableCellAttachmentLink)) {
|
|
37
|
-
let attachment = {
|
|
38
|
-
type: "Picture",
|
|
39
|
-
path: runData.tableCellAttachmentLink,
|
|
40
|
-
};
|
|
41
|
-
attachments.push(attachment);
|
|
42
|
-
}
|
|
43
|
-
else if(/<[^>]*>/.test(runData.value)) {
|
|
44
|
-
HtmlData = runData.value || "";
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
styles.Uri = runData.relativeUrl
|
|
48
|
-
? runData.relativeUrl
|
|
49
|
-
: runData.Uri
|
|
50
|
-
? runData.Uri
|
|
51
|
-
: null;
|
|
52
|
-
styles.InsertLineBreak = false;
|
|
53
|
-
let jsonRun = new JSONRun(runData.value, styles);
|
|
54
|
-
runs = [...runs, ...jsonRun.getRun()];
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
else if(/<[^>]*>/.test(data.value)) {
|
|
59
|
-
HtmlData = data.value || "";
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
styles.Uri = data.relativeUrl
|
|
63
|
-
? data.relativeUrl
|
|
64
|
-
: data.url
|
|
65
|
-
? data.url
|
|
66
|
-
: null;
|
|
67
|
-
let text = data.value || "";
|
|
68
|
-
let jsonRun = new JSONRun(`${text}`, styles);
|
|
69
|
-
runs = [...runs, ...jsonRun.getRun()];
|
|
70
|
-
}
|
|
71
|
-
if (HtmlData!= "")
|
|
72
|
-
{
|
|
73
|
-
let Html:JsonHtml = {
|
|
74
|
-
type:"html",
|
|
75
|
-
Html:HtmlData
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
attachments: attachments,
|
|
79
|
-
Paragraphs: [
|
|
80
|
-
{
|
|
81
|
-
Runs: runs,
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
Html
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
else{
|
|
88
|
-
return {
|
|
89
|
-
attachments: attachments,
|
|
90
|
-
Paragraphs: [
|
|
91
|
-
{
|
|
92
|
-
Runs: runs,
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
} //generateJsonCells
|
|
98
|
-
|
|
99
|
-
isPictureUri(uri: string) {
|
|
100
|
-
try {
|
|
101
|
-
let fileExt = extname(uri);
|
|
102
|
-
logger.debug(`attachment extension: ${fileExt}`);
|
|
103
|
-
if (fileExt == ".PNG" || fileExt == ".jpg") {
|
|
104
|
-
return true;
|
|
105
|
-
} else {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
} catch (e) {
|
|
109
|
-
logger.error(`error parsing file extension for : ${uri}`);
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
getJsonCell(): TableCell {
|
|
115
|
-
return this.cell;
|
|
116
|
-
}
|
|
117
|
-
} //class
|
|
1
|
+
import { extname } from "path";
|
|
2
|
+
import {
|
|
3
|
+
TableCell,
|
|
4
|
+
Run,
|
|
5
|
+
Attachment,
|
|
6
|
+
WIProperty,
|
|
7
|
+
MultipeValuesWIProperty,
|
|
8
|
+
StyleOptions,
|
|
9
|
+
JsonHtml,
|
|
10
|
+
} from "../wordJsonModels";
|
|
11
|
+
import JSONRun from "../JSONRun";
|
|
12
|
+
import logger from "../../../services/logger";
|
|
13
|
+
|
|
14
|
+
export default class JSONTableCell {
|
|
15
|
+
cell: TableCell;
|
|
16
|
+
constructor(data: WIProperty, tableStyles: StyleOptions) {
|
|
17
|
+
this.cell = this.generateJsonCell(data, tableStyles);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
generateJsonCell(
|
|
21
|
+
data: WIProperty | MultipeValuesWIProperty,
|
|
22
|
+
styles
|
|
23
|
+
): TableCell {
|
|
24
|
+
let runs: Run[] = [];
|
|
25
|
+
let attachments: Attachment[] = [];
|
|
26
|
+
let HtmlData: string = ""
|
|
27
|
+
|
|
28
|
+
//multiple values
|
|
29
|
+
if (
|
|
30
|
+
typeof data.value !== "string" &&
|
|
31
|
+
typeof data.value !== "number" &&
|
|
32
|
+
data.value
|
|
33
|
+
) {
|
|
34
|
+
data.value.forEach((runData) => {
|
|
35
|
+
//check if photo type
|
|
36
|
+
if (this.isPictureUri(runData.tableCellAttachmentLink)) {
|
|
37
|
+
let attachment = {
|
|
38
|
+
type: "Picture",
|
|
39
|
+
path: runData.tableCellAttachmentLink,
|
|
40
|
+
};
|
|
41
|
+
attachments.push(attachment);
|
|
42
|
+
}
|
|
43
|
+
else if(/<[^>]*>/.test(runData.value)) {
|
|
44
|
+
HtmlData = runData.value || "";
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
styles.Uri = runData.relativeUrl
|
|
48
|
+
? runData.relativeUrl
|
|
49
|
+
: runData.Uri
|
|
50
|
+
? runData.Uri
|
|
51
|
+
: null;
|
|
52
|
+
styles.InsertLineBreak = false;
|
|
53
|
+
let jsonRun = new JSONRun(runData.value, styles);
|
|
54
|
+
runs = [...runs, ...jsonRun.getRun()];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else if(/<[^>]*>/.test(data.value)) {
|
|
59
|
+
HtmlData = data.value || "";
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
styles.Uri = data.relativeUrl
|
|
63
|
+
? data.relativeUrl
|
|
64
|
+
: data.url
|
|
65
|
+
? data.url
|
|
66
|
+
: null;
|
|
67
|
+
let text = data.value || "";
|
|
68
|
+
let jsonRun = new JSONRun(`${text}`, styles);
|
|
69
|
+
runs = [...runs, ...jsonRun.getRun()];
|
|
70
|
+
}
|
|
71
|
+
if (HtmlData!= "")
|
|
72
|
+
{
|
|
73
|
+
let Html:JsonHtml = {
|
|
74
|
+
type:"html",
|
|
75
|
+
Html:HtmlData
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
attachments: attachments,
|
|
79
|
+
Paragraphs: [
|
|
80
|
+
{
|
|
81
|
+
Runs: runs,
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
Html
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
else{
|
|
88
|
+
return {
|
|
89
|
+
attachments: attachments,
|
|
90
|
+
Paragraphs: [
|
|
91
|
+
{
|
|
92
|
+
Runs: runs,
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
} //generateJsonCells
|
|
98
|
+
|
|
99
|
+
isPictureUri(uri: string) {
|
|
100
|
+
try {
|
|
101
|
+
let fileExt = extname(uri);
|
|
102
|
+
logger.debug(`attachment extension: ${fileExt}`);
|
|
103
|
+
if (fileExt == ".PNG" || fileExt == ".jpg") {
|
|
104
|
+
return true;
|
|
105
|
+
} else {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
} catch (e) {
|
|
109
|
+
logger.error(`error parsing file extension for : ${uri}`);
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
getJsonCell(): TableCell {
|
|
115
|
+
return this.cell;
|
|
116
|
+
}
|
|
117
|
+
} //class
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TableRow,
|
|
3
|
-
TableCell,
|
|
4
|
-
WIData,
|
|
5
|
-
WIProperty,
|
|
6
|
-
StyleOptions
|
|
7
|
-
} from "../wordJsonModels";
|
|
8
|
-
import JSONTableCell from "./JSONTableCell";
|
|
9
|
-
|
|
10
|
-
export default class JSONTableRow {
|
|
11
|
-
row: TableRow;
|
|
12
|
-
|
|
13
|
-
constructor(data: WIData, tableStyles: StyleOptions) {
|
|
14
|
-
this.row = this.generateJsonRow(data, tableStyles);
|
|
15
|
-
} //constructor
|
|
16
|
-
|
|
17
|
-
generateJsonRow(data: WIData, styles: StyleOptions): TableRow {
|
|
18
|
-
let tableCells: TableCell[] = [];
|
|
19
|
-
|
|
20
|
-
data.fields.forEach((wiProperty: WIProperty) => {
|
|
21
|
-
if (wiProperty.name === "id") {
|
|
22
|
-
styles.Uri = data.url;
|
|
23
|
-
}
|
|
24
|
-
let jsonTableCell = new JSONTableCell(wiProperty, styles);
|
|
25
|
-
tableCells.push(JSON.parse(JSON.stringify(jsonTableCell.getJsonCell())));
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
return { Cells: tableCells };
|
|
29
|
-
} //generateJsonRow
|
|
30
|
-
|
|
31
|
-
getRow(): TableRow {
|
|
32
|
-
return this.row;
|
|
33
|
-
} //getRow
|
|
34
|
-
} //class
|
|
1
|
+
import {
|
|
2
|
+
TableRow,
|
|
3
|
+
TableCell,
|
|
4
|
+
WIData,
|
|
5
|
+
WIProperty,
|
|
6
|
+
StyleOptions
|
|
7
|
+
} from "../wordJsonModels";
|
|
8
|
+
import JSONTableCell from "./JSONTableCell";
|
|
9
|
+
|
|
10
|
+
export default class JSONTableRow {
|
|
11
|
+
row: TableRow;
|
|
12
|
+
|
|
13
|
+
constructor(data: WIData, tableStyles: StyleOptions) {
|
|
14
|
+
this.row = this.generateJsonRow(data, tableStyles);
|
|
15
|
+
} //constructor
|
|
16
|
+
|
|
17
|
+
generateJsonRow(data: WIData, styles: StyleOptions): TableRow {
|
|
18
|
+
let tableCells: TableCell[] = [];
|
|
19
|
+
|
|
20
|
+
data.fields.forEach((wiProperty: WIProperty) => {
|
|
21
|
+
if (wiProperty.name === "id") {
|
|
22
|
+
styles.Uri = data.url;
|
|
23
|
+
}
|
|
24
|
+
let jsonTableCell = new JSONTableCell(wiProperty, styles);
|
|
25
|
+
tableCells.push(JSON.parse(JSON.stringify(jsonTableCell.getJsonCell())));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return { Cells: tableCells };
|
|
29
|
+
} //generateJsonRow
|
|
30
|
+
|
|
31
|
+
getRow(): TableRow {
|
|
32
|
+
return this.row;
|
|
33
|
+
} //getRow
|
|
34
|
+
} //class
|