@pie-element/match 5.5.1-beta.3 → 5.5.1-beta.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/configure/lib/add-row.js +60 -0
- package/configure/lib/add-row.js.map +1 -0
- package/configure/lib/answer-config-block.js +294 -0
- package/configure/lib/answer-config-block.js.map +1 -0
- package/configure/lib/common.js +34 -0
- package/configure/lib/common.js.map +1 -0
- package/configure/lib/configure.js +350 -0
- package/configure/lib/configure.js.map +1 -0
- package/configure/lib/defaults.js +113 -0
- package/configure/lib/defaults.js.map +1 -0
- package/configure/lib/general-config-block.js +168 -0
- package/configure/lib/general-config-block.js.map +1 -0
- package/configure/lib/index.js +117 -0
- package/configure/lib/index.js.map +1 -0
- package/configure/lib/row.js +348 -0
- package/configure/lib/row.js.map +1 -0
- package/controller/lib/defaults.js +23 -0
- package/controller/lib/defaults.js.map +1 -0
- package/controller/lib/index.js +351 -0
- package/controller/lib/index.js.map +1 -0
- package/lib/answer-grid.js +223 -0
- package/lib/answer-grid.js.map +1 -0
- package/lib/index.js +98 -0
- package/lib/index.js.map +1 -0
- package/lib/main.js +191 -0
- package/lib/main.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createCorrectResponseSession = void 0;
|
|
8
|
+
exports.createDefaultModel = createDefaultModel;
|
|
9
|
+
exports.model = model;
|
|
10
|
+
exports.validate = exports.outcome = exports.normalize = void 0;
|
|
11
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
12
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
+
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
15
|
+
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
16
|
+
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
17
|
+
var _feedback = require("@pie-lib/feedback");
|
|
18
|
+
var _controllerUtils = require("@pie-lib/controller-utils");
|
|
19
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
20
|
+
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
21
|
+
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; }
|
|
22
|
+
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; }
|
|
23
|
+
var log = (0, _debug["default"])('@pie-element:match:controller');
|
|
24
|
+
var getResponseCorrectness = function getResponseCorrectness(model, answers) {
|
|
25
|
+
var env = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
26
|
+
var isPartialScoring = _controllerUtils.partialScoring.enabled(model, env);
|
|
27
|
+
var rows = model.rows;
|
|
28
|
+
var checkboxMode = model.choiceMode === 'checkbox';
|
|
29
|
+
if (!answers || Object.keys(answers).length === 0) {
|
|
30
|
+
return 'unanswered';
|
|
31
|
+
}
|
|
32
|
+
var totalCorrectAnswers = checkboxMode ? getTotalCorrectAnswers(model) : getTotalCorrect(model);
|
|
33
|
+
var correctAnswers;
|
|
34
|
+
var incorrectAnswers = 0;
|
|
35
|
+
if (checkboxMode) {
|
|
36
|
+
var checkboxes = getCheckboxes(rows, answers);
|
|
37
|
+
correctAnswers = checkboxes.correctAnswers;
|
|
38
|
+
incorrectAnswers = checkboxes.incorrectAnswers;
|
|
39
|
+
} else {
|
|
40
|
+
correctAnswers = getCorrectRadios(rows, answers);
|
|
41
|
+
}
|
|
42
|
+
if (totalCorrectAnswers === correctAnswers && !incorrectAnswers) {
|
|
43
|
+
return 'correct';
|
|
44
|
+
} else if (correctAnswers === 0) {
|
|
45
|
+
return 'incorrect';
|
|
46
|
+
} else if (isPartialScoring) {
|
|
47
|
+
return 'partial';
|
|
48
|
+
}
|
|
49
|
+
return 'incorrect';
|
|
50
|
+
};
|
|
51
|
+
var getCorrectness = function getCorrectness(question, env) {
|
|
52
|
+
var answers = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
53
|
+
if (env.mode === 'evaluate') {
|
|
54
|
+
return getResponseCorrectness(question, answers, env);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var getCheckboxes = function getCheckboxes(rows, answers) {
|
|
58
|
+
var correctAnswers = 0;
|
|
59
|
+
var incorrectAnswers = 0;
|
|
60
|
+
rows.forEach(function (row) {
|
|
61
|
+
var answer = answers[row.id];
|
|
62
|
+
if (answer) {
|
|
63
|
+
row.values.forEach(function (v, i) {
|
|
64
|
+
if (answer[i] && answer[i] === v) {
|
|
65
|
+
correctAnswers += 1;
|
|
66
|
+
} else if (answer[i] && answer[i] !== v) {
|
|
67
|
+
incorrectAnswers += 1;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
correctAnswers: correctAnswers,
|
|
74
|
+
incorrectAnswers: incorrectAnswers
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
var getCorrectRadios = function getCorrectRadios(rows, answers) {
|
|
78
|
+
var correctAnswers = 0;
|
|
79
|
+
rows.forEach(function (row) {
|
|
80
|
+
if ((0, _isEqual["default"])(row.values, answers[row.id])) {
|
|
81
|
+
correctAnswers += 1;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return correctAnswers;
|
|
85
|
+
};
|
|
86
|
+
var getTotalCorrect = function getTotalCorrect(question) {
|
|
87
|
+
var checkboxMode = question.choiceMode === 'checkbox';
|
|
88
|
+
var matchingTable = checkboxMode ? question.layout - 1 : 1;
|
|
89
|
+
return (question.rows.length || 0) * matchingTable;
|
|
90
|
+
};
|
|
91
|
+
var getTotalCorrectAnswers = function getTotalCorrectAnswers(question) {
|
|
92
|
+
var noOfTotalCorrectAnswers = 0;
|
|
93
|
+
question.rows.forEach(function (row) {
|
|
94
|
+
row.values.forEach(function (value) {
|
|
95
|
+
if (value) {
|
|
96
|
+
noOfTotalCorrectAnswers += 1;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
return noOfTotalCorrectAnswers;
|
|
101
|
+
};
|
|
102
|
+
var getPartialScore = function getPartialScore(question, answers) {
|
|
103
|
+
var checkboxMode = question.choiceMode === 'checkbox';
|
|
104
|
+
if (checkboxMode) {
|
|
105
|
+
var _getCheckboxes = getCheckboxes(question.rows, answers),
|
|
106
|
+
correctAnswers = _getCheckboxes.correctAnswers,
|
|
107
|
+
incorrectAnswers = _getCheckboxes.incorrectAnswers;
|
|
108
|
+
var totalCorrect = getTotalCorrectAnswers(question);
|
|
109
|
+
var total = totalCorrect === 0 ? 1 : totalCorrect;
|
|
110
|
+
if (correctAnswers + incorrectAnswers > totalCorrect) {
|
|
111
|
+
var extraAnswers = correctAnswers + incorrectAnswers - totalCorrect;
|
|
112
|
+
var score = parseFloat(((correctAnswers - extraAnswers) / total).toFixed(2));
|
|
113
|
+
return score < 0 ? 0 : score;
|
|
114
|
+
} else {
|
|
115
|
+
return parseFloat((correctAnswers / total).toFixed(2));
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
var _correctAnswers = getCorrectRadios(question.rows, answers);
|
|
119
|
+
var _totalCorrect = getTotalCorrect(question) === 0 ? 1 : getTotalCorrect(question);
|
|
120
|
+
return parseFloat((_correctAnswers / _totalCorrect).toFixed(2));
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
var getOutComeScore = function getOutComeScore(question, env) {
|
|
124
|
+
var answers = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
125
|
+
var correctness = getCorrectness(question, env, answers);
|
|
126
|
+
var isPartialScoring = _controllerUtils.partialScoring.enabled(question, env);
|
|
127
|
+
return correctness === 'correct' ? 1 : correctness === 'partial' && isPartialScoring ? getPartialScore(question, answers) : 0;
|
|
128
|
+
};
|
|
129
|
+
var outcome = function outcome(question, session, env) {
|
|
130
|
+
return new Promise(function (resolve) {
|
|
131
|
+
if (env.mode !== 'evaluate') {
|
|
132
|
+
resolve({
|
|
133
|
+
score: undefined,
|
|
134
|
+
completed: undefined
|
|
135
|
+
});
|
|
136
|
+
} else {
|
|
137
|
+
if (!session || (0, _isEmpty["default"])(session)) {
|
|
138
|
+
resolve({
|
|
139
|
+
score: 0,
|
|
140
|
+
empty: true
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
var out = {
|
|
144
|
+
score: getOutComeScore(question, env, session.answers)
|
|
145
|
+
};
|
|
146
|
+
resolve(out);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
exports.outcome = outcome;
|
|
151
|
+
function createDefaultModel() {
|
|
152
|
+
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
153
|
+
return new Promise(function (resolve) {
|
|
154
|
+
resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
var normalize = function normalize(question) {
|
|
158
|
+
return _objectSpread({
|
|
159
|
+
feedbackEnabled: true,
|
|
160
|
+
promptEnabled: true,
|
|
161
|
+
rationaleEnabled: true,
|
|
162
|
+
teacherInstructionsEnabled: true,
|
|
163
|
+
studentInstructionsEnabled: true
|
|
164
|
+
}, question);
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
*
|
|
169
|
+
* @param {*} question
|
|
170
|
+
* @param {*} session
|
|
171
|
+
* @param {*} env
|
|
172
|
+
* @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
|
|
173
|
+
*/
|
|
174
|
+
exports.normalize = normalize;
|
|
175
|
+
function model(question, session, env, updateSession) {
|
|
176
|
+
return new Promise( /*#__PURE__*/function () {
|
|
177
|
+
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(resolve) {
|
|
178
|
+
var normalizedQuestion, correctness, score, correctResponse, correctInfo, lockChoiceOrder, fb;
|
|
179
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
180
|
+
while (1) switch (_context.prev = _context.next) {
|
|
181
|
+
case 0:
|
|
182
|
+
normalizedQuestion = (0, _cloneDeep["default"])(normalize(question));
|
|
183
|
+
if ((!session || (0, _isEmpty["default"])(session)) && env.mode === 'evaluate') {
|
|
184
|
+
correctness = 'unanswered';
|
|
185
|
+
score = '0%';
|
|
186
|
+
} else {
|
|
187
|
+
correctness = getCorrectness(normalizedQuestion, env, session && session.answers);
|
|
188
|
+
score = "".concat(getOutComeScore(normalizedQuestion, env, session && session.answers) * 100, "%");
|
|
189
|
+
}
|
|
190
|
+
correctResponse = {};
|
|
191
|
+
correctInfo = {
|
|
192
|
+
score: score,
|
|
193
|
+
correctness: correctness
|
|
194
|
+
};
|
|
195
|
+
lockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion, session, env);
|
|
196
|
+
if (lockChoiceOrder) {
|
|
197
|
+
_context.next = 9;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
_context.next = 8;
|
|
201
|
+
return (0, _controllerUtils.getShuffledChoices)(normalizedQuestion.rows, session, updateSession, 'id');
|
|
202
|
+
case 8:
|
|
203
|
+
normalizedQuestion.rows = _context.sent;
|
|
204
|
+
case 9:
|
|
205
|
+
normalizedQuestion.rows.forEach(function (row) {
|
|
206
|
+
correctResponse[row.id] = row.values;
|
|
207
|
+
if (env.mode !== 'evaluate') {
|
|
208
|
+
delete row.values;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
fb = env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled ? (0, _feedback.getFeedbackForCorrectness)(correctInfo.correctness, normalizedQuestion.feedback) : Promise.resolve(undefined);
|
|
212
|
+
fb.then(function (feedback) {
|
|
213
|
+
var out = {
|
|
214
|
+
allowFeedback: normalizedQuestion.feedbackEnabled,
|
|
215
|
+
prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
|
|
216
|
+
config: _objectSpread(_objectSpread({}, normalizedQuestion), {}, {
|
|
217
|
+
shuffled: !normalizedQuestion.lockChoiceOrder
|
|
218
|
+
}),
|
|
219
|
+
feedback: feedback,
|
|
220
|
+
disabled: env.mode !== 'gather',
|
|
221
|
+
view: env.mode === 'view'
|
|
222
|
+
};
|
|
223
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
224
|
+
out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
|
|
225
|
+
out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
|
|
226
|
+
} else {
|
|
227
|
+
out.rationale = null;
|
|
228
|
+
out.teacherInstructions = null;
|
|
229
|
+
out.config.rationale = null;
|
|
230
|
+
out.config.teacherInstructions = null;
|
|
231
|
+
}
|
|
232
|
+
if (env.mode === 'evaluate') {
|
|
233
|
+
Object.assign(out, {
|
|
234
|
+
correctResponse: correctResponse,
|
|
235
|
+
correctness: correctInfo
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
log('out: ', out);
|
|
239
|
+
resolve(out);
|
|
240
|
+
});
|
|
241
|
+
case 12:
|
|
242
|
+
case "end":
|
|
243
|
+
return _context.stop();
|
|
244
|
+
}
|
|
245
|
+
}, _callee);
|
|
246
|
+
}));
|
|
247
|
+
return function (_x) {
|
|
248
|
+
return _ref.apply(this, arguments);
|
|
249
|
+
};
|
|
250
|
+
}());
|
|
251
|
+
}
|
|
252
|
+
var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
|
|
253
|
+
return new Promise(function (resolve) {
|
|
254
|
+
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
255
|
+
var rows = question.rows;
|
|
256
|
+
var answers = {};
|
|
257
|
+
rows.forEach(function (r) {
|
|
258
|
+
answers[r.id] = r.values;
|
|
259
|
+
});
|
|
260
|
+
resolve({
|
|
261
|
+
answers: answers,
|
|
262
|
+
id: '1'
|
|
263
|
+
});
|
|
264
|
+
} else {
|
|
265
|
+
resolve(null);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
270
|
+
var markupToText = function markupToText(s) {
|
|
271
|
+
return s.replace(/(<([^>]+)>)/ig, '');
|
|
272
|
+
};
|
|
273
|
+
var validate = function validate() {
|
|
274
|
+
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
275
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
276
|
+
var rows = model.rows,
|
|
277
|
+
choiceMode = model.choiceMode,
|
|
278
|
+
headers = model.headers;
|
|
279
|
+
var minQuestions = config.minQuestions,
|
|
280
|
+
maxQuestions = config.maxQuestions,
|
|
281
|
+
maxLengthQuestionsHeading = config.maxLengthQuestionsHeading,
|
|
282
|
+
maxAnswers = config.maxAnswers,
|
|
283
|
+
maxLengthAnswers = config.maxLengthAnswers,
|
|
284
|
+
maxLengthFirstColumnHeading = config.maxLengthFirstColumnHeading;
|
|
285
|
+
var rowsErrors = {};
|
|
286
|
+
var columnsErrors = {};
|
|
287
|
+
var errors = {};
|
|
288
|
+
if (rows.length < minQuestions) {
|
|
289
|
+
errors.noOfRowsError = "There should be at least ".concat(minQuestions, " question rows.");
|
|
290
|
+
} else if (rows.length > maxQuestions) {
|
|
291
|
+
errors.noOfRowsError = "No more than ".concat(maxQuestions, " question rows should be defined.");
|
|
292
|
+
}
|
|
293
|
+
(rows || []).forEach(function (row, index) {
|
|
294
|
+
var id = row.id,
|
|
295
|
+
_row$values = row.values,
|
|
296
|
+
values = _row$values === void 0 ? [] : _row$values,
|
|
297
|
+
title = row.title;
|
|
298
|
+
var hasCorrectResponse = false;
|
|
299
|
+
rowsErrors[id] = '';
|
|
300
|
+
if (maxLengthQuestionsHeading && markupToText(title).length > maxLengthQuestionsHeading) {
|
|
301
|
+
rowsErrors[id] += "Questions rows content length should not be more than ".concat(maxLengthQuestionsHeading, " characters. ");
|
|
302
|
+
} else if (title === '' || title === '<div></div>') {
|
|
303
|
+
rowsErrors[id] += 'Content should not be empty. ';
|
|
304
|
+
} else {
|
|
305
|
+
var identicalAnswer = rows.slice(index + 1).some(function (r) {
|
|
306
|
+
return r.title === title;
|
|
307
|
+
});
|
|
308
|
+
if (identicalAnswer) {
|
|
309
|
+
rowsErrors[id] = 'Content should be unique. ';
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
values.forEach(function (value) {
|
|
313
|
+
if (value) {
|
|
314
|
+
hasCorrectResponse = true;
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
if (!hasCorrectResponse) {
|
|
318
|
+
rowsErrors[id] += 'No correct response defined.';
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
if (maxAnswers && headers.length - 1 > maxAnswers) {
|
|
322
|
+
errors.columnsLengthError = "There should be maximum ".concat(maxAnswers, " answers.");
|
|
323
|
+
}
|
|
324
|
+
if (maxLengthFirstColumnHeading && headers[0].length > maxLengthFirstColumnHeading) {
|
|
325
|
+
columnsErrors[0] = "The first column heading should have the maximum length of ".concat(maxLengthFirstColumnHeading, " characters.");
|
|
326
|
+
}
|
|
327
|
+
(headers || []).slice(1).forEach(function (heading, index) {
|
|
328
|
+
if (heading === '' || heading === '<div></div>') {
|
|
329
|
+
columnsErrors[index + 1] = 'Content should not be empty.';
|
|
330
|
+
} else if (maxLengthAnswers && heading.length > maxLengthAnswers) {
|
|
331
|
+
columnsErrors[index + 1] = "Content length should be maximum ".concat(maxLengthAnswers, " characters.");
|
|
332
|
+
} else {
|
|
333
|
+
var identicalAnswer = headers.slice(index + 2).some(function (h) {
|
|
334
|
+
return h === heading;
|
|
335
|
+
});
|
|
336
|
+
if (identicalAnswer) {
|
|
337
|
+
columnsErrors[index + 2] = 'Content should be unique.';
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
if (!(0, _isEmpty["default"])(rowsErrors)) {
|
|
342
|
+
errors.rowsErrors = rowsErrors;
|
|
343
|
+
errors.correctResponseError = choiceMode === 'radio' ? 'There should be a correct response defined for every row.' : 'There should be at least one correct response defined for every row.';
|
|
344
|
+
}
|
|
345
|
+
if (!(0, _isEmpty["default"])(columnsErrors)) {
|
|
346
|
+
errors.columnsErrors = columnsErrors;
|
|
347
|
+
}
|
|
348
|
+
return errors;
|
|
349
|
+
};
|
|
350
|
+
exports.validate = validate;
|
|
351
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_isEqual","_interopRequireDefault","require","_isEmpty","_cloneDeep","_feedback","_controllerUtils","_debug","_defaults","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","log","debug","getResponseCorrectness","model","answers","env","undefined","isPartialScoring","partialScoring","enabled","rows","checkboxMode","choiceMode","totalCorrectAnswers","getTotalCorrectAnswers","getTotalCorrect","correctAnswers","incorrectAnswers","checkboxes","getCheckboxes","getCorrectRadios","getCorrectness","question","mode","row","answer","id","values","v","isEqual","matchingTable","layout","noOfTotalCorrectAnswers","value","getPartialScore","_getCheckboxes","totalCorrect","total","extraAnswers","score","parseFloat","toFixed","getOutComeScore","correctness","outcome","session","Promise","resolve","completed","isEmpty","empty","out","exports","createDefaultModel","defaults","normalize","feedbackEnabled","promptEnabled","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","updateSession","_ref","_asyncToGenerator2","_regenerator","mark","_callee","normalizedQuestion","correctResponse","correctInfo","lockChoiceOrder","fb","wrap","_callee$","_context","prev","next","cloneDeep","concat","lockChoices","getShuffledChoices","sent","getFeedbackForCorrectness","feedback","then","allowFeedback","prompt","config","shuffled","disabled","view","role","teacherInstructions","rationale","assign","stop","_x","createCorrectResponseSession","r","markupToText","s","replace","validate","headers","minQuestions","maxQuestions","maxLengthQuestionsHeading","maxAnswers","maxLengthAnswers","maxLengthFirstColumnHeading","rowsErrors","columnsErrors","errors","noOfRowsError","index","_row$values","title","hasCorrectResponse","identicalAnswer","slice","some","columnsLengthError","heading","h","correctResponseError"],"sources":["../src/index.js"],"sourcesContent":["import isEqual from 'lodash/isEqual';\nimport isEmpty from 'lodash/isEmpty';\nimport cloneDeep from 'lodash/cloneDeep';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';\nimport debug from 'debug';\n\nconst log = debug('@pie-element:match:controller');\n\nimport defaults from './defaults';\n\nconst getResponseCorrectness = (model, answers, env = {}) => {\n const isPartialScoring = partialScoring.enabled(model, env);\n const rows = model.rows;\n const checkboxMode = model.choiceMode === 'checkbox';\n\n if (!answers || Object.keys(answers).length === 0) {\n return 'unanswered';\n }\n\n const totalCorrectAnswers = checkboxMode ? getTotalCorrectAnswers(model) : getTotalCorrect(model);\n let correctAnswers;\n let incorrectAnswers = 0;\n\n if (checkboxMode) {\n const checkboxes = getCheckboxes(rows, answers);\n\n correctAnswers = checkboxes.correctAnswers;\n incorrectAnswers = checkboxes.incorrectAnswers;\n } else {\n correctAnswers = getCorrectRadios(rows, answers);\n }\n\n if (totalCorrectAnswers === correctAnswers && !incorrectAnswers) {\n return 'correct';\n } else if (correctAnswers === 0) {\n return 'incorrect';\n } else if (isPartialScoring) {\n return 'partial';\n }\n\n return 'incorrect';\n};\n\nconst getCorrectness = (question, env, answers = {}) => {\n if (env.mode === 'evaluate') {\n return getResponseCorrectness(question, answers, env);\n }\n};\n\nconst getCheckboxes = (rows, answers) => {\n let correctAnswers = 0;\n let incorrectAnswers = 0;\n\n rows.forEach((row) => {\n const answer = answers[row.id];\n\n if (answer) {\n row.values.forEach((v, i) => {\n if (answer[i] && answer[i] === v) {\n correctAnswers += 1;\n } else if (answer[i] && answer[i] !== v) {\n incorrectAnswers += 1;\n }\n });\n }\n });\n\n return { correctAnswers, incorrectAnswers };\n};\n\nconst getCorrectRadios = (rows, answers) => {\n let correctAnswers = 0;\n\n rows.forEach((row) => {\n if (isEqual(row.values, answers[row.id])) {\n correctAnswers += 1;\n }\n });\n\n return correctAnswers;\n};\n\nconst getTotalCorrect = (question) => {\n const checkboxMode = question.choiceMode === 'checkbox';\n const matchingTable = checkboxMode ? question.layout - 1 : 1;\n return (question.rows.length || 0) * matchingTable;\n};\n\nconst getTotalCorrectAnswers = (question) => {\n let noOfTotalCorrectAnswers = 0;\n\n question.rows.forEach((row) => {\n row.values.forEach((value) => {\n if (value) {\n noOfTotalCorrectAnswers += 1;\n }\n });\n });\n\n return noOfTotalCorrectAnswers;\n};\n\nconst getPartialScore = (question, answers) => {\n const checkboxMode = question.choiceMode === 'checkbox';\n\n if (checkboxMode) {\n const { correctAnswers, incorrectAnswers } = getCheckboxes(question.rows, answers);\n const totalCorrect = getTotalCorrectAnswers(question);\n\n const total = totalCorrect === 0 ? 1 : totalCorrect;\n\n if (correctAnswers + incorrectAnswers > totalCorrect) {\n const extraAnswers = correctAnswers + incorrectAnswers - totalCorrect;\n const score = parseFloat(((correctAnswers - extraAnswers) / total).toFixed(2));\n\n return score < 0 ? 0 : score;\n } else {\n return parseFloat((correctAnswers / total).toFixed(2));\n }\n } else {\n const correctAnswers = getCorrectRadios(question.rows, answers);\n const totalCorrect = getTotalCorrect(question) === 0 ? 1 : getTotalCorrect(question);\n\n return parseFloat((correctAnswers / totalCorrect).toFixed(2));\n }\n};\n\nconst getOutComeScore = (question, env, answers = {}) => {\n const correctness = getCorrectness(question, env, answers);\n const isPartialScoring = partialScoring.enabled(question, env);\n\n return correctness === 'correct'\n ? 1\n : correctness === 'partial' && isPartialScoring\n ? getPartialScore(question, answers)\n : 0;\n};\n\nexport const outcome = (question, session, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate') {\n resolve({ score: undefined, completed: undefined });\n } else {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n const out = {\n score: getOutComeScore(question, env, session.answers),\n };\n\n resolve(out);\n }\n });\n};\n\nexport function createDefaultModel(model = {}) {\n return new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n}\n\nexport const normalize = (question) => ({\n feedbackEnabled: true,\n promptEnabled: true,\n rationaleEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question,\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport function model(question, session, env, updateSession) {\n return new Promise(async (resolve) => {\n const normalizedQuestion = cloneDeep(normalize(question));\n let correctness, score;\n\n if ((!session || isEmpty(session)) && env.mode === 'evaluate') {\n correctness = 'unanswered';\n score = '0%';\n } else {\n correctness = getCorrectness(normalizedQuestion, env, session && session.answers);\n score = `${getOutComeScore(normalizedQuestion, env, session && session.answers) * 100}%`;\n }\n\n const correctResponse = {};\n const correctInfo = {\n score,\n correctness,\n };\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n normalizedQuestion.rows = await getShuffledChoices(normalizedQuestion.rows, session, updateSession, 'id');\n }\n\n normalizedQuestion.rows.forEach((row) => {\n correctResponse[row.id] = row.values;\n\n if (env.mode !== 'evaluate') {\n delete row.values;\n }\n });\n\n const fb =\n env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled\n ? getFeedbackForCorrectness(correctInfo.correctness, normalizedQuestion.feedback)\n : Promise.resolve(undefined);\n\n fb.then((feedback) => {\n const out = {\n allowFeedback: normalizedQuestion.feedbackEnabled,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n config: {\n ...normalizedQuestion,\n shuffled: !normalizedQuestion.lockChoiceOrder,\n },\n feedback,\n disabled: env.mode !== 'gather',\n view: env.mode === 'view',\n };\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n out.config.rationale = null;\n out.config.teacherInstructions = null;\n }\n\n if (env.mode === 'evaluate') {\n Object.assign(out, {\n correctResponse,\n correctness: correctInfo,\n });\n }\n\n log('out: ', out);\n resolve(out);\n });\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { rows } = question;\n const answers = {};\n\n rows.forEach((r) => {\n answers[r.id] = r.values;\n });\n\n resolve({\n answers,\n id: '1',\n });\n } else {\n resolve(null);\n }\n });\n};\n\nconst markupToText = (s) => {\n return s.replace(/(<([^>]+)>)/ig, '');\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { rows, choiceMode, headers } = model;\n const {\n minQuestions,\n maxQuestions,\n maxLengthQuestionsHeading,\n maxAnswers,\n maxLengthAnswers,\n maxLengthFirstColumnHeading\n } = config;\n const rowsErrors = {};\n const columnsErrors = {};\n const errors = {};\n\n if (rows.length < minQuestions) {\n errors.noOfRowsError = `There should be at least ${minQuestions} question rows.`;\n } else if (rows.length > maxQuestions) {\n errors.noOfRowsError = `No more than ${maxQuestions} question rows should be defined.`;\n }\n\n (rows || []).forEach((row, index) => {\n const { id, values = [], title } = row;\n let hasCorrectResponse = false;\n\n rowsErrors[id] = '';\n\n if (maxLengthQuestionsHeading && markupToText(title).length > maxLengthQuestionsHeading) {\n rowsErrors[id] += `Questions rows content length should not be more than ${maxLengthQuestionsHeading} characters. `;\n } else if (title === '' || title === '<div></div>') {\n rowsErrors[id] += 'Content should not be empty. ';\n } else {\n const identicalAnswer = rows.slice(index + 1).some((r) => {\n return r.title === title;\n });\n\n if (identicalAnswer) {\n rowsErrors[id] = 'Content should be unique. ';\n }\n }\n\n values.forEach((value) => {\n if (value) {\n hasCorrectResponse = true;\n }\n });\n\n if (!hasCorrectResponse) {\n rowsErrors[id] += 'No correct response defined.';\n }\n });\n\n if (maxAnswers && headers.length - 1 > maxAnswers) {\n errors.columnsLengthError = `There should be maximum ${maxAnswers} answers.`;\n }\n\n if (maxLengthFirstColumnHeading && headers[0].length > maxLengthFirstColumnHeading) {\n columnsErrors[0] = `The first column heading should have the maximum length of ${maxLengthFirstColumnHeading} characters.`;\n }\n\n (headers || []).slice(1).forEach((heading, index) => {\n if (heading === '' || heading === '<div></div>') {\n columnsErrors[index + 1] = 'Content should not be empty.';\n } else if (maxLengthAnswers && heading.length > maxLengthAnswers) {\n columnsErrors[index + 1] = `Content length should be maximum ${maxLengthAnswers} characters.`;\n } else {\n const identicalAnswer = headers.slice(index + 2).some((h) => {\n return h === heading;\n });\n\n if (identicalAnswer) {\n columnsErrors[index + 2] = 'Content should be unique.';\n }\n }\n });\n\n\n if (!isEmpty(rowsErrors)) {\n errors.rowsErrors = rowsErrors;\n errors.correctResponseError =\n choiceMode === 'radio'\n ? 'There should be a correct response defined for every row.'\n : 'There should be at least one correct response defined for every row.';\n }\n\n if (!isEmpty(columnsErrors)) {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,GAAG,CAAC,CAAC,CAACM,IAAI,CAAC,UAACG,CAAC,EAAK;QAC3D,OAAOA,CAAC,KAAKD,OAAO;MACtB,CAAC,CAAC;MAEF,IAAIJ,eAAe,EAAE;QACnBP,aAAa,CAACG,KAAK,GAAG,CAAC,CAAC,GAAG,2BAA2B;MACxD;IACF;EACF,CAAC,CAAC;EAGF,IAAI,CAAC,IAAAjE,mBAAO,EAAC6D,UAAU,CAAC,EAAE;IACxBE,MAAM,CAACF,UAAU,GAAGA,UAAU;IAC9BE,MAAM,CAACY,oBAAoB,GACzBhH,UAAU,KAAK,OAAO,GAClB,2DAA2D,GAC3D,sEAAsE;EAC9E;EAEA,IAAI,CAAC,IAAAqC,mBAAO,EAAC8D,aAAa,CAAC,EAAE;IAC3BC,MAAM,CAACD,aAAa,GAAGA,aAAa;EACtC;EAEA,OAAOC,MAAM;AACf,CAAC;AAAC5D,OAAA,CAAAkD,QAAA,GAAAA,QAAA"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = exports.AnswerGrid = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
11
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
12
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
var _react = _interopRequireDefault(require("react"));
|
|
16
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
17
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
18
|
+
var _Radio = _interopRequireDefault(require("@material-ui/core/Radio"));
|
|
19
|
+
var _Checkbox = _interopRequireDefault(require("@material-ui/core/Checkbox"));
|
|
20
|
+
var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
|
|
21
|
+
var _styles = require("@material-ui/core/styles");
|
|
22
|
+
var _renderUi = require("@pie-lib/render-ui");
|
|
23
|
+
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; }
|
|
24
|
+
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; }
|
|
25
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
26
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
27
|
+
var AnswerGrid = /*#__PURE__*/function (_React$Component) {
|
|
28
|
+
(0, _inherits2["default"])(AnswerGrid, _React$Component);
|
|
29
|
+
var _super = _createSuper(AnswerGrid);
|
|
30
|
+
function AnswerGrid() {
|
|
31
|
+
var _this;
|
|
32
|
+
(0, _classCallCheck2["default"])(this, AnswerGrid);
|
|
33
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
34
|
+
args[_key] = arguments[_key];
|
|
35
|
+
}
|
|
36
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
37
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onRowValueChange", function (rowId, answerIndex) {
|
|
38
|
+
return function (event) {
|
|
39
|
+
var _this$props = _this.props,
|
|
40
|
+
onAnswerChange = _this$props.onAnswerChange,
|
|
41
|
+
choiceMode = _this$props.choiceMode,
|
|
42
|
+
answers = _this$props.answers;
|
|
43
|
+
var newAnswers = _objectSpread({}, answers);
|
|
44
|
+
if (choiceMode === 'radio') {
|
|
45
|
+
for (var i = 0; i < newAnswers[rowId].length; i++) {
|
|
46
|
+
newAnswers[rowId][i] = false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
newAnswers[rowId][answerIndex] = event.target.checked;
|
|
50
|
+
onAnswerChange(newAnswers);
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "answerIsCorrect", function (rowId, rowValue, rowValueIndex) {
|
|
54
|
+
var correctAnswers = _this.props.correctAnswers;
|
|
55
|
+
return correctAnswers[rowId][rowValueIndex] === rowValue && rowValue === true;
|
|
56
|
+
});
|
|
57
|
+
// needs a separate method because what isn't correct isn't necessarily incorrect
|
|
58
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "answerIsIncorrect", function (rowId, rowValue, rowValueIndex) {
|
|
59
|
+
var correctAnswers = _this.props.correctAnswers;
|
|
60
|
+
return correctAnswers[rowId][rowValueIndex] === true && rowValue === false || correctAnswers[rowId][rowValueIndex] === false && rowValue === true;
|
|
61
|
+
});
|
|
62
|
+
return _this;
|
|
63
|
+
}
|
|
64
|
+
(0, _createClass2["default"])(AnswerGrid, [{
|
|
65
|
+
key: "render",
|
|
66
|
+
value: function render() {
|
|
67
|
+
var _this2 = this;
|
|
68
|
+
var _this$props2 = this.props,
|
|
69
|
+
classes = _this$props2.classes,
|
|
70
|
+
showCorrect = _this$props2.showCorrect,
|
|
71
|
+
headers = _this$props2.headers,
|
|
72
|
+
rows = _this$props2.rows,
|
|
73
|
+
choiceMode = _this$props2.choiceMode,
|
|
74
|
+
answers = _this$props2.answers,
|
|
75
|
+
disabled = _this$props2.disabled,
|
|
76
|
+
view = _this$props2.view;
|
|
77
|
+
var Tag = choiceMode === 'radio' ? _Radio["default"] : _Checkbox["default"];
|
|
78
|
+
var evaluate = disabled && !view;
|
|
79
|
+
if (!rows || rows.length === 0) {
|
|
80
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
81
|
+
className: classes.controlsContainer
|
|
82
|
+
}, /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
|
|
83
|
+
className: classes.empty,
|
|
84
|
+
component: "div"
|
|
85
|
+
}, "There are currently no questions to show."));
|
|
86
|
+
}
|
|
87
|
+
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
88
|
+
className: classes.controlsContainer
|
|
89
|
+
}, /*#__PURE__*/_react["default"].createElement("table", {
|
|
90
|
+
className: classes.table
|
|
91
|
+
}, /*#__PURE__*/_react["default"].createElement("colgroup", null, (headers || []).map(function (header, idx) {
|
|
92
|
+
return /*#__PURE__*/_react["default"].createElement("col", {
|
|
93
|
+
key: "col-".concat(idx)
|
|
94
|
+
});
|
|
95
|
+
})), /*#__PURE__*/_react["default"].createElement("thead", null, /*#__PURE__*/_react["default"].createElement("tr", null, (headers || []).map(function (header, idx) {
|
|
96
|
+
return /*#__PURE__*/_react["default"].createElement("th", {
|
|
97
|
+
className: classes.rowHeader,
|
|
98
|
+
key: "th-".concat(idx),
|
|
99
|
+
"data-colno": "".concat(idx),
|
|
100
|
+
scope: "row"
|
|
101
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
102
|
+
className: (0, _classnames["default"])(classes.rowItem, (0, _defineProperty2["default"])({}, classes.questionText, idx === 0)),
|
|
103
|
+
dangerouslySetInnerHTML: {
|
|
104
|
+
__html: header
|
|
105
|
+
}
|
|
106
|
+
}));
|
|
107
|
+
}))), (rows || []).map(function (row, idx) {
|
|
108
|
+
return /*#__PURE__*/_react["default"].createElement("tbody", {
|
|
109
|
+
key: "row-".concat(idx),
|
|
110
|
+
role: "group"
|
|
111
|
+
}, /*#__PURE__*/_react["default"].createElement("tr", {
|
|
112
|
+
className: classes.separator
|
|
113
|
+
}, /*#__PURE__*/_react["default"].createElement("td", {
|
|
114
|
+
key: "td-title-".concat(idx),
|
|
115
|
+
"data-colno": '0'
|
|
116
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
117
|
+
className: (0, _classnames["default"])(classes.rowItem, classes.questionText),
|
|
118
|
+
dangerouslySetInnerHTML: {
|
|
119
|
+
__html: row.title
|
|
120
|
+
}
|
|
121
|
+
})), (answers[row.id] || []).map(function (rowItem, answerIndex) {
|
|
122
|
+
var _cx2;
|
|
123
|
+
return /*#__PURE__*/_react["default"].createElement("td", {
|
|
124
|
+
key: "td-".concat(idx, "-").concat(answerIndex),
|
|
125
|
+
className: classes.column,
|
|
126
|
+
"data-colno": "".concat(answerIndex + 1)
|
|
127
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
128
|
+
className: classes.rowItem
|
|
129
|
+
}, /*#__PURE__*/_react["default"].createElement(Tag, {
|
|
130
|
+
className: (0, _classnames["default"])((_cx2 = {}, (0, _defineProperty2["default"])(_cx2, classes.correct, showCorrect && rowItem === true || evaluate && _this2.answerIsCorrect(row.id, rowItem, answerIndex)), (0, _defineProperty2["default"])(_cx2, classes.tag, true), (0, _defineProperty2["default"])(_cx2, classes.checked, rowItem === true && !evaluate), (0, _defineProperty2["default"])(_cx2, classes.tagDisabled, disabled), (0, _defineProperty2["default"])(_cx2, classes.incorrect, evaluate && _this2.answerIsIncorrect(row.id, rowItem, answerIndex)), _cx2)),
|
|
131
|
+
disabled: disabled,
|
|
132
|
+
onChange: _this2.onRowValueChange(row.id, answerIndex),
|
|
133
|
+
checked: rowItem === true
|
|
134
|
+
})));
|
|
135
|
+
})));
|
|
136
|
+
})));
|
|
137
|
+
}
|
|
138
|
+
}]);
|
|
139
|
+
return AnswerGrid;
|
|
140
|
+
}(_react["default"].Component);
|
|
141
|
+
exports.AnswerGrid = AnswerGrid;
|
|
142
|
+
(0, _defineProperty2["default"])(AnswerGrid, "propTypes", {
|
|
143
|
+
classes: _propTypes["default"].object.isRequired,
|
|
144
|
+
correctAnswers: _propTypes["default"].object,
|
|
145
|
+
view: _propTypes["default"].bool.isRequired,
|
|
146
|
+
showCorrect: _propTypes["default"].bool.isRequired,
|
|
147
|
+
disabled: _propTypes["default"].bool.isRequired,
|
|
148
|
+
onAnswerChange: _propTypes["default"].func.isRequired,
|
|
149
|
+
choiceMode: _propTypes["default"].string.isRequired,
|
|
150
|
+
rows: _propTypes["default"].array.isRequired,
|
|
151
|
+
headers: _propTypes["default"].array.isRequired,
|
|
152
|
+
answers: _propTypes["default"].object.isRequired
|
|
153
|
+
});
|
|
154
|
+
var styles = function styles(theme) {
|
|
155
|
+
return {
|
|
156
|
+
controlsContainer: {
|
|
157
|
+
marginLeft: 'auto',
|
|
158
|
+
marginRight: 'auto',
|
|
159
|
+
marginTop: theme.spacing.unit,
|
|
160
|
+
marginBottom: theme.spacing.unit
|
|
161
|
+
},
|
|
162
|
+
column: {
|
|
163
|
+
padding: '5px 0'
|
|
164
|
+
},
|
|
165
|
+
correct: {
|
|
166
|
+
color: "".concat(_renderUi.color.correct(), " !important")
|
|
167
|
+
},
|
|
168
|
+
incorrect: {
|
|
169
|
+
color: "".concat(_renderUi.color.incorrect(), " !important")
|
|
170
|
+
},
|
|
171
|
+
empty: {
|
|
172
|
+
margin: theme.spacing.unit * 2
|
|
173
|
+
},
|
|
174
|
+
rowContainer: {
|
|
175
|
+
display: 'flex',
|
|
176
|
+
alignItems: 'center'
|
|
177
|
+
},
|
|
178
|
+
rowHeader: {
|
|
179
|
+
padding: 0
|
|
180
|
+
},
|
|
181
|
+
rowItem: {
|
|
182
|
+
padding: '12px',
|
|
183
|
+
textAlign: 'center'
|
|
184
|
+
},
|
|
185
|
+
separator: {
|
|
186
|
+
border: 0,
|
|
187
|
+
borderTop: "2.5px solid ".concat(_renderUi.color.primaryLight()),
|
|
188
|
+
width: '100%'
|
|
189
|
+
},
|
|
190
|
+
tag: {
|
|
191
|
+
padding: '6px',
|
|
192
|
+
color: _renderUi.color.text(),
|
|
193
|
+
'&:hover': {
|
|
194
|
+
color: _renderUi.color.primaryLight()
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
checked: {
|
|
198
|
+
color: "".concat(_renderUi.color.primary(), " !important")
|
|
199
|
+
},
|
|
200
|
+
tagDisabled: {
|
|
201
|
+
color: _renderUi.color.disabled(),
|
|
202
|
+
cursor: 'not-allowed !important',
|
|
203
|
+
pointerEvents: 'initial !important',
|
|
204
|
+
opacity: 0.7,
|
|
205
|
+
'&:hover': {
|
|
206
|
+
color: _renderUi.color.disabled()
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
table: {
|
|
210
|
+
color: _renderUi.color.text(),
|
|
211
|
+
backgroundColor: _renderUi.color.background(),
|
|
212
|
+
borderCollapse: 'collapse',
|
|
213
|
+
borderSpacing: 0,
|
|
214
|
+
marginBottom: 0
|
|
215
|
+
},
|
|
216
|
+
questionText: {
|
|
217
|
+
textAlign: 'left'
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
var _default = (0, _styles.withStyles)(styles)(AnswerGrid);
|
|
222
|
+
exports["default"] = _default;
|
|
223
|
+
//# sourceMappingURL=answer-grid.js.map
|