@legalplace/prerenderx 2.2.2 → 2.2.4
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/.gitlab-ci.yml +5 -8
- package/.prettierrc.js +10 -0
- package/.vscode/settings.json +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/libs/ConditionsRunner.d.ts +4 -4
- package/dist/libs/ConditionsRunner.js +12 -29
- package/dist/libs/DocumentRender.d.ts +4 -4
- package/dist/libs/DocumentRender.js +1 -1
- package/dist/libs/NumAuto.js +1 -1
- package/dist/libs/OptionRender.d.ts +4 -4
- package/dist/libs/OptionRender.js +4 -14
- package/dist/libs/OutputParser.d.ts +2 -2
- package/dist/libs/OutputParser.js +10 -13
- package/dist/libs/Prerender.d.ts +3 -3
- package/dist/libs/Prerender.js +4 -8
- package/dist/libs/SectionRender.d.ts +4 -4
- package/dist/libs/SectionRender.js +4 -11
- package/package.json +10 -8
- package/src/index.ts +2 -2
- package/src/libs/ConditionsRunner.ts +50 -104
- package/src/libs/DataPopulator.ts +96 -133
- package/src/libs/DocumentRender.ts +22 -27
- package/src/libs/InputsInitiator.ts +51 -89
- package/src/libs/NumAuto.ts +14 -16
- package/src/libs/OptionRender.ts +39 -78
- package/src/libs/OutputParser.ts +38 -83
- package/src/libs/OvcConverter.ts +44 -52
- package/src/libs/Prerender.ts +41 -62
- package/src/libs/SectionRender.ts +35 -54
- package/src/libs/ovc.type.ts +6 -6
|
@@ -1,166 +1,112 @@
|
|
|
1
1
|
/* eslint-disable max-len */
|
|
2
|
-
import LpLogic from
|
|
3
|
-
import { Types } from
|
|
4
|
-
import { ConditionV3 } from
|
|
5
|
-
import DataPopulator, { ConditionDataMap } from
|
|
2
|
+
import LpLogic from '@legalplace/lplogic'
|
|
3
|
+
import { Types } from '@legalplace/referencesparser'
|
|
4
|
+
import { ConditionV3 } from '@legalplace/models-v3-types'
|
|
5
|
+
import DataPopulator, { ConditionDataMap } from './DataPopulator'
|
|
6
6
|
|
|
7
7
|
type OVC_TYPE = {
|
|
8
8
|
options: {
|
|
9
|
-
[key: string]: boolean[]
|
|
10
|
-
}
|
|
9
|
+
[key: string]: boolean[]
|
|
10
|
+
}
|
|
11
11
|
variables: {
|
|
12
|
-
[key: string]: (number | string)[]
|
|
13
|
-
}
|
|
14
|
-
}
|
|
12
|
+
[key: string]: (number | string)[]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
15
|
|
|
16
16
|
interface ConditionData {
|
|
17
|
-
o: Record<string, boolean[]
|
|
18
|
-
v: Record<string, (string | number)[]
|
|
17
|
+
o: Record<string, boolean[]>
|
|
18
|
+
v: Record<string, (string | number)[]>
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
class ConditionsRunner {
|
|
22
|
-
private references: Types.ReferencesType
|
|
22
|
+
private references: Types.ReferencesType
|
|
23
23
|
|
|
24
|
-
private ovc: OVC_TYPE
|
|
24
|
+
private ovc: OVC_TYPE
|
|
25
25
|
|
|
26
26
|
constructor(references: Types.ReferencesType, ovc: OVC_TYPE) {
|
|
27
|
-
this.references = references
|
|
28
|
-
this.ovc = ovc
|
|
27
|
+
this.references = references
|
|
28
|
+
this.ovc = ovc
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
isOptionRelatedToOption(optionA: number, optionB: number): boolean {
|
|
32
32
|
// Getting B relations
|
|
33
|
-
const OptionBParents = this.references.relations.options[optionB].parents
|
|
34
|
-
const OptionBRoot = OptionBParents[OptionBParents.length - 1]
|
|
35
|
-
const OptionBRootRelations = OptionBRoot
|
|
36
|
-
? this.references.relations.options[OptionBRoot]
|
|
37
|
-
: undefined;
|
|
33
|
+
const OptionBParents = this.references.relations.options[optionB].parents
|
|
34
|
+
const OptionBRoot = OptionBParents[OptionBParents.length - 1]
|
|
35
|
+
const OptionBRootRelations = OptionBRoot ? this.references.relations.options[OptionBRoot] : undefined
|
|
38
36
|
|
|
39
37
|
// Checking if B option is related to the option that changed
|
|
40
38
|
if (OptionBRootRelations) {
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
OptionBRootRelations.children.options.includes(optionA) ||
|
|
44
|
-
OptionBRootRelations.dependants.includes(optionA)
|
|
45
|
-
) {
|
|
46
|
-
return true;
|
|
39
|
+
if (optionA === optionB || OptionBRootRelations.children.options.includes(optionA) || OptionBRootRelations.dependants.includes(optionA)) {
|
|
40
|
+
return true
|
|
47
41
|
}
|
|
48
42
|
}
|
|
49
43
|
|
|
50
|
-
return false
|
|
44
|
+
return false
|
|
51
45
|
}
|
|
52
46
|
|
|
53
47
|
isVariableRelatedToOption(variableId: number, optionId: number): boolean {
|
|
54
48
|
// Variable parent
|
|
55
|
-
const variableParentId = this.references.relations.variables[variableId]
|
|
56
|
-
.parents[0];
|
|
49
|
+
const variableParentId = this.references.relations.variables[variableId].parents[0]
|
|
57
50
|
|
|
58
51
|
// Getting B relations
|
|
59
|
-
const optionParents = this.references.relations.options[variableParentId]
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const optionRootRelations = optionRoot
|
|
63
|
-
? this.references.relations.options[optionRoot]
|
|
64
|
-
: undefined;
|
|
52
|
+
const optionParents = this.references.relations.options[variableParentId].parents
|
|
53
|
+
const optionRoot = optionParents[optionParents.length - 1]
|
|
54
|
+
const optionRootRelations = optionRoot ? this.references.relations.options[optionRoot] : undefined
|
|
65
55
|
|
|
66
56
|
// Checking if B option is related to the option that changed
|
|
67
57
|
if (optionRootRelations) {
|
|
68
|
-
if (
|
|
69
|
-
|
|
70
|
-
optionRootRelations.dependants.includes(optionId)
|
|
71
|
-
) {
|
|
72
|
-
return true;
|
|
58
|
+
if (optionRootRelations.children.options.includes(optionId) || optionRootRelations.dependants.includes(optionId)) {
|
|
59
|
+
return true
|
|
73
60
|
}
|
|
74
61
|
}
|
|
75
62
|
|
|
76
|
-
return false
|
|
63
|
+
return false
|
|
77
64
|
}
|
|
78
65
|
|
|
79
66
|
isVariableRelatedToVariable(variableA: number, variableB: number): boolean {
|
|
80
67
|
// Getting variables options
|
|
81
|
-
const optionA = this.references.relations.variables[variableA].parents[0]
|
|
82
|
-
const optionB = this.references.relations.variables[variableB].parents[0]
|
|
68
|
+
const optionA = this.references.relations.variables[variableA].parents[0]
|
|
69
|
+
const optionB = this.references.relations.variables[variableB].parents[0]
|
|
83
70
|
|
|
84
71
|
// Getting B relations
|
|
85
|
-
const OptionBParents = this.references.relations.options[optionB].parents
|
|
86
|
-
const OptionBRoot = OptionBParents[OptionBParents.length - 1]
|
|
87
|
-
const OptionBRootRelations = OptionBRoot
|
|
88
|
-
? this.references.relations.options[OptionBRoot]
|
|
89
|
-
: undefined;
|
|
72
|
+
const OptionBParents = this.references.relations.options[optionB].parents
|
|
73
|
+
const OptionBRoot = OptionBParents[OptionBParents.length - 1]
|
|
74
|
+
const OptionBRootRelations = OptionBRoot ? this.references.relations.options[OptionBRoot] : undefined
|
|
90
75
|
|
|
91
76
|
// Checking if B option is related to the option that changed
|
|
92
77
|
if (OptionBRootRelations) {
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
OptionBRootRelations.children.options.includes(optionA) ||
|
|
96
|
-
OptionBRootRelations.dependants.includes(optionA)
|
|
97
|
-
) {
|
|
98
|
-
return true;
|
|
78
|
+
if (optionA === optionB || OptionBRootRelations.children.options.includes(optionA) || OptionBRootRelations.dependants.includes(optionA)) {
|
|
79
|
+
return true
|
|
99
80
|
}
|
|
100
81
|
}
|
|
101
82
|
|
|
102
|
-
return false
|
|
83
|
+
return false
|
|
103
84
|
}
|
|
104
85
|
|
|
105
86
|
executeCondition(
|
|
106
87
|
condition: {
|
|
107
|
-
dataMap: ConditionDataMap
|
|
108
|
-
conditions: ConditionV3
|
|
88
|
+
dataMap: ConditionDataMap
|
|
89
|
+
conditions: ConditionV3
|
|
109
90
|
},
|
|
110
91
|
id: number,
|
|
111
92
|
index: number,
|
|
112
|
-
conditionType:
|
|
113
|
-
| "options"
|
|
114
|
-
| "optionValidator"
|
|
115
|
-
| "variables"
|
|
116
|
-
| "prefillers"
|
|
117
|
-
| "variableValidator"
|
|
118
|
-
| "sections"
|
|
119
|
-
| "documents"
|
|
93
|
+
conditionType: 'options' | 'optionValidator' | 'variables' | 'prefillers' | 'variableValidator' | 'sections' | 'documents'
|
|
120
94
|
): any {
|
|
121
|
-
if (Array.isArray(condition))
|
|
122
|
-
return condition.map(_condition =>
|
|
123
|
-
this.executeCondition(_condition, id, index, conditionType)
|
|
124
|
-
);
|
|
95
|
+
if (Array.isArray(condition)) return condition.map(_condition => this.executeCondition(_condition, id, index, conditionType))
|
|
125
96
|
|
|
126
97
|
// Populating Data
|
|
127
|
-
let currentData
|
|
128
|
-
if (conditionType ===
|
|
129
|
-
currentData = new DataPopulator(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
index
|
|
136
|
-
).getData();
|
|
137
|
-
} else if (
|
|
138
|
-
conditionType === "variables" ||
|
|
139
|
-
conditionType === "prefillers" ||
|
|
140
|
-
conditionType === "variableValidator"
|
|
141
|
-
) {
|
|
142
|
-
const dataId = this.references.relations.variables[id].parents[0];
|
|
143
|
-
currentData = new DataPopulator(
|
|
144
|
-
this,
|
|
145
|
-
this.references,
|
|
146
|
-
this.ovc,
|
|
147
|
-
condition.dataMap,
|
|
148
|
-
dataId,
|
|
149
|
-
index
|
|
150
|
-
).getData();
|
|
151
|
-
} else if (conditionType === "sections" || conditionType === "documents") {
|
|
152
|
-
currentData = new DataPopulator(
|
|
153
|
-
this,
|
|
154
|
-
this.references,
|
|
155
|
-
this.ovc,
|
|
156
|
-
condition.dataMap,
|
|
157
|
-
id,
|
|
158
|
-
index
|
|
159
|
-
).getData();
|
|
98
|
+
let currentData
|
|
99
|
+
if (conditionType === 'options' || conditionType === 'optionValidator') {
|
|
100
|
+
currentData = new DataPopulator(this, this.references, this.ovc, condition.dataMap, id, index).getData()
|
|
101
|
+
} else if (conditionType === 'variables' || conditionType === 'prefillers' || conditionType === 'variableValidator') {
|
|
102
|
+
const dataId = this.references.relations.variables[id].parents[0]
|
|
103
|
+
currentData = new DataPopulator(this, this.references, this.ovc, condition.dataMap, dataId, index).getData()
|
|
104
|
+
} else if (conditionType === 'sections' || conditionType === 'documents') {
|
|
105
|
+
currentData = new DataPopulator(this, this.references, this.ovc, condition.dataMap, id, index).getData()
|
|
160
106
|
}
|
|
161
107
|
|
|
162
|
-
return LpLogic(condition.conditions, currentData)
|
|
108
|
+
return LpLogic(condition.conditions, currentData)
|
|
163
109
|
}
|
|
164
110
|
}
|
|
165
111
|
|
|
166
|
-
export default ConditionsRunner
|
|
112
|
+
export default ConditionsRunner
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { Types } from
|
|
2
|
-
import ConditionsRunner from
|
|
1
|
+
import { Types } from '@legalplace/referencesparser'
|
|
2
|
+
import ConditionsRunner from './ConditionsRunner'
|
|
3
3
|
|
|
4
4
|
type OVC_TYPE = {
|
|
5
5
|
options: {
|
|
6
|
-
[key: string]: boolean[]
|
|
7
|
-
}
|
|
6
|
+
[key: string]: boolean[]
|
|
7
|
+
}
|
|
8
8
|
variables: {
|
|
9
|
-
[key: string]: (number | string)[]
|
|
10
|
-
}
|
|
11
|
-
}
|
|
9
|
+
[key: string]: (number | string)[]
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
12
|
|
|
13
13
|
class DataPopulator {
|
|
14
|
-
private references: Types.ReferencesType
|
|
14
|
+
private references: Types.ReferencesType
|
|
15
15
|
|
|
16
|
-
private ovc: OVC_TYPE
|
|
16
|
+
private ovc: OVC_TYPE
|
|
17
17
|
|
|
18
|
-
private conditionsRunner: ConditionsRunner
|
|
18
|
+
private conditionsRunner: ConditionsRunner
|
|
19
19
|
|
|
20
|
-
private id?: number
|
|
20
|
+
private id?: number
|
|
21
21
|
|
|
22
|
-
private index?: number
|
|
22
|
+
private index?: number
|
|
23
23
|
|
|
24
|
-
private dataMap: ConditionDataMap
|
|
24
|
+
private dataMap: ConditionDataMap
|
|
25
25
|
|
|
26
26
|
private data: ConditionData = {
|
|
27
27
|
o: {},
|
|
@@ -30,54 +30,46 @@ class DataPopulator {
|
|
|
30
30
|
o: {},
|
|
31
31
|
s: {}
|
|
32
32
|
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
constructor(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
dataMap
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
) {
|
|
43
|
-
this.id = id;
|
|
44
|
-
this.ovc = ovc;
|
|
45
|
-
this.index = index;
|
|
46
|
-
this.dataMap = dataMap;
|
|
47
|
-
this.references = references;
|
|
48
|
-
this.conditionsRunner = conditionsRunner;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
constructor(conditionsRunner: ConditionsRunner, references: Types.ReferencesType, ovc: OVC_TYPE, dataMap: ConditionDataMap, id?: number, index?: number) {
|
|
36
|
+
this.id = id
|
|
37
|
+
this.ovc = ovc
|
|
38
|
+
this.index = index
|
|
39
|
+
this.dataMap = dataMap
|
|
40
|
+
this.references = references
|
|
41
|
+
this.conditionsRunner = conditionsRunner
|
|
49
42
|
|
|
50
43
|
// Populating variables
|
|
51
|
-
this.populateVariables()
|
|
44
|
+
this.populateVariables()
|
|
52
45
|
|
|
53
46
|
// Populating options
|
|
54
|
-
this.populateOptions()
|
|
47
|
+
this.populateOptions()
|
|
55
48
|
|
|
56
49
|
// Populating conditions
|
|
57
|
-
this.populateConditions()
|
|
50
|
+
this.populateConditions()
|
|
58
51
|
}
|
|
59
52
|
|
|
60
53
|
/**
|
|
61
54
|
* Returns resulting data object
|
|
62
55
|
*/
|
|
63
56
|
public getData(): Readonly<ConditionData> {
|
|
64
|
-
return this.data
|
|
57
|
+
return this.data
|
|
65
58
|
}
|
|
66
59
|
|
|
67
60
|
private populateConditions(): void {
|
|
68
61
|
// Sections
|
|
69
62
|
for (let i = 0; i < this.dataMap.c.s.length; i += 1) {
|
|
70
|
-
const sectionId = this.dataMap.c.s[i]
|
|
71
|
-
const sectionCondition = this.sectionConditionValue(sectionId)
|
|
72
|
-
this.data.c.s[sectionId] = [sectionCondition === true]
|
|
63
|
+
const sectionId = this.dataMap.c.s[i]
|
|
64
|
+
const sectionCondition = this.sectionConditionValue(sectionId)
|
|
65
|
+
this.data.c.s[sectionId] = [sectionCondition === true]
|
|
73
66
|
}
|
|
74
67
|
|
|
75
68
|
// Options
|
|
76
69
|
for (let i = 0; i < this.dataMap.c.o.length; i += 1) {
|
|
77
|
-
const optionId = this.dataMap.c.o[i]
|
|
78
|
-
const optionCondition = this.optionConditionValue(optionId)
|
|
79
|
-
this.data.c.o[optionId] =
|
|
80
|
-
optionCondition === undefined ? [false] : optionCondition;
|
|
70
|
+
const optionId = this.dataMap.c.o[i]
|
|
71
|
+
const optionCondition = this.optionConditionValue(optionId)
|
|
72
|
+
this.data.c.o[optionId] = optionCondition === undefined ? [false] : optionCondition
|
|
81
73
|
}
|
|
82
74
|
}
|
|
83
75
|
|
|
@@ -86,17 +78,17 @@ class DataPopulator {
|
|
|
86
78
|
*/
|
|
87
79
|
private populateVariables(): void {
|
|
88
80
|
for (let i = 0; i < this.dataMap.v.length; i += 1) {
|
|
89
|
-
const variableId = this.dataMap.v[i]
|
|
90
|
-
const variableReference = this.references.variables[variableId]
|
|
91
|
-
let values = this.getVariableValues(variableId)
|
|
81
|
+
const variableId = this.dataMap.v[i]
|
|
82
|
+
const variableReference = this.references.variables[variableId]
|
|
83
|
+
let values = this.getVariableValues(variableId)
|
|
92
84
|
|
|
93
85
|
// If variable is of type number
|
|
94
|
-
if (variableReference.type ===
|
|
95
|
-
values = values.map(v => (typeof v ===
|
|
86
|
+
if (variableReference.type === 'number') {
|
|
87
|
+
values = values.map(v => (typeof v === 'number' ? v : parseFloat(v)))
|
|
96
88
|
}
|
|
97
89
|
|
|
98
90
|
// Adding variables
|
|
99
|
-
this.data.v[variableId] = [...values]
|
|
91
|
+
this.data.v[variableId] = [...values]
|
|
100
92
|
}
|
|
101
93
|
}
|
|
102
94
|
|
|
@@ -105,36 +97,29 @@ class DataPopulator {
|
|
|
105
97
|
* @param variableId Variable's id
|
|
106
98
|
*/
|
|
107
99
|
private getVariableValues(variableId: number): Readonly<(string | number)[]> {
|
|
108
|
-
const conditions = this.variableConditionValue(variableId)
|
|
109
|
-
const value = this.ovc.variables[variableId]
|
|
100
|
+
const conditions = this.variableConditionValue(variableId)
|
|
101
|
+
const value = this.ovc.variables[variableId]
|
|
110
102
|
if (this.id === undefined || this.index === undefined) {
|
|
111
|
-
return value
|
|
103
|
+
return value
|
|
112
104
|
}
|
|
113
105
|
|
|
114
106
|
// Getting variable parent option
|
|
115
|
-
const variableRootParent = this.getVariableRootParent(variableId)
|
|
116
|
-
const variableRootRelations = this.references.relations.options[
|
|
117
|
-
|
|
118
|
-
];
|
|
119
|
-
if (
|
|
120
|
-
variableRootRelations.children.options.includes(this.id) ||
|
|
121
|
-
variableRootRelations.dependants.includes(this.id) ||
|
|
122
|
-
this.id === variableRootParent
|
|
123
|
-
) {
|
|
107
|
+
const variableRootParent = this.getVariableRootParent(variableId)
|
|
108
|
+
const variableRootRelations = this.references.relations.options[variableRootParent]
|
|
109
|
+
if (variableRootRelations.children.options.includes(this.id) || variableRootRelations.dependants.includes(this.id) || this.id === variableRootParent) {
|
|
124
110
|
// TODO: Replace fAl$e with a safer solution
|
|
125
|
-
if (conditions !== undefined && conditions[this.index] === false)
|
|
126
|
-
|
|
127
|
-
return [value[this.index]];
|
|
111
|
+
if (conditions !== undefined && conditions[this.index] === false) return ['fAl$e']
|
|
112
|
+
return [value[this.index]]
|
|
128
113
|
}
|
|
129
114
|
|
|
130
|
-
const cleanValues = this.cleanArrayFromNullValues([...value])
|
|
115
|
+
const cleanValues = this.cleanArrayFromNullValues([...value])
|
|
131
116
|
|
|
132
|
-
if (conditions === undefined) return cleanValues
|
|
117
|
+
if (conditions === undefined) return cleanValues
|
|
133
118
|
|
|
134
119
|
return cleanValues.map((currentValue, index) => {
|
|
135
|
-
if (conditions[index] === false) return
|
|
136
|
-
return currentValue
|
|
137
|
-
})
|
|
120
|
+
if (conditions[index] === false) return 'fAl$e'
|
|
121
|
+
return currentValue
|
|
122
|
+
})
|
|
138
123
|
}
|
|
139
124
|
|
|
140
125
|
/**
|
|
@@ -142,9 +127,8 @@ class DataPopulator {
|
|
|
142
127
|
* @param variableId Variable's id
|
|
143
128
|
*/
|
|
144
129
|
private getVariableRootParent(variableId: number) {
|
|
145
|
-
const variableParents = this.references.relations.variables[variableId]
|
|
146
|
-
|
|
147
|
-
return variableParents[variableParents.length - 1];
|
|
130
|
+
const variableParents = this.references.relations.variables[variableId].parents
|
|
131
|
+
return variableParents[variableParents.length - 1]
|
|
148
132
|
}
|
|
149
133
|
|
|
150
134
|
/**
|
|
@@ -152,10 +136,8 @@ class DataPopulator {
|
|
|
152
136
|
* with an empty string
|
|
153
137
|
* @param arr Values array
|
|
154
138
|
*/
|
|
155
|
-
private cleanArrayFromNullValues(
|
|
156
|
-
arr
|
|
157
|
-
): (string | number)[] {
|
|
158
|
-
return arr.map(v => (v === null ? "" : v));
|
|
139
|
+
private cleanArrayFromNullValues(arr: (string | number | null)[]): (string | number)[] {
|
|
140
|
+
return arr.map(v => (v === null ? '' : v))
|
|
159
141
|
}
|
|
160
142
|
|
|
161
143
|
/**
|
|
@@ -163,11 +145,11 @@ class DataPopulator {
|
|
|
163
145
|
*/
|
|
164
146
|
populateOptions() {
|
|
165
147
|
for (let i = 0; i < this.dataMap.o.length; i += 1) {
|
|
166
|
-
const optionId = this.dataMap.o[i]
|
|
167
|
-
const inputs = this.getOptionInputs(optionId)
|
|
148
|
+
const optionId = this.dataMap.o[i]
|
|
149
|
+
const inputs = this.getOptionInputs(optionId)
|
|
168
150
|
|
|
169
151
|
// Adding option
|
|
170
|
-
this.data.o[optionId] = [...inputs]
|
|
152
|
+
this.data.o[optionId] = [...inputs]
|
|
171
153
|
}
|
|
172
154
|
}
|
|
173
155
|
|
|
@@ -176,33 +158,26 @@ class DataPopulator {
|
|
|
176
158
|
* @param optionId Option's id
|
|
177
159
|
*/
|
|
178
160
|
private getOptionInputs(optionId: number): Readonly<boolean[]> {
|
|
179
|
-
const conditions = this.optionConditionValue(optionId)
|
|
180
|
-
const inputs = this.ovc.options[optionId]
|
|
161
|
+
const conditions = this.optionConditionValue(optionId)
|
|
162
|
+
const inputs = this.ovc.options[optionId]
|
|
181
163
|
if (this.id === undefined || this.index === undefined) {
|
|
182
|
-
return inputs
|
|
164
|
+
return inputs
|
|
183
165
|
}
|
|
184
166
|
|
|
185
167
|
// Getting variable parent option
|
|
186
|
-
const optionRootParent = this.getOptionRootParent(optionId)
|
|
187
|
-
const optionRootRelations = this.references.relations.options[
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
optionRootRelations.children.options.includes(this.id) ||
|
|
192
|
-
optionRootRelations.dependants.includes(this.id) ||
|
|
193
|
-
this.id === optionRootParent
|
|
194
|
-
) {
|
|
195
|
-
if (conditions !== undefined && conditions[this.index] === false)
|
|
196
|
-
return [false];
|
|
197
|
-
return [inputs[this.index]];
|
|
168
|
+
const optionRootParent = this.getOptionRootParent(optionId)
|
|
169
|
+
const optionRootRelations = this.references.relations.options[optionRootParent]
|
|
170
|
+
if (optionRootRelations.children.options.includes(this.id) || optionRootRelations.dependants.includes(this.id) || this.id === optionRootParent) {
|
|
171
|
+
if (conditions !== undefined && conditions[this.index] === false) return [false]
|
|
172
|
+
return [inputs[this.index]]
|
|
198
173
|
}
|
|
199
174
|
|
|
200
|
-
if (conditions === undefined) return inputs
|
|
175
|
+
if (conditions === undefined) return inputs
|
|
201
176
|
|
|
202
177
|
return inputs.map((value, index) => {
|
|
203
|
-
if (conditions[index] === false) return false
|
|
204
|
-
return value
|
|
205
|
-
})
|
|
178
|
+
if (conditions[index] === false) return false
|
|
179
|
+
return value
|
|
180
|
+
})
|
|
206
181
|
}
|
|
207
182
|
|
|
208
183
|
/**
|
|
@@ -210,10 +185,8 @@ class DataPopulator {
|
|
|
210
185
|
* @param optionId Root parent
|
|
211
186
|
*/
|
|
212
187
|
private getOptionRootParent(optionId: number) {
|
|
213
|
-
const optionParents = this.references.relations.options[optionId].parents
|
|
214
|
-
return optionParents.length > 0
|
|
215
|
-
? optionParents[optionParents.length - 1]
|
|
216
|
-
: optionId;
|
|
188
|
+
const optionParents = this.references.relations.options[optionId].parents
|
|
189
|
+
return optionParents.length > 0 ? optionParents[optionParents.length - 1] : optionId
|
|
217
190
|
}
|
|
218
191
|
|
|
219
192
|
/**
|
|
@@ -221,20 +194,15 @@ class DataPopulator {
|
|
|
221
194
|
*/
|
|
222
195
|
private optionConditionValue(optionId: number) {
|
|
223
196
|
// Getting option conditions
|
|
224
|
-
const conditions = this.references.conditions.options[optionId]
|
|
225
|
-
if (conditions === undefined) return undefined
|
|
197
|
+
const conditions = this.references.conditions.options[optionId]
|
|
198
|
+
if (conditions === undefined) return undefined
|
|
226
199
|
|
|
227
200
|
// Getting option inputs length
|
|
228
|
-
const inputs = this.ovc.options[optionId]
|
|
201
|
+
const inputs = this.ovc.options[optionId]
|
|
229
202
|
|
|
230
203
|
return inputs.map((input, index) => {
|
|
231
|
-
return this.conditionsRunner.executeCondition(
|
|
232
|
-
|
|
233
|
-
optionId,
|
|
234
|
-
index,
|
|
235
|
-
"options"
|
|
236
|
-
);
|
|
237
|
-
});
|
|
204
|
+
return this.conditionsRunner.executeCondition(conditions, optionId, index, 'options')
|
|
205
|
+
})
|
|
238
206
|
}
|
|
239
207
|
|
|
240
208
|
/**
|
|
@@ -242,20 +210,15 @@ class DataPopulator {
|
|
|
242
210
|
*/
|
|
243
211
|
private variableConditionValue(variableId: number) {
|
|
244
212
|
// Getting variable conditions
|
|
245
|
-
const conditions = this.references.conditions.variables[variableId]
|
|
246
|
-
if (conditions === undefined) return undefined
|
|
213
|
+
const conditions = this.references.conditions.variables[variableId]
|
|
214
|
+
if (conditions === undefined) return undefined
|
|
247
215
|
|
|
248
216
|
// Getting variable inputs length
|
|
249
|
-
const inputs = this.ovc.variables[variableId]
|
|
217
|
+
const inputs = this.ovc.variables[variableId]
|
|
250
218
|
|
|
251
219
|
return inputs.map((input, index) => {
|
|
252
|
-
return this.conditionsRunner.executeCondition(
|
|
253
|
-
|
|
254
|
-
variableId,
|
|
255
|
-
index,
|
|
256
|
-
"variables"
|
|
257
|
-
);
|
|
258
|
-
});
|
|
220
|
+
return this.conditionsRunner.executeCondition(conditions, variableId, index, 'variables')
|
|
221
|
+
})
|
|
259
222
|
}
|
|
260
223
|
|
|
261
224
|
/**
|
|
@@ -263,29 +226,29 @@ class DataPopulator {
|
|
|
263
226
|
*/
|
|
264
227
|
private sectionConditionValue(sectionId: number) {
|
|
265
228
|
// Getting section conditions
|
|
266
|
-
const conditions = this.references.conditions.sections.main[sectionId]
|
|
267
|
-
if (conditions === undefined) return undefined
|
|
229
|
+
const conditions = this.references.conditions.sections.main[sectionId]
|
|
230
|
+
if (conditions === undefined) return undefined
|
|
268
231
|
|
|
269
|
-
return this.conditionsRunner.executeCondition(conditions, 0, 0,
|
|
232
|
+
return this.conditionsRunner.executeCondition(conditions, 0, 0, 'sections')
|
|
270
233
|
}
|
|
271
234
|
}
|
|
272
235
|
|
|
273
236
|
export interface ConditionDataMap {
|
|
274
|
-
o: number[]
|
|
275
|
-
v: number[]
|
|
237
|
+
o: number[]
|
|
238
|
+
v: number[]
|
|
276
239
|
c: {
|
|
277
|
-
o: number[]
|
|
278
|
-
s: number[]
|
|
279
|
-
}
|
|
240
|
+
o: number[]
|
|
241
|
+
s: number[]
|
|
242
|
+
}
|
|
280
243
|
}
|
|
281
244
|
|
|
282
245
|
export interface ConditionData {
|
|
283
|
-
o: Record<string, boolean[]
|
|
284
|
-
v: Record<string, (string | number)[]
|
|
246
|
+
o: Record<string, boolean[]>
|
|
247
|
+
v: Record<string, (string | number)[]>
|
|
285
248
|
c: {
|
|
286
|
-
o: Record<string, boolean[]
|
|
287
|
-
s: Record<string, boolean[]
|
|
288
|
-
}
|
|
249
|
+
o: Record<string, boolean[]>
|
|
250
|
+
s: Record<string, boolean[]>
|
|
251
|
+
}
|
|
289
252
|
}
|
|
290
253
|
|
|
291
|
-
export default DataPopulator
|
|
254
|
+
export default DataPopulator
|
|
@@ -1,37 +1,32 @@
|
|
|
1
|
-
import { Types } from
|
|
2
|
-
import ConditionsRunner from
|
|
3
|
-
import SectionRender from
|
|
4
|
-
import OVC_TYPE from
|
|
5
|
-
import NumAuto from
|
|
1
|
+
import { Types } from '@legalplace/referencesparser'
|
|
2
|
+
import ConditionsRunner from './ConditionsRunner'
|
|
3
|
+
import SectionRender from './SectionRender'
|
|
4
|
+
import OVC_TYPE from './ovc.type'
|
|
5
|
+
import NumAuto from './NumAuto'
|
|
6
6
|
|
|
7
7
|
class DocumentRender {
|
|
8
|
-
references: Types.ReferencesType
|
|
8
|
+
references: Types.ReferencesType
|
|
9
9
|
|
|
10
|
-
conditions: ConditionsRunner
|
|
10
|
+
conditions: ConditionsRunner
|
|
11
11
|
|
|
12
|
-
ovc: OVC_TYPE
|
|
12
|
+
ovc: OVC_TYPE
|
|
13
13
|
|
|
14
|
-
documents: Record<string, string[]> = {}
|
|
14
|
+
documents: Record<string, string[]> = {}
|
|
15
15
|
|
|
16
|
-
documentsNamesHash: Record<string, string> = {}
|
|
16
|
+
documentsNamesHash: Record<string, string> = {}
|
|
17
17
|
|
|
18
|
-
private NumAuto: NumAuto
|
|
18
|
+
private NumAuto: NumAuto
|
|
19
19
|
|
|
20
|
-
constructor(
|
|
21
|
-
references
|
|
22
|
-
conditions
|
|
23
|
-
ovc
|
|
24
|
-
numauto
|
|
25
|
-
) {
|
|
26
|
-
this.references = references;
|
|
27
|
-
this.conditions = conditions;
|
|
28
|
-
this.ovc = ovc;
|
|
29
|
-
this.NumAuto = numauto;
|
|
20
|
+
constructor(references: Types.ReferencesType, conditions: ConditionsRunner, ovc: OVC_TYPE, numauto: NumAuto) {
|
|
21
|
+
this.references = references
|
|
22
|
+
this.conditions = conditions
|
|
23
|
+
this.ovc = ovc
|
|
24
|
+
this.NumAuto = numauto
|
|
30
25
|
}
|
|
31
26
|
|
|
32
27
|
public renderDocument(documentName: string) {
|
|
33
|
-
const documentOutputs: string[] = []
|
|
34
|
-
this.NumAuto.resetIndexes()
|
|
28
|
+
const documentOutputs: string[] = []
|
|
29
|
+
this.NumAuto.resetIndexes()
|
|
35
30
|
Object.keys(this.references.sections[documentName]).forEach(sectionId => {
|
|
36
31
|
documentOutputs.push(
|
|
37
32
|
...new SectionRender({
|
|
@@ -42,11 +37,11 @@ class DocumentRender {
|
|
|
42
37
|
currentSection: parseInt(sectionId, 10),
|
|
43
38
|
numauto: this.NumAuto
|
|
44
39
|
}).getOutputs()
|
|
45
|
-
)
|
|
46
|
-
})
|
|
40
|
+
)
|
|
41
|
+
})
|
|
47
42
|
|
|
48
|
-
return documentOutputs.join(
|
|
43
|
+
return documentOutputs.join('')
|
|
49
44
|
}
|
|
50
45
|
}
|
|
51
46
|
|
|
52
|
-
export default DocumentRender
|
|
47
|
+
export default DocumentRender
|