@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,71 +1,68 @@
|
|
|
1
|
-
import { Types } from
|
|
1
|
+
import { Types } from '@legalplace/referencesparser'
|
|
2
2
|
|
|
3
|
-
type References = Types.ReferencesType
|
|
3
|
+
type References = Types.ReferencesType
|
|
4
4
|
|
|
5
5
|
type OVC_TYPE = {
|
|
6
6
|
options: {
|
|
7
|
-
[key: string]: boolean[]
|
|
8
|
-
}
|
|
7
|
+
[key: string]: boolean[]
|
|
8
|
+
}
|
|
9
9
|
variables: {
|
|
10
|
-
[key: string]: (number | string)[]
|
|
11
|
-
}
|
|
12
|
-
}
|
|
10
|
+
[key: string]: (number | string)[]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
13
|
|
|
14
14
|
class IntputsInitiator {
|
|
15
15
|
private inputs: OVC_TYPE = {
|
|
16
16
|
options: {},
|
|
17
17
|
variables: {}
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
private references: References
|
|
20
|
+
private references: References
|
|
21
21
|
|
|
22
|
-
private ovc: OVC_TYPE | null
|
|
22
|
+
private ovc: OVC_TYPE | null
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* InitalConditions Constructor
|
|
26
26
|
* @param references References object
|
|
27
27
|
*/
|
|
28
28
|
constructor(references: References, ovc: OVC_TYPE | null) {
|
|
29
|
-
this.references = references
|
|
30
|
-
this.ovc = ovc
|
|
29
|
+
this.references = references
|
|
30
|
+
this.ovc = ovc
|
|
31
31
|
|
|
32
32
|
// Setting multiples
|
|
33
|
-
this.setMultiples()
|
|
33
|
+
this.setMultiples()
|
|
34
34
|
|
|
35
35
|
// Initiating inputs
|
|
36
|
-
this.initOptionsInputs()
|
|
37
|
-
this.initVariablesInputs()
|
|
36
|
+
this.initOptionsInputs()
|
|
37
|
+
this.initVariablesInputs()
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
public getInputs() {
|
|
41
|
-
return this.inputs
|
|
41
|
+
return this.inputs
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
private setMultiples() {
|
|
45
|
-
if (this.ovc === null) return
|
|
45
|
+
if (this.ovc === null) return
|
|
46
46
|
Object.keys(this.ovc.options).forEach(id => {
|
|
47
|
-
if (this.ovc === null) return
|
|
48
|
-
const inputs = this.ovc.options[id]
|
|
47
|
+
if (this.ovc === null) return
|
|
48
|
+
const inputs = this.ovc.options[id]
|
|
49
49
|
|
|
50
50
|
if (inputs.length > 1) {
|
|
51
51
|
// Getting parents
|
|
52
|
-
const parentsTree = this.references.relations.options[id].parents
|
|
52
|
+
const parentsTree = this.references.relations.options[id].parents
|
|
53
53
|
|
|
54
54
|
// root parent
|
|
55
|
-
const rootOptionId =
|
|
56
|
-
parentsTree.length > 0 ? parentsTree[parentsTree.length - 1] : id;
|
|
55
|
+
const rootOptionId = parentsTree.length > 0 ? parentsTree[parentsTree.length - 1] : id
|
|
57
56
|
|
|
58
57
|
if (!this.ovc.options[rootOptionId]) {
|
|
59
58
|
// root Option reference
|
|
60
|
-
const rootReference = this.references.options[rootOptionId]
|
|
61
|
-
if (rootReference.meta.type ===
|
|
62
|
-
this.ovc.options[rootOptionId] = new Array(inputs.length).fill(
|
|
63
|
-
true
|
|
64
|
-
);
|
|
59
|
+
const rootReference = this.references.options[rootOptionId]
|
|
60
|
+
if (rootReference.meta.type === 'static') {
|
|
61
|
+
this.ovc.options[rootOptionId] = new Array(inputs.length).fill(true)
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
64
|
}
|
|
68
|
-
})
|
|
65
|
+
})
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
/**
|
|
@@ -73,44 +70,23 @@ class IntputsInitiator {
|
|
|
73
70
|
*/
|
|
74
71
|
private initOptionsInputs() {
|
|
75
72
|
// Options
|
|
76
|
-
const optionsIds = Object.keys(this.references.options)
|
|
73
|
+
const optionsIds = Object.keys(this.references.options)
|
|
77
74
|
for (let i = 0; i < optionsIds.length; i += 1) {
|
|
78
|
-
const optionId = optionsIds[i]
|
|
79
|
-
const option = this.references.options[optionId]
|
|
80
|
-
|
|
81
|
-
let values = [false]
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
) {
|
|
86
|
-
if (
|
|
87
|
-
[
|
|
88
|
-
"static",
|
|
89
|
-
"hidden",
|
|
90
|
-
"brut-text",
|
|
91
|
-
"repeated",
|
|
92
|
-
"box",
|
|
93
|
-
"separator"
|
|
94
|
-
].includes(option.meta.type)
|
|
95
|
-
) {
|
|
96
|
-
values = new Array(this.ovc.options[optionId].length).fill(true);
|
|
75
|
+
const optionId = optionsIds[i]
|
|
76
|
+
const option = this.references.options[optionId]
|
|
77
|
+
|
|
78
|
+
let values = [false]
|
|
79
|
+
if (this.ovc && Object.prototype.hasOwnProperty.call(this.ovc.options, optionId)) {
|
|
80
|
+
if (['static', 'hidden', 'brut-text', 'repeated', 'box', 'separator'].includes(option.meta.type)) {
|
|
81
|
+
values = new Array(this.ovc.options[optionId].length).fill(true)
|
|
97
82
|
} else {
|
|
98
|
-
values = this.ovc.options[optionId]
|
|
83
|
+
values = this.ovc.options[optionId]
|
|
99
84
|
}
|
|
100
|
-
} else if (
|
|
101
|
-
[
|
|
102
|
-
"static",
|
|
103
|
-
"hidden",
|
|
104
|
-
"brut-text",
|
|
105
|
-
"repeated",
|
|
106
|
-
"box",
|
|
107
|
-
"separator"
|
|
108
|
-
].includes(option.meta.type)
|
|
109
|
-
) {
|
|
110
|
-
values = [true];
|
|
85
|
+
} else if (['static', 'hidden', 'brut-text', 'repeated', 'box', 'separator'].includes(option.meta.type)) {
|
|
86
|
+
values = [true]
|
|
111
87
|
}
|
|
112
88
|
|
|
113
|
-
this.inputs.options[optionId] = values
|
|
89
|
+
this.inputs.options[optionId] = values
|
|
114
90
|
}
|
|
115
91
|
}
|
|
116
92
|
|
|
@@ -118,42 +94,28 @@ class IntputsInitiator {
|
|
|
118
94
|
* Initates variables inputs
|
|
119
95
|
*/
|
|
120
96
|
private initVariablesInputs() {
|
|
121
|
-
const variablesIds = Object.keys(this.references.variables)
|
|
97
|
+
const variablesIds = Object.keys(this.references.variables)
|
|
122
98
|
for (let i = 0; i < variablesIds.length; i += 1) {
|
|
123
|
-
const variableId = variablesIds[i]
|
|
124
|
-
|
|
125
|
-
let values: (string | number)[] = [
|
|
126
|
-
if (
|
|
127
|
-
this.ovc
|
|
128
|
-
Object.prototype.hasOwnProperty.call(this.ovc.variables, variableId)
|
|
129
|
-
) {
|
|
130
|
-
values = this.ovc.variables[variableId];
|
|
99
|
+
const variableId = variablesIds[i]
|
|
100
|
+
|
|
101
|
+
let values: (string | number)[] = ['']
|
|
102
|
+
if (this.ovc && Object.prototype.hasOwnProperty.call(this.ovc.variables, variableId)) {
|
|
103
|
+
values = this.ovc.variables[variableId]
|
|
131
104
|
} else {
|
|
132
|
-
let defaultValue =
|
|
105
|
+
let defaultValue = ''
|
|
133
106
|
|
|
134
107
|
// Checking for first prefill without condition
|
|
135
|
-
const { prefillings } = this.references.variables[variableId]
|
|
136
|
-
if (
|
|
137
|
-
prefillings
|
|
138
|
-
|
|
139
|
-
prefillings.length > 0
|
|
140
|
-
) {
|
|
141
|
-
const noConditionsPrefills = prefillings.filter(
|
|
142
|
-
prefill =>
|
|
143
|
-
typeof prefill.conditions === "undefined" ||
|
|
144
|
-
Object.keys(prefill.conditions).length === 0
|
|
145
|
-
);
|
|
146
|
-
defaultValue =
|
|
147
|
-
noConditionsPrefills.length > 0
|
|
148
|
-
? noConditionsPrefills[0].value
|
|
149
|
-
: "";
|
|
108
|
+
const { prefillings } = this.references.variables[variableId]
|
|
109
|
+
if (prefillings && Array.isArray(prefillings) && prefillings.length > 0) {
|
|
110
|
+
const noConditionsPrefills = prefillings.filter(prefill => typeof prefill.conditions === 'undefined' || Object.keys(prefill.conditions).length === 0)
|
|
111
|
+
defaultValue = noConditionsPrefills.length > 0 ? noConditionsPrefills[0].value : ''
|
|
150
112
|
}
|
|
151
|
-
values = [defaultValue]
|
|
113
|
+
values = [defaultValue]
|
|
152
114
|
}
|
|
153
115
|
|
|
154
|
-
this.inputs.variables[variableId] = values
|
|
116
|
+
this.inputs.variables[variableId] = values
|
|
155
117
|
}
|
|
156
118
|
}
|
|
157
119
|
}
|
|
158
120
|
|
|
159
|
-
export default IntputsInitiator
|
|
121
|
+
export default IntputsInitiator
|
package/src/libs/NumAuto.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class NumAuto {
|
|
2
|
-
indexesList: Record<string, any> = {}
|
|
2
|
+
indexesList: Record<string, any> = {}
|
|
3
3
|
|
|
4
|
-
tagsIndex: Record<string, number> = {}
|
|
4
|
+
tagsIndex: Record<string, number> = {}
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Increments the given index by 1 and
|
|
@@ -12,19 +12,18 @@ class NumAuto {
|
|
|
12
12
|
// In case the index doesn't exist
|
|
13
13
|
if (!Object.prototype.hasOwnProperty.call(this.indexesList, index)) {
|
|
14
14
|
// Let's first make sure it's not a tag and return it if it is
|
|
15
|
-
if (Object.prototype.hasOwnProperty.call(this.tagsIndex, index))
|
|
16
|
-
return this.tagsIndex[index];
|
|
15
|
+
if (Object.prototype.hasOwnProperty.call(this.tagsIndex, index)) return this.tagsIndex[index]
|
|
17
16
|
|
|
18
17
|
// Otherwise we set a new index
|
|
19
|
-
this.indexesList[index] = 0
|
|
18
|
+
this.indexesList[index] = 0
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
this.indexesList[index] += 1
|
|
21
|
+
this.indexesList[index] += 1
|
|
23
22
|
|
|
24
|
-
if (typeof tag ===
|
|
23
|
+
if (typeof tag === 'string') this.tagsIndex[tag] = this.indexesList[index]
|
|
25
24
|
|
|
26
|
-
return this.indexesList[index]
|
|
27
|
-
}
|
|
25
|
+
return this.indexesList[index]
|
|
26
|
+
}
|
|
28
27
|
|
|
29
28
|
/**
|
|
30
29
|
* Returns the current count of the given index
|
|
@@ -34,15 +33,14 @@ class NumAuto {
|
|
|
34
33
|
// In case the index doesn't exist
|
|
35
34
|
if (!Object.prototype.hasOwnProperty.call(this.indexesList, index)) {
|
|
36
35
|
// Let's first make sure it's not a tag and return it if it is
|
|
37
|
-
if (Object.prototype.hasOwnProperty.call(this.tagsIndex, index))
|
|
38
|
-
return this.tagsIndex[index];
|
|
36
|
+
if (Object.prototype.hasOwnProperty.call(this.tagsIndex, index)) return this.tagsIndex[index]
|
|
39
37
|
}
|
|
40
|
-
return this.indexesList[index]
|
|
41
|
-
}
|
|
38
|
+
return this.indexesList[index]
|
|
39
|
+
}
|
|
42
40
|
|
|
43
41
|
resetIndexes = () => {
|
|
44
|
-
this.indexesList = {}
|
|
45
|
-
}
|
|
42
|
+
this.indexesList = {}
|
|
43
|
+
}
|
|
46
44
|
}
|
|
47
45
|
|
|
48
|
-
export default NumAuto
|
|
46
|
+
export default NumAuto
|
package/src/libs/OptionRender.ts
CHANGED
|
@@ -1,110 +1,71 @@
|
|
|
1
|
-
import { Types } from
|
|
2
|
-
import ConditionsRunner from
|
|
3
|
-
import OVC_TYPE from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
getRelatedVariablesValues
|
|
7
|
-
} from "./OutputParser";
|
|
8
|
-
import NumAuto from "./NumAuto";
|
|
1
|
+
import { Types } from '@legalplace/referencesparser'
|
|
2
|
+
import ConditionsRunner from './ConditionsRunner'
|
|
3
|
+
import OVC_TYPE from './ovc.type'
|
|
4
|
+
import { parseOutputWithVariables, getRelatedVariablesValues } from './OutputParser'
|
|
5
|
+
import NumAuto from './NumAuto'
|
|
9
6
|
|
|
10
7
|
class OptionRender {
|
|
11
|
-
outputs: string[] = []
|
|
8
|
+
outputs: string[] = []
|
|
12
9
|
|
|
13
|
-
references: Types.ReferencesType
|
|
10
|
+
references: Types.ReferencesType
|
|
14
11
|
|
|
15
|
-
index: number
|
|
12
|
+
index: number
|
|
16
13
|
|
|
17
|
-
id: number
|
|
14
|
+
id: number
|
|
18
15
|
|
|
19
|
-
conditions: ConditionsRunner
|
|
16
|
+
conditions: ConditionsRunner
|
|
20
17
|
|
|
21
|
-
ovc: OVC_TYPE
|
|
18
|
+
ovc: OVC_TYPE
|
|
22
19
|
|
|
23
|
-
private NumAuto: NumAuto
|
|
20
|
+
private NumAuto: NumAuto
|
|
24
21
|
|
|
25
|
-
constructor(options: {
|
|
26
|
-
references
|
|
27
|
-
conditions
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
numauto
|
|
32
|
-
}) {
|
|
33
|
-
this.references = options.references;
|
|
34
|
-
this.conditions = options.conditions;
|
|
35
|
-
this.index = options.index;
|
|
36
|
-
this.id = options.id;
|
|
37
|
-
this.ovc = options.ovc;
|
|
38
|
-
this.NumAuto = options.numauto;
|
|
22
|
+
constructor(options: { references: Types.ReferencesType; conditions: ConditionsRunner; ovc: OVC_TYPE; index: number; id: number; numauto: NumAuto }) {
|
|
23
|
+
this.references = options.references
|
|
24
|
+
this.conditions = options.conditions
|
|
25
|
+
this.index = options.index
|
|
26
|
+
this.id = options.id
|
|
27
|
+
this.ovc = options.ovc
|
|
28
|
+
this.NumAuto = options.numauto
|
|
39
29
|
|
|
40
|
-
this.renderOption()
|
|
30
|
+
this.renderOption()
|
|
41
31
|
}
|
|
42
32
|
|
|
43
33
|
getOutputs() {
|
|
44
|
-
return this.outputs
|
|
34
|
+
return this.outputs
|
|
45
35
|
}
|
|
46
36
|
|
|
47
37
|
private renderOption() {
|
|
48
|
-
const option = this.references.options[this.id]
|
|
49
|
-
const conditionObject = this.references.conditions.options[this.id]
|
|
50
|
-
const condition =
|
|
51
|
-
conditionObject === undefined
|
|
52
|
-
? true
|
|
53
|
-
: this.conditions.executeCondition(
|
|
54
|
-
conditionObject,
|
|
55
|
-
this.id,
|
|
56
|
-
this.index,
|
|
57
|
-
"options"
|
|
58
|
-
);
|
|
38
|
+
const option = this.references.options[this.id]
|
|
39
|
+
const conditionObject = this.references.conditions.options[this.id]
|
|
40
|
+
const condition = conditionObject === undefined ? true : this.conditions.executeCondition(conditionObject, this.id, this.index, 'options')
|
|
59
41
|
|
|
60
42
|
// Rendering documents sections
|
|
61
43
|
if (condition === true) {
|
|
62
|
-
if (
|
|
63
|
-
typeof option.meta.output === "string" &&
|
|
64
|
-
option.meta.output.trim().length > 0
|
|
65
|
-
) {
|
|
44
|
+
if (typeof option.meta.output === 'string' && option.meta.output.trim().length > 0) {
|
|
66
45
|
// output Reference
|
|
67
|
-
const outputReference = this.references.outputs[this.id]
|
|
46
|
+
const outputReference = this.references.outputs[this.id]
|
|
68
47
|
|
|
69
48
|
// Autonums
|
|
70
|
-
let autonums: [string, string, number, string | null][] = []
|
|
49
|
+
let autonums: [string, string, number, string | null][] = []
|
|
71
50
|
if (condition !== false) {
|
|
72
51
|
autonums = outputReference.autonums.map(currentAn => {
|
|
73
|
-
const fn =
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
: this.NumAuto.getNum;
|
|
77
|
-
return [
|
|
78
|
-
currentAn[0],
|
|
79
|
-
currentAn[1],
|
|
80
|
-
fn(currentAn[1], currentAn[2]),
|
|
81
|
-
currentAn[2]
|
|
82
|
-
];
|
|
83
|
-
});
|
|
52
|
+
const fn = currentAn[0] === 'numauto-pre' ? this.NumAuto.getNumPre : this.NumAuto.getNum
|
|
53
|
+
return [currentAn[0], currentAn[1], fn(currentAn[1], currentAn[2]), currentAn[2]]
|
|
54
|
+
})
|
|
84
55
|
}
|
|
85
56
|
|
|
86
57
|
// variables
|
|
87
|
-
const variables = getRelatedVariablesValues(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.ovc,
|
|
92
|
-
this.references
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const output = parseOutputWithVariables(
|
|
96
|
-
option.meta.output,
|
|
97
|
-
variables,
|
|
98
|
-
autonums
|
|
99
|
-
);
|
|
100
|
-
this.outputs.push(output);
|
|
58
|
+
const variables = getRelatedVariablesValues(this.id, this.index, outputReference.variables, this.ovc, this.references)
|
|
59
|
+
|
|
60
|
+
const output = parseOutputWithVariables(option.meta.output, variables, autonums)
|
|
61
|
+
this.outputs.push(output)
|
|
101
62
|
}
|
|
102
|
-
this.renderChildren()
|
|
63
|
+
this.renderChildren()
|
|
103
64
|
}
|
|
104
65
|
}
|
|
105
66
|
|
|
106
67
|
private renderChildren() {
|
|
107
|
-
const option = this.references.options[this.id]
|
|
68
|
+
const option = this.references.options[this.id]
|
|
108
69
|
option.options.forEach(optionId => {
|
|
109
70
|
this.outputs = [
|
|
110
71
|
...this.outputs,
|
|
@@ -116,9 +77,9 @@ class OptionRender {
|
|
|
116
77
|
conditions: this.conditions,
|
|
117
78
|
numauto: this.NumAuto
|
|
118
79
|
}).getOutputs()
|
|
119
|
-
]
|
|
120
|
-
})
|
|
80
|
+
]
|
|
81
|
+
})
|
|
121
82
|
}
|
|
122
83
|
}
|
|
123
84
|
|
|
124
|
-
export default OptionRender
|
|
85
|
+
export default OptionRender
|
package/src/libs/OutputParser.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Types } from
|
|
2
|
-
import OVC_TYPE from
|
|
1
|
+
import { Types } from '@legalplace/referencesparser'
|
|
2
|
+
import OVC_TYPE from './ovc.type'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Returns option's related variable values
|
|
@@ -7,64 +7,41 @@ import OVC_TYPE from "./ovc.type";
|
|
|
7
7
|
* @param index Occurency index
|
|
8
8
|
* @param variables Variables ids list
|
|
9
9
|
*/
|
|
10
|
-
type relVarsValsT = Record<string, string | number
|
|
11
|
-
type getRelatedVarsT = (
|
|
12
|
-
|
|
13
|
-
index: number,
|
|
14
|
-
variables: number[],
|
|
15
|
-
ovc: OVC_TYPE,
|
|
16
|
-
references: Types.ReferencesType
|
|
17
|
-
) => relVarsValsT;
|
|
18
|
-
export const getRelatedVariablesValues: getRelatedVarsT = (
|
|
19
|
-
optionId,
|
|
20
|
-
index,
|
|
21
|
-
variables,
|
|
22
|
-
ovc,
|
|
23
|
-
references
|
|
24
|
-
) => {
|
|
10
|
+
type relVarsValsT = Record<string, string | number>
|
|
11
|
+
type getRelatedVarsT = (optionId: number, index: number, variables: number[], ovc: OVC_TYPE, references: Types.ReferencesType) => relVarsValsT
|
|
12
|
+
export const getRelatedVariablesValues: getRelatedVarsT = (optionId, index, variables, ovc, references) => {
|
|
25
13
|
// Getting variables values
|
|
26
|
-
const variablesValues: Record<string, string> = {}
|
|
14
|
+
const variablesValues: Record<string, string> = {}
|
|
27
15
|
variables.forEach(currentVariableId => {
|
|
28
16
|
// Getting option value
|
|
29
|
-
let value = ovc.variables[currentVariableId] || [
|
|
30
|
-
const variableParents =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
);
|
|
36
|
-
const rootVariableParentId = variableParents[variableParents.length - 1];
|
|
37
|
-
const rootVariableParentRelations =
|
|
38
|
-
references.relations.options[rootVariableParentId];
|
|
39
|
-
if (rootVariableParentRelations === undefined)
|
|
40
|
-
throw new Error(`Option ${rootVariableParentId} does not exist`);
|
|
17
|
+
let value = ovc.variables[currentVariableId] || ['']
|
|
18
|
+
const variableParents = references.relations.variables[currentVariableId].parents
|
|
19
|
+
if (variableParents === undefined) throw new Error(`Variable ${currentVariableId} parents object does not exist`)
|
|
20
|
+
const rootVariableParentId = variableParents[variableParents.length - 1]
|
|
21
|
+
const rootVariableParentRelations = references.relations.options[rootVariableParentId]
|
|
22
|
+
if (rootVariableParentRelations === undefined) throw new Error(`Option ${rootVariableParentId} does not exist`)
|
|
41
23
|
|
|
42
|
-
if (typeof variableParents ===
|
|
24
|
+
if (typeof variableParents === 'undefined') return
|
|
43
25
|
|
|
44
26
|
// Getting rootOption parent
|
|
45
27
|
|
|
46
28
|
// Checking if current option is related to the option that changed
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
rootVariableParentRelations.dependants.includes(optionId) ||
|
|
50
|
-
optionId === rootVariableParentId
|
|
51
|
-
)
|
|
52
|
-
value = [value[index]];
|
|
29
|
+
if (rootVariableParentRelations.children.options.includes(optionId) || rootVariableParentRelations.dependants.includes(optionId) || optionId === rootVariableParentId)
|
|
30
|
+
value = [value[index]]
|
|
53
31
|
|
|
54
32
|
// Making sure all values are strings
|
|
55
33
|
const cleanValues = value.map(currentValue => {
|
|
56
|
-
if (typeof currentValue ===
|
|
57
|
-
if (typeof currentValue ===
|
|
58
|
-
return
|
|
59
|
-
})
|
|
34
|
+
if (typeof currentValue === 'number') return currentValue.toString()
|
|
35
|
+
if (typeof currentValue === 'string') return currentValue
|
|
36
|
+
return ''
|
|
37
|
+
})
|
|
60
38
|
|
|
61
39
|
// Joining multiple variables
|
|
62
|
-
variablesValues[currentVariableId] =
|
|
63
|
-
|
|
64
|
-
});
|
|
40
|
+
variablesValues[currentVariableId] = cleanValues.length === 1 ? cleanValues[0] : cleanValues.join(', ')
|
|
41
|
+
})
|
|
65
42
|
|
|
66
|
-
return variablesValues
|
|
67
|
-
}
|
|
43
|
+
return variablesValues
|
|
44
|
+
}
|
|
68
45
|
|
|
69
46
|
/**
|
|
70
47
|
* Parses output with variables
|
|
@@ -74,52 +51,30 @@ export const getRelatedVariablesValues: getRelatedVarsT = (
|
|
|
74
51
|
* @param variables Variables values list
|
|
75
52
|
* @param autonums Autonums values
|
|
76
53
|
*/
|
|
77
|
-
type autonumsType = [string, string, number, string | null][]
|
|
78
|
-
type parseOutputT = (
|
|
79
|
-
|
|
80
|
-
variables: relVarsValsT,
|
|
81
|
-
autonums: autonumsType
|
|
82
|
-
) => string;
|
|
83
|
-
export const parseOutputWithVariables: parseOutputT = (
|
|
84
|
-
output,
|
|
85
|
-
variables,
|
|
86
|
-
autonums
|
|
87
|
-
) => {
|
|
54
|
+
type autonumsType = [string, string, number, string | null][]
|
|
55
|
+
type parseOutputT = (output: string, variables: relVarsValsT, autonums: autonumsType) => string
|
|
56
|
+
export const parseOutputWithVariables: parseOutputT = (output, variables, autonums) => {
|
|
88
57
|
// Inserting values
|
|
89
|
-
let parsedOutput = `${output}
|
|
58
|
+
let parsedOutput = `${output}`
|
|
90
59
|
Object.keys(variables).forEach(variableId => {
|
|
91
|
-
let value: string = variables[variableId].toString()
|
|
60
|
+
let value: string = variables[variableId].toString()
|
|
92
61
|
if (value.trim().length === 0) {
|
|
93
|
-
value = new Array(16).join(
|
|
62
|
+
value = new Array(16).join('_')
|
|
94
63
|
}
|
|
95
|
-
parsedOutput = parsedOutput.replace(
|
|
96
|
-
|
|
97
|
-
value
|
|
98
|
-
);
|
|
99
|
-
});
|
|
64
|
+
parsedOutput = parsedOutput.replace(new RegExp(`\\[var:${variableId}\\]`, 'g'), value)
|
|
65
|
+
})
|
|
100
66
|
|
|
101
67
|
// Inserting page breaks
|
|
102
|
-
parsedOutput = parsedOutput.replace(
|
|
103
|
-
/\[\[PAGE_BREAK\]\]/gi,
|
|
104
|
-
'<div style="page-break-after:always"></div>'
|
|
105
|
-
);
|
|
68
|
+
parsedOutput = parsedOutput.replace(/\[\[PAGE_BREAK\]\]/gi, '<div style="page-break-after:always"></div>')
|
|
106
69
|
|
|
107
70
|
// Cleaning BLURS
|
|
108
|
-
parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi,
|
|
71
|
+
parsedOutput = parsedOutput.replace(/\[(E|B)_BLUR\]/gi, '')
|
|
109
72
|
|
|
110
73
|
// Inserting autonums
|
|
111
74
|
autonums.forEach(currentAn => {
|
|
112
|
-
if (currentAn[3] === null)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
`<span class="${currentAn[0]}">${currentAn[2]}</span>`
|
|
116
|
-
);
|
|
117
|
-
else
|
|
118
|
-
parsedOutput = parsedOutput.replace(
|
|
119
|
-
`[${currentAn[0]}:${currentAn[1]}](${currentAn[3]})`,
|
|
120
|
-
`<span class="${currentAn[0]}">${currentAn[2]}</span>`
|
|
121
|
-
);
|
|
122
|
-
});
|
|
75
|
+
if (currentAn[3] === null) parsedOutput = parsedOutput.replace(`[${currentAn[0]}:${currentAn[1]}]`, `<span class="${currentAn[0]}">${currentAn[2]}</span>`)
|
|
76
|
+
else parsedOutput = parsedOutput.replace(`[${currentAn[0]}:${currentAn[1]}](${currentAn[3]})`, `<span class="${currentAn[0]}">${currentAn[2]}</span>`)
|
|
77
|
+
})
|
|
123
78
|
|
|
124
|
-
return parsedOutput
|
|
125
|
-
}
|
|
79
|
+
return parsedOutput
|
|
80
|
+
}
|