@pie-element/charting 10.3.4-next.3 → 11.0.0-beta.0
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/configure/lib/charting-config.js +149 -220
- package/configure/lib/charting-config.js.map +1 -1
- package/configure/lib/configure.js +279 -378
- package/configure/lib/configure.js.map +1 -1
- package/configure/lib/correct-response.js +183 -258
- package/configure/lib/correct-response.js.map +1 -1
- package/configure/lib/defaults.js +2 -4
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/index.js +99 -163
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/utils.js +24 -41
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +12 -10
- package/controller/lib/defaults.js +2 -4
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +161 -230
- package/controller/lib/index.js.map +1 -1
- package/controller/package.json +4 -4
- package/lib/index.js +52 -99
- package/lib/index.js.map +1 -1
- package/lib/main.js +145 -208
- package/lib/main.js.map +1 -1
- package/package.json +12 -10
- package/esm/configure.js +0 -18067
- package/esm/configure.js.map +0 -1
- package/esm/controller.js +0 -4555
- package/esm/controller.js.map +0 -1
- package/esm/element.js +0 -10956
- package/esm/element.js.map +0 -1
- package/esm/package.json +0 -3
package/controller/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -10,119 +9,82 @@ exports.model = model;
|
|
|
10
9
|
exports.normalize = void 0;
|
|
11
10
|
exports.outcome = outcome;
|
|
12
11
|
exports.validate = exports.setCorrectness = void 0;
|
|
13
|
-
|
|
14
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
15
|
-
|
|
16
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
-
|
|
18
12
|
var _debug = _interopRequireDefault(require("debug"));
|
|
19
|
-
|
|
20
13
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
21
|
-
|
|
22
14
|
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
23
|
-
|
|
24
15
|
var _pick = _interopRequireDefault(require("lodash/pick"));
|
|
25
|
-
|
|
26
16
|
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
27
|
-
|
|
28
17
|
var _controllerUtils = require("@pie-lib/controller-utils");
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
34
|
-
|
|
35
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
36
|
-
|
|
37
|
-
var log = (0, _debug["default"])('@pie-element:graphing:controller');
|
|
38
|
-
|
|
39
|
-
var lowerCase = function lowerCase(string) {
|
|
40
|
-
return (string || '').toLowerCase();
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
var checkLabelsEquality = function checkLabelsEquality(givenAnswerLabel, correctAnswerLabel) {
|
|
44
|
-
return lowerCase(givenAnswerLabel) === lowerCase(correctAnswerLabel);
|
|
45
|
-
};
|
|
46
|
-
|
|
18
|
+
const log = (0, _debug.default)('@pie-element:graphing:controller');
|
|
19
|
+
const lowerCase = string => (string || '').toLowerCase();
|
|
20
|
+
const checkLabelsEquality = (givenAnswerLabel, correctAnswerLabel) => lowerCase(givenAnswerLabel) === lowerCase(correctAnswerLabel);
|
|
47
21
|
exports.checkLabelsEquality = checkLabelsEquality;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}) : [];
|
|
58
|
-
};
|
|
59
|
-
|
|
22
|
+
const setCorrectness = (answers, partialScoring) => answers ? answers.map(answer => ({
|
|
23
|
+
...answer,
|
|
24
|
+
correctness: {
|
|
25
|
+
value: partialScoring ? 'incorrect' : 'correct',
|
|
26
|
+
label: partialScoring ? 'incorrect' : 'correct'
|
|
27
|
+
}
|
|
28
|
+
})) : [];
|
|
60
29
|
exports.setCorrectness = setCorrectness;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
};
|
|
65
|
-
|
|
30
|
+
const normalize = question => ({
|
|
31
|
+
..._defaults.default,
|
|
32
|
+
...question
|
|
33
|
+
});
|
|
66
34
|
exports.normalize = normalize;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
var isPartialScoring = _controllerUtils.partialScoring.enabled({
|
|
35
|
+
const getScore = (question, session, env = {}) => {
|
|
36
|
+
const {
|
|
37
|
+
correctAnswer,
|
|
38
|
+
data: initialData = [],
|
|
39
|
+
scoringType
|
|
40
|
+
} = question;
|
|
41
|
+
let correctResponses = [];
|
|
42
|
+
const isPartialScoring = _controllerUtils.partialScoring.enabled({
|
|
77
43
|
partialScoring: scoringType !== undefined ? scoringType === 'partial scoring' : scoringType
|
|
78
44
|
}, env);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var answers = setCorrectness(session && session.answer || defaultAnswers, isPartialScoring);
|
|
86
|
-
var result = 0;
|
|
87
|
-
|
|
45
|
+
const {
|
|
46
|
+
data: correctAnswers = []
|
|
47
|
+
} = correctAnswer || {};
|
|
48
|
+
const defaultAnswers = filterCategories(initialData);
|
|
49
|
+
let answers = setCorrectness(session && session.answer || defaultAnswers, isPartialScoring);
|
|
50
|
+
let result = 0;
|
|
88
51
|
if (isPartialScoring) {
|
|
89
52
|
// if score type is "partial scoring"
|
|
90
53
|
// maxScore is calculated based on the correct response
|
|
91
54
|
// score is calculated based on the given response
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
55
|
+
let maxScore = 0;
|
|
56
|
+
let score = 0;
|
|
57
|
+
const scoreForLabelAndValueEditable = (answer, corrAnswer) => {
|
|
58
|
+
const {
|
|
59
|
+
value,
|
|
60
|
+
label,
|
|
61
|
+
index
|
|
62
|
+
} = answer;
|
|
63
|
+
const valueIsCorrect = value === corrAnswer.value;
|
|
64
|
+
const labelIsCorrect = checkLabelsEquality(label, corrAnswer.label);
|
|
101
65
|
maxScore += 2;
|
|
102
|
-
|
|
103
66
|
if (valueIsCorrect) {
|
|
104
|
-
|
|
67
|
+
score += 1;
|
|
105
68
|
answer.correctness.value = 'correct';
|
|
106
69
|
}
|
|
107
|
-
|
|
108
70
|
if (labelIsCorrect) {
|
|
109
|
-
|
|
71
|
+
score += 1;
|
|
110
72
|
answer.correctness.label = 'correct';
|
|
111
73
|
}
|
|
112
|
-
|
|
113
74
|
if (valueIsCorrect && labelIsCorrect) {
|
|
114
75
|
correctResponses.push({
|
|
115
76
|
label: label,
|
|
116
77
|
index: index
|
|
117
78
|
});
|
|
118
79
|
}
|
|
119
|
-
};
|
|
120
|
-
|
|
80
|
+
};
|
|
121
81
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
82
|
+
// if given answer has more categories than the correct answers, the "extra" will be ignored
|
|
83
|
+
correctAnswers.forEach((corrAnswer, index) => {
|
|
84
|
+
const defaultAnswer = defaultAnswers[index];
|
|
85
|
+
const answer = answers[index];
|
|
125
86
|
|
|
87
|
+
// if there is a corresponding category at the same position in the given answer
|
|
126
88
|
if (answer) {
|
|
127
89
|
// if there is a corresponding category at the same position in the default answer
|
|
128
90
|
if (defaultAnswer) {
|
|
@@ -130,17 +92,17 @@ var getScore = function getScore(question, session) {
|
|
|
130
92
|
// it means that this category values only one point (only the value can be changed)
|
|
131
93
|
if (!defaultAnswer.editable && answer.interactive) {
|
|
132
94
|
maxScore += 1;
|
|
133
|
-
|
|
134
95
|
if (answer.value === corrAnswer.value) {
|
|
135
|
-
|
|
96
|
+
score += 1;
|
|
136
97
|
answer.correctness.value = 'correct';
|
|
137
98
|
correctResponses.push({
|
|
138
99
|
label: answer.label,
|
|
139
100
|
index: index
|
|
140
101
|
});
|
|
141
102
|
}
|
|
103
|
+
answer.correctness.label = 'correct';
|
|
142
104
|
|
|
143
|
-
|
|
105
|
+
// if category's label (in default answer) was editable
|
|
144
106
|
// it means that this category values 2 points (both label and value can be changed)
|
|
145
107
|
} else if (defaultAnswer.editable && answer.interactive) {
|
|
146
108
|
scoreForLabelAndValueEditable(answer, corrAnswer);
|
|
@@ -162,131 +124,120 @@ var getScore = function getScore(question, session) {
|
|
|
162
124
|
maxScore += 2;
|
|
163
125
|
}
|
|
164
126
|
});
|
|
165
|
-
result = maxScore ?
|
|
127
|
+
result = maxScore ? score / maxScore : 0;
|
|
166
128
|
} else {
|
|
167
129
|
// all-or-nothing scoring: overall score is 1 only if lengths and all values/labels match
|
|
168
|
-
result = correctAnswers.length === answers.length ? 1 : 0;
|
|
169
|
-
|
|
170
|
-
answers = answers.map(function (answer, index) {
|
|
171
|
-
var correctAnswer = correctAnswers[index];
|
|
172
|
-
var valueIsCorrect = correctAnswer ? answer.value === correctAnswer.value : false;
|
|
173
|
-
var labelIsCorrect = correctAnswer ? lowerCase(answer.label) === lowerCase(correctAnswer.label) : false;
|
|
130
|
+
result = correctAnswers.length === answers.length ? 1 : 0;
|
|
174
131
|
|
|
132
|
+
// regardless of overall result, mark each answer individually for user feedback
|
|
133
|
+
answers = answers.map((answer, index) => {
|
|
134
|
+
const correctAnswer = correctAnswers[index];
|
|
135
|
+
const valueIsCorrect = correctAnswer ? answer.value === correctAnswer.value : false;
|
|
136
|
+
const labelIsCorrect = correctAnswer ? lowerCase(answer.label) === lowerCase(correctAnswer.label) : false;
|
|
175
137
|
if (!valueIsCorrect || !labelIsCorrect) {
|
|
176
138
|
result = 0;
|
|
177
139
|
}
|
|
178
|
-
|
|
179
140
|
if (valueIsCorrect && labelIsCorrect) {
|
|
180
141
|
correctResponses.push({
|
|
181
142
|
label: answer.label,
|
|
182
|
-
index
|
|
143
|
+
index
|
|
183
144
|
});
|
|
184
145
|
}
|
|
185
|
-
|
|
186
|
-
|
|
146
|
+
return {
|
|
147
|
+
...answer,
|
|
187
148
|
correctness: {
|
|
188
149
|
value: valueIsCorrect ? 'correct' : 'incorrect',
|
|
189
150
|
label: labelIsCorrect ? 'correct' : 'incorrect'
|
|
190
151
|
}
|
|
191
|
-
}
|
|
152
|
+
};
|
|
192
153
|
});
|
|
193
154
|
}
|
|
194
|
-
|
|
195
|
-
var score = {
|
|
155
|
+
const score = {
|
|
196
156
|
score: parseFloat(result.toFixed(2)),
|
|
197
|
-
answers
|
|
157
|
+
answers
|
|
198
158
|
};
|
|
199
|
-
|
|
200
159
|
if (env.extraProps && env.extraProps.correctResponseEnabled) {
|
|
201
160
|
score.correctResponses = correctResponses;
|
|
202
161
|
}
|
|
203
|
-
|
|
204
162
|
return score;
|
|
205
|
-
}; // eslint-disable-next-line no-unused-vars
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
exports.getScore = getScore;
|
|
209
|
-
|
|
210
|
-
var filterCategories = function filterCategories(categories) {
|
|
211
|
-
return categories ? categories.map(function (_ref2) {
|
|
212
|
-
var deletable = _ref2.deletable,
|
|
213
|
-
rest = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
|
|
214
|
-
return rest;
|
|
215
|
-
}) : [];
|
|
216
163
|
};
|
|
217
164
|
|
|
165
|
+
// eslint-disable-next-line no-unused-vars
|
|
166
|
+
exports.getScore = getScore;
|
|
167
|
+
const filterCategories = categories => categories ? categories.map(({
|
|
168
|
+
deletable,
|
|
169
|
+
...rest
|
|
170
|
+
}) => rest) : [];
|
|
218
171
|
exports.filterCategories = filterCategories;
|
|
219
|
-
|
|
220
172
|
function model(question, session, env) {
|
|
221
|
-
return new Promise(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
173
|
+
return new Promise(resolve => {
|
|
174
|
+
const normalizedQuestion = normalize(question);
|
|
175
|
+
const {
|
|
176
|
+
addCategoryEnabled,
|
|
177
|
+
chartType,
|
|
178
|
+
data,
|
|
179
|
+
domain,
|
|
180
|
+
graph,
|
|
181
|
+
prompt,
|
|
182
|
+
promptEnabled,
|
|
183
|
+
range,
|
|
184
|
+
rationale,
|
|
185
|
+
title,
|
|
186
|
+
rationaleEnabled,
|
|
187
|
+
teacherInstructions,
|
|
188
|
+
teacherInstructionsEnabled,
|
|
189
|
+
correctAnswer,
|
|
190
|
+
scoringType,
|
|
191
|
+
studentNewCategoryDefaultLabel,
|
|
192
|
+
language,
|
|
193
|
+
extraCSSRules
|
|
194
|
+
} = normalizedQuestion;
|
|
195
|
+
const correctInfo = {
|
|
242
196
|
correctness: 'incorrect',
|
|
243
197
|
score: '0%'
|
|
244
198
|
};
|
|
245
|
-
|
|
246
|
-
addCategoryEnabled
|
|
247
|
-
chartType
|
|
199
|
+
const base = {
|
|
200
|
+
addCategoryEnabled,
|
|
201
|
+
chartType,
|
|
248
202
|
data: filterCategories(data),
|
|
249
|
-
domain
|
|
250
|
-
graph
|
|
203
|
+
domain,
|
|
204
|
+
graph,
|
|
251
205
|
prompt: promptEnabled ? prompt : null,
|
|
252
|
-
range
|
|
253
|
-
rationale
|
|
254
|
-
title
|
|
206
|
+
range,
|
|
207
|
+
rationale,
|
|
208
|
+
title,
|
|
255
209
|
size: graph,
|
|
256
210
|
showToggle: false,
|
|
257
211
|
correctness: correctInfo,
|
|
258
212
|
disabled: env.mode !== 'gather',
|
|
259
|
-
scoringType
|
|
260
|
-
studentNewCategoryDefaultLabel
|
|
261
|
-
language
|
|
262
|
-
env
|
|
263
|
-
extraCSSRules
|
|
213
|
+
scoringType,
|
|
214
|
+
studentNewCategoryDefaultLabel,
|
|
215
|
+
language,
|
|
216
|
+
env,
|
|
217
|
+
extraCSSRules
|
|
264
218
|
};
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
219
|
+
const scoreObject = getScore(normalizedQuestion, session, env);
|
|
220
|
+
const answers = filterCategories(scoreObject.answers);
|
|
268
221
|
if (env.mode === 'view') {
|
|
269
222
|
// eslint-disable-next-line no-unused-vars
|
|
270
|
-
base.correctedAnswer = answers.map(
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
223
|
+
base.correctedAnswer = answers.map(({
|
|
224
|
+
correctness,
|
|
225
|
+
...rest
|
|
226
|
+
}) => {
|
|
227
|
+
return {
|
|
228
|
+
...rest,
|
|
274
229
|
interactive: false
|
|
275
|
-
}
|
|
230
|
+
};
|
|
276
231
|
});
|
|
277
232
|
base.addCategoryEnabled = false;
|
|
278
233
|
}
|
|
279
|
-
|
|
280
234
|
if (env.mode === 'evaluate') {
|
|
281
|
-
var _correctAnswer$data;
|
|
282
|
-
|
|
283
235
|
base.correctedAnswer = answers;
|
|
284
236
|
base.correctAnswer = correctAnswer;
|
|
285
|
-
base.showToggle = !!
|
|
237
|
+
base.showToggle = !!correctAnswer?.data?.length && scoreObject.score !== 1;
|
|
286
238
|
base.addCategoryEnabled = false;
|
|
287
239
|
base.showKeyLegend = true;
|
|
288
240
|
}
|
|
289
|
-
|
|
290
241
|
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
291
242
|
base.rationale = rationaleEnabled ? rationale : null;
|
|
292
243
|
base.teacherInstructions = teacherInstructionsEnabled ? teacherInstructions : null;
|
|
@@ -294,43 +245,45 @@ function model(question, session, env) {
|
|
|
294
245
|
base.rationale = null;
|
|
295
246
|
base.teacherInstructions = null;
|
|
296
247
|
}
|
|
297
|
-
|
|
298
248
|
log('base: ', base);
|
|
299
249
|
resolve(base);
|
|
300
250
|
});
|
|
301
251
|
}
|
|
302
|
-
|
|
303
252
|
function outcome(model, session, env) {
|
|
304
|
-
return new Promise(
|
|
305
|
-
|
|
306
|
-
|
|
253
|
+
return new Promise(resolve => {
|
|
254
|
+
const scoreObject = getScore(model, session, env);
|
|
255
|
+
const result = {
|
|
307
256
|
score: scoreObject.score,
|
|
308
|
-
empty: !session || (0, _isEmpty
|
|
257
|
+
empty: !session || (0, _isEmpty.default)(session)
|
|
309
258
|
};
|
|
310
|
-
|
|
311
259
|
if (env.extraProps && env.extraProps.correctResponseEnabled) {
|
|
312
260
|
result.extraProps = {
|
|
313
261
|
correctResponse: scoreObject.correctResponses
|
|
314
262
|
};
|
|
315
263
|
}
|
|
316
|
-
|
|
317
264
|
resolve(result);
|
|
318
265
|
});
|
|
319
266
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
return new Promise(function (resolve) {
|
|
267
|
+
const createCorrectResponseSession = (question, env) => {
|
|
268
|
+
return new Promise(resolve => {
|
|
323
269
|
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
324
|
-
|
|
325
|
-
|
|
270
|
+
const {
|
|
271
|
+
correctAnswer
|
|
272
|
+
} = question;
|
|
273
|
+
let answers = correctAnswer && correctAnswer.data;
|
|
326
274
|
|
|
275
|
+
// for IBX preview mode
|
|
327
276
|
if (env.mode === 'gather') {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
277
|
+
const {
|
|
278
|
+
data
|
|
279
|
+
} = question;
|
|
280
|
+
answers = (correctAnswer && correctAnswer.data || []).map((answer, index) => {
|
|
281
|
+
return {
|
|
282
|
+
...data[index],
|
|
283
|
+
...answer
|
|
284
|
+
};
|
|
331
285
|
});
|
|
332
286
|
}
|
|
333
|
-
|
|
334
287
|
resolve({
|
|
335
288
|
answer: answers,
|
|
336
289
|
id: '1'
|
|
@@ -339,78 +292,56 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
|
|
|
339
292
|
return resolve(null);
|
|
340
293
|
}
|
|
341
294
|
});
|
|
342
|
-
}; // remove all html tags
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
346
|
-
|
|
347
|
-
var getInnerText = function getInnerText(html) {
|
|
348
|
-
return (html || '').replaceAll(/<[^>]*>/g, '');
|
|
349
|
-
}; // remove all html tags except img, iframe and source tag for audio
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
var getContent = function getContent(html) {
|
|
353
|
-
return (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
354
295
|
};
|
|
355
296
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
297
|
+
// remove all html tags
|
|
298
|
+
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
299
|
+
const getInnerText = html => (html || '').replaceAll(/<[^>]*>/g, '');
|
|
300
|
+
|
|
301
|
+
// remove all html tags except img, iframe and source tag for audio
|
|
302
|
+
const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
303
|
+
const validate = (model = {}, config = {}) => {
|
|
304
|
+
const {
|
|
305
|
+
correctAnswer,
|
|
306
|
+
data
|
|
307
|
+
} = model || {};
|
|
308
|
+
const {
|
|
309
|
+
data: correctData
|
|
310
|
+
} = correctAnswer || {};
|
|
311
|
+
const categories = correctData || [];
|
|
312
|
+
const errors = {};
|
|
313
|
+
const correctAnswerErrors = {};
|
|
314
|
+
const categoryErrors = {};
|
|
315
|
+
['teacherInstructions', 'prompt', 'rationale'].forEach(field => {
|
|
316
|
+
if (config[field]?.required && !getContent(model[field])) {
|
|
375
317
|
errors[field] = 'This field is required.';
|
|
376
318
|
}
|
|
377
319
|
});
|
|
378
|
-
categories.forEach(
|
|
379
|
-
|
|
380
|
-
|
|
320
|
+
categories.forEach((category, index) => {
|
|
321
|
+
const {
|
|
322
|
+
label
|
|
323
|
+
} = category;
|
|
381
324
|
if (!getInnerText(label)) {
|
|
382
325
|
categoryErrors[index] = 'Content should not be empty. ';
|
|
383
326
|
} else {
|
|
384
|
-
|
|
385
|
-
return c.label === label && index !== i;
|
|
386
|
-
});
|
|
387
|
-
|
|
327
|
+
const identicalAnswer = categories.some((c, i) => c.label === label && index !== i);
|
|
388
328
|
if (identicalAnswer) {
|
|
389
329
|
categoryErrors[index] = 'Category names should be unique. ';
|
|
390
330
|
}
|
|
391
331
|
}
|
|
392
332
|
});
|
|
393
|
-
|
|
394
333
|
if (categories.length < 1 || categories.length > 20) {
|
|
395
334
|
correctAnswerErrors.categoriesError = 'The correct answer should include between 1 and 20 categories.';
|
|
396
|
-
} else if ((0, _isEqual
|
|
397
|
-
return (0, _pick["default"])(category, 'value', 'label');
|
|
398
|
-
}), correctData.map(function (category) {
|
|
399
|
-
return (0, _pick["default"])(category, 'value', 'label');
|
|
400
|
-
}))) {
|
|
335
|
+
} else if ((0, _isEqual.default)(data.map(category => (0, _pick.default)(category, 'value', 'label')), correctData.map(category => (0, _pick.default)(category, 'value', 'label')))) {
|
|
401
336
|
correctAnswerErrors.identicalError = 'Correct answer should not be identical to the chart’s initial state';
|
|
402
337
|
}
|
|
403
|
-
|
|
404
|
-
if (!(0, _isEmpty["default"])(categoryErrors)) {
|
|
338
|
+
if (!(0, _isEmpty.default)(categoryErrors)) {
|
|
405
339
|
errors.categoryErrors = categoryErrors;
|
|
406
340
|
}
|
|
407
|
-
|
|
408
|
-
if (!(0, _isEmpty["default"])(correctAnswerErrors)) {
|
|
341
|
+
if (!(0, _isEmpty.default)(correctAnswerErrors)) {
|
|
409
342
|
errors.correctAnswerErrors = correctAnswerErrors;
|
|
410
343
|
}
|
|
411
|
-
|
|
412
344
|
return errors;
|
|
413
345
|
};
|
|
414
|
-
|
|
415
346
|
exports.validate = validate;
|
|
416
347
|
//# sourceMappingURL=index.js.map
|