@media-quest/builder 0.0.24 → 0.0.25
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/package.json +2 -2
- package/src/Builder-option.ts +64 -66
- package/src/Builder-page.spec.ts +320 -320
- package/src/Builder-page.ts +259 -257
- package/src/Builder-question.spec.ts +68 -68
- package/src/Builder-question.ts +102 -101
- package/src/Builder-schema.spec.ts +17 -17
- package/src/Builder-schema.ts +14 -8
- package/src/Builder-text.spec.ts +24 -24
- package/src/Builder-text.ts +57 -57
- package/src/BuilderObject.ts +29 -61
- package/src/BuilderTag.ts +96 -97
- package/src/codebook.ts +72 -72
- package/src/primitives/ID.spec.ts +39 -0
- package/src/primitives/ID.ts +119 -0
- package/src/primitives/page-prefix.ts +59 -58
- package/src/primitives/varID.ts +12 -11
- package/src/public-api.ts +3 -1
- package/src/rulebuilder/Builder-rule.spec.ts +323 -322
- package/src/rulebuilder/Builder-rule.ts +191 -190
- package/src/rulebuilder/RuleBuilder-test-utils.ts +320 -316
- package/src/rulebuilder/RuleVariable.ts +48 -49
- package/src/rulebuilder/page-action-manager.ts +33 -31
- package/src/rulebuilder/rule2/Rule2.ts +215 -211
- package/src/schema-config.ts +25 -25
- package/src/variable/{mq-variable.ts → b-variable.ts} +5 -5
- package/src/variable/mq-variable.spec.ts +6 -5
- package/src/variable/sum-score-variable.ts +50 -0
- package/src/variable/sum-score.ts +6 -14
package/src/Builder-question.ts
CHANGED
|
@@ -1,101 +1,102 @@
|
|
|
1
|
-
import type { BuilderOptionDto } from "./Builder-option";
|
|
2
|
-
import { BuilderOption } from "./Builder-option";
|
|
3
|
-
import { BuilderObject
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
1
|
+
import type { BuilderOptionDto } from "./Builder-option";
|
|
2
|
+
import { BuilderOption } from "./Builder-option";
|
|
3
|
+
import { BuilderObject } from "./BuilderObject";
|
|
4
|
+
import { QuestionID } from "./primitives/ID";
|
|
5
|
+
|
|
6
|
+
export type BuilderQuestionType =
|
|
7
|
+
| "select-one"
|
|
8
|
+
| "select-many"
|
|
9
|
+
| "text"
|
|
10
|
+
| "color"
|
|
11
|
+
| "radio"
|
|
12
|
+
| "email"
|
|
13
|
+
| "time"
|
|
14
|
+
| "checkbox"
|
|
15
|
+
| "textarea"
|
|
16
|
+
| "date"
|
|
17
|
+
| "numeric-range"
|
|
18
|
+
| "duration";
|
|
19
|
+
|
|
20
|
+
export interface BuilderQuestionDto {
|
|
21
|
+
readonly id: QuestionID;
|
|
22
|
+
_type: BuilderQuestionType;
|
|
23
|
+
text: string;
|
|
24
|
+
options: ReadonlyArray<BuilderOptionDto>;
|
|
25
|
+
prefix: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class BuilderQuestion extends BuilderObject<"builder-question", BuilderQuestionDto> {
|
|
29
|
+
readonly objectType = "builder-question";
|
|
30
|
+
id: QuestionID;
|
|
31
|
+
type: BuilderQuestionType;
|
|
32
|
+
questionText = "";
|
|
33
|
+
options: BuilderOption[] = [];
|
|
34
|
+
prefix = "";
|
|
35
|
+
|
|
36
|
+
static create = (type: BuilderQuestionType) => {
|
|
37
|
+
const id = QuestionID.create();
|
|
38
|
+
|
|
39
|
+
return new BuilderQuestion({
|
|
40
|
+
id,
|
|
41
|
+
_type: type,
|
|
42
|
+
text: "",
|
|
43
|
+
options: [],
|
|
44
|
+
prefix: "",
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
public static fromJson(dto: BuilderQuestionDto): BuilderQuestion {
|
|
49
|
+
const question = new BuilderQuestion(dto);
|
|
50
|
+
return question;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private constructor(dto: BuilderQuestionDto) {
|
|
54
|
+
super(dto);
|
|
55
|
+
this.id = QuestionID.validateOrCreate(dto.id);
|
|
56
|
+
this.type = dto._type;
|
|
57
|
+
this.questionText = dto.text;
|
|
58
|
+
this.prefix = dto.prefix;
|
|
59
|
+
this.options = dto.options.map((o) => BuilderOption.fromJson(o));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
addOption(label: string, value: number, atIndex = -1) {
|
|
63
|
+
const option = BuilderOption.create(value, label);
|
|
64
|
+
if (atIndex >= 0 && atIndex < this.options.length) {
|
|
65
|
+
this.options.splice(atIndex, 0, option);
|
|
66
|
+
} else {
|
|
67
|
+
this.options.push(option);
|
|
68
|
+
}
|
|
69
|
+
return option;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
deleteOption(option: BuilderOption): boolean {
|
|
73
|
+
const filtered = this.options.filter((o) => o.id !== option.id);
|
|
74
|
+
const didDelete = filtered.length === this.options.length - 1;
|
|
75
|
+
this.options = filtered;
|
|
76
|
+
return didDelete;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
toJson() {
|
|
80
|
+
const optionsJson = this.options.map((o) => o.toJson());
|
|
81
|
+
const dto: BuilderQuestionDto = {
|
|
82
|
+
id: this.id,
|
|
83
|
+
prefix: this.prefix,
|
|
84
|
+
_type: this.type,
|
|
85
|
+
text: this.questionText,
|
|
86
|
+
options: optionsJson,
|
|
87
|
+
};
|
|
88
|
+
return dto;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
clone(): BuilderQuestionDto {
|
|
92
|
+
const cloneId = QuestionID.create();
|
|
93
|
+
const dto = this.toJson();
|
|
94
|
+
const optionsClone = this.options.map((o) => o.clone());
|
|
95
|
+
const clonedDto: BuilderQuestionDto = {
|
|
96
|
+
...dto,
|
|
97
|
+
id: cloneId,
|
|
98
|
+
options: optionsClone,
|
|
99
|
+
};
|
|
100
|
+
return clonedDto;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -3,11 +3,11 @@ import { BuilderSchema } from "./Builder-schema";
|
|
|
3
3
|
import { BuilderPage } from "./Builder-page";
|
|
4
4
|
import type { BuilderTagDto } from "./BuilderTag";
|
|
5
5
|
import { BuilderTag } from "./BuilderTag";
|
|
6
|
-
import type { BuilderObjectId } from "./BuilderObject";
|
|
7
|
-
import { PageID, SchemaID } from "@media-quest/engine";
|
|
8
6
|
import { PagePrefix } from "./primitives/page-prefix";
|
|
9
7
|
import { SchemaPrefix } from "./primitives/schema-prefix";
|
|
10
|
-
|
|
8
|
+
|
|
9
|
+
import { SumScoreVariableDto } from "./variable/sum-score-variable";
|
|
10
|
+
import { OptionID, PageID, QuestionID, SchemaID } from "./primitives/ID";
|
|
11
11
|
|
|
12
12
|
const tag1: BuilderTagDto = BuilderTag.create("tag1", "This tag is defined in schemaDto1").toJson();
|
|
13
13
|
|
|
@@ -34,7 +34,7 @@ const schemaDto1: BuilderSchemaDto = {
|
|
|
34
34
|
],
|
|
35
35
|
pages: [
|
|
36
36
|
{
|
|
37
|
-
id: PageID.
|
|
37
|
+
id: PageID.validateOrCreate("a".repeat(24)),
|
|
38
38
|
_type: "info-page",
|
|
39
39
|
prefix: PagePrefix.fromStringOrThrow("p1"),
|
|
40
40
|
mainText: {
|
|
@@ -45,28 +45,28 @@ const schemaDto1: BuilderSchemaDto = {
|
|
|
45
45
|
},
|
|
46
46
|
|
|
47
47
|
nextButton: {
|
|
48
|
-
id: "next-button-text-id" as
|
|
48
|
+
id: "next-button-text-id" as OptionID,
|
|
49
49
|
label: "Neste",
|
|
50
50
|
value: -1,
|
|
51
51
|
},
|
|
52
52
|
defaultQuestion: {
|
|
53
|
-
id:
|
|
53
|
+
id: QuestionID.create(),
|
|
54
54
|
prefix: "one-prefix",
|
|
55
55
|
_type: "select-one",
|
|
56
56
|
text: "q1-text",
|
|
57
57
|
options: [
|
|
58
58
|
{
|
|
59
|
-
id: "opt-nei" as
|
|
59
|
+
id: "opt-nei" as OptionID,
|
|
60
60
|
value: 0,
|
|
61
61
|
label: "Nei",
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
|
-
id: "opt-ja" as
|
|
64
|
+
id: "opt-ja" as OptionID,
|
|
65
65
|
value: 1,
|
|
66
66
|
label: "Ja",
|
|
67
67
|
},
|
|
68
68
|
{
|
|
69
|
-
id: "opt-vet-ikke" as
|
|
69
|
+
id: "opt-vet-ikke" as OptionID,
|
|
70
70
|
value: 9,
|
|
71
71
|
label: "Vet ikke",
|
|
72
72
|
},
|
|
@@ -82,7 +82,7 @@ const schemaDto1: BuilderSchemaDto = {
|
|
|
82
82
|
autoplaySequence: [],
|
|
83
83
|
},
|
|
84
84
|
{
|
|
85
|
-
id: PageID.
|
|
85
|
+
id: PageID.validateOrCreate("b".repeat(24)),
|
|
86
86
|
_type: "multi-select",
|
|
87
87
|
prefix: PagePrefix.fromStringOrThrow("page2-prefix"),
|
|
88
88
|
tags: [tag3.tag],
|
|
@@ -93,12 +93,12 @@ const schemaDto1: BuilderSchemaDto = {
|
|
|
93
93
|
audioFile: false,
|
|
94
94
|
},
|
|
95
95
|
nextButton: {
|
|
96
|
-
id: "next-button-id-page2" as
|
|
96
|
+
id: "next-button-id-page2" as OptionID,
|
|
97
97
|
label: "Neste",
|
|
98
98
|
value: -1,
|
|
99
99
|
},
|
|
100
100
|
defaultQuestion: {
|
|
101
|
-
id: "default-
|
|
101
|
+
id: QuestionID.validateOrCreate("default-question-id"),
|
|
102
102
|
prefix: "one-prefix",
|
|
103
103
|
_type: "select-one",
|
|
104
104
|
text: "q1",
|
|
@@ -106,23 +106,23 @@ const schemaDto1: BuilderSchemaDto = {
|
|
|
106
106
|
},
|
|
107
107
|
questions: [
|
|
108
108
|
{
|
|
109
|
-
id:
|
|
109
|
+
id: QuestionID.create(),
|
|
110
110
|
prefix: "one-prefix",
|
|
111
111
|
_type: "select-one",
|
|
112
112
|
text: "q1-text",
|
|
113
113
|
options: [
|
|
114
114
|
{
|
|
115
|
-
id: "opt-nei" as
|
|
115
|
+
id: "opt-nei" as OptionID,
|
|
116
116
|
value: 0,
|
|
117
117
|
label: "Nei",
|
|
118
118
|
},
|
|
119
119
|
{
|
|
120
|
-
id: "opt-ja" as
|
|
120
|
+
id: "opt-ja" as OptionID,
|
|
121
121
|
value: 1,
|
|
122
122
|
label: "Ja",
|
|
123
123
|
},
|
|
124
124
|
{
|
|
125
|
-
id: "opt-vet-ikke" as
|
|
125
|
+
id: "opt-vet-ikke" as OptionID,
|
|
126
126
|
value: 9,
|
|
127
127
|
label: "Vet ikke",
|
|
128
128
|
},
|
|
@@ -326,7 +326,7 @@ describe("Builder schema", () => {
|
|
|
326
326
|
p2.defaultQuestion.addOption("Nei", 0);
|
|
327
327
|
|
|
328
328
|
const ruleInput = builderSchema.getRuleInput();
|
|
329
|
-
const ss1:
|
|
329
|
+
const ss1: SumScoreVariableDto = {
|
|
330
330
|
label: "ss1",
|
|
331
331
|
varId: "ss1_var_id",
|
|
332
332
|
initialValue: 0,
|
package/src/Builder-schema.ts
CHANGED
|
@@ -13,14 +13,16 @@ import type { BuilderTagDto } from "./BuilderTag";
|
|
|
13
13
|
import { BuilderTag, TagCollection } from "./BuilderTag";
|
|
14
14
|
import { DefaultThemeCompiler } from "./theme/default-theme-compiler";
|
|
15
15
|
import { ImageFile } from "./media-files";
|
|
16
|
-
import { DUtil
|
|
16
|
+
import { DUtil } from "@media-quest/engine";
|
|
17
17
|
import { PagePrefix } from "./primitives/page-prefix";
|
|
18
18
|
import { SchemaPrefix, SchemaPrefixValue } from "./primitives/schema-prefix";
|
|
19
19
|
import { CodeBook } from "./codebook";
|
|
20
|
-
import { PredefinedVariable } from "./variable/
|
|
20
|
+
import { PredefinedVariable } from "./variable/b-variable";
|
|
21
21
|
import { SchemaConfig } from "./schema-config";
|
|
22
22
|
import { CompilerOption, CompilerOutput } from "./builder-compiler";
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
import { SumScoreVariableDto } from "./variable/sum-score-variable";
|
|
25
|
+
import { SchemaID } from "./primitives/ID";
|
|
24
26
|
|
|
25
27
|
const U = DUtil;
|
|
26
28
|
|
|
@@ -34,13 +36,13 @@ export interface BuilderSchemaDto {
|
|
|
34
36
|
readonly baseHeight: number;
|
|
35
37
|
readonly baseWidth: number;
|
|
36
38
|
readonly predefinedVariables?: Array<PredefinedVariable>;
|
|
37
|
-
readonly sumScoreVariables?:
|
|
39
|
+
readonly sumScoreVariables?: ReadonlyArray<SumScoreVariableDto>;
|
|
38
40
|
readonly rules: ReadonlyArray<BuilderRuleDto>;
|
|
39
41
|
readonly tags: ReadonlyArray<BuilderTagDto>;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
class SumScoreVariableCollection {
|
|
43
|
-
private _all: Array<
|
|
45
|
+
private _all: Array<SumScoreVariableDto> = [];
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
export class BuilderSchema {
|
|
@@ -52,11 +54,11 @@ export class BuilderSchema {
|
|
|
52
54
|
mainImage: ImageFile | false = false;
|
|
53
55
|
predefinedVariables: PredefinedVariable[] = [];
|
|
54
56
|
private _rules: BuilderRule[] = [];
|
|
55
|
-
private _sumVariables:
|
|
57
|
+
private _sumVariables: SumScoreVariableDto[] = [];
|
|
56
58
|
get rules(): ReadonlyArray<BuilderRule> {
|
|
57
59
|
return [...this._rules];
|
|
58
60
|
}
|
|
59
|
-
get sumScoreVariables(): ReadonlyArray<
|
|
61
|
+
get sumScoreVariables(): ReadonlyArray<SumScoreVariableDto> {
|
|
60
62
|
return [...this._sumVariables];
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -77,6 +79,7 @@ export class BuilderSchema {
|
|
|
77
79
|
const schemaPrefix = SchemaPrefix.castOrCreateRandom(dto.prefix);
|
|
78
80
|
const schema = new BuilderSchema(dto.id, dto.name, schemaPrefix);
|
|
79
81
|
const pages = dto.pages.map(BuilderPage.fromJson);
|
|
82
|
+
|
|
80
83
|
schema._tagCollection.init(dto.tags);
|
|
81
84
|
schema.backgroundColor = dto.backgroundColor;
|
|
82
85
|
schema.baseHeight = dto.baseHeight;
|
|
@@ -87,6 +90,8 @@ export class BuilderSchema {
|
|
|
87
90
|
schema.mainImage = dto.mainImage ?? false;
|
|
88
91
|
const rulesDto = dto.rules ?? [];
|
|
89
92
|
const ruleInput = schema.getRuleInput();
|
|
93
|
+
|
|
94
|
+
schema._sumVariables = Array.isArray(dto.sumScoreVariables) ? [...dto.sumScoreVariables] : [];
|
|
90
95
|
schema._rules = rulesDto.map((r) => BuilderRule.fromDto(r, ruleInput));
|
|
91
96
|
return schema;
|
|
92
97
|
}
|
|
@@ -106,6 +111,7 @@ export class BuilderSchema {
|
|
|
106
111
|
rules,
|
|
107
112
|
tags,
|
|
108
113
|
predefinedVariables: this.predefinedVariables,
|
|
114
|
+
sumScoreVariables: [...this.sumScoreVariables],
|
|
109
115
|
mainImage: this.mainImage,
|
|
110
116
|
prefix: this.prefix.value,
|
|
111
117
|
};
|
|
@@ -130,7 +136,7 @@ export class BuilderSchema {
|
|
|
130
136
|
return newPage;
|
|
131
137
|
}
|
|
132
138
|
|
|
133
|
-
addSumScoreVariable(variable:
|
|
139
|
+
addSumScoreVariable(variable: SumScoreVariableDto) {
|
|
134
140
|
// TODO VALIDATE.
|
|
135
141
|
this._sumVariables.push({ ...variable });
|
|
136
142
|
}
|
package/src/Builder-text.spec.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type { BuilderTextDto } from "./Builder-text";
|
|
2
|
-
import { BuilderText } from "./Builder-text";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
const textDto: BuilderTextDto = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
let text1 = BuilderText.create("text one created");
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe("Builder Text", () => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
1
|
+
import type { BuilderTextDto } from "./Builder-text";
|
|
2
|
+
import { BuilderText } from "./Builder-text";
|
|
3
|
+
import { TextID } from "./primitives/ID";
|
|
4
|
+
|
|
5
|
+
const textDto: BuilderTextDto = {
|
|
6
|
+
id: "dto1" as TextID,
|
|
7
|
+
name: "dto1-name",
|
|
8
|
+
text: "text one",
|
|
9
|
+
translationRequired: true,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
let text1 = BuilderText.create("text one created");
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
text1 = BuilderText.create("text one created");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("Builder Text", () => {
|
|
19
|
+
test("Can serialize", () => {
|
|
20
|
+
const instance1 = BuilderText.fromJson(textDto);
|
|
21
|
+
const json = instance1.toJson();
|
|
22
|
+
expect(textDto).toStrictEqual(json);
|
|
23
|
+
});
|
|
24
|
+
});
|
package/src/Builder-text.ts
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
this.
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const dto = this.toJson();
|
|
44
|
-
const withNewId: BuilderTextDto = { ...dto, id:
|
|
45
|
-
return withNewId;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
toJson(): BuilderTextDto {
|
|
49
|
-
const dto: BuilderTextDto = {
|
|
50
|
-
id: this.id,
|
|
51
|
-
name: this.name,
|
|
52
|
-
text: this.text,
|
|
53
|
-
translationRequired: this.translateRequired
|
|
54
|
-
};
|
|
55
|
-
return dto;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
1
|
+
import { BuilderObject } from "./BuilderObject";
|
|
2
|
+
import { TextID } from "./primitives/ID";
|
|
3
|
+
|
|
4
|
+
export interface BuilderTextDto {
|
|
5
|
+
readonly id: TextID;
|
|
6
|
+
text: string;
|
|
7
|
+
name: string;
|
|
8
|
+
translationRequired: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class BuilderText extends BuilderObject<"builder-text", BuilderTextDto> {
|
|
12
|
+
readonly objectType = "builder-text";
|
|
13
|
+
id: TextID;
|
|
14
|
+
text = "";
|
|
15
|
+
name = "";
|
|
16
|
+
translateRequired = false;
|
|
17
|
+
// audio: {id: B}
|
|
18
|
+
private constructor(dto: BuilderTextDto) {
|
|
19
|
+
super(dto);
|
|
20
|
+
this.id = dto.id;
|
|
21
|
+
this.translateRequired = dto.translationRequired;
|
|
22
|
+
this.name = dto.name;
|
|
23
|
+
this.text = dto.text;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public static create(name: string) {
|
|
27
|
+
const id = TextID.create();
|
|
28
|
+
const dto: BuilderTextDto = {
|
|
29
|
+
id,
|
|
30
|
+
name,
|
|
31
|
+
text: "",
|
|
32
|
+
translationRequired: false,
|
|
33
|
+
};
|
|
34
|
+
const instance = new BuilderText(dto);
|
|
35
|
+
return instance;
|
|
36
|
+
}
|
|
37
|
+
public static fromJson(dto: BuilderTextDto) {
|
|
38
|
+
const instance = new BuilderText(dto);
|
|
39
|
+
return instance;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
clone(): BuilderTextDto {
|
|
43
|
+
const dto = this.toJson();
|
|
44
|
+
const withNewId: BuilderTextDto = { ...dto, id: TextID.create() };
|
|
45
|
+
return withNewId;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
toJson(): BuilderTextDto {
|
|
49
|
+
const dto: BuilderTextDto = {
|
|
50
|
+
id: this.id,
|
|
51
|
+
name: this.name,
|
|
52
|
+
text: this.text,
|
|
53
|
+
translationRequired: this.translateRequired,
|
|
54
|
+
};
|
|
55
|
+
return dto;
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/BuilderObject.ts
CHANGED
|
@@ -1,61 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
| "builder-
|
|
11
|
-
| "builder-
|
|
12
|
-
| "builder-
|
|
13
|
-
| "builder-
|
|
14
|
-
| "builder-
|
|
15
|
-
| "builder-
|
|
16
|
-
| "builder-
|
|
17
|
-
| "builder-condition"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export const mainTextId = (): MainTextID => {
|
|
32
|
-
return createId("builder-main-text") as MainTextID;
|
|
33
|
-
};
|
|
34
|
-
export const textId = (): TextID => {
|
|
35
|
-
return createId("builder-text") as TextID;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const questionOptionId = (): QuestionOptionID => {
|
|
39
|
-
return createId("builder-question-option") as QuestionOptionID;
|
|
40
|
-
};
|
|
41
|
-
export const questionId = (): QuestionID => {
|
|
42
|
-
return createId("builder-question") as QuestionID;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const createId = (type: BuilderObjectType): string => {
|
|
46
|
-
const id = U.randomString(24);
|
|
47
|
-
return type + "-" + id;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export abstract class BuilderObject<T extends BuilderObjectType, Dto extends {}> {
|
|
52
|
-
// abstract readonly id: string;
|
|
53
|
-
abstract readonly objectType: T;
|
|
54
|
-
abstract toJson(): Dto;
|
|
55
|
-
abstract clone(): Dto;
|
|
56
|
-
protected readonly originalDto: Dto;
|
|
57
|
-
protected constructor(dto: Dto) {
|
|
58
|
-
this.originalDto = dto;
|
|
59
|
-
// this.objectId = dto.objectId;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Builder objects are complex objects that are embedded inside
|
|
3
|
+
* a Builder-schema, and needs to be serialized to json. Often these objects
|
|
4
|
+
* are used in collections, and that is why most of them need an id.
|
|
5
|
+
*/
|
|
6
|
+
type BuilderObjectType =
|
|
7
|
+
| "builder-page"
|
|
8
|
+
| "builder-question-option"
|
|
9
|
+
| "builder-question"
|
|
10
|
+
| "builder-main-text"
|
|
11
|
+
| "builder-text"
|
|
12
|
+
| "builder-rule"
|
|
13
|
+
| "builder-tag"
|
|
14
|
+
| "builder-sum-score-variable"
|
|
15
|
+
| "builder-condition"
|
|
16
|
+
| "builder-variable"
|
|
17
|
+
| "builder-condition-group";
|
|
18
|
+
|
|
19
|
+
export abstract class BuilderObject<T extends BuilderObjectType, Dto extends {}> {
|
|
20
|
+
// abstract readonly id: string;
|
|
21
|
+
abstract readonly objectType: T;
|
|
22
|
+
abstract toJson(): Dto;
|
|
23
|
+
abstract clone(): Dto;
|
|
24
|
+
protected readonly originalDto: Dto;
|
|
25
|
+
protected constructor(dto: Dto) {
|
|
26
|
+
this.originalDto = dto;
|
|
27
|
+
// this.objectId = dto.objectId;
|
|
28
|
+
}
|
|
29
|
+
}
|