@media-quest/builder 0.0.27 → 0.0.29
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 +36 -32
- package/dist/public-api.js +53 -6
- package/dist/public-api.js.map +1 -1
- package/package.json +2 -2
- package/src/Builder-schema.ts +17 -4
- package/src/page/Builder-page-collection.spec.ts +10 -0
- package/src/page/Builder-page-collection.ts +18 -2
- package/src/page/Builder-page.spec.ts +15 -1
- package/src/page/Builder-page.ts +13 -1
- package/src/public-api.ts +1 -1
- package/src/sum-score/sum-score-variable.spec.ts +308 -253
- package/src/sum-score/sum-score-variable.ts +102 -98
- package/src/sum-score/sum-score.ts +6 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@media-quest/builder",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
4
4
|
"description": "Builder library for Media-quest schemas",
|
|
5
5
|
"main": "dist/public-api.js",
|
|
6
6
|
"types": "dist/public-api.d.js",
|
|
@@ -24,6 +24,6 @@
|
|
|
24
24
|
"dts": true
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@media-quest/engine": "0.0.
|
|
27
|
+
"@media-quest/engine": "0.0.29"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/src/Builder-schema.ts
CHANGED
|
@@ -98,6 +98,8 @@ export class BuilderSchema {
|
|
|
98
98
|
const rulesDto = dto.rules ?? [];
|
|
99
99
|
const ruleInput = schema.getRuleInput();
|
|
100
100
|
schema._rules = rulesDto.map((r) => BuilderRule.fromDto(r, ruleInput));
|
|
101
|
+
|
|
102
|
+
schema.updateSumScoreRelations();
|
|
101
103
|
return schema;
|
|
102
104
|
}
|
|
103
105
|
|
|
@@ -145,16 +147,27 @@ export class BuilderSchema {
|
|
|
145
147
|
return variable;
|
|
146
148
|
}
|
|
147
149
|
sumScoreVariableAddToPage(sumScoreVariable: SumScoreVariable, page: BuilderPage, weight: number) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
+
const added = this._pageCollection.addSumScoreVariable(sumScoreVariable, page.id, weight);
|
|
151
|
+
this.updateSumScoreRelations();
|
|
152
|
+
return added;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private updateSumScoreRelations() {
|
|
156
|
+
const sumScoreVariables = this._sumScoreCollection.asArray();
|
|
157
|
+
this._pageCollection.updateRelationShips({ sumScoreVariables });
|
|
150
158
|
}
|
|
151
159
|
|
|
152
160
|
sumScoreVariableUpdate(id: SumScoreVariableID, data: Partial<SumScoreVariableDto>) {
|
|
153
161
|
const didUpdate = this._sumScoreCollection._updateOne(id, data);
|
|
154
|
-
this.
|
|
162
|
+
this.updateSumScoreRelations();
|
|
155
163
|
return didUpdate;
|
|
156
164
|
}
|
|
157
165
|
|
|
166
|
+
sumScoreVariableDeleteFromPage(pageId: PageID, sumScoreVariableId: SumScoreVariableID) {
|
|
167
|
+
this._pageCollection.sumScoreVariableDeleteFromPage(pageId, sumScoreVariableId);
|
|
168
|
+
this.updateSumScoreRelations();
|
|
169
|
+
}
|
|
170
|
+
|
|
158
171
|
insertPage(page: BuilderPage, atIndex: number): boolean {
|
|
159
172
|
return this.insertPageAtIndex(page, atIndex);
|
|
160
173
|
}
|
|
@@ -286,7 +299,7 @@ export class BuilderSchema {
|
|
|
286
299
|
sumScoreVariableDelete(id: SumScoreVariableID) {
|
|
287
300
|
const didDelete = this._sumScoreCollection._deleteVariable(id);
|
|
288
301
|
const sumScoreVariables = [...this._sumScoreCollection];
|
|
289
|
-
this._pageCollection.
|
|
302
|
+
this._pageCollection.updateRelationShips({ sumScoreVariables });
|
|
290
303
|
this._pageCollection.sumScoreVariableDelete(id);
|
|
291
304
|
return didDelete;
|
|
292
305
|
}
|
|
@@ -206,4 +206,14 @@ describe("Builder page collection", () => {
|
|
|
206
206
|
expect(beforeSize).toBe(empty.size);
|
|
207
207
|
expect(result).toBe(false);
|
|
208
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
|
+
});
|
|
209
219
|
});
|
|
@@ -99,9 +99,18 @@ export class BuilderPageCollection implements Iterable<BuilderPage> {
|
|
|
99
99
|
return true;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
updateRelationShips(context: { sumScoreVariables: ReadonlyArray<SumScoreVariable> }) {
|
|
103
|
+
const { sumScoreVariables } = context;
|
|
104
|
+
|
|
105
|
+
// Update all relationships in pages.
|
|
103
106
|
this._all.forEach((p) => {
|
|
104
|
-
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);
|
|
105
114
|
});
|
|
106
115
|
}
|
|
107
116
|
|
|
@@ -110,4 +119,11 @@ export class BuilderPageCollection implements Iterable<BuilderPage> {
|
|
|
110
119
|
p.sumScoreVariableDelete(sumScoreVariableID);
|
|
111
120
|
});
|
|
112
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
|
+
}
|
|
113
129
|
}
|
|
@@ -4,7 +4,8 @@ import type { BuilderQuestionDto } from "../Builder-question";
|
|
|
4
4
|
import { DUtil } from "@media-quest/engine";
|
|
5
5
|
import { PagePrefix } from "../primitives/page-prefix";
|
|
6
6
|
import { SchemaPrefix } from "../primitives/schema-prefix";
|
|
7
|
-
import { OptionID, PageID, QuestionID } from "../primitives/ID";
|
|
7
|
+
import { OptionID, PageID, QuestionID, SumScoreVariableID } from "../primitives/ID";
|
|
8
|
+
import { SumScoreVariable } from "../sum-score/sum-score-variable";
|
|
8
9
|
|
|
9
10
|
const U = DUtil;
|
|
10
11
|
const deleteIdsFromPage = (page: BuilderPageDto) => {
|
|
@@ -160,4 +161,17 @@ describe("Builder Page", () => {
|
|
|
160
161
|
// expect(page1.questions.length).toBe(3);
|
|
161
162
|
// expect(m1).toBe(false);
|
|
162
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
|
+
});
|
|
163
177
|
});
|
package/src/page/Builder-page.ts
CHANGED
|
@@ -160,6 +160,7 @@ export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
|
|
|
160
160
|
this._prefix.value = value;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
/** @internal */
|
|
163
164
|
sumScoreVariableSet(sumScoreVariable: SumScoreVariable, weight: number) {
|
|
164
165
|
const { id, name, description } = sumScoreVariable;
|
|
165
166
|
|
|
@@ -173,7 +174,8 @@ export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
|
|
|
173
174
|
return true;
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
|
|
177
|
+
/** @internal */
|
|
178
|
+
updateRelationShips(variables: ReadonlyArray<SumScoreVariable>) {
|
|
177
179
|
variables.forEach((v) => {
|
|
178
180
|
const sumScoreEntry = this._includedInSumScores.get(v.id);
|
|
179
181
|
if (sumScoreEntry) {
|
|
@@ -232,6 +234,16 @@ export class BuilderPage extends BuilderObject<"builder-page", BuilderPageDto> {
|
|
|
232
234
|
}
|
|
233
235
|
}
|
|
234
236
|
|
|
237
|
+
/**
|
|
238
|
+
* @internal
|
|
239
|
+
*/
|
|
240
|
+
_isIncludedInSumScore(sumScoreId: SumScoreVariableID) {
|
|
241
|
+
return this._includedInSumScores.has(sumScoreId);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* @internal
|
|
246
|
+
*/
|
|
235
247
|
sumScoreVariableDelete(sumScoreVariableID: SumScoreVariableID) {
|
|
236
248
|
this._includedInSumScores.delete(sumScoreVariableID);
|
|
237
249
|
}
|
package/src/public-api.ts
CHANGED
|
@@ -23,6 +23,6 @@ export * from "./primitives/ID";
|
|
|
23
23
|
export * from "./code-book/codebook-variable";
|
|
24
24
|
export * from "./builder-compiler";
|
|
25
25
|
export * from "./sum-score/sum-score";
|
|
26
|
-
export { SumScoreVariableDto } from "./sum-score/sum-score-variable";
|
|
26
|
+
export { SumScoreVariableDto, SumScoreVariable } from "./sum-score/sum-score-variable";
|
|
27
27
|
export { SumScoreAnswer } from "./sum-score/sum-score-answer";
|
|
28
28
|
export { TagCollection } from "./tag/Tag-Collection";
|