@pie-element/placement-ordering 9.4.1-next.42 → 9.4.1-next.43
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/choice-editor.js +477 -0
- package/configure/lib/choice-editor.js.map +1 -0
- package/configure/lib/choice-tile.js +279 -0
- package/configure/lib/choice-tile.js.map +1 -0
- package/configure/lib/defaults.js +135 -0
- package/configure/lib/defaults.js.map +1 -0
- package/configure/lib/design.js +455 -0
- package/configure/lib/design.js.map +1 -0
- package/configure/lib/help.js +22 -0
- package/configure/lib/help.js.map +1 -0
- package/configure/lib/index.js +230 -0
- package/configure/lib/index.js.map +1 -0
- package/configure/lib/utils.js +14 -0
- package/configure/lib/utils.js.map +1 -0
- package/configure/package.json +1 -1
- package/controller/lib/defaults.js +28 -0
- package/controller/lib/defaults.js.map +1 -0
- package/controller/lib/index.js +282 -0
- package/controller/lib/index.js.map +1 -0
- package/controller/lib/scoring.js +150 -0
- package/controller/lib/scoring.js.map +1 -0
- package/controller/package.json +1 -1
- package/lib/index.js +149 -0
- package/lib/index.js.map +1 -0
- package/lib/main.js +69 -0
- package/lib/main.js.map +1 -0
- package/lib/ordering.js +214 -0
- package/lib/ordering.js.map +1 -0
- package/lib/placement-ordering.js +456 -0
- package/lib/placement-ordering.js.map +1 -0
- package/lib/tile.js +271 -0
- package/lib/tile.js.map +1 -0
- package/lib/tiler.js +234 -0
- package/lib/tiler.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = exports.addWeightToCorrectResponse = void 0;
|
|
9
|
+
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
14
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
+
|
|
16
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
17
|
+
|
|
18
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
19
|
+
|
|
20
|
+
var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
|
|
21
|
+
|
|
22
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
+
|
|
24
|
+
var _pieConfigureEvents = require("@pie-framework/pie-configure-events");
|
|
25
|
+
|
|
26
|
+
var _design = _interopRequireDefault(require("./design"));
|
|
27
|
+
|
|
28
|
+
var _react = _interopRequireDefault(require("react"));
|
|
29
|
+
|
|
30
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
31
|
+
|
|
32
|
+
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
33
|
+
|
|
34
|
+
var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
|
|
35
|
+
|
|
36
|
+
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; }
|
|
37
|
+
|
|
38
|
+
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; }
|
|
39
|
+
|
|
40
|
+
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); }; }
|
|
41
|
+
|
|
42
|
+
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; } }
|
|
43
|
+
|
|
44
|
+
var prepareCustomizationObject = function prepareCustomizationObject(config, model) {
|
|
45
|
+
var configuration = (0, _defaults2["default"])(config, _defaults["default"].configuration);
|
|
46
|
+
return {
|
|
47
|
+
configuration: configuration,
|
|
48
|
+
model: model
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
var addWeightToCorrectResponse = function addWeightToCorrectResponse(correctResponse) {
|
|
53
|
+
return correctResponse && correctResponse.map(function (correct) {
|
|
54
|
+
// if weight is set
|
|
55
|
+
if (correct.weight !== undefined) {
|
|
56
|
+
return {
|
|
57
|
+
id: correct.id,
|
|
58
|
+
weight: correct.weight
|
|
59
|
+
};
|
|
60
|
+
} else {
|
|
61
|
+
return {
|
|
62
|
+
id: correct.id || correct,
|
|
63
|
+
weight: 0
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* assuming that the correct response will be set via ui, not via config,
|
|
70
|
+
* correctResponse (if not set) will be initialized with choices default order
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
exports.addWeightToCorrectResponse = addWeightToCorrectResponse;
|
|
75
|
+
|
|
76
|
+
var PlacementOrdering = /*#__PURE__*/function (_HTMLElement) {
|
|
77
|
+
(0, _inherits2["default"])(PlacementOrdering, _HTMLElement);
|
|
78
|
+
|
|
79
|
+
var _super = _createSuper(PlacementOrdering);
|
|
80
|
+
|
|
81
|
+
function PlacementOrdering() {
|
|
82
|
+
var _this;
|
|
83
|
+
|
|
84
|
+
(0, _classCallCheck2["default"])(this, PlacementOrdering);
|
|
85
|
+
_this = _super.call(this);
|
|
86
|
+
_this._model = PlacementOrdering.createDefaultModel();
|
|
87
|
+
_this._configuration = _defaults["default"].configuration;
|
|
88
|
+
|
|
89
|
+
_this.onModelChanged = function (model, resetSession) {
|
|
90
|
+
_this._model = model;
|
|
91
|
+
|
|
92
|
+
_this._rerender();
|
|
93
|
+
|
|
94
|
+
_this.dispatchUpdate(resetSession);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
_this.onConfigurationChanged = function (configuration) {
|
|
98
|
+
_this._configuration = prepareCustomizationObject(configuration).configuration;
|
|
99
|
+
|
|
100
|
+
_this.onModelChanged(_this._model);
|
|
101
|
+
|
|
102
|
+
_this._rerender();
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
_this.insertImage = function (handler) {
|
|
106
|
+
_this.dispatchEvent(new _pieConfigureEvents.InsertImageEvent(handler));
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
_this.deleteImage = function (src, done) {
|
|
110
|
+
_this.dispatchEvent(new _pieConfigureEvents.DeleteImageEvent(src, done));
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return _this;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
(0, _createClass2["default"])(PlacementOrdering, [{
|
|
117
|
+
key: "dispatchUpdate",
|
|
118
|
+
value: function dispatchUpdate(reset) {
|
|
119
|
+
this.dispatchEvent(new _pieConfigureEvents.ModelUpdatedEvent(this._model, reset));
|
|
120
|
+
}
|
|
121
|
+
}, {
|
|
122
|
+
key: "model",
|
|
123
|
+
set: function set(s) {
|
|
124
|
+
this._model = PlacementOrdering.createDefaultModel(s);
|
|
125
|
+
|
|
126
|
+
this._rerender();
|
|
127
|
+
}
|
|
128
|
+
}, {
|
|
129
|
+
key: "configuration",
|
|
130
|
+
set: function set(c) {
|
|
131
|
+
var _newConfiguration$lan,
|
|
132
|
+
_this2 = this;
|
|
133
|
+
|
|
134
|
+
var info = prepareCustomizationObject(c, this._model);
|
|
135
|
+
this.onModelChanged(info.model);
|
|
136
|
+
|
|
137
|
+
var newConfiguration = _objectSpread(_objectSpread({}, _defaults["default"].configuration), info.configuration);
|
|
138
|
+
|
|
139
|
+
this._configuration = newConfiguration; // if language:enabled is true, then the corresponding default item model should include a language value;
|
|
140
|
+
// if it is false, then the language field should be omitted from the item model.
|
|
141
|
+
// if a default item model includes a language value (e.g., en_US) and the corresponding authoring view settings have language:settings = true,
|
|
142
|
+
// then (a) language:enabled should also be true, and (b) that default language value should be represented in languageChoices[] (as a key).
|
|
143
|
+
|
|
144
|
+
if (newConfiguration !== null && newConfiguration !== void 0 && (_newConfiguration$lan = newConfiguration.language) !== null && _newConfiguration$lan !== void 0 && _newConfiguration$lan.enabled) {
|
|
145
|
+
var _newConfiguration$lan2, _newConfiguration$lan3;
|
|
146
|
+
|
|
147
|
+
if (newConfiguration !== null && newConfiguration !== void 0 && (_newConfiguration$lan2 = newConfiguration.languageChoices) !== null && _newConfiguration$lan2 !== void 0 && (_newConfiguration$lan3 = _newConfiguration$lan2.options) !== null && _newConfiguration$lan3 !== void 0 && _newConfiguration$lan3.length) {
|
|
148
|
+
this._model.language = newConfiguration === null || newConfiguration === void 0 ? void 0 : newConfiguration.languageChoices.options[0].value;
|
|
149
|
+
}
|
|
150
|
+
} else if (newConfiguration.language.settings && this._model.language) {
|
|
151
|
+
this._configuration.language.enabled = true;
|
|
152
|
+
|
|
153
|
+
if (!this._configuration.languageChoices.options || !this._configuration.languageChoices.options.length) {
|
|
154
|
+
this._configuration.languageChoices.options = [];
|
|
155
|
+
} // check if the language is already included in the languageChoices.options array
|
|
156
|
+
// and if not, then add it.
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
if (!this._configuration.languageChoices.options.find(function (option) {
|
|
160
|
+
return option.value === _this2._model.language;
|
|
161
|
+
})) {
|
|
162
|
+
this._configuration.languageChoices.options.push({
|
|
163
|
+
value: this._model.language,
|
|
164
|
+
label: this._model.language
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
} else {
|
|
168
|
+
delete this._model.language;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
this._rerender();
|
|
172
|
+
}
|
|
173
|
+
}, {
|
|
174
|
+
key: "insertSound",
|
|
175
|
+
value: function insertSound(handler) {
|
|
176
|
+
this.dispatchEvent(new _pieConfigureEvents.InsertSoundEvent(handler));
|
|
177
|
+
}
|
|
178
|
+
}, {
|
|
179
|
+
key: "onDeleteSound",
|
|
180
|
+
value: function onDeleteSound(src, done) {
|
|
181
|
+
this.dispatchEvent(new _pieConfigureEvents.DeleteSoundEvent(src, done));
|
|
182
|
+
}
|
|
183
|
+
}, {
|
|
184
|
+
key: "_rerender",
|
|
185
|
+
value: function _rerender() {
|
|
186
|
+
var element = /*#__PURE__*/_react["default"].createElement(_design["default"], {
|
|
187
|
+
model: this._model,
|
|
188
|
+
configuration: this._configuration,
|
|
189
|
+
onModelChanged: this.onModelChanged,
|
|
190
|
+
onConfigurationChanged: this.onConfigurationChanged,
|
|
191
|
+
imageSupport: {
|
|
192
|
+
add: this.insertImage,
|
|
193
|
+
"delete": this.deleteImage
|
|
194
|
+
},
|
|
195
|
+
uploadSoundSupport: {
|
|
196
|
+
add: this.insertSound.bind(this),
|
|
197
|
+
"delete": this.onDeleteSound.bind(this)
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
_reactDom["default"].render(element, this);
|
|
202
|
+
}
|
|
203
|
+
}]);
|
|
204
|
+
return PlacementOrdering;
|
|
205
|
+
}( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(HTMLElement));
|
|
206
|
+
|
|
207
|
+
exports["default"] = PlacementOrdering;
|
|
208
|
+
(0, _defineProperty2["default"])(PlacementOrdering, "createDefaultModel", function () {
|
|
209
|
+
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
210
|
+
|
|
211
|
+
var mapChoicesToReturnCorrectResponse = function mapChoicesToReturnCorrectResponse(choices) {
|
|
212
|
+
return choices && choices.map(function (ch) {
|
|
213
|
+
return {
|
|
214
|
+
id: ch.id,
|
|
215
|
+
weight: 0
|
|
216
|
+
};
|
|
217
|
+
});
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
var correctResponse = addWeightToCorrectResponse(model.correctResponse) || mapChoicesToReturnCorrectResponse(model.choices);
|
|
221
|
+
|
|
222
|
+
var defaultModel = _objectSpread(_objectSpread({}, _defaults["default"].model), model);
|
|
223
|
+
|
|
224
|
+
if (correctResponse) {
|
|
225
|
+
defaultModel.correctResponse = correctResponse;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return defaultModel;
|
|
229
|
+
});
|
|
230
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["prepareCustomizationObject","config","model","configuration","defaultValues","addWeightToCorrectResponse","correctResponse","map","correct","weight","undefined","id","PlacementOrdering","_model","createDefaultModel","_configuration","onModelChanged","resetSession","_rerender","dispatchUpdate","onConfigurationChanged","insertImage","handler","dispatchEvent","InsertImageEvent","deleteImage","src","done","DeleteImageEvent","reset","ModelUpdatedEvent","s","c","info","newConfiguration","language","enabled","languageChoices","options","length","value","settings","find","option","push","label","InsertSoundEvent","DeleteSoundEvent","element","React","createElement","Main","imageSupport","add","uploadSoundSupport","insertSound","bind","onDeleteSound","ReactDOM","render","HTMLElement","mapChoicesToReturnCorrectResponse","choices","ch","defaultModel"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAQA;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\n DeleteSoundEvent,\n} from '@pie-framework/pie-configure-events';\n\nimport Main from './design';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport defaultValues from './defaults';\nimport defaults from 'lodash/defaults';\n\nconst prepareCustomizationObject = (config, model) => {\n const configuration = defaults(config, defaultValues.configuration);\n\n return { configuration, model };\n};\n\nexport const addWeightToCorrectResponse = (correctResponse) =>\n correctResponse &&\n correctResponse.map((correct) => {\n // if weight is set\n if (correct.weight !== undefined) {\n return { id: correct.id, weight: correct.weight };\n } else {\n return { id: correct.id || correct, weight: 0 };\n }\n });\n/**\n * assuming that the correct response will be set via ui, not via config,\n * correctResponse (if not set) will be initialized with choices default order\n */\nexport default class PlacementOrdering extends HTMLElement {\n static createDefaultModel = (model = {}) => {\n const mapChoicesToReturnCorrectResponse = (choices) => choices && choices.map((ch) => ({ id: ch.id, weight: 0 }));\n\n let correctResponse =\n addWeightToCorrectResponse(model.correctResponse) || mapChoicesToReturnCorrectResponse(model.choices);\n\n const defaultModel = {\n ...defaultValues.model,\n ...model,\n };\n\n if (correctResponse) {\n defaultModel.correctResponse = correctResponse;\n }\n\n return defaultModel;\n };\n\n constructor() {\n super();\n\n this._model = PlacementOrdering.createDefaultModel();\n this._configuration = defaultValues.configuration;\n\n this.onModelChanged = (model, resetSession) => {\n this._model = model;\n this._rerender();\n this.dispatchUpdate(resetSession);\n };\n\n this.onConfigurationChanged = (configuration) => {\n this._configuration = prepareCustomizationObject(configuration).configuration;\n\n this.onModelChanged(this._model);\n this._rerender();\n };\n\n this.insertImage = (handler) => {\n this.dispatchEvent(new InsertImageEvent(handler));\n };\n\n this.deleteImage = (src, done) => {\n this.dispatchEvent(new DeleteImageEvent(src, done));\n };\n }\n\n dispatchUpdate(reset) {\n this.dispatchEvent(new ModelUpdatedEvent(this._model, reset));\n }\n\n set model(s) {\n this._model = PlacementOrdering.createDefaultModel(s);\n this._rerender();\n }\n\n set configuration(c) {\n const info = prepareCustomizationObject(c, this._model);\n\n this.onModelChanged(info.model);\n\n const newConfiguration = {\n ...defaultValues.configuration,\n ...info.configuration,\n };\n\n this._configuration = newConfiguration;\n\n // if language:enabled is true, then the corresponding default item model should include a language value;\n // if it is false, then the language field should be omitted from the item model.\n // if a default item model includes a language value (e.g., en_US) and the corresponding authoring view settings have language:settings = true,\n // then (a) language:enabled should also be true, and (b) that default language value should be represented in languageChoices[] (as a key).\n if (newConfiguration?.language?.enabled) {\n if (newConfiguration?.languageChoices?.options?.length) {\n this._model.language = newConfiguration?.languageChoices.options[0].value;\n }\n } else if (newConfiguration.language.settings && this._model.language) {\n this._configuration.language.enabled = true;\n\n if (!this._configuration.languageChoices.options || !this._configuration.languageChoices.options.length) {\n this._configuration.languageChoices.options = [];\n }\n\n // check if the language is already included in the languageChoices.options array\n // and if not, then add it.\n if (!this._configuration.languageChoices.options.find(option => option.value === this._model.language)) {\n this._configuration.languageChoices.options.push({\n value: this._model.language,\n label: this._model.language,\n });\n }\n } else {\n delete this._model.language;\n }\n\n this._rerender();\n }\n\n insertSound(handler) {\n this.dispatchEvent(new InsertSoundEvent(handler));\n }\n\n onDeleteSound(src, done) {\n this.dispatchEvent(new DeleteSoundEvent(src, done));\n }\n\n _rerender() {\n let element = React.createElement(Main, {\n model: this._model,\n configuration: this._configuration,\n onModelChanged: this.onModelChanged,\n onConfigurationChanged: this.onConfigurationChanged,\n imageSupport: {\n add: this.insertImage,\n delete: this.deleteImage,\n },\n uploadSoundSupport: {\n add: this.insertSound.bind(this),\n delete: this.onDeleteSound.bind(this),\n },\n });\n\n ReactDOM.render(element, this);\n }\n}\n"],"file":"index.js"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateValidationMessage = void 0;
|
|
7
|
+
|
|
8
|
+
var generateValidationMessage = function generateValidationMessage() {
|
|
9
|
+
var answersMessage = '\nThere should be at least 3 tokens.' + '\nThe tokens should not be empty and should be unique.' + '\nThe correct ordering should not be identical to the initial ordering.';
|
|
10
|
+
return 'Validation requirements:' + answersMessage;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
exports.generateValidationMessage = generateValidationMessage;
|
|
14
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.js"],"names":["generateValidationMessage","answersMessage"],"mappings":";;;;;;;AAAO,IAAMA,yBAAyB,GAAG,SAA5BA,yBAA4B,GAAM;AAC7C,MAAMC,cAAc,GAClB,yCACA,wDADA,GAEA,yEAHF;AAKA,SAAO,6BAA6BA,cAApC;AACD,CAPM","sourcesContent":["export const generateValidationMessage = () => {\n const answersMessage =\n '\\nThere should be at least 3 tokens.' +\n '\\nThe tokens should not be empty and should be unique.' +\n '\\nThe correct ordering should not be identical to the initial ordering.';\n\n return 'Validation requirements:' + answersMessage;\n};\n"],"file":"utils.js"}
|
package/configure/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"@material-ui/core": "^3.9.2",
|
|
9
9
|
"@material-ui/icons": "^3.0.1",
|
|
10
10
|
"@pie-framework/pie-configure-events": "^1.3.0",
|
|
11
|
-
"@pie-lib/pie-toolbox": "1.8.
|
|
11
|
+
"@pie-lib/pie-toolbox": "1.8.1",
|
|
12
12
|
"debug": "^3.1.0",
|
|
13
13
|
"lodash": "^4.17.15",
|
|
14
14
|
"nested-property": "^0.0.7",
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _default = {
|
|
8
|
+
choiceLabel: '',
|
|
9
|
+
choices: [],
|
|
10
|
+
correctResponse: [],
|
|
11
|
+
enableImages: false,
|
|
12
|
+
prompt: 'Item Stem goes here',
|
|
13
|
+
numberedGuides: false,
|
|
14
|
+
orientation: 'vertical',
|
|
15
|
+
partialScoring: true,
|
|
16
|
+
placementArea: false,
|
|
17
|
+
choiceLabelEnabled: true,
|
|
18
|
+
removeTilesAfterPlacing: true,
|
|
19
|
+
scoringType: 'auto',
|
|
20
|
+
targetLabel: '',
|
|
21
|
+
rationaleEnabled: true,
|
|
22
|
+
feedbackEnabled: false,
|
|
23
|
+
promptEnabled: true,
|
|
24
|
+
teacherInstructionsEnabled: true,
|
|
25
|
+
studentInstructionsEnabled: true
|
|
26
|
+
};
|
|
27
|
+
exports["default"] = _default;
|
|
28
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/defaults.js"],"names":["choiceLabel","choices","correctResponse","enableImages","prompt","numberedGuides","orientation","partialScoring","placementArea","choiceLabelEnabled","removeTilesAfterPlacing","scoringType","targetLabel","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled"],"mappings":";;;;;;eAAe;AACbA,EAAAA,WAAW,EAAE,EADA;AAEbC,EAAAA,OAAO,EAAE,EAFI;AAGbC,EAAAA,eAAe,EAAE,EAHJ;AAIbC,EAAAA,YAAY,EAAE,KAJD;AAKbC,EAAAA,MAAM,EAAE,qBALK;AAMbC,EAAAA,cAAc,EAAE,KANH;AAObC,EAAAA,WAAW,EAAE,UAPA;AAQbC,EAAAA,cAAc,EAAE,IARH;AASbC,EAAAA,aAAa,EAAE,KATF;AAUbC,EAAAA,kBAAkB,EAAE,IAVP;AAWbC,EAAAA,uBAAuB,EAAE,IAXZ;AAYbC,EAAAA,WAAW,EAAE,MAZA;AAabC,EAAAA,WAAW,EAAE,EAbA;AAcbC,EAAAA,gBAAgB,EAAE,IAdL;AAebC,EAAAA,eAAe,EAAE,KAfJ;AAgBbC,EAAAA,aAAa,EAAE,IAhBF;AAiBbC,EAAAA,0BAA0B,EAAE,IAjBf;AAkBbC,EAAAA,0BAA0B,EAAE;AAlBf,C","sourcesContent":["export default {\n choiceLabel: '',\n choices: [],\n correctResponse: [],\n enableImages: false,\n prompt: 'Item Stem goes here',\n numberedGuides: false,\n orientation: 'vertical',\n partialScoring: true,\n placementArea: false,\n choiceLabelEnabled: true,\n removeTilesAfterPlacing: true,\n scoringType: 'auto',\n targetLabel: '',\n rationaleEnabled: true,\n feedbackEnabled: false,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n};\n"],"file":"defaults.js"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createCorrectResponseSession = void 0;
|
|
9
|
+
exports.createDefaultModel = createDefaultModel;
|
|
10
|
+
exports.model = model;
|
|
11
|
+
exports.normalize = void 0;
|
|
12
|
+
exports.outcome = outcome;
|
|
13
|
+
exports.validate = exports.questionError = void 0;
|
|
14
|
+
|
|
15
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
16
|
+
|
|
17
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
18
|
+
|
|
19
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
20
|
+
|
|
21
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
22
|
+
|
|
23
|
+
var _scoring = require("./scoring");
|
|
24
|
+
|
|
25
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
26
|
+
|
|
27
|
+
var _feedback = require("@pie-lib/pie-toolbox/feedback");
|
|
28
|
+
|
|
29
|
+
var _controllerUtils = require("@pie-lib/pie-toolbox/controller-utils");
|
|
30
|
+
|
|
31
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
32
|
+
|
|
33
|
+
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
34
|
+
|
|
35
|
+
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
36
|
+
|
|
37
|
+
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
38
|
+
|
|
39
|
+
var _translator = _interopRequireDefault(require("@pie-lib/pie-toolbox/translator"));
|
|
40
|
+
|
|
41
|
+
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; }
|
|
42
|
+
|
|
43
|
+
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; }
|
|
44
|
+
|
|
45
|
+
var log = (0, _debug["default"])('@pie-element:placement-ordering:controller');
|
|
46
|
+
var translator = _translator["default"].translator;
|
|
47
|
+
|
|
48
|
+
var questionError = function questionError() {
|
|
49
|
+
return new Error('Question is missing required array: correctResponse');
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.questionError = questionError;
|
|
53
|
+
|
|
54
|
+
function outcome(question, session, env) {
|
|
55
|
+
return new Promise(function (resolve, reject) {
|
|
56
|
+
if (!session || _lodash["default"].isEmpty(session)) {
|
|
57
|
+
resolve({
|
|
58
|
+
score: 0,
|
|
59
|
+
empty: true
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!question || !question.correctResponse || _lodash["default"].isEmpty(question.correctResponse)) {
|
|
64
|
+
reject(questionError());
|
|
65
|
+
} else {
|
|
66
|
+
try {
|
|
67
|
+
var s = (0, _scoring.score)(question, session);
|
|
68
|
+
var finalScore = _controllerUtils.partialScoring.enabled(question, env || {}) ? s : s === 1 ? 1 : 0;
|
|
69
|
+
resolve({
|
|
70
|
+
score: finalScore
|
|
71
|
+
});
|
|
72
|
+
} catch (e) {
|
|
73
|
+
reject(e);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function createDefaultModel() {
|
|
80
|
+
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
81
|
+
return new Promise(function (resolve) {
|
|
82
|
+
resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
var normalize = function normalize(question) {
|
|
87
|
+
return _objectSpread(_objectSpread({}, _defaults["default"]), {}, {
|
|
88
|
+
rationaleEnabled: true,
|
|
89
|
+
feedbackEnabled: false,
|
|
90
|
+
promptEnabled: true,
|
|
91
|
+
teacherInstructionsEnabled: true,
|
|
92
|
+
studentInstructionsEnabled: true
|
|
93
|
+
}, question);
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* @param {*} question
|
|
98
|
+
* @param {*} session
|
|
99
|
+
* @param {*} env
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
exports.normalize = normalize;
|
|
104
|
+
|
|
105
|
+
function model(question, session, env) {
|
|
106
|
+
return new Promise( /*#__PURE__*/function () {
|
|
107
|
+
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(resolve) {
|
|
108
|
+
var normalizedQuestion, base, value, allCorrectResponses, bestSetOfResponses, allCorrect, fb;
|
|
109
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
110
|
+
while (1) {
|
|
111
|
+
switch (_context.prev = _context.next) {
|
|
112
|
+
case 0:
|
|
113
|
+
normalizedQuestion = normalize(question);
|
|
114
|
+
base = {};
|
|
115
|
+
|
|
116
|
+
if (question.alternateResponses && _lodash["default"].every(question.alternateResponses, _lodash["default"].isArray)) {
|
|
117
|
+
log('Deprecated structure of alternateResponses is in use'); // eslint-disable-next-line no-console
|
|
118
|
+
|
|
119
|
+
console.error('Deprecated structure of alternateResponses is in use');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
base.env = env;
|
|
123
|
+
base.outcomes = [];
|
|
124
|
+
base.completeLength = (normalizedQuestion.correctResponse || []).length;
|
|
125
|
+
base.choices = (normalizedQuestion.choices || []).filter(function (choice) {
|
|
126
|
+
return choice.label;
|
|
127
|
+
});
|
|
128
|
+
base.note = normalizedQuestion.note;
|
|
129
|
+
base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;
|
|
130
|
+
base.language = normalizedQuestion.language;
|
|
131
|
+
log('[model] removing tileSize for the moment.');
|
|
132
|
+
base.prompt = normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null;
|
|
133
|
+
base.config = {
|
|
134
|
+
orientation: normalizedQuestion.orientation || 'vertical',
|
|
135
|
+
includeTargets: normalizedQuestion.placementArea,
|
|
136
|
+
choiceLabelEnabled: normalizedQuestion.choiceLabelEnabled,
|
|
137
|
+
targetLabel: normalizedQuestion.targetLabel,
|
|
138
|
+
choiceLabel: normalizedQuestion.choiceLabel,
|
|
139
|
+
showOrdering: normalizedQuestion.numberedGuides,
|
|
140
|
+
allowSameChoiceInTargets: !normalizedQuestion.removeTilesAfterPlacing
|
|
141
|
+
};
|
|
142
|
+
base.disabled = env.mode !== 'gather';
|
|
143
|
+
|
|
144
|
+
if (!base.note) {
|
|
145
|
+
base.note = translator.t('common:commonCorrectAnswerWithAlternates', {
|
|
146
|
+
lng: normalizedQuestion.language
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
151
|
+
base.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
|
|
152
|
+
base.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
|
|
153
|
+
} else {
|
|
154
|
+
base.rationale = null;
|
|
155
|
+
base.teacherInstructions = null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (env.mode === 'evaluate') {
|
|
159
|
+
value = session && session.value || [];
|
|
160
|
+
allCorrectResponses = (0, _scoring.getAllCorrectResponses)(normalizedQuestion);
|
|
161
|
+
bestSetOfResponses = allCorrectResponses.reduce(function (info, cr) {
|
|
162
|
+
var currentScore = _lodash["default"].reduce(value, function (acc, c, idx) {
|
|
163
|
+
return acc + (cr[idx] === c ? 1 : 0);
|
|
164
|
+
}, 0);
|
|
165
|
+
|
|
166
|
+
if (currentScore > info.score) {
|
|
167
|
+
return {
|
|
168
|
+
arr: cr,
|
|
169
|
+
score: currentScore
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return info;
|
|
174
|
+
}, {
|
|
175
|
+
arr: [],
|
|
176
|
+
score: 0
|
|
177
|
+
});
|
|
178
|
+
base.outcomes = _lodash["default"].map(value, function (c, idx) {
|
|
179
|
+
return {
|
|
180
|
+
id: c,
|
|
181
|
+
outcome: bestSetOfResponses.arr[idx] === c ? 'correct' : 'incorrect'
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
allCorrect = allCorrectResponses.reduce(function (correct, cr) {
|
|
185
|
+
if (_lodash["default"].isEqual(cr, value)) {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return correct;
|
|
190
|
+
}, false);
|
|
191
|
+
base.correctness = allCorrect ? 'correct' : 'incorrect';
|
|
192
|
+
|
|
193
|
+
if (!allCorrect) {
|
|
194
|
+
base.correctResponse = (0, _scoring.flattenCorrect)(normalizedQuestion);
|
|
195
|
+
} // requirement made in PD-2182
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
if (!normalizedQuestion.feedback) {
|
|
199
|
+
normalizedQuestion.feedbackEnabled = false;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
fb = normalizedQuestion.feedbackEnabled ? (0, _feedback.getFeedbackForCorrectness)(base.correctness, normalizedQuestion.feedback) : Promise.resolve(undefined);
|
|
203
|
+
fb.then(function (feedback) {
|
|
204
|
+
base.feedback = feedback;
|
|
205
|
+
resolve(base);
|
|
206
|
+
});
|
|
207
|
+
} else {
|
|
208
|
+
resolve(base);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
case 17:
|
|
212
|
+
case "end":
|
|
213
|
+
return _context.stop();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}, _callee);
|
|
217
|
+
}));
|
|
218
|
+
|
|
219
|
+
return function (_x) {
|
|
220
|
+
return _ref.apply(this, arguments);
|
|
221
|
+
};
|
|
222
|
+
}());
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
|
|
226
|
+
return new Promise(function (resolve) {
|
|
227
|
+
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
228
|
+
resolve({
|
|
229
|
+
id: '1',
|
|
230
|
+
value: (0, _scoring.flattenCorrect)(question)
|
|
231
|
+
});
|
|
232
|
+
} else {
|
|
233
|
+
resolve(null);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
239
|
+
|
|
240
|
+
var validate = function validate() {
|
|
241
|
+
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
242
|
+
var choices = model.choices,
|
|
243
|
+
correctResponse = model.correctResponse;
|
|
244
|
+
var errors = {};
|
|
245
|
+
var reversedChoices = (0, _toConsumableArray2["default"])(choices || []).reverse();
|
|
246
|
+
var choicesErrors = {};
|
|
247
|
+
reversedChoices.forEach(function (choice, index) {
|
|
248
|
+
var id = choice.id,
|
|
249
|
+
label = choice.label;
|
|
250
|
+
|
|
251
|
+
if (label === '' || label === '<div></div>') {
|
|
252
|
+
choicesErrors[id] = 'Content should not be empty.';
|
|
253
|
+
} else {
|
|
254
|
+
var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
|
|
255
|
+
return c.label === label;
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
if (identicalAnswer) {
|
|
259
|
+
choicesErrors[id] = 'Content should be unique.';
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
var choicesIds = (choices || []).map(function (choice) {
|
|
264
|
+
return choice.id;
|
|
265
|
+
});
|
|
266
|
+
var correctResponseIds = (correctResponse || []).map(function (response) {
|
|
267
|
+
return response.id || response;
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
if ((0, _isEqual["default"])(choicesIds, correctResponseIds)) {
|
|
271
|
+
errors.orderError = 'The correct ordering should not be identical to the initial ordering.';
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (!(0, _isEmpty["default"])(choicesErrors)) {
|
|
275
|
+
errors.choicesErrors = choicesErrors;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return errors;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
exports.validate = validate;
|
|
282
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["log","translator","Translator","questionError","Error","outcome","question","session","env","Promise","resolve","reject","_","isEmpty","score","empty","correctResponse","s","finalScore","partialScoring","enabled","e","createDefaultModel","model","defaults","normalize","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","normalizedQuestion","base","alternateResponses","every","isArray","console","error","outcomes","completeLength","length","choices","filter","choice","label","note","showNote","language","prompt","config","orientation","includeTargets","placementArea","choiceLabelEnabled","targetLabel","choiceLabel","showOrdering","numberedGuides","allowSameChoiceInTargets","removeTilesAfterPlacing","disabled","mode","t","lng","role","rationale","teacherInstructions","value","allCorrectResponses","bestSetOfResponses","reduce","info","cr","currentScore","acc","c","idx","arr","map","id","allCorrect","correct","isEqual","correctness","feedback","fb","undefined","then","createCorrectResponseSession","validate","errors","reversedChoices","reverse","choicesErrors","forEach","index","identicalAnswer","slice","some","choicesIds","correctResponseIds","response","orderError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAGA;;;;;;AADA,IAAMA,GAAG,GAAG,uBAAM,4CAAN,CAAZ;AAGA,IAAQC,UAAR,GAAuBC,sBAAvB,CAAQD,UAAR;;AAEO,IAAME,aAAa,GAAG,SAAhBA,aAAgB;AAAA,SAC3B,IAAIC,KAAJ,CAAU,qDAAV,CAD2B;AAAA,CAAtB;;;;AAGA,SAASC,OAAT,CAAiBC,QAAjB,EAA2BC,OAA3B,EAAoCC,GAApC,EAAyC;AAC9C,SAAO,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV,EAAqB;AACtC,QAAI,CAACJ,OAAD,IAAYK,mBAAEC,OAAF,CAAUN,OAAV,CAAhB,EAAoC;AAClCG,MAAAA,OAAO,CAAC;AAAEI,QAAAA,KAAK,EAAE,CAAT;AAAYC,QAAAA,KAAK,EAAE;AAAnB,OAAD,CAAP;AACD;;AAED,QACE,CAACT,QAAD,IACA,CAACA,QAAQ,CAACU,eADV,IAEAJ,mBAAEC,OAAF,CAAUP,QAAQ,CAACU,eAAnB,CAHF,EAIE;AACAL,MAAAA,MAAM,CAACR,aAAa,EAAd,CAAN;AACD,KAND,MAMO;AACL,UAAI;AACF,YAAMc,CAAC,GAAG,oBAAMX,QAAN,EAAgBC,OAAhB,CAAV;AACA,YAAMW,UAAU,GAAGC,gCAAeC,OAAf,CAAuBd,QAAvB,EAAiCE,G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G,OAAhB,CAAwB,UAACnD,MAAD,EAASoD,KAAT,EAAmB;AACzC,QAAQhB,EAAR,GAAsBpC,MAAtB,CAAQoC,EAAR;AAAA,QAAYnC,KAAZ,GAAsBD,MAAtB,CAAYC,KAAZ;;AAEA,QAAIA,KAAK,KAAK,EAAV,IAAgBA,KAAK,KAAK,aAA9B,EAA6C;AAC3CiD,MAAAA,aAAa,CAACd,EAAD,CAAb,GAAoB,8BAApB;AACD,KAFD,MAEO;AACL,UAAMiB,eAAe,GAAGL,eAAe,CAACM,KAAhB,CAAsBF,KAAK,GAAG,CAA9B,EAAiCG,IAAjC,CAAsC,UAAAvB,CAAC;AAAA,eAAIA,CAAC,CAAC/B,KAAF,KAAYA,KAAhB;AAAA,OAAvC,CAAxB;;AAEA,UAAIoD,eAAJ,EAAqB;AACnBH,QAAAA,aAAa,CAACd,EAAD,CAAb,GAAoB,2BAApB;AACD;AACF;AACF,GAZD;AAcA,MAAMoB,UAAU,GAAG,CAAC1D,OAAO,IAAI,EAAZ,EAAgBqC,GAAhB,CAAoB,UAAAnC,MAAM;AAAA,WAAIA,MAAM,CAACoC,EAAX;AAAA,GAA1B,CAAnB;AACA,MAAMqB,kBAAkB,GAAG,CAACpF,eAAe,IAAI,EAApB,EAAwB8D,GAAxB,CAA4B,UAAAuB,QAAQ;AAAA,WAAIA,QAAQ,CAACtB,EAAT,IAAesB,QAAnB;AAAA,GAApC,CAA3B;;AAEA,MAAI,yBAAQF,UAAR,EAAoBC,kBAApB,CAAJ,EAA6C;AAC3CV,IAAAA,MAAM,CAACY,UAAP,GAAoB,uEAApB;AACD;;AAED,MAAI,CAAC,yBAAQT,aAAR,CAAL,EAA6B;AAC3BH,IAAAA,MAAM,CAACG,aAAP,GAAuBA,aAAvB;AACD;;AAED,SAAOH,MAAP;AACD,CAjCM","sourcesContent":["import { flattenCorrect, getAllCorrectResponses, score } from './scoring';\n\nimport _ from 'lodash';\nimport { getFeedbackForCorrectness } from '@pie-lib/pie-toolbox/feedback';\nimport { partialScoring } from '@pie-lib/pie-toolbox/controller-utils';\nimport debug from 'debug';\n\nimport defaults from './defaults';\nimport isEqual from 'lodash/isEqual';\nimport isEmpty from 'lodash/isEmpty';\n\nconst log = debug('@pie-element:placement-ordering:controller');\nimport Translator from '@pie-lib/pie-toolbox/translator';\n\nconst { translator } = Translator;\n\nexport const questionError = () =>\n new Error('Question is missing required array: correctResponse');\n\nexport function outcome(question, session, env) {\n return new Promise((resolve, reject) => {\n if (!session || _.isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (\n !question ||\n !question.correctResponse ||\n _.isEmpty(question.correctResponse)\n ) {\n reject(questionError());\n } else {\n try {\n const s = score(question, session);\n const finalScore = partialScoring.enabled(question, env || {})\n ? s\n : s === 1\n ? 1\n : 0;\n resolve({\n score: finalScore\n });\n } catch (e) {\n reject(e);\n }\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 ...defaults,\n rationaleEnabled: true,\n feedbackEnabled: false,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport function model(question, session, env) {\n return new Promise(async resolve => {\n const normalizedQuestion = normalize(question);\n const base = {};\n\n if (question.alternateResponses && _.every(question.alternateResponses, _.isArray)) {\n log('Deprecated structure of alternateResponses is in use');\n // eslint-disable-next-line no-console\n console.error('Deprecated structure of alternateResponses is in use');\n }\n\n base.env = env;\n base.outcomes = [];\n base.completeLength = (normalizedQuestion.correctResponse || []).length;\n base.choices = (normalizedQuestion.choices || []).filter(choice => choice.label);\n base.note = normalizedQuestion.note;\n base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;\n base.language = normalizedQuestion.language;\n\n log('[model] removing tileSize for the moment.');\n\n base.prompt = normalizedQuestion.promptEnabled\n ? normalizedQuestion.prompt\n : null;\n base.config = {\n orientation: normalizedQuestion.orientation || 'vertical',\n includeTargets: normalizedQuestion.placementArea,\n choiceLabelEnabled: normalizedQuestion.choiceLabelEnabled,\n targetLabel: normalizedQuestion.targetLabel,\n choiceLabel: normalizedQuestion.choiceLabel,\n showOrdering: normalizedQuestion.numberedGuides,\n allowSameChoiceInTargets: !normalizedQuestion.removeTilesAfterPlacing\n };\n\n base.disabled = env.mode !== 'gather';\n\n if (!base.note) {\n base.note = translator.t('common:commonCorrectAnswerWithAlternates', { lng: normalizedQuestion.language });\n }\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n base.rationale = normalizedQuestion.rationaleEnabled\n ? normalizedQuestion.rationale\n : null;\n base.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n base.rationale = null;\n base.teacherInstructions = null;\n }\n\n if (env.mode === 'evaluate') {\n const value = (session && session.value) || [];\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n\n const bestSetOfResponses = allCorrectResponses.reduce(\n (info, cr) => {\n const currentScore = _.reduce(\n value,\n (acc, c, idx) => acc + (cr[idx] === c ? 1 : 0),\n 0\n );\n\n if (currentScore > info.score) {\n return {\n arr: cr,\n score: currentScore\n };\n }\n\n return info;\n },\n { arr: [], score: 0 }\n );\n\n base.outcomes = _.map(value, function(c, idx) {\n return {\n id: c,\n outcome: bestSetOfResponses.arr[idx] === c ? 'correct' : 'incorrect'\n };\n });\n\n const allCorrect = allCorrectResponses.reduce((correct, cr) => {\n if (_.isEqual(cr, value)) {\n return true;\n }\n\n return correct;\n }, false);\n\n base.correctness = allCorrect ? 'correct' : 'incorrect';\n\n if (!allCorrect) {\n base.correctResponse = flattenCorrect(normalizedQuestion);\n }\n\n // requirement made in PD-2182\n if (!normalizedQuestion.feedback) {\n normalizedQuestion.feedbackEnabled = false;\n }\n\n const fb = normalizedQuestion.feedbackEnabled\n ? getFeedbackForCorrectness(base.correctness, normalizedQuestion.feedback)\n : Promise.resolve(undefined);\n\n fb.then((feedback) => {\n base.feedback = feedback;\n resolve(base);\n });\n } else {\n resolve(base);\n }\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n resolve({\n id: '1',\n value: flattenCorrect(question)\n });\n } else {\n resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}) => {\n const { choices, correctResponse } = model;\n const errors = {};\n\n const reversedChoices = [...choices || []].reverse();\n const choicesErrors = {};\n\n reversedChoices.forEach((choice, index) => {\n const { id, label } = choice;\n\n if (label === '' || label === '<div></div>') {\n choicesErrors[id] = 'Content should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some(c => c.label === label);\n\n if (identicalAnswer) {\n choicesErrors[id] = 'Content should be unique.';\n }\n }\n });\n\n const choicesIds = (choices || []).map(choice => choice.id);\n const correctResponseIds = (correctResponse || []).map(response => response.id || response);\n\n if (isEqual(choicesIds, correctResponseIds)) {\n errors.orderError = 'The correct ordering should not be identical to the initial ordering.';\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choicesErrors = choicesErrors;\n }\n\n return errors;\n};\n"],"file":"index.js"}
|