@media-quest/builder 0.0.26 → 0.0.28
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/dist/public-api.d.ts +820 -0
- package/dist/public-api.js +2740 -0
- package/dist/public-api.js.map +1 -0
- package/package.json +29 -15
- package/src/Builder-question.ts +0 -4
- package/src/Builder-schema.spec.ts +79 -60
- package/src/Builder-schema.ts +73 -63
- package/src/code-book/codebook-variable.ts +27 -29
- package/src/code-book/codebook.ts +81 -72
- package/src/page/Builder-page-collection.spec.ts +219 -0
- package/src/page/Builder-page-collection.ts +129 -0
- package/src/{Builder-page.spec.ts → page/Builder-page.spec.ts} +21 -6
- package/src/{Builder-page.ts → page/Builder-page.ts} +84 -16
- package/src/primitives/ID.ts +135 -138
- package/src/public-api.ts +28 -28
- package/src/rulebuilder/RuleAction.ts +105 -106
- package/src/sum-score/sum-score-variable-collection.spec.ts +68 -0
- package/src/sum-score/sum-score-variable-collection.ts +101 -0
- package/src/sum-score/sum-score-variable.spec.ts +308 -151
- package/src/sum-score/sum-score-variable.ts +102 -36
- package/src/sum-score/sum-score.ts +161 -122
- package/src/tag/BuilderTag.ts +45 -0
- package/src/tag/Tag-Collection.ts +53 -0
- package/src/theme/default-theme-compiler.ts +358 -358
- package/tsconfig.json +19 -15
- package/src/BuilderTag.ts +0 -96
- package/src/sum-score/sum-score-manager.spec.ts +0 -189
- package/src/sum-score/sum-score-manager.ts +0 -154
- package/src/sum-score/sum-score-membership.ts +0 -45
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,72 +1,81 @@
|
|
|
1
|
-
import { BuilderPageDto } from "../Builder-page";
|
|
2
|
-
import { BuilderSchemaDto } from "../Builder-schema";
|
|
3
|
-
import { CodeBookQuestionVariable, CodebookPredefinedVariable } from "./codebook-variable";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
readonly
|
|
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
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
1
|
+
import { BuilderPageDto } from "../page/Builder-page";
|
|
2
|
+
import { BuilderSchemaDto } from "../Builder-schema";
|
|
3
|
+
import { CodeBookQuestionVariable, CodebookPredefinedVariable } from "./codebook-variable";
|
|
4
|
+
import { SumScoreVariableDto } from "../sum-score/sum-score-variable";
|
|
5
|
+
|
|
6
|
+
export interface Codebook {
|
|
7
|
+
readonly predefinedVariables: ReadonlyArray<CodebookPredefinedVariable>;
|
|
8
|
+
readonly pageVariables: ReadonlyArray<CodeBookQuestionVariable>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const fromPage = (
|
|
12
|
+
page: BuilderPageDto,
|
|
13
|
+
sumScoreVariables: ReadonlyArray<SumScoreVariableDto>,
|
|
14
|
+
pagePosition: number,
|
|
15
|
+
modulePrefix: string,
|
|
16
|
+
): CodeBookQuestionVariable[] => {
|
|
17
|
+
const variables: CodeBookQuestionVariable[] = [];
|
|
18
|
+
|
|
19
|
+
if (page._type !== "question") {
|
|
20
|
+
// TODO Implement form field variables
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const options: CodeBookQuestionVariable["options"] = page.defaultQuestion.options.map((o) => {
|
|
25
|
+
return { value: o.value, label: o.label };
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const varId = modulePrefix + "_" + page.prefix;
|
|
29
|
+
|
|
30
|
+
const includedInSumScores = page.includedInSumScores.filter((a) => true);
|
|
31
|
+
|
|
32
|
+
const variable: CodeBookQuestionVariable = {
|
|
33
|
+
kind: "codebook-question-variable",
|
|
34
|
+
label: page.mainText.text,
|
|
35
|
+
pageId: page.id,
|
|
36
|
+
pagePrefix: page.prefix,
|
|
37
|
+
options,
|
|
38
|
+
modulePrefix,
|
|
39
|
+
pagePosition,
|
|
40
|
+
varId,
|
|
41
|
+
includedInSumScores: [],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
variables.push(variable);
|
|
45
|
+
|
|
46
|
+
return variables;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Converts a list of pages into a list of question-variables
|
|
51
|
+
* @param pages
|
|
52
|
+
* @param sumScoreVariables
|
|
53
|
+
* @param modulePrefix
|
|
54
|
+
*/
|
|
55
|
+
const getPageVariablesFromPages = (
|
|
56
|
+
pages: ReadonlyArray<BuilderPageDto>,
|
|
57
|
+
sumScoreVariables: ReadonlyArray<SumScoreVariableDto>,
|
|
58
|
+
modulePrefix: string,
|
|
59
|
+
): CodeBookQuestionVariable[] => {
|
|
60
|
+
const variables: CodeBookQuestionVariable[] = [];
|
|
61
|
+
pages.forEach((page, index) => {
|
|
62
|
+
const pageVariables = fromPage(page, sumScoreVariables, index, modulePrefix);
|
|
63
|
+
variables.push(...pageVariables);
|
|
64
|
+
});
|
|
65
|
+
return variables;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const fromSchema = (schema: BuilderSchemaDto): Codebook => {
|
|
69
|
+
const modulePrefix = schema.prefix;
|
|
70
|
+
const sumScoreVariables = schema.sumScoreVariables ?? [];
|
|
71
|
+
const pageVariables = getPageVariablesFromPages(schema.pages, sumScoreVariables, modulePrefix);
|
|
72
|
+
const vs = schema.predefinedVariables;
|
|
73
|
+
const predefinedVariables: CodebookPredefinedVariable[] = vs ? [...vs] : [];
|
|
74
|
+
return { pageVariables, predefinedVariables };
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const _CodeBook = {
|
|
78
|
+
fromSchema,
|
|
79
|
+
} as const;
|
|
80
|
+
|
|
81
|
+
export const CodeBook = Object.freeze(_CodeBook);
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { BuilderTag, BuilderTagDto } from "../tag/BuilderTag";
|
|
2
|
+
import { PagePrefix } from "../primitives/page-prefix";
|
|
3
|
+
import { BuilderPageCollection } from "./Builder-page-collection";
|
|
4
|
+
import { OptionID, PageID, QuestionID } from "../primitives/ID";
|
|
5
|
+
import { BuilderPage, BuilderPageDto } from "./Builder-page";
|
|
6
|
+
import { SumScoreVariable } from "../sum-score/sum-score-variable";
|
|
7
|
+
import { SumScoreVariableCollection } from "../sum-score/sum-score-variable-collection";
|
|
8
|
+
|
|
9
|
+
const tag1: BuilderTagDto = BuilderTag.create("tag1", "This tag is defined in schemaDto1").toJson();
|
|
10
|
+
|
|
11
|
+
const tag2: BuilderTagDto = BuilderTag.create("tag2", "This tag is defined in schemaDto1").toJson();
|
|
12
|
+
const tag3: BuilderTagDto = BuilderTag.create("tag3", "This tag is defined in schemaDto1").toJson();
|
|
13
|
+
|
|
14
|
+
const sumScoreVariable1 = SumScoreVariable.create({
|
|
15
|
+
name: "ss1",
|
|
16
|
+
useAvg: true,
|
|
17
|
+
description: "ss1 description",
|
|
18
|
+
});
|
|
19
|
+
const sumScoreVariable2 = SumScoreVariable.create({
|
|
20
|
+
name: "ss2",
|
|
21
|
+
useAvg: true,
|
|
22
|
+
description: "ss2 description",
|
|
23
|
+
});
|
|
24
|
+
const sumScoreVariable3 = SumScoreVariable.create({
|
|
25
|
+
name: "ss3",
|
|
26
|
+
useAvg: true,
|
|
27
|
+
description: "ss3 description",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const pages: BuilderPageDto[] = [
|
|
31
|
+
{
|
|
32
|
+
id: PageID.validateOrCreate("a".repeat(24)),
|
|
33
|
+
_type: "info-page",
|
|
34
|
+
prefix: PagePrefix.fromStringOrThrow("p1"),
|
|
35
|
+
mainText: {
|
|
36
|
+
text: "hello from test",
|
|
37
|
+
autoplay: false,
|
|
38
|
+
autoplayDelay: 0,
|
|
39
|
+
audioFile: false,
|
|
40
|
+
},
|
|
41
|
+
includedInSumScores: [{ sumScoreVariableId: sumScoreVariable1.id, weight: 1 }],
|
|
42
|
+
|
|
43
|
+
nextButton: {
|
|
44
|
+
id: OptionID.create(),
|
|
45
|
+
label: "Neste",
|
|
46
|
+
value: -1,
|
|
47
|
+
},
|
|
48
|
+
defaultQuestion: {
|
|
49
|
+
id: QuestionID.create(),
|
|
50
|
+
prefix: "one-prefix",
|
|
51
|
+
_type: "select-one",
|
|
52
|
+
text: "q1-text",
|
|
53
|
+
options: [
|
|
54
|
+
{
|
|
55
|
+
id: "opt-nei" as OptionID,
|
|
56
|
+
value: 0,
|
|
57
|
+
label: "Nei",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: "opt-ja" as OptionID,
|
|
61
|
+
value: 1,
|
|
62
|
+
label: "Ja",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: "opt-vet-ikke" as OptionID,
|
|
66
|
+
value: 9,
|
|
67
|
+
label: "Vet ikke",
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
tags: [
|
|
72
|
+
tag1.tag,
|
|
73
|
+
tag2.tag,
|
|
74
|
+
// { tag: 'can_read', description: 'The patient can read' },
|
|
75
|
+
// { tag: 'is grown up', description: 'Is grownUp.' }
|
|
76
|
+
],
|
|
77
|
+
autoplaySequence: [],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
id: PageID.dummy.b,
|
|
81
|
+
_type: "question",
|
|
82
|
+
prefix: PagePrefix.fromStringOrThrow("page2-prefix"),
|
|
83
|
+
tags: [tag3.tag],
|
|
84
|
+
includedInSumScores: [],
|
|
85
|
+
mainText: {
|
|
86
|
+
text: "hello from test",
|
|
87
|
+
autoplay: false,
|
|
88
|
+
autoplayDelay: 0,
|
|
89
|
+
audioFile: false,
|
|
90
|
+
},
|
|
91
|
+
nextButton: {
|
|
92
|
+
id: "next-button-id-page2" as OptionID,
|
|
93
|
+
label: "Neste",
|
|
94
|
+
value: -1,
|
|
95
|
+
},
|
|
96
|
+
defaultQuestion: {
|
|
97
|
+
id: QuestionID.validateOrCreate("default-question-id"),
|
|
98
|
+
prefix: "one-prefix",
|
|
99
|
+
_type: "select-one",
|
|
100
|
+
text: "q1",
|
|
101
|
+
options: [],
|
|
102
|
+
},
|
|
103
|
+
autoplaySequence: [],
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
let sumScoreVariableCollection = SumScoreVariableCollection.create([
|
|
108
|
+
sumScoreVariable1,
|
|
109
|
+
sumScoreVariable2,
|
|
110
|
+
sumScoreVariable3,
|
|
111
|
+
]);
|
|
112
|
+
let empty = BuilderPageCollection.create([]);
|
|
113
|
+
beforeEach(() => {
|
|
114
|
+
sumScoreVariableCollection = SumScoreVariableCollection.create([
|
|
115
|
+
sumScoreVariable1,
|
|
116
|
+
sumScoreVariable2,
|
|
117
|
+
sumScoreVariable3,
|
|
118
|
+
]);
|
|
119
|
+
empty = BuilderPageCollection.create([]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe("Builder page collection", () => {
|
|
123
|
+
test("Can add pages.", () => {
|
|
124
|
+
const p1 = empty.add("question");
|
|
125
|
+
const p2 = empty.add("info-page");
|
|
126
|
+
expect(empty.size).toBe(2);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test("Can delete page by id,", () => {
|
|
130
|
+
const p1 = empty.add("question");
|
|
131
|
+
const p2 = empty.add("question");
|
|
132
|
+
const p3 = empty.add("info-page");
|
|
133
|
+
expect(empty.size).toBe(3);
|
|
134
|
+
const result = empty.deleteById(p1.id);
|
|
135
|
+
expect(empty.size).toBe(2);
|
|
136
|
+
expect(result).toBe(true);
|
|
137
|
+
const result2 = empty.deleteById(p2.id);
|
|
138
|
+
expect(result2).toBe(true);
|
|
139
|
+
expect(empty.size).toBe(1);
|
|
140
|
+
expect(empty.pages[0]).toBe(p3);
|
|
141
|
+
const result3 = empty.deleteById(PageID.create());
|
|
142
|
+
expect(result3).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("fromJson === toJson", () => {
|
|
146
|
+
const col = BuilderPageCollection.create(pages);
|
|
147
|
+
const json = col.toJson();
|
|
148
|
+
expect(pages).toStrictEqual(json);
|
|
149
|
+
});
|
|
150
|
+
//
|
|
151
|
+
|
|
152
|
+
test("Can add page at concrete index", () => {
|
|
153
|
+
const p1 = empty.add("question");
|
|
154
|
+
expect(p1.pageType).toBe("question");
|
|
155
|
+
const p2 = empty.add("info-page", 0);
|
|
156
|
+
expect(p2.pageType).toBe("info-page");
|
|
157
|
+
|
|
158
|
+
expect(empty.pages[0].id).toBe(p2.id);
|
|
159
|
+
empty.add("question");
|
|
160
|
+
empty.add("question");
|
|
161
|
+
const last = empty.add("question");
|
|
162
|
+
expect(empty.pages[empty.pages.length - 1]).toBe(last);
|
|
163
|
+
const p3 = empty.add("info-page", 4);
|
|
164
|
+
expect(empty.pages[4].id).toBe(p3.id);
|
|
165
|
+
});
|
|
166
|
+
//
|
|
167
|
+
test("Can move page up and down", () => {
|
|
168
|
+
const p1 = empty.add("question");
|
|
169
|
+
const p2 = empty.add("question");
|
|
170
|
+
const p3 = empty.add("question");
|
|
171
|
+
const p4 = empty.add("info-page");
|
|
172
|
+
const last = empty.add("question");
|
|
173
|
+
empty.movePage(p2, 0);
|
|
174
|
+
expect(empty.pages[0]).toBe(p2);
|
|
175
|
+
expect(empty.pages[1]).toBe(p1);
|
|
176
|
+
expect(empty.movePage(p4, 4)).toBeTruthy();
|
|
177
|
+
expect(empty.movePage(p4, 5)).toBeFalsy();
|
|
178
|
+
expect(empty.movePage(p4, 10)).toBeFalsy();
|
|
179
|
+
|
|
180
|
+
expect(empty.pages[4].id).toBe(p4.id);
|
|
181
|
+
expect(empty.pages[3].id).toBe(last.id);
|
|
182
|
+
});
|
|
183
|
+
//
|
|
184
|
+
test("Can clone a page and insert at index", () => {
|
|
185
|
+
const p1 = empty.add("question");
|
|
186
|
+
const p2 = empty.add("question");
|
|
187
|
+
const p3 = empty.add("question");
|
|
188
|
+
const mainTextContent = "Hello from test";
|
|
189
|
+
const p4 = empty.add("info-page");
|
|
190
|
+
p3.mainText.text = mainTextContent;
|
|
191
|
+
const p1Clone = BuilderPage.fromJson(p1.clone());
|
|
192
|
+
const beforSize = empty.size;
|
|
193
|
+
empty.insertPage(p1Clone, 2);
|
|
194
|
+
// const pages = s1.pages;
|
|
195
|
+
expect(beforSize + 1).toBe(empty.size);
|
|
196
|
+
expect(empty.pages[2]).toBe(p1Clone);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("Will not insert a page that is already in array.", () => {
|
|
200
|
+
const p1 = empty.add("question");
|
|
201
|
+
const p2 = empty.add("question");
|
|
202
|
+
const p3 = empty.add("question");
|
|
203
|
+
const beforeSize = empty.size;
|
|
204
|
+
const result = empty.insertPage(p1, 0);
|
|
205
|
+
const pages = empty.pages;
|
|
206
|
+
expect(beforeSize).toBe(empty.size);
|
|
207
|
+
expect(result).toBe(false);
|
|
208
|
+
});
|
|
209
|
+
test("Will always update the page-number on every page.", () => {
|
|
210
|
+
const p1 = empty.add("question");
|
|
211
|
+
const p2 = empty.add("question");
|
|
212
|
+
const p3 = empty.add("question");
|
|
213
|
+
const beforeSize = empty.size;
|
|
214
|
+
const result = empty.insertPage(p1, 0);
|
|
215
|
+
const pages = empty.pages;
|
|
216
|
+
expect(beforeSize).toBe(empty.size);
|
|
217
|
+
expect(result).toBe(false);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { DUtil } from "@media-quest/engine";
|
|
2
|
+
import { BuilderPage, BuilderPageDto } from "./Builder-page";
|
|
3
|
+
import { PageID, PagePrefix, SumScoreVariableID } from "../public-api";
|
|
4
|
+
import { SumScoreVariableCollection } from "../sum-score/sum-score-variable-collection";
|
|
5
|
+
import { SumScoreVariable } from "../sum-score/sum-score-variable";
|
|
6
|
+
|
|
7
|
+
const U = DUtil;
|
|
8
|
+
export type BuilderPageType = "info-page" | "question";
|
|
9
|
+
|
|
10
|
+
export class BuilderPageCollection implements Iterable<BuilderPage> {
|
|
11
|
+
private _all: Array<BuilderPage> = [];
|
|
12
|
+
|
|
13
|
+
public static create(pages: BuilderPageDto[]) {
|
|
14
|
+
const page = new BuilderPageCollection(pages);
|
|
15
|
+
page._all = pages.map((p) => BuilderPage.fromJson(p));
|
|
16
|
+
return page;
|
|
17
|
+
}
|
|
18
|
+
private constructor(initialPages: BuilderPageDto[]) {}
|
|
19
|
+
|
|
20
|
+
/** @internal - used by Schema*/
|
|
21
|
+
_init(pages: BuilderPageDto[]) {
|
|
22
|
+
this._all = pages.map(BuilderPage.fromJson);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
add(type: BuilderPageType, atIndex = -1): BuilderPage {
|
|
26
|
+
const pagePrefix = PagePrefix.create();
|
|
27
|
+
const newPage = BuilderPage.create(type, pagePrefix.value);
|
|
28
|
+
if (atIndex >= 0 && atIndex < this._all.length) {
|
|
29
|
+
this._all.splice(atIndex, 0, newPage);
|
|
30
|
+
} else {
|
|
31
|
+
this._all.push(newPage);
|
|
32
|
+
}
|
|
33
|
+
return newPage;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
deleteById(id: PageID) {
|
|
37
|
+
const index = this._all.findIndex((p) => p.id === id);
|
|
38
|
+
if (index !== -1) {
|
|
39
|
+
this._all.splice(index, 1);
|
|
40
|
+
return true;
|
|
41
|
+
} else {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private getPageById(pageId: PageID) {
|
|
47
|
+
const maybePage = this._all.find((p) => p.id === pageId);
|
|
48
|
+
return maybePage ?? false;
|
|
49
|
+
}
|
|
50
|
+
get size() {
|
|
51
|
+
return this._all.length;
|
|
52
|
+
}
|
|
53
|
+
get pages(): ReadonlyArray<BuilderPage> {
|
|
54
|
+
return [...this._all];
|
|
55
|
+
}
|
|
56
|
+
toJson(): ReadonlyArray<BuilderPageDto> {
|
|
57
|
+
return this._all.map((p) => p.toJson());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
[Symbol.iterator]() {
|
|
61
|
+
const list = [...this._all];
|
|
62
|
+
return list[Symbol.iterator]();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
movePage(page: BuilderPage, toIndex: number) {
|
|
66
|
+
const index = this._all.indexOf(page);
|
|
67
|
+
if (index < 0) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const isValidIndex = U.isInRange(0, this._all.length - 1);
|
|
71
|
+
if (!isValidIndex(toIndex)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
// console.log('Moving from :' + index + ' to: ' + toIndex);
|
|
75
|
+
this._all.splice(index, 1);
|
|
76
|
+
this._all.splice(toIndex, 0, page);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
insertPage(page: BuilderPage, atIndex: number) {
|
|
81
|
+
const isValidIndex = U.isInRange(0, this._all.length - 1);
|
|
82
|
+
if (!isValidIndex(atIndex)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
const exists = !!this._all.find((p) => p.id === page.id);
|
|
86
|
+
if (exists) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
this._all.splice(atIndex, 0, page);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
addSumScoreVariable(sumScoreVariable: SumScoreVariable, pageId: PageID, weight: number) {
|
|
94
|
+
const maybePage = this.getPageById(pageId);
|
|
95
|
+
if (!maybePage) return false;
|
|
96
|
+
maybePage.sumScoreVariableSet(sumScoreVariable, weight);
|
|
97
|
+
|
|
98
|
+
// maybePage.addSumScoreVariable(maybeVariable, weight);
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
updateRelationShips(context: { sumScoreVariables: ReadonlyArray<SumScoreVariable> }) {
|
|
103
|
+
const { sumScoreVariables } = context;
|
|
104
|
+
|
|
105
|
+
// Update all relationships in pages.
|
|
106
|
+
this._all.forEach((p) => {
|
|
107
|
+
p.updateRelationShips(context.sumScoreVariables);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Set the used in pages array on every variable.
|
|
111
|
+
sumScoreVariables.forEach((v) => {
|
|
112
|
+
const usedInPages = this._all.filter((p) => p._isIncludedInSumScore(v.id));
|
|
113
|
+
v._setUsedInPages(usedInPages);
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
sumScoreVariableDelete(sumScoreVariableID: SumScoreVariableID) {
|
|
118
|
+
this._all.forEach((p) => {
|
|
119
|
+
p.sumScoreVariableDelete(sumScoreVariableID);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
sumScoreVariableDeleteFromPage(pageId: PageID, sumScoreVariableId: SumScoreVariableID) {
|
|
124
|
+
const maybePage = this.getPageById(pageId);
|
|
125
|
+
if (!maybePage) return false;
|
|
126
|
+
maybePage.sumScoreVariableDelete(sumScoreVariableId);
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BuilderPage } from "./Builder-page";
|
|
2
2
|
import type { BuilderPageDto } from "./Builder-page";
|
|
3
|
-
import type { BuilderQuestionDto } from "
|
|
4
|
-
import { BuilderQuestion } from "./Builder-question";
|
|
3
|
+
import type { BuilderQuestionDto } from "../Builder-question";
|
|
5
4
|
import { DUtil } from "@media-quest/engine";
|
|
6
|
-
import { PagePrefix } from "
|
|
7
|
-
import { SchemaPrefix } from "
|
|
8
|
-
import { OptionID, PageID, QuestionID } from "
|
|
5
|
+
import { PagePrefix } from "../primitives/page-prefix";
|
|
6
|
+
import { SchemaPrefix } from "../primitives/schema-prefix";
|
|
7
|
+
import { OptionID, PageID, QuestionID, SumScoreVariableID } from "../primitives/ID";
|
|
8
|
+
import { SumScoreVariable } from "../sum-score/sum-score-variable";
|
|
9
9
|
|
|
10
10
|
const U = DUtil;
|
|
11
11
|
const deleteIdsFromPage = (page: BuilderPageDto) => {
|
|
@@ -24,6 +24,7 @@ const pxx = PagePrefix.fromStringOrThrow("pxx");
|
|
|
24
24
|
const questionPageDto: BuilderPageDto = {
|
|
25
25
|
_type: "question",
|
|
26
26
|
autoplaySequence: [],
|
|
27
|
+
includedInSumScores: [],
|
|
27
28
|
mainText: {
|
|
28
29
|
text: "Velkommen til denne undersøkelsen.",
|
|
29
30
|
audioFile: false,
|
|
@@ -66,7 +67,8 @@ const questionPageDto: BuilderPageDto = {
|
|
|
66
67
|
};
|
|
67
68
|
|
|
68
69
|
const multiQuestionPageDto: BuilderPageDto = {
|
|
69
|
-
_type: "
|
|
70
|
+
_type: "question",
|
|
71
|
+
includedInSumScores: [],
|
|
70
72
|
mainText: {
|
|
71
73
|
text: "Velkommen til denne undersøkelsen.",
|
|
72
74
|
audioFile: false,
|
|
@@ -159,4 +161,17 @@ describe("Builder Page", () => {
|
|
|
159
161
|
// expect(page1.questions.length).toBe(3);
|
|
160
162
|
// expect(m1).toBe(false);
|
|
161
163
|
});
|
|
164
|
+
test("Can check if page is included in sum-score-variable", () => {
|
|
165
|
+
const prefix = PagePrefix.fromStringOrThrow("as1");
|
|
166
|
+
const page = BuilderPage.create("question", prefix);
|
|
167
|
+
const ss1 = SumScoreVariable.create({ name: "ss1", description: "ss1_desc", useAvg: true });
|
|
168
|
+
const ss2 = SumScoreVariable.create({ name: "ss1", description: "ss1_desc", useAvg: true });
|
|
169
|
+
const success1 = page.sumScoreVariableSet(ss1, 1);
|
|
170
|
+
const success2 = page.sumScoreVariableSet(ss2, 1);
|
|
171
|
+
expect(success1).toBe(true);
|
|
172
|
+
expect(success2).toBe(true);
|
|
173
|
+
expect(page._isIncludedInSumScore(ss1.id)).toBe(true);
|
|
174
|
+
expect(page._isIncludedInSumScore(ss2.id)).toBe(true);
|
|
175
|
+
expect(page._isIncludedInSumScore(SumScoreVariableID.dummy.a)).toBe(false);
|
|
176
|
+
});
|
|
162
177
|
});
|