@pie-element/multiple-choice 11.0.1-next.27 → 11.0.1-next.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/configure/package.json +3 -3
- package/controller/package.json +1 -1
- package/module/controller.js +80 -77
- package/module/element.js +1 -1
- package/module/manifest.json +0 -4
- package/module/print.js +1 -1
- package/package.json +6 -6
package/configure/package.json
CHANGED
|
@@ -8,9 +8,9 @@
|
|
|
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/config-ui": "^11.25.
|
|
12
|
-
"@pie-lib/editable-html": "^11.17.
|
|
13
|
-
"@pie-lib/render-ui": "^4.31.
|
|
11
|
+
"@pie-lib/config-ui": "^11.25.1",
|
|
12
|
+
"@pie-lib/editable-html": "^11.17.1",
|
|
13
|
+
"@pie-lib/render-ui": "^4.31.1",
|
|
14
14
|
"debug": "^3.1.0",
|
|
15
15
|
"lodash": "^4.17.15",
|
|
16
16
|
"prop-types": "^15.6.2",
|
package/controller/package.json
CHANGED
package/module/controller.js
CHANGED
|
@@ -2541,26 +2541,6 @@ var defaults = {
|
|
|
2541
2541
|
keyboardEventsEnabled: false,
|
|
2542
2542
|
};
|
|
2543
2543
|
|
|
2544
|
-
const enabled = (config, env, defaultValue) => {
|
|
2545
|
-
// if model.partialScoring = false
|
|
2546
|
-
// - if env.partialScoring = false || env.partialScoring = true => use dichotomous scoring
|
|
2547
|
-
// else if model.partialScoring = true || undefined
|
|
2548
|
-
// - if env.partialScoring = false, use dichotomous scoring
|
|
2549
|
-
// - else if env.partialScoring = true, use partial scoring
|
|
2550
|
-
config = config || {};
|
|
2551
|
-
env = env || {};
|
|
2552
|
-
|
|
2553
|
-
if (config.partialScoring === false) {
|
|
2554
|
-
return false;
|
|
2555
|
-
}
|
|
2556
|
-
|
|
2557
|
-
if (env.partialScoring === false) {
|
|
2558
|
-
return false;
|
|
2559
|
-
}
|
|
2560
|
-
|
|
2561
|
-
return typeof defaultValue === 'boolean' ? defaultValue : true;
|
|
2562
|
-
};
|
|
2563
|
-
|
|
2564
2544
|
var baseGetTag = _baseGetTag,
|
|
2565
2545
|
isObjectLike = isObjectLike_1;
|
|
2566
2546
|
|
|
@@ -3127,67 +3107,90 @@ function shuffle(collection) {
|
|
|
3127
3107
|
|
|
3128
3108
|
var shuffle_1 = shuffle;
|
|
3129
3109
|
|
|
3130
|
-
|
|
3131
|
-
|
|
3110
|
+
const enabled = (config, env, defaultValue) => {
|
|
3111
|
+
// if model.partialScoring = false
|
|
3112
|
+
// - if env.partialScoring = false || env.partialScoring = true => use dichotomous scoring
|
|
3113
|
+
// else if model.partialScoring = true || undefined
|
|
3114
|
+
// - if env.partialScoring = false, use dichotomous scoring
|
|
3115
|
+
// - else if env.partialScoring = true, use partial scoring
|
|
3116
|
+
config = config || {};
|
|
3117
|
+
env = env || {};
|
|
3118
|
+
|
|
3119
|
+
if (config.partialScoring === false) {
|
|
3120
|
+
return false;
|
|
3121
|
+
}
|
|
3122
|
+
|
|
3123
|
+
if (env.partialScoring === false) {
|
|
3124
|
+
return false;
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
return typeof defaultValue === 'boolean' ? defaultValue : true;
|
|
3128
|
+
};
|
|
3129
|
+
|
|
3130
|
+
var partialScoring = /*#__PURE__*/Object.freeze({
|
|
3131
|
+
__proto__: null,
|
|
3132
|
+
enabled: enabled
|
|
3133
|
+
});
|
|
3134
|
+
|
|
3135
|
+
const lg = n => console[n].bind(console, 'controller-utils:');
|
|
3136
|
+
|
|
3132
3137
|
const debug = lg('debug');
|
|
3133
3138
|
const log = lg('log');
|
|
3134
3139
|
const warn = lg('warn');
|
|
3135
3140
|
const error = lg('error');
|
|
3136
|
-
|
|
3137
|
-
const compact = (arr) => {
|
|
3141
|
+
const compact = arr => {
|
|
3138
3142
|
if (Array.isArray(arr)) {
|
|
3139
|
-
return arr.filter(
|
|
3143
|
+
return arr.filter(v => v !== null && v !== undefined);
|
|
3140
3144
|
}
|
|
3145
|
+
|
|
3141
3146
|
return arr;
|
|
3142
3147
|
};
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
console.error('update session failed for: ', session.id, e),
|
|
3177
|
-
);
|
|
3178
|
-
}
|
|
3179
|
-
} catch (e) {
|
|
3180
|
-
warn('unable to save shuffled order for choices');
|
|
3181
|
-
error(e);
|
|
3148
|
+
const getShuffledChoices = (choices, session, updateSession, choiceKey) => new Promise(resolve => {
|
|
3149
|
+
var _session$data;
|
|
3150
|
+
|
|
3151
|
+
log('updateSession type: ', typeof updateSession);
|
|
3152
|
+
log('session: ', session);
|
|
3153
|
+
const currentShuffled = compact((session == null ? void 0 : (_session$data = session.data) == null ? void 0 : _session$data.shuffledValues) || (session == null ? void 0 : session.shuffledValues) || []);
|
|
3154
|
+
|
|
3155
|
+
if (!session) {
|
|
3156
|
+
// eslint-disable-next-line quotes
|
|
3157
|
+
warn("unable to save shuffled choices because there's no session.");
|
|
3158
|
+
resolve(undefined);
|
|
3159
|
+
} else if (!isEmpty_1(currentShuffled)) {
|
|
3160
|
+
var _session$data2;
|
|
3161
|
+
|
|
3162
|
+
debug('use shuffledValues to sort the choices...', (_session$data2 = session.data) == null ? void 0 : _session$data2.shuffledValues);
|
|
3163
|
+
resolve(compact(currentShuffled.map(v => choices.find(c => c[choiceKey] === v))));
|
|
3164
|
+
} else {
|
|
3165
|
+
const shuffledChoices = shuffle_1(choices);
|
|
3166
|
+
|
|
3167
|
+
if (updateSession && typeof updateSession === 'function') {
|
|
3168
|
+
try {
|
|
3169
|
+
//Note: session.id refers to the id of the element within a session
|
|
3170
|
+
const shuffledValues = compact(shuffledChoices.map(c => c[choiceKey]));
|
|
3171
|
+
log('try to save shuffledValues to session...', shuffledValues);
|
|
3172
|
+
log('call updateSession... ', session.id, session.element);
|
|
3173
|
+
|
|
3174
|
+
if (isEmpty_1(shuffledValues)) {
|
|
3175
|
+
error(`shuffledValues is an empty array? - refusing to call updateSession: shuffledChoices: ${JSON.stringify(shuffledChoices)}, key: ${choiceKey}`);
|
|
3176
|
+
} else {
|
|
3177
|
+
updateSession(session.id, session.element, {
|
|
3178
|
+
shuffledValues
|
|
3179
|
+
}).catch(e => // eslint-disable-next-line no-console
|
|
3180
|
+
console.error('update session failed for: ', session.id, e));
|
|
3182
3181
|
}
|
|
3183
|
-
}
|
|
3184
|
-
warn('unable to save shuffled
|
|
3182
|
+
} catch (e) {
|
|
3183
|
+
warn('unable to save shuffled order for choices');
|
|
3184
|
+
error(e);
|
|
3185
3185
|
}
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
}
|
|
3189
|
-
});
|
|
3186
|
+
} else {
|
|
3187
|
+
warn('unable to save shuffled choices, shuffle will happen every time.');
|
|
3188
|
+
} //save this shuffle to the session for later retrieval
|
|
3190
3189
|
|
|
3190
|
+
|
|
3191
|
+
resolve(shuffledChoices);
|
|
3192
|
+
}
|
|
3193
|
+
});
|
|
3191
3194
|
/**
|
|
3192
3195
|
* If we return:
|
|
3193
3196
|
* - true - that means that the order of the choices will be ordinal (as is created in the configure item)
|
|
@@ -3198,6 +3201,7 @@ const getShuffledChoices = (choices, session, updateSession, choiceKey) =>
|
|
|
3198
3201
|
* @param env - env to check if we should lock order
|
|
3199
3202
|
* @returns {boolean}
|
|
3200
3203
|
*/
|
|
3204
|
+
|
|
3201
3205
|
const lockChoices = (model, session, env) => {
|
|
3202
3206
|
if (model.lockChoiceOrder) {
|
|
3203
3207
|
return true;
|
|
@@ -3213,17 +3217,16 @@ const lockChoices = (model, session, env) => {
|
|
|
3213
3217
|
|
|
3214
3218
|
if (role === 'instructor') {
|
|
3215
3219
|
// TODO: .. in the future the instructor can toggle between ordinal and shuffled here, so keeping this code until then
|
|
3216
|
-
/*const alreadyShuffled = hasShuffledValues(session);
|
|
3217
3220
|
|
|
3218
|
-
|
|
3221
|
+
/*const alreadyShuffled = hasShuffledValues(session);
|
|
3222
|
+
if (alreadyShuffled) {
|
|
3219
3223
|
return false;
|
|
3220
3224
|
}
|
|
3221
|
-
|
|
3222
|
-
return true;*/
|
|
3225
|
+
return true;*/
|
|
3223
3226
|
return true;
|
|
3224
|
-
}
|
|
3227
|
+
} // here it's a student, so don't lock and it will shuffle if needs be
|
|
3228
|
+
|
|
3225
3229
|
|
|
3226
|
-
// here it's a student, so don't lock and it will shuffle if needs be
|
|
3227
3230
|
return false;
|
|
3228
3231
|
};
|
|
3229
3232
|
|
|
@@ -3379,7 +3382,7 @@ function outcome(model, session, env) {
|
|
|
3379
3382
|
if (!session || isEmpty_1(session)) {
|
|
3380
3383
|
resolve({ score: 0, empty: true });
|
|
3381
3384
|
} else {
|
|
3382
|
-
const partialScoringEnabled = enabled(model, env) && model.choiceMode !== 'radio';
|
|
3385
|
+
const partialScoringEnabled = partialScoring.enabled(model, env) && model.choiceMode !== 'radio';
|
|
3383
3386
|
const score = getScore(model, session);
|
|
3384
3387
|
|
|
3385
3388
|
resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0, empty: false });
|