@pie-lib/controller-utils 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- # [0.5.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.5.0) (2025-07-31)
6
+ # [0.7.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.7.0) (2025-07-31)
7
7
 
8
8
  **Note:** Version bump only for package @pie-lib/controller-utils
9
9
 
@@ -11,7 +11,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
11
11
 
12
12
 
13
13
 
14
- # [0.4.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.4.0) (2025-07-31)
14
+ # [0.6.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.6.0) (2025-07-31)
15
15
 
16
16
  **Note:** Version bump only for package @pie-lib/controller-utils
17
17
 
@@ -19,7 +19,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
19
19
 
20
20
 
21
21
 
22
- # [0.3.0-beta.8](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.8) (2025-07-25)
22
+ # [0.5.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.5.0) (2025-07-31)
23
23
 
24
24
  **Note:** Version bump only for package @pie-lib/controller-utils
25
25
 
@@ -27,7 +27,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
27
27
 
28
28
 
29
29
 
30
- # [0.3.0-beta.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.7) (2025-07-25)
30
+ # [0.6.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.6.0) (2025-07-31)
31
31
 
32
32
  **Note:** Version bump only for package @pie-lib/controller-utils
33
33
 
@@ -35,7 +35,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
35
35
 
36
36
 
37
37
 
38
- # [0.3.0-beta.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.7) (2025-07-25)
38
+ # [0.5.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.5.0) (2025-07-31)
39
39
 
40
40
  **Note:** Version bump only for package @pie-lib/controller-utils
41
41
 
@@ -43,7 +43,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
43
43
 
44
44
 
45
45
 
46
- # [0.3.0-beta.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.6) (2025-07-25)
46
+ # [0.4.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.4.0) (2025-07-31)
47
47
 
48
48
  **Note:** Version bump only for package @pie-lib/controller-utils
49
49
 
@@ -51,118 +51,90 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
51
51
 
52
52
 
53
53
 
54
- # [0.3.0-beta.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.6) (2025-07-25)
54
+ # [0.4.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.4.0) (2025-07-31)
55
55
 
56
56
  **Note:** Version bump only for package @pie-lib/controller-utils
57
57
 
58
+ # [0.5.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.5.0) (2025-07-31)
58
59
 
60
+ **Note:** Version bump only for package @pie-lib/controller-utils
59
61
 
60
-
61
-
62
- # [0.3.0-beta.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.5) (2025-07-25)
62
+ # [0.4.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.4.0) (2025-07-31)
63
63
 
64
64
  **Note:** Version bump only for package @pie-lib/controller-utils
65
65
 
66
+ # [0.3.0-beta.8](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.8) (2025-07-25)
66
67
 
68
+ **Note:** Version bump only for package @pie-lib/controller-utils
67
69
 
70
+ # [0.3.0-beta.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.7) (2025-07-25)
68
71
 
72
+ **Note:** Version bump only for package @pie-lib/controller-utils
69
73
 
70
- # [0.3.0-beta.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.5) (2025-07-25)
74
+ # [0.3.0-beta.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.7) (2025-07-25)
71
75
 
72
76
  **Note:** Version bump only for package @pie-lib/controller-utils
73
77
 
78
+ # [0.3.0-beta.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.6) (2025-07-25)
74
79
 
80
+ **Note:** Version bump only for package @pie-lib/controller-utils
75
81
 
82
+ # [0.3.0-beta.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.6) (2025-07-25)
76
83
 
84
+ **Note:** Version bump only for package @pie-lib/controller-utils
77
85
 
78
- # [0.3.0-beta.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.4) (2025-07-25)
86
+ # [0.3.0-beta.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.5) (2025-07-25)
79
87
 
80
88
  **Note:** Version bump only for package @pie-lib/controller-utils
81
89
 
90
+ # [0.3.0-beta.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.5) (2025-07-25)
82
91
 
92
+ **Note:** Version bump only for package @pie-lib/controller-utils
83
93
 
94
+ # [0.3.0-beta.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.4) (2025-07-25)
84
95
 
96
+ **Note:** Version bump only for package @pie-lib/controller-utils
85
97
 
86
98
  # [0.3.0-beta.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.3) (2025-07-25)
87
99
 
88
100
  **Note:** Version bump only for package @pie-lib/controller-utils
89
101
 
90
-
91
-
92
-
93
-
94
102
  # [0.3.0-beta.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.4) (2025-07-23)
95
103
 
96
104
  **Note:** Version bump only for package @pie-lib/controller-utils
97
105
 
98
-
99
-
100
-
101
-
102
106
  # [0.3.0-beta.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.3) (2025-07-23)
103
107
 
104
108
  **Note:** Version bump only for package @pie-lib/controller-utils
105
109
 
106
-
107
-
108
-
109
-
110
110
  # [0.3.0-beta.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.3) (2025-07-20)
111
111
 
112
112
  **Note:** Version bump only for package @pie-lib/controller-utils
113
113
 
114
-
115
-
116
-
117
-
118
114
  # [0.3.0-beta.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.2) (2025-07-20)
119
115
 
120
116
  **Note:** Version bump only for package @pie-lib/controller-utils
121
117
 
122
-
123
-
124
-
125
-
126
118
  # [0.3.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.1) (2025-07-20)
127
119
 
128
120
  **Note:** Version bump only for package @pie-lib/controller-utils
129
121
 
130
-
131
-
132
-
133
-
134
122
  # [0.3.0-beta.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.2) (2025-07-20)
135
123
 
136
124
  **Note:** Version bump only for package @pie-lib/controller-utils
137
125
 
138
-
139
-
140
-
141
-
142
126
  # [0.3.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.1) (2025-07-20)
143
127
 
144
128
  **Note:** Version bump only for package @pie-lib/controller-utils
145
129
 
146
-
147
-
148
-
149
-
150
130
  # [0.3.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.1) (2025-07-20)
151
131
 
152
132
  **Note:** Version bump only for package @pie-lib/controller-utils
153
133
 
154
-
155
-
156
-
157
-
158
134
  # [0.3.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.3.0-beta.0) (2025-07-20)
159
135
 
160
136
  **Note:** Version bump only for package @pie-lib/controller-utils
161
137
 
162
-
163
-
164
-
165
-
166
138
  # [0.4.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.44...@pie-lib/controller-utils@0.4.0-beta.0) (2025-07-15)
167
139
 
168
140
  **Note:** Version bump only for package @pie-lib/controller-utils
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/controller-utils",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
@@ -14,5 +14,5 @@
14
14
  "scripts": {},
15
15
  "author": "",
16
16
  "license": "ISC",
17
- "gitHead": "ecb1ca31aa1c24d23af00d5ad04ce73ed8871057"
17
+ "gitHead": "889a13bfea2c768b8a3a6eabfc6fe7b7725aa832"
18
18
  }
package/lib/index.js DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- var _typeof = require("@babel/runtime/helpers/typeof");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- Object.defineProperty(exports, "getShuffledChoices", {
9
- enumerable: true,
10
- get: function get() {
11
- return _persistence.getShuffledChoices;
12
- }
13
- });
14
- Object.defineProperty(exports, "lockChoices", {
15
- enumerable: true,
16
- get: function get() {
17
- return _persistence.lockChoices;
18
- }
19
- });
20
- exports.partialScoring = void 0;
21
-
22
- var partialScoring = _interopRequireWildcard(require("./partial-scoring"));
23
-
24
- exports.partialScoring = partialScoring;
25
-
26
- var _persistence = require("./persistence");
27
-
28
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
-
30
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
31
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;AAEA","sourcesContent":["import * as partialScoring from './partial-scoring';\n\nexport { lockChoices, getShuffledChoices } from './persistence';\nexport { partialScoring };\n"],"file":"index.js"}
@@ -1,29 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.enabled = void 0;
7
-
8
- var enabled = function enabled(config, env, defaultValue) {
9
- // if model.partialScoring = false
10
- // - if env.partialScoring = false || env.partialScoring = true => use dichotomous scoring
11
- // else if model.partialScoring = true || undefined
12
- // - if env.partialScoring = false, use dichotomous scoring
13
- // - else if env.partialScoring = true, use partial scoring
14
- config = config || {};
15
- env = env || {};
16
-
17
- if (config.partialScoring === false) {
18
- return false;
19
- }
20
-
21
- if (env.partialScoring === false) {
22
- return false;
23
- }
24
-
25
- return typeof defaultValue === 'boolean' ? defaultValue : true;
26
- };
27
-
28
- exports.enabled = enabled;
29
- //# sourceMappingURL=partial-scoring.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/partial-scoring.js"],"names":["enabled","config","env","defaultValue","partialScoring"],"mappings":";;;;;;;AAAO,IAAMA,OAAO,GAAG,SAAVA,OAAU,CAACC,MAAD,EAASC,GAAT,EAAcC,YAAd,EAA+B;AACpD;AACA;AACA;AACA;AACA;AACAF,EAAAA,MAAM,GAAGA,MAAM,IAAI,EAAnB;AACAC,EAAAA,GAAG,GAAGA,GAAG,IAAI,EAAb;;AAEA,MAAID,MAAM,CAACG,cAAP,KAA0B,KAA9B,EAAqC;AACnC,WAAO,KAAP;AACD;;AAED,MAAIF,GAAG,CAACE,cAAJ,KAAuB,KAA3B,EAAkC;AAChC,WAAO,KAAP;AACD;;AAED,SAAO,OAAOD,YAAP,KAAwB,SAAxB,GAAoCA,YAApC,GAAmD,IAA1D;AACD,CAlBM","sourcesContent":["export const enabled = (config, env, defaultValue) => {\n // if model.partialScoring = false\n // - if env.partialScoring = false || env.partialScoring = true => use dichotomous scoring\n // else if model.partialScoring = true || undefined\n // - if env.partialScoring = false, use dichotomous scoring\n // - else if env.partialScoring = true, use partial scoring\n config = config || {};\n env = env || {};\n\n if (config.partialScoring === false) {\n return false;\n }\n\n if (env.partialScoring === false) {\n return false;\n }\n\n return typeof defaultValue === 'boolean' ? defaultValue : true;\n};\n"],"file":"partial-scoring.js"}
@@ -1,140 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.lockChoices = exports.getShuffledChoices = exports.compact = void 0;
9
-
10
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
-
12
- var _get = _interopRequireDefault(require("lodash/get"));
13
-
14
- var _shuffle = _interopRequireDefault(require("lodash/shuffle"));
15
-
16
- var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
17
-
18
- // eslint-disable-next-line no-console
19
- var lg = function lg(n) {
20
- return console[n].bind(console, 'controller-utils:');
21
- };
22
-
23
- var debug = lg('debug');
24
- var log = lg('log');
25
- var warn = lg('warn');
26
- var error = lg('error');
27
-
28
- var compact = function compact(arr) {
29
- if (Array.isArray(arr)) {
30
- return arr.filter(function (v) {
31
- return v !== null && v !== undefined;
32
- });
33
- }
34
-
35
- return arr;
36
- };
37
-
38
- exports.compact = compact;
39
-
40
- var getShuffledChoices = function getShuffledChoices(choices, session, updateSession, choiceKey) {
41
- return new Promise(function (resolve) {
42
- var _session$data;
43
-
44
- log('updateSession type: ', (0, _typeof2["default"])(updateSession));
45
- log('session: ', session);
46
- var currentShuffled = compact((session === null || session === void 0 ? void 0 : (_session$data = session.data) === null || _session$data === void 0 ? void 0 : _session$data.shuffledValues) || (session === null || session === void 0 ? void 0 : session.shuffledValues) || []);
47
-
48
- if (!session) {
49
- // eslint-disable-next-line quotes
50
- warn("unable to save shuffled choices because there's no session.");
51
- resolve(undefined);
52
- } else if (!(0, _isEmpty["default"])(currentShuffled)) {
53
- var _session$data2;
54
-
55
- debug('use shuffledValues to sort the choices...', (_session$data2 = session.data) === null || _session$data2 === void 0 ? void 0 : _session$data2.shuffledValues);
56
- resolve(compact(currentShuffled.map(function (v) {
57
- return choices.find(function (c) {
58
- return c[choiceKey] === v;
59
- });
60
- })));
61
- } else {
62
- var shuffledChoices = (0, _shuffle["default"])(choices);
63
-
64
- if (updateSession && typeof updateSession === 'function') {
65
- try {
66
- //Note: session.id refers to the id of the element within a session
67
- var shuffledValues = compact(shuffledChoices.map(function (c) {
68
- return c[choiceKey];
69
- }));
70
- log('try to save shuffledValues to session...', shuffledValues);
71
- log('call updateSession... ', session.id, session.element);
72
-
73
- if ((0, _isEmpty["default"])(shuffledValues)) {
74
- error("shuffledValues is an empty array? - refusing to call updateSession: shuffledChoices: ".concat(JSON.stringify(shuffledChoices), ", key: ").concat(choiceKey));
75
- } else {
76
- updateSession(session.id, session.element, {
77
- shuffledValues: shuffledValues
78
- })["catch"](function (e) {
79
- return (// eslint-disable-next-line no-console
80
- console.error('update session failed for: ', session.id, e)
81
- );
82
- });
83
- }
84
- } catch (e) {
85
- warn('unable to save shuffled order for choices');
86
- error(e);
87
- }
88
- } else {
89
- warn('unable to save shuffled choices, shuffle will happen every time.');
90
- } //save this shuffle to the session for later retrieval
91
-
92
-
93
- resolve(shuffledChoices);
94
- }
95
- });
96
- };
97
- /**
98
- * If we return:
99
- * - true - that means that the order of the choices will be ordinal (as is created in the configure item)
100
- * - false - that means the getShuffledChoices above will be called and that in turn means that we either
101
- * return the shuffled values on the session (if any exists) or we shuffle the choices
102
- * @param model - model to check if we should lock order
103
- * @param session - session to check if we should lock order
104
- * @param env - env to check if we should lock order
105
- * @returns {boolean}
106
- */
107
-
108
-
109
- exports.getShuffledChoices = getShuffledChoices;
110
-
111
- var lockChoices = function lockChoices(model, session, env) {
112
- if (model.lockChoiceOrder) {
113
- return true;
114
- }
115
-
116
- log('lockChoiceOrder: ', (0, _get["default"])(env, ['@pie-element', 'lockChoiceOrder'], false));
117
-
118
- if ((0, _get["default"])(env, ['@pie-element', 'lockChoiceOrder'], false)) {
119
- return true;
120
- }
121
-
122
- var role = (0, _get["default"])(env, 'role', 'student');
123
-
124
- if (role === 'instructor') {
125
- // TODO: .. in the future the instructor can toggle between ordinal and shuffled here, so keeping this code until then
126
-
127
- /*const alreadyShuffled = hasShuffledValues(session);
128
- if (alreadyShuffled) {
129
- return false;
130
- }
131
- return true;*/
132
- return true;
133
- } // here it's a student, so don't lock and it will shuffle if needs be
134
-
135
-
136
- return false;
137
- };
138
-
139
- exports.lockChoices = lockChoices;
140
- //# sourceMappingURL=persistence.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/persistence.js"],"names":["lg","n","console","bind","debug","log","warn","error","compact","arr","Array","isArray","filter","v","undefined","getShuffledChoices","choices","session","updateSession","choiceKey","Promise","resolve","currentShuffled","data","shuffledValues","map","find","c","shuffledChoices","id","element","JSON","stringify","e","lockChoices","model","env","lockChoiceOrder","role"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;AACA,IAAMA,EAAE,GAAG,SAALA,EAAK,CAACC,CAAD;AAAA,SAAOC,OAAO,CAACD,CAAD,CAAP,CAAWE,IAAX,CAAgBD,OAAhB,EAAyB,mBAAzB,CAAP;AAAA,CAAX;;AACA,IAAME,KAAK,GAAGJ,EAAE,CAAC,OAAD,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L;;;AACAe,MAAAA,OAAO,CAACO,eAAD,CAAP;AACD;AACF,GA5CD,CADgC;AAAA,CAA3B;AA+CP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,IAAMM,WAAW,GAAG,SAAdA,WAAc,CAACC,KAAD,EAAQlB,OAAR,EAAiBmB,GAAjB,EAAyB;AAClD,MAAID,KAAK,CAACE,eAAV,EAA2B;AACzB,WAAO,IAAP;AACD;;AAEDhC,EAAAA,GAAG,CAAC,mBAAD,EAAsB,qBAAI+B,GAAJ,EAAS,CAAC,cAAD,EAAiB,iBAAjB,CAAT,EAA8C,KAA9C,CAAtB,CAAH;;AAEA,MAAI,qBAAIA,GAAJ,EAAS,CAAC,cAAD,EAAiB,iBAAjB,CAAT,EAA8C,KAA9C,CAAJ,EAA0D;AACxD,WAAO,IAAP;AACD;;AAED,MAAME,IAAI,GAAG,qBAAIF,GAAJ,EAAS,MAAT,EAAiB,SAAjB,CAAb;;AAEA,MAAIE,IAAI,KAAK,YAAb,EAA2B;AACzB;;AACA;AACJ;AACA;AACA;AACA;AAGI,WAAO,IAAP;AACD,GAvBiD,CAyBlD;;;AACA,SAAO,KAAP;AACD,CA3BM","sourcesContent":["import get from 'lodash/get';\nimport shuffle from 'lodash/shuffle';\nimport isEmpty from 'lodash/isEmpty';\n\n// eslint-disable-next-line no-console\nconst lg = (n) => console[n].bind(console, 'controller-utils:');\nconst debug = lg('debug');\nconst log = lg('log');\nconst warn = lg('warn');\nconst error = lg('error');\n\nexport const compact = (arr) => {\n if (Array.isArray(arr)) {\n return arr.filter((v) => v !== null && v !== undefined);\n }\n return arr;\n};\n\nexport const getShuffledChoices = (choices, session, updateSession, choiceKey) =>\n new Promise((resolve) => {\n log('updateSession type: ', typeof updateSession);\n log('session: ', session);\n\n const currentShuffled = compact(session?.data?.shuffledValues || session?.shuffledValues || []);\n\n if (!session) {\n // eslint-disable-next-line quotes\n warn(\"unable to save shuffled choices because there's no session.\");\n resolve(undefined);\n } else if (!isEmpty(currentShuffled)) {\n debug('use shuffledValues to sort the choices...', session.data?.shuffledValues);\n resolve(compact(currentShuffled.map((v) => choices.find((c) => c[choiceKey] === v))));\n } else {\n const shuffledChoices = shuffle(choices);\n\n if (updateSession && typeof updateSession === 'function') {\n try {\n //Note: session.id refers to the id of the element within a session\n const shuffledValues = compact(shuffledChoices.map((c) => c[choiceKey]));\n log('try to save shuffledValues to session...', shuffledValues);\n log('call updateSession... ', session.id, session.element);\n if (isEmpty(shuffledValues)) {\n error(\n `shuffledValues is an empty array? - refusing to call updateSession: shuffledChoices: ${JSON.stringify(\n shuffledChoices,\n )}, key: ${choiceKey}`,\n );\n } else {\n updateSession(session.id, session.element, { shuffledValues }).catch((e) =>\n // eslint-disable-next-line no-console\n console.error('update session failed for: ', session.id, e),\n );\n }\n } catch (e) {\n warn('unable to save shuffled order for choices');\n error(e);\n }\n } else {\n warn('unable to save shuffled choices, shuffle will happen every time.');\n }\n //save this shuffle to the session for later retrieval\n resolve(shuffledChoices);\n }\n });\n\n/**\n * If we return:\n * - true - that means that the order of the choices will be ordinal (as is created in the configure item)\n * - false - that means the getShuffledChoices above will be called and that in turn means that we either\n * return the shuffled values on the session (if any exists) or we shuffle the choices\n * @param model - model to check if we should lock order\n * @param session - session to check if we should lock order\n * @param env - env to check if we should lock order\n * @returns {boolean}\n */\nexport const lockChoices = (model, session, env) => {\n if (model.lockChoiceOrder) {\n return true;\n }\n\n log('lockChoiceOrder: ', get(env, ['@pie-element', 'lockChoiceOrder'], false));\n\n if (get(env, ['@pie-element', 'lockChoiceOrder'], false)) {\n return true;\n }\n\n const role = get(env, 'role', 'student');\n\n if (role === 'instructor') {\n // TODO: .. in the future the instructor can toggle between ordinal and shuffled here, so keeping this code until then\n /*const alreadyShuffled = hasShuffledValues(session);\n\n if (alreadyShuffled) {\n return false;\n }\n\n return true;*/\n return true;\n }\n\n // here it's a student, so don't lock and it will shuffle if needs be\n return false;\n};\n"],"file":"persistence.js"}