@legalplace/prerenderx 3.2.1 → 3.3.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/.eslintrc +3 -47
- package/CHANGELOG.md +21 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/libs/DocumentRender.d.ts +4 -4
- package/dist/libs/DocumentRender.js +2 -2
- package/dist/libs/FillPdfForm.d.ts +1 -1
- package/dist/libs/FillPdfForm.js +30 -24
- package/dist/libs/InputsInitiator.d.ts +1 -1
- package/dist/libs/InputsInitiator.js +35 -11
- package/dist/libs/NumAuto.js +1 -1
- package/dist/libs/OptionRender.d.ts +4 -4
- package/dist/libs/OptionRender.js +30 -18
- package/dist/libs/OutputParser.d.ts +2 -2
- package/dist/libs/OutputParser.js +34 -25
- package/dist/libs/Prerender.d.ts +8 -8
- package/dist/libs/Prerender.js +29 -22
- package/dist/libs/SectionRender.d.ts +4 -4
- package/dist/libs/SectionRender.js +22 -13
- package/dist/libs/misc/FillPdfFormBase.d.ts +3 -3
- package/dist/libs/misc/FillPdfFormBase.js +25 -17
- package/package.json +14 -18
- package/src/index.ts +3 -3
- package/src/libs/DocumentRender.ts +27 -22
- package/src/libs/FillPdfForm.ts +72 -59
- package/src/libs/InputsInitiator.ts +91 -53
- package/src/libs/NumAuto.ts +16 -14
- package/src/libs/OptionRender.ts +85 -45
- package/src/libs/OutputParser.ts +112 -58
- package/src/libs/Prerender.ts +119 -75
- package/src/libs/SectionRender.ts +57 -38
- package/src/libs/misc/FillPdfFormBase.ts +71 -39
- package/src/types/types.ts +17 -14
- package/tsconfig.json +3 -1
- package/.gitlab-ci.yml +0 -43
- package/.prettierrc.js +0 -10
- package/.vscode/settings.json +0 -17
- package/.vscode/tasks.json +0 -24
- package/tsconfig.eslint.json +0 -12
package/src/libs/OutputParser.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { Types } from
|
|
2
|
-
import InputsType from
|
|
3
|
-
|
|
1
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Parses number to correct french number format ("," instead of ".")
|
|
7
6
|
*/
|
|
8
7
|
const frenchNumber = (value: string | number) => {
|
|
9
|
-
let result = typeof value ===
|
|
8
|
+
let result = typeof value === "number" ? value.toString() : value;
|
|
10
9
|
if (/^([0-9]+)\.([0-9]+)$/.test(result.trim()))
|
|
11
|
-
result = result.trim().replace(
|
|
10
|
+
result = result.trim().replace(".", ",");
|
|
12
11
|
return result;
|
|
13
12
|
};
|
|
14
13
|
|
|
@@ -18,43 +17,67 @@ const frenchNumber = (value: string | number) => {
|
|
|
18
17
|
* @param index Occurency index
|
|
19
18
|
* @param variables Variables ids list
|
|
20
19
|
*/
|
|
21
|
-
type relVarsValsT = Record<string, string | number
|
|
22
|
-
type getRelatedVarsT = (
|
|
23
|
-
|
|
20
|
+
type relVarsValsT = Record<string, string | number>;
|
|
21
|
+
type getRelatedVarsT = (
|
|
22
|
+
optionId: number,
|
|
23
|
+
index: number,
|
|
24
|
+
variables: number[],
|
|
25
|
+
ovc: InputsType,
|
|
26
|
+
references: Types.ReferencesType
|
|
27
|
+
) => relVarsValsT;
|
|
28
|
+
export const getRelatedVariablesValues: getRelatedVarsT = (
|
|
29
|
+
optionId,
|
|
30
|
+
index,
|
|
31
|
+
variables,
|
|
32
|
+
ovc,
|
|
33
|
+
references
|
|
34
|
+
) => {
|
|
24
35
|
// Getting variables values
|
|
25
|
-
const variablesValues: Record<string, string> = {}
|
|
26
|
-
variables.forEach(currentVariableId => {
|
|
36
|
+
const variablesValues: Record<string, string> = {};
|
|
37
|
+
variables.forEach((currentVariableId) => {
|
|
27
38
|
// Getting option value
|
|
28
|
-
let value = ovc.variables[currentVariableId] || [
|
|
29
|
-
const variableParents =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
let value = ovc.variables[currentVariableId] || [""];
|
|
40
|
+
const variableParents =
|
|
41
|
+
references.relations.variables[currentVariableId].parents;
|
|
42
|
+
if (variableParents === undefined)
|
|
43
|
+
throw new Error(
|
|
44
|
+
`Variable ${currentVariableId} parents object does not exist`
|
|
45
|
+
);
|
|
46
|
+
const rootVariableParentId = variableParents[variableParents.length - 1];
|
|
47
|
+
const rootVariableParentRelations =
|
|
48
|
+
references.relations.options[rootVariableParentId];
|
|
49
|
+
if (rootVariableParentRelations === undefined)
|
|
50
|
+
throw new Error(`Option ${rootVariableParentId} does not exist`);
|
|
51
|
+
|
|
52
|
+
if (typeof variableParents === "undefined") return;
|
|
36
53
|
|
|
37
54
|
// Getting rootOption parent
|
|
38
55
|
|
|
39
56
|
// Checking if current option is related to the option that changed
|
|
40
|
-
if (
|
|
41
|
-
|
|
57
|
+
if (
|
|
58
|
+
rootVariableParentRelations.children.options.includes(optionId) ||
|
|
59
|
+
rootVariableParentRelations.dependants.includes(optionId) ||
|
|
60
|
+
optionId === rootVariableParentId
|
|
61
|
+
)
|
|
62
|
+
value = [value[index]];
|
|
42
63
|
|
|
43
64
|
// Making sure all values are strings
|
|
44
|
-
const cleanValues = value.map(currentValue => {
|
|
45
|
-
if ([
|
|
46
|
-
|
|
47
|
-
|
|
65
|
+
const cleanValues = value.map((currentValue) => {
|
|
66
|
+
if (["number", "string"].includes(typeof currentValue))
|
|
67
|
+
return frenchNumber(currentValue);
|
|
68
|
+
return "";
|
|
69
|
+
});
|
|
48
70
|
|
|
49
71
|
// Joining multiple variables if needed
|
|
50
|
-
const currentVariableValue =
|
|
72
|
+
const currentVariableValue =
|
|
73
|
+
cleanValues.length === 1 ? cleanValues[0] : cleanValues.join(", ");
|
|
51
74
|
|
|
52
75
|
// Setting variable value
|
|
53
|
-
variablesValues[currentVariableId] = currentVariableValue
|
|
54
|
-
})
|
|
76
|
+
variablesValues[currentVariableId] = currentVariableValue;
|
|
77
|
+
});
|
|
55
78
|
|
|
56
|
-
return variablesValues
|
|
57
|
-
}
|
|
79
|
+
return variablesValues;
|
|
80
|
+
};
|
|
58
81
|
|
|
59
82
|
/**
|
|
60
83
|
* Parses output with variables
|
|
@@ -64,53 +87,84 @@ export const getRelatedVariablesValues: getRelatedVarsT = (optionId, index, vari
|
|
|
64
87
|
* @param variables Variables values list
|
|
65
88
|
* @param autonums Autonums values
|
|
66
89
|
*/
|
|
67
|
-
type autonumsType = [string, string, number, string | null][]
|
|
68
|
-
type parseOutputT = (
|
|
69
|
-
|
|
90
|
+
type autonumsType = [string, string, number, string | null][];
|
|
91
|
+
type parseOutputT = (
|
|
92
|
+
output: string,
|
|
93
|
+
index: number,
|
|
94
|
+
variables: relVarsValsT,
|
|
95
|
+
autonums: autonumsType
|
|
96
|
+
) => string;
|
|
97
|
+
export const parseOutputWithVariables: parseOutputT = (
|
|
98
|
+
output,
|
|
99
|
+
index,
|
|
100
|
+
variables,
|
|
101
|
+
autonums
|
|
102
|
+
) => {
|
|
70
103
|
// Inserting values
|
|
71
|
-
let parsedOutput = `${output}
|
|
72
|
-
Object.keys(variables).forEach(variableId => {
|
|
73
|
-
let value: string = variables[variableId].toString()
|
|
104
|
+
let parsedOutput = `${output}`;
|
|
105
|
+
Object.keys(variables).forEach((variableId) => {
|
|
106
|
+
let value: string = variables[variableId].toString();
|
|
74
107
|
if (value.trim().length === 0) {
|
|
75
|
-
value = new Array(16).join(
|
|
108
|
+
value = new Array(16).join("_");
|
|
76
109
|
}
|
|
77
110
|
|
|
78
111
|
// Replacing linebreaks with br tags
|
|
79
|
-
value = value.replace(/\n/g,
|
|
80
|
-
parsedOutput = parsedOutput.replace(
|
|
81
|
-
|
|
112
|
+
value = value.replace(/\n/g, "<br />");
|
|
113
|
+
parsedOutput = parsedOutput.replace(
|
|
114
|
+
new RegExp(`\\[var:${variableId}\\]`, "g"),
|
|
115
|
+
value
|
|
116
|
+
);
|
|
117
|
+
});
|
|
82
118
|
|
|
83
119
|
// Inserting page breaks
|
|
84
|
-
parsedOutput = parsedOutput.replace(
|
|
120
|
+
parsedOutput = parsedOutput.replace(
|
|
121
|
+
/\[\[PAGE_BREAK\]\]/gi,
|
|
122
|
+
'<div style="page-break-after:always"></div>'
|
|
123
|
+
);
|
|
85
124
|
|
|
86
125
|
// Cleaning BLURS
|
|
87
|
-
parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi,
|
|
126
|
+
parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi, "");
|
|
88
127
|
|
|
89
128
|
// Parsing Signatures
|
|
90
|
-
parsedOutput = parsedOutput.replace(
|
|
129
|
+
parsedOutput = parsedOutput.replace(
|
|
130
|
+
/\[signature:([0-9]+)\]/g,
|
|
131
|
+
(v, signatureId) =>
|
|
132
|
+
`<span data-signature-id="${signatureId}" data-signer-index="${index}"></span>`
|
|
133
|
+
);
|
|
91
134
|
|
|
92
135
|
// Inserting autonums
|
|
93
|
-
autonums.forEach(currentAn => {
|
|
94
|
-
if (currentAn[3] === null)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
136
|
+
autonums.forEach((currentAn) => {
|
|
137
|
+
if (currentAn[3] === null)
|
|
138
|
+
parsedOutput = parsedOutput.replace(
|
|
139
|
+
`[${currentAn[0]}:${currentAn[1]}]`,
|
|
140
|
+
`<span class="${currentAn[0]}">${currentAn[2]}</span>`
|
|
141
|
+
);
|
|
142
|
+
else
|
|
143
|
+
parsedOutput = parsedOutput.replace(
|
|
144
|
+
`[${currentAn[0]}:${currentAn[1]}](${currentAn[3]})`,
|
|
145
|
+
`<span class="${currentAn[0]}">${currentAn[2]}</span>`
|
|
146
|
+
);
|
|
147
|
+
});
|
|
101
148
|
|
|
149
|
+
return parsedOutput;
|
|
150
|
+
};
|
|
102
151
|
|
|
103
152
|
/**
|
|
104
153
|
* Parses document name with variables
|
|
105
154
|
* @param text Document's name
|
|
106
155
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
156
|
+
type TParseDocumentNameWithVariables = (
|
|
157
|
+
text: string,
|
|
158
|
+
ovc: InputsType,
|
|
159
|
+
references: Types.ReferencesType,
|
|
160
|
+
fallback?: string
|
|
112
161
|
) => string;
|
|
113
|
-
export const parseDocumentNameWithVariables: TParseDocumentNameWithVariables = (
|
|
162
|
+
export const parseDocumentNameWithVariables: TParseDocumentNameWithVariables = (
|
|
163
|
+
text,
|
|
164
|
+
ovc,
|
|
165
|
+
references,
|
|
166
|
+
fallback
|
|
167
|
+
) => {
|
|
114
168
|
/**
|
|
115
169
|
* Variables
|
|
116
170
|
*/
|
|
@@ -139,7 +193,7 @@ export const parseDocumentNameWithVariables: TParseDocumentNameWithVariables = (
|
|
|
139
193
|
// Getting values
|
|
140
194
|
const variablesValues: Record<string, string> = {};
|
|
141
195
|
variables.forEach((variableId) => {
|
|
142
|
-
const value = ovc.variables[variableId]?.[0] ||
|
|
196
|
+
const value = ovc.variables[variableId]?.[0] || "";
|
|
143
197
|
variablesValues[variableId] = value.toString();
|
|
144
198
|
});
|
|
145
199
|
|
|
@@ -150,7 +204,7 @@ export const parseDocumentNameWithVariables: TParseDocumentNameWithVariables = (
|
|
|
150
204
|
if (value.trim().length === 0 && fallback) parsedText = fallback;
|
|
151
205
|
if (parsedText === fallback && fallback) return;
|
|
152
206
|
parsedText = parsedText.replace(
|
|
153
|
-
new RegExp(`\\[var:${variableId}\\]`,
|
|
207
|
+
new RegExp(`\\[var:${variableId}\\]`, "gi"),
|
|
154
208
|
value
|
|
155
209
|
);
|
|
156
210
|
});
|
package/src/libs/Prerender.ts
CHANGED
|
@@ -1,149 +1,193 @@
|
|
|
1
|
-
import { ModelV3 } from
|
|
2
|
-
import { Types
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
1
|
+
import type { ModelV3 } from "@legalplace/models-v3-types";
|
|
2
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
3
|
+
import { ReferencesParser } from "@legalplace/referencesparser";
|
|
4
|
+
import ConditionsRunner from "@legalplace/conditions-runner";
|
|
5
|
+
import OvcConverter from "@legalplace/ovc-converter";
|
|
6
|
+
import type OvcType from "@legalplace/types/dist/ovc";
|
|
7
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
8
|
+
import crypto from "crypto";
|
|
9
|
+
import DocumentRender from "./DocumentRender";
|
|
10
|
+
import NumAuto from "./NumAuto";
|
|
11
|
+
import IntputsInitiator from "./InputsInitiator";
|
|
12
|
+
import FillPdfForm from "./FillPdfForm";
|
|
13
|
+
import { parseDocumentNameWithVariables } from "./OutputParser";
|
|
14
|
+
import type {
|
|
15
|
+
FDFType,
|
|
16
|
+
DocumentIndex,
|
|
17
|
+
DocumentOutputIndex,
|
|
18
|
+
DocumentPdfFormIndex,
|
|
19
|
+
} from "../types/types";
|
|
14
20
|
|
|
15
21
|
class Prerender {
|
|
16
|
-
private
|
|
22
|
+
private references: Types.ReferencesType;
|
|
17
23
|
|
|
18
|
-
private
|
|
24
|
+
private ovc: InputsType;
|
|
19
25
|
|
|
20
|
-
private
|
|
26
|
+
private conditions: ConditionsRunner;
|
|
21
27
|
|
|
22
|
-
private
|
|
28
|
+
private documentRender: DocumentRender;
|
|
23
29
|
|
|
24
|
-
private
|
|
30
|
+
private pdfFiller: FillPdfForm;
|
|
25
31
|
|
|
26
|
-
private
|
|
32
|
+
private NumAuto: NumAuto;
|
|
27
33
|
|
|
28
|
-
private
|
|
34
|
+
private documentsIndex: DocumentIndex = {};
|
|
29
35
|
|
|
30
|
-
private
|
|
31
|
-
|
|
32
|
-
private renderedDocuments: Record<string, string | FDFType> = {}
|
|
33
|
-
|
|
34
|
-
constructor(model: ModelV3, ovc: InputsType | OvcType) {
|
|
35
|
-
this.model = model
|
|
36
|
+
private renderedDocuments: Record<string, string | FDFType> = {};
|
|
36
37
|
|
|
38
|
+
constructor(
|
|
39
|
+
model: ModelV3 | Types.ReferencesType,
|
|
40
|
+
ovc: InputsType | OvcType
|
|
41
|
+
) {
|
|
37
42
|
// Initiating num auto
|
|
38
|
-
this.NumAuto = new NumAuto()
|
|
43
|
+
this.NumAuto = new NumAuto();
|
|
39
44
|
|
|
40
45
|
// Parsing references
|
|
41
|
-
this.references =
|
|
46
|
+
this.references = ReferencesParser.isReferences(model)
|
|
47
|
+
? model
|
|
48
|
+
: new ReferencesParser(model).getReferences();
|
|
42
49
|
|
|
43
50
|
// Converting OVC if needed
|
|
44
|
-
this.ovc = OvcConverter.isOvc(ovc)
|
|
51
|
+
this.ovc = OvcConverter.isOvc(ovc)
|
|
52
|
+
? OvcConverter.convertToOptionsVariables(ovc, this.references)
|
|
53
|
+
: ovc;
|
|
45
54
|
|
|
46
55
|
// Initiating inputs
|
|
47
|
-
const inputs = new IntputsInitiator(this.references, this.ovc).getInputs()
|
|
56
|
+
const inputs = new IntputsInitiator(this.references, this.ovc).getInputs();
|
|
48
57
|
|
|
49
58
|
// Initiating ConditionsRunner
|
|
50
|
-
this.conditions = new ConditionsRunner(this.references, inputs)
|
|
59
|
+
this.conditions = new ConditionsRunner(this.references, inputs);
|
|
51
60
|
|
|
52
61
|
// Rendering documents
|
|
53
|
-
this.documentRender = new DocumentRender(
|
|
62
|
+
this.documentRender = new DocumentRender(
|
|
63
|
+
this.references,
|
|
64
|
+
this.conditions,
|
|
65
|
+
inputs,
|
|
66
|
+
this.NumAuto
|
|
67
|
+
);
|
|
54
68
|
|
|
55
69
|
// Filling pdf documents
|
|
56
|
-
this.pdfFiller = new FillPdfForm(this.references, this.conditions, inputs)
|
|
70
|
+
this.pdfFiller = new FillPdfForm(this.references, this.conditions, inputs);
|
|
57
71
|
|
|
58
|
-
this.generateDocumentNamesHash()
|
|
72
|
+
this.generateDocumentNamesHash();
|
|
59
73
|
}
|
|
60
74
|
|
|
61
75
|
public getDocumentsIndexWithoutFdf() {
|
|
62
|
-
return this.documentsIndex
|
|
76
|
+
return this.documentsIndex;
|
|
63
77
|
}
|
|
64
78
|
|
|
65
79
|
public getDocumentsIndex() {
|
|
66
|
-
this.generateAllDocuments()
|
|
67
|
-
this.fillPdfForms()
|
|
68
|
-
return this.documentsIndex
|
|
80
|
+
this.generateAllDocuments();
|
|
81
|
+
this.fillPdfForms();
|
|
82
|
+
return this.documentsIndex;
|
|
69
83
|
}
|
|
70
84
|
|
|
71
85
|
public getDocument(documentNameHash: string) {
|
|
72
86
|
if (this.renderedDocuments[documentNameHash]) {
|
|
73
|
-
return this.renderedDocuments[documentNameHash]
|
|
87
|
+
return this.renderedDocuments[documentNameHash];
|
|
74
88
|
}
|
|
75
89
|
|
|
76
|
-
const index = this.documentsIndex[documentNameHash]
|
|
90
|
+
const index = this.documentsIndex[documentNameHash];
|
|
77
91
|
|
|
78
|
-
this.renderedDocuments[documentNameHash] = Prerender.isPdfForm(index)
|
|
92
|
+
this.renderedDocuments[documentNameHash] = Prerender.isPdfForm(index)
|
|
93
|
+
? this.pdfFiller.fillDocument(index.slug)
|
|
94
|
+
: this.documentRender.renderDocument(index.slug);
|
|
79
95
|
|
|
80
|
-
return this.renderedDocuments[documentNameHash]
|
|
96
|
+
return this.renderedDocuments[documentNameHash];
|
|
81
97
|
}
|
|
82
98
|
|
|
83
99
|
private generateDocumentNamesHash() {
|
|
84
|
-
Object.keys(this.
|
|
85
|
-
const document = this.
|
|
86
|
-
const documentParams = this.
|
|
87
|
-
const conditionObject = this.references.conditions.documents[slug]
|
|
88
|
-
const condition =
|
|
100
|
+
Object.keys(this.references.documents).forEach((slug) => {
|
|
101
|
+
const document = this.references.documents[slug];
|
|
102
|
+
const documentParams = this.references.documents[slug].params;
|
|
103
|
+
const conditionObject = this.references.conditions.documents[slug];
|
|
104
|
+
const condition =
|
|
105
|
+
conditionObject === undefined
|
|
106
|
+
? true
|
|
107
|
+
: this.conditions.executeCondition(
|
|
108
|
+
conditionObject,
|
|
109
|
+
0,
|
|
110
|
+
0,
|
|
111
|
+
"documents"
|
|
112
|
+
);
|
|
89
113
|
|
|
90
114
|
// Rendering documents sections
|
|
91
115
|
if (condition === true) {
|
|
92
|
-
const hash = crypto
|
|
93
|
-
.createHash('sha1')
|
|
94
|
-
.update(slug)
|
|
95
|
-
.digest('hex')
|
|
116
|
+
const hash = crypto.createHash("sha1").update(slug).digest("hex");
|
|
96
117
|
|
|
97
118
|
// Referencing in index
|
|
98
|
-
if (
|
|
119
|
+
if (
|
|
120
|
+
typeof document.pdf === "object" &&
|
|
121
|
+
typeof document.pdf.id === "string" &&
|
|
122
|
+
typeof document.pdf.form === "object"
|
|
123
|
+
) {
|
|
99
124
|
this.documentsIndex[hash] = {
|
|
100
|
-
name: parseDocumentNameWithVariables(
|
|
125
|
+
name: parseDocumentNameWithVariables(
|
|
126
|
+
document.name,
|
|
127
|
+
this.ovc,
|
|
128
|
+
this.references,
|
|
129
|
+
document.fallbackName
|
|
130
|
+
),
|
|
101
131
|
slug,
|
|
102
132
|
form: true,
|
|
103
133
|
fdf: {
|
|
104
|
-
id:
|
|
105
|
-
fields: {}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
134
|
+
id: "",
|
|
135
|
+
fields: {},
|
|
136
|
+
},
|
|
137
|
+
};
|
|
108
138
|
} else {
|
|
109
139
|
this.documentsIndex[hash] = {
|
|
110
|
-
name: parseDocumentNameWithVariables(
|
|
140
|
+
name: parseDocumentNameWithVariables(
|
|
141
|
+
document.name,
|
|
142
|
+
this.ovc,
|
|
143
|
+
this.references,
|
|
144
|
+
document.fallbackName
|
|
145
|
+
),
|
|
111
146
|
slug,
|
|
112
147
|
pdf: documentParams?.formats?.pdf !== false,
|
|
113
|
-
docx: documentParams?.formats?.docx !== false
|
|
114
|
-
}
|
|
148
|
+
docx: documentParams?.formats?.docx !== false,
|
|
149
|
+
};
|
|
115
150
|
}
|
|
116
151
|
}
|
|
117
|
-
})
|
|
152
|
+
});
|
|
118
153
|
}
|
|
119
154
|
|
|
120
155
|
private fillPdfForms() {
|
|
121
|
-
Object.keys(this.documentsIndex).forEach(documentNameHash => {
|
|
122
|
-
const index = this.documentsIndex[documentNameHash]
|
|
156
|
+
Object.keys(this.documentsIndex).forEach((documentNameHash) => {
|
|
157
|
+
const index = this.documentsIndex[documentNameHash];
|
|
123
158
|
if (Prerender.isPdfForm(index)) {
|
|
124
|
-
index.fdf = this.getDocument(documentNameHash) as FDFType
|
|
159
|
+
index.fdf = this.getDocument(documentNameHash) as FDFType;
|
|
125
160
|
}
|
|
126
|
-
})
|
|
161
|
+
});
|
|
127
162
|
}
|
|
128
163
|
|
|
129
164
|
private generateAllDocuments() {
|
|
130
|
-
Object.keys(this.documentsIndex).forEach(documentNameHash => {
|
|
131
|
-
const index = this.documentsIndex[documentNameHash]
|
|
165
|
+
Object.keys(this.documentsIndex).forEach((documentNameHash) => {
|
|
166
|
+
const index = this.documentsIndex[documentNameHash];
|
|
132
167
|
if (Prerender.isPdfForm(index)) {
|
|
133
|
-
this.renderedDocuments[documentNameHash] = this.pdfFiller.fillDocument(
|
|
168
|
+
this.renderedDocuments[documentNameHash] = this.pdfFiller.fillDocument(
|
|
169
|
+
this.documentsIndex[documentNameHash].slug
|
|
170
|
+
);
|
|
134
171
|
} else {
|
|
135
|
-
this.renderedDocuments[documentNameHash] =
|
|
172
|
+
this.renderedDocuments[documentNameHash] =
|
|
173
|
+
this.documentRender.renderDocument(
|
|
174
|
+
this.documentsIndex[documentNameHash].slug
|
|
175
|
+
);
|
|
136
176
|
}
|
|
137
|
-
})
|
|
177
|
+
});
|
|
138
178
|
}
|
|
139
179
|
|
|
140
|
-
static isPdfForm(
|
|
141
|
-
|
|
180
|
+
static isPdfForm(
|
|
181
|
+
index: DocumentOutputIndex | DocumentPdfFormIndex
|
|
182
|
+
): index is DocumentPdfFormIndex {
|
|
183
|
+
return Object.prototype.hasOwnProperty.call(index, "form");
|
|
142
184
|
}
|
|
143
185
|
|
|
144
|
-
static isOutput(
|
|
145
|
-
|
|
186
|
+
static isOutput(
|
|
187
|
+
index: DocumentOutputIndex | DocumentPdfFormIndex
|
|
188
|
+
): index is DocumentOutputIndex {
|
|
189
|
+
return !Object.prototype.hasOwnProperty.call(index, "form");
|
|
146
190
|
}
|
|
147
191
|
}
|
|
148
192
|
|
|
149
|
-
export default Prerender
|
|
193
|
+
export default Prerender;
|
|
@@ -1,61 +1,80 @@
|
|
|
1
|
-
import { Types } from
|
|
2
|
-
import ConditionsRunner from
|
|
3
|
-
import InputsType from
|
|
4
|
-
import OptionRender from
|
|
5
|
-
import NumAuto from
|
|
1
|
+
import type { Types } from "@legalplace/referencesparser";
|
|
2
|
+
import type ConditionsRunner from "@legalplace/conditions-runner";
|
|
3
|
+
import type InputsType from "@legalplace/types/dist/inputs";
|
|
4
|
+
import OptionRender from "./OptionRender";
|
|
5
|
+
import type NumAuto from "./NumAuto";
|
|
6
6
|
|
|
7
7
|
class SectionRender {
|
|
8
|
-
outputs: string[] = []
|
|
8
|
+
outputs: string[] = [];
|
|
9
9
|
|
|
10
|
-
references: Types.ReferencesType
|
|
10
|
+
references: Types.ReferencesType;
|
|
11
11
|
|
|
12
|
-
currentSection: number
|
|
12
|
+
currentSection: number;
|
|
13
13
|
|
|
14
|
-
documentName: string
|
|
14
|
+
documentName: string;
|
|
15
15
|
|
|
16
|
-
conditions: ConditionsRunner
|
|
16
|
+
conditions: ConditionsRunner;
|
|
17
17
|
|
|
18
|
-
ovc: InputsType
|
|
18
|
+
ovc: InputsType;
|
|
19
19
|
|
|
20
|
-
private NumAuto: NumAuto
|
|
20
|
+
private NumAuto: NumAuto;
|
|
21
21
|
|
|
22
|
-
constructor(options: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
constructor(options: {
|
|
23
|
+
references: Types.ReferencesType;
|
|
24
|
+
conditions: ConditionsRunner;
|
|
25
|
+
ovc: InputsType;
|
|
26
|
+
documentName: string;
|
|
27
|
+
currentSection: number;
|
|
28
|
+
numauto: NumAuto;
|
|
29
|
+
}) {
|
|
30
|
+
this.references = options.references;
|
|
31
|
+
this.conditions = options.conditions;
|
|
32
|
+
this.documentName = options.documentName;
|
|
33
|
+
this.currentSection = options.currentSection;
|
|
34
|
+
this.ovc = options.ovc;
|
|
35
|
+
this.NumAuto = options.numauto;
|
|
29
36
|
|
|
30
|
-
this.renderSection()
|
|
37
|
+
this.renderSection();
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
getOutputs() {
|
|
34
|
-
return this.outputs
|
|
41
|
+
return this.outputs;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
44
|
private renderSection() {
|
|
38
|
-
const section =
|
|
39
|
-
|
|
40
|
-
const
|
|
45
|
+
const section =
|
|
46
|
+
this.references.sections[this.documentName][this.currentSection];
|
|
47
|
+
const conditionObject =
|
|
48
|
+
this.references.conditions.sections[this.documentName][
|
|
49
|
+
this.currentSection
|
|
50
|
+
];
|
|
51
|
+
const condition =
|
|
52
|
+
conditionObject === undefined
|
|
53
|
+
? true
|
|
54
|
+
: this.conditions.executeCondition(conditionObject, 0, 0, "sections");
|
|
41
55
|
|
|
42
56
|
// Rendering documents sections
|
|
43
57
|
if (condition === true) {
|
|
44
|
-
section.options.forEach(optionId => {
|
|
45
|
-
const option = this.references.options[optionId]
|
|
46
|
-
let repeatOption = optionId
|
|
47
|
-
if (option.meta.type ===
|
|
48
|
-
if (option.meta.repeatOption === undefined) return
|
|
49
|
-
repeatOption =
|
|
58
|
+
section.options.forEach((optionId) => {
|
|
59
|
+
const option = this.references.options[optionId];
|
|
60
|
+
let repeatOption = optionId;
|
|
61
|
+
if (option.meta.type === "repeated") {
|
|
62
|
+
if (option.meta.repeatOption === undefined) return;
|
|
63
|
+
repeatOption =
|
|
64
|
+
typeof option.meta.repeatOption === "number"
|
|
65
|
+
? option.meta.repeatOption
|
|
66
|
+
: parseInt(option.meta.repeatOption, 10);
|
|
50
67
|
}
|
|
51
68
|
|
|
52
69
|
// Option inputs
|
|
53
|
-
const inputs = this.ovc.options[repeatOption] || [
|
|
70
|
+
const inputs = this.ovc.options[repeatOption] || [
|
|
71
|
+
!["radio", "checkbox"].includes(option.meta.type),
|
|
72
|
+
]; // Falling back on a single value array if option doesn't exist in ovc
|
|
54
73
|
|
|
55
74
|
// Looping through inputs
|
|
56
75
|
inputs.forEach((value, index) => {
|
|
57
76
|
// If value is false we stop here
|
|
58
|
-
if (value !== true) return
|
|
77
|
+
if (value !== true) return;
|
|
59
78
|
|
|
60
79
|
this.outputs = [
|
|
61
80
|
...this.outputs,
|
|
@@ -65,13 +84,13 @@ class SectionRender {
|
|
|
65
84
|
ovc: this.ovc,
|
|
66
85
|
index,
|
|
67
86
|
conditions: this.conditions,
|
|
68
|
-
numauto: this.NumAuto
|
|
69
|
-
}).getOutputs()
|
|
70
|
-
]
|
|
71
|
-
})
|
|
72
|
-
})
|
|
87
|
+
numauto: this.NumAuto,
|
|
88
|
+
}).getOutputs(),
|
|
89
|
+
];
|
|
90
|
+
});
|
|
91
|
+
});
|
|
73
92
|
}
|
|
74
93
|
}
|
|
75
94
|
}
|
|
76
95
|
|
|
77
|
-
export default SectionRender
|
|
96
|
+
export default SectionRender;
|