@pie-lib/controller-utils 0.2.44 → 0.3.0-beta.2

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.2.44](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.43...@pie-lib/controller-utils@0.2.44) (2023-06-24)
6
+ # [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)
7
7
 
8
8
  **Note:** Version bump only for package @pie-lib/controller-utils
9
9
 
@@ -11,18 +11,15 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
11
11
 
12
12
 
13
13
 
14
- ## [0.2.43](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.42...@pie-lib/controller-utils@0.2.43) (2023-04-19)
15
-
16
-
17
- ### Bug Fixes
14
+ # [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)
18
15
 
19
- * **eslint:** fix eslint problems-PD-2732 ([9eb9976](https://github.com/pie-framework/pie-lib/commit/9eb9976749753da86e1057a07bd2cfc65bf64ae4))
16
+ **Note:** Version bump only for package @pie-lib/controller-utils
20
17
 
21
18
 
22
19
 
23
20
 
24
21
 
25
- ## [0.2.42](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.40...@pie-lib/controller-utils@0.2.42) (2023-01-31)
22
+ # [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)
26
23
 
27
24
  **Note:** Version bump only for package @pie-lib/controller-utils
28
25
 
@@ -30,7 +27,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
30
27
 
31
28
 
32
29
 
33
- ## [0.2.40](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.39...@pie-lib/controller-utils@0.2.40) (2023-01-31)
30
+ # [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)
34
31
 
35
32
  **Note:** Version bump only for package @pie-lib/controller-utils
36
33
 
@@ -38,54 +35,56 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
38
35
 
39
36
 
40
37
 
41
- ## [0.2.39](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.38...@pie-lib/controller-utils@0.2.39) (2023-01-31)
38
+ # [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)
42
39
 
43
40
  **Note:** Version bump only for package @pie-lib/controller-utils
44
41
 
42
+ # [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-15)
45
43
 
44
+ **Note:** Version bump only for package @pie-lib/controller-utils
46
45
 
47
-
48
-
49
- ## [0.2.38](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.37...@pie-lib/controller-utils@0.2.38) (2023-01-31)
46
+ ## [0.2.44](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.43...@pie-lib/controller-utils@0.2.44) (2023-06-24)
50
47
 
51
48
  **Note:** Version bump only for package @pie-lib/controller-utils
52
49
 
50
+ ## [0.2.43](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.42...@pie-lib/controller-utils@0.2.43) (2023-04-19)
53
51
 
52
+ ### Bug Fixes
54
53
 
54
+ - **eslint:** fix eslint problems-PD-2732 ([9eb9976](https://github.com/pie-framework/pie-lib/commit/9eb9976749753da86e1057a07bd2cfc65bf64ae4))
55
55
 
56
-
57
- ## [0.2.37](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.31...@pie-lib/controller-utils@0.2.37) (2023-01-31)
56
+ ## [0.2.42](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.40...@pie-lib/controller-utils@0.2.42) (2023-01-31)
58
57
 
59
58
  **Note:** Version bump only for package @pie-lib/controller-utils
60
59
 
60
+ ## [0.2.40](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.39...@pie-lib/controller-utils@0.2.40) (2023-01-31)
61
61
 
62
+ **Note:** Version bump only for package @pie-lib/controller-utils
62
63
 
64
+ ## [0.2.39](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.38...@pie-lib/controller-utils@0.2.39) (2023-01-31)
63
65
 
66
+ **Note:** Version bump only for package @pie-lib/controller-utils
64
67
 
65
- ## [0.2.31](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.29...@pie-lib/controller-utils@0.2.31) (2023-01-31)
68
+ ## [0.2.38](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.37...@pie-lib/controller-utils@0.2.38) (2023-01-31)
66
69
 
67
70
  **Note:** Version bump only for package @pie-lib/controller-utils
68
71
 
72
+ ## [0.2.37](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.31...@pie-lib/controller-utils@0.2.37) (2023-01-31)
69
73
 
74
+ **Note:** Version bump only for package @pie-lib/controller-utils
70
75
 
76
+ ## [0.2.31](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.29...@pie-lib/controller-utils@0.2.31) (2023-01-31)
71
77
 
78
+ **Note:** Version bump only for package @pie-lib/controller-utils
72
79
 
73
80
  ## [0.2.29](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.27...@pie-lib/controller-utils@0.2.29) (2023-01-31)
74
81
 
75
82
  **Note:** Version bump only for package @pie-lib/controller-utils
76
83
 
77
-
78
-
79
-
80
-
81
84
  ## [0.2.27](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.26...@pie-lib/controller-utils@0.2.27) (2022-11-23)
82
85
 
83
86
  **Note:** Version bump only for package @pie-lib/controller-utils
84
87
 
85
-
86
-
87
-
88
-
89
88
  ## [0.2.26](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.2.24...@pie-lib/controller-utils@0.2.26) (2021-06-25)
90
89
 
91
90
  **Note:** Version bump only for package @pie-lib/controller-utils
@@ -0,0 +1 @@
1
+ []
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/controller-utils",
3
- "version": "0.2.44",
3
+ "version": "0.3.0-beta.2",
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": "4043c98430c000ce3a25357d92845175b076ea21"
17
+ "gitHead": "e2aa3ddac60f49bcb8c2562370f496323642f453"
18
18
  }
@@ -0,0 +1,25 @@
1
+ import { enabled } from '../partial-scoring';
2
+
3
+ describe('enabled', () => {
4
+ const assertEnabled = (config, env, expected) => {
5
+ it(`returns ${expected} for: config: ${config.partialScoring}, env:${env.partialScoring}`, () => {
6
+ const result = enabled(config, env);
7
+ expect(result).toEqual(expected);
8
+ });
9
+ };
10
+
11
+ const config = (v) => ({ partialScoring: v });
12
+ const env = (v) => ({ partialScoring: v });
13
+
14
+ assertEnabled(config(undefined), env(undefined), true);
15
+ assertEnabled(config(undefined), env(true), true);
16
+ assertEnabled(config(undefined), env(false), false);
17
+
18
+ assertEnabled(config(false), env(undefined), false);
19
+ assertEnabled(config(false), env(true), false);
20
+ assertEnabled(config(false), env(false), false);
21
+
22
+ assertEnabled(config(true), env(undefined), true);
23
+ assertEnabled(config(true), env(true), true);
24
+ assertEnabled(config(true), env(false), false);
25
+ });
@@ -0,0 +1,151 @@
1
+ import { getShuffledChoices, lockChoices } from '../persistence';
2
+
3
+ describe('getShuffledChoices', () => {
4
+ let choices, session, updateSession, key;
5
+
6
+ beforeEach(() => {
7
+ updateSession = jest.fn().mockResolvedValue([]);
8
+ session = {
9
+ id: '1',
10
+ element: 'element',
11
+ };
12
+ choices = [
13
+ {
14
+ value: 1,
15
+ },
16
+ {
17
+ value: 2,
18
+ },
19
+ ];
20
+ key = 'value';
21
+ });
22
+
23
+ describe('0 key', () => {
24
+ it('calls update session w/ 0 as a key', async () => {
25
+ const result = await getShuffledChoices([{ value: 0 }, { value: 1 }], session, updateSession, 'value');
26
+ expect(updateSession).toHaveBeenCalledWith(session.id, session.element, {
27
+ shuffledValues: expect.arrayContaining([0, 1]),
28
+ });
29
+ });
30
+ });
31
+
32
+ describe('handles null values in session', () => {
33
+ beforeEach(async () => {
34
+ const result = await getShuffledChoices(choices, { ...session, shuffledValues: [null] }, updateSession, 'value');
35
+ });
36
+
37
+ it('calls updateSession w/ new shuffle cos [null] is treated as empty', () => {
38
+ expect(updateSession).toHaveBeenCalledWith(session.id, session.element, {
39
+ shuffledValues: expect.arrayContaining([1, 2]),
40
+ });
41
+ });
42
+ });
43
+ describe('bad shuffle generation does not call updateSession', () => {
44
+ beforeEach(async () => {
45
+ const result = await getShuffledChoices(choices, {}, updateSession, 'foo');
46
+ });
47
+ it('does not call update session', () => {
48
+ expect(updateSession).not.toHaveBeenCalled();
49
+ });
50
+ });
51
+
52
+ describe('session does not exist', () => {
53
+ it('returns undefined for empty session', async () => {
54
+ const result = await getShuffledChoices(choices, undefined, updateSession, key);
55
+ expect(result).toEqual(undefined);
56
+ });
57
+ });
58
+
59
+ describe('session exists', () => {
60
+ it('returns compact choices if session has shuffledValues', async () => {
61
+ session = { shuffledValues: [2, 1] };
62
+ const result = await getShuffledChoices(choices, session, updateSession, key);
63
+ expect(result).toEqual(expect.arrayContaining(choices));
64
+ });
65
+
66
+ it('returns shuffled choices if updateSession is a function', async () => {
67
+ session = {};
68
+ updateSession = jest.fn().mockResolvedValue();
69
+ const result = await getShuffledChoices(choices, session, updateSession, key);
70
+ expect(result).toEqual(expect.arrayContaining(choices));
71
+ });
72
+
73
+ it('calls updateSession as expected if updateSession is a function', async () => {
74
+ session = { id: '1', element: 'pie-element' };
75
+ await getShuffledChoices(choices, session, updateSession, key);
76
+ expect(updateSession).toHaveBeenCalledWith('1', 'pie-element', {
77
+ shuffledValues: expect.arrayContaining([1, 2]),
78
+ });
79
+ });
80
+ });
81
+ });
82
+
83
+ describe('lockChoices', () => {
84
+ const env = (lockChoiceOrder, role = 'student') => ({
85
+ '@pie-element': { lockChoiceOrder },
86
+ role,
87
+ });
88
+ const session = (shuffledValues) => ({ shuffledValues });
89
+ it.each`
90
+ modelLock | session | env | expected
91
+ ${true} | ${session()} | ${env(true)} | ${true}
92
+ ${true} | ${session()} | ${env(false)} | ${true}
93
+ ${false} | ${session()} | ${env(true)} | ${true}
94
+ ${false} | ${session()} | ${env(false)} | ${false}
95
+ ${false} | ${session()} | ${undefined} | ${false}
96
+ ${false} | ${undefined} | ${undefined} | ${false}
97
+ ${undefined} | ${session()} | ${env(false)} | ${false}
98
+ ${undefined} | ${session()} | ${env(undefined)} | ${false}
99
+ ${false} | ${session()} | ${env(false, 'instructor')} | ${true}
100
+ ${false} | ${session([0, 1])} | ${env(false, 'instructor')} | ${true}
101
+ ${false} | ${undefined} | ${env(false, 'instructor')} | ${true}
102
+ `('1. model.lockChoiceOrder: $modelLock, $session, $env => $expected', ({ modelLock, session, env, expected }) => {
103
+ const model = { lockChoiceOrder: modelLock };
104
+ const result = lockChoices(model, session, env);
105
+ expect(result).toEqual(expected);
106
+ });
107
+ });
108
+
109
+ describe('lockChoices mod', () => {
110
+ const env = (lockChoiceOrder, role = 'student') => ({
111
+ '@pie-element': { lockChoiceOrder },
112
+ role,
113
+ });
114
+ const session = (answers = ['foo', 'bar']) => ({ answers });
115
+ it.each`
116
+ modelLock | session | env | expected
117
+ ${true} | ${session()} | ${env(true)} | ${true}
118
+ ${true} | ${session()} | ${env(false)} | ${true}
119
+ ${false} | ${session()} | ${env(true)} | ${true}
120
+ ${false} | ${session()} | ${env(false)} | ${false}
121
+ ${undefined} | ${session()} | ${env(true)} | ${true}
122
+ ${undefined} | ${session()} | ${env(undefined)} | ${false}
123
+ ${undefined} | ${session()} | ${env(undefined, 'instructor')} | ${true}
124
+ `('2. model.lockChoiceOrder: $modelLock, $session, $env => $expected', ({ modelLock, session, env, expected }) => {
125
+ const model = { lockChoiceOrder: modelLock };
126
+ const result = lockChoices(model, session, env);
127
+ expect(result).toEqual(expected);
128
+ });
129
+ });
130
+
131
+ describe('lockChoices', () => {
132
+ const env = (lockChoiceOrder, role = 'student') => ({
133
+ '@pie-element': { lockChoiceOrder },
134
+ role,
135
+ });
136
+ const session = (shuffledValues) => ({ shuffledValues, answers: ['foo', 'bar'] });
137
+ it.each`
138
+ modelLock | session | env | expected
139
+ ${true} | ${session()} | ${env(true)} | ${true}
140
+ ${true} | ${session()} | ${env(false)} | ${true}
141
+ ${false} | ${session()} | ${env(true)} | ${true}
142
+ ${false} | ${session()} | ${env(false)} | ${false}
143
+ ${undefined} | ${session()} | ${env(true)} | ${true}
144
+ ${undefined} | ${session()} | ${env(undefined)} | ${false}
145
+ ${undefined} | ${session()} | ${env(undefined, 'instructor')} | ${true}
146
+ `('3. model.lockChoiceOrder: $modelLock, $env => $expected', ({ modelLock, session, env, expected }) => {
147
+ const model = { lockChoiceOrder: modelLock };
148
+ const result = lockChoices(model, session, env);
149
+ expect(result).toEqual(expected);
150
+ });
151
+ });
package/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  import * as partialScoring from './partial-scoring';
2
+
2
3
  export { lockChoices, getShuffledChoices } from './persistence';
3
4
  export { partialScoring };
@@ -1,5 +1,3 @@
1
- import _ from 'lodash';
2
-
3
1
  export const enabled = (config, env, defaultValue) => {
4
2
  // if model.partialScoring = false
5
3
  // - if env.partialScoring = false || env.partialScoring = true => use dichotomous scoring
@@ -17,5 +15,5 @@ export const enabled = (config, env, defaultValue) => {
17
15
  return false;
18
16
  }
19
17
 
20
- return _.isBoolean(defaultValue) ? defaultValue : true;
18
+ return typeof defaultValue === 'boolean' ? defaultValue : true;
21
19
  };
@@ -1,8 +1,6 @@
1
1
  import get from 'lodash/get';
2
2
  import shuffle from 'lodash/shuffle';
3
3
  import isEmpty from 'lodash/isEmpty';
4
- import isNull from 'lodash/isNull';
5
- import isUndefined from 'lodash/isUndefined';
6
4
 
7
5
  // eslint-disable-next-line no-console
8
6
  const lg = (n) => console[n].bind(console, 'controller-utils:');
@@ -13,7 +11,7 @@ const error = lg('error');
13
11
 
14
12
  export const compact = (arr) => {
15
13
  if (Array.isArray(arr)) {
16
- return arr.filter((v) => !isNull(v) && !isUndefined(v));
14
+ return arr.filter((v) => v !== null && v !== undefined);
17
15
  }
18
16
  return arr;
19
17
  };
@@ -23,14 +21,14 @@ export const getShuffledChoices = (choices, session, updateSession, choiceKey) =
23
21
  log('updateSession type: ', typeof updateSession);
24
22
  log('session: ', session);
25
23
 
26
- const currentShuffled = compact((session || {}).shuffledValues);
24
+ const currentShuffled = compact(session?.data?.shuffledValues || session?.shuffledValues || []);
27
25
 
28
26
  if (!session) {
29
27
  // eslint-disable-next-line quotes
30
28
  warn("unable to save shuffled choices because there's no session.");
31
29
  resolve(undefined);
32
30
  } else if (!isEmpty(currentShuffled)) {
33
- debug('use shuffledValues to sort the choices...', session.shuffledValues);
31
+ debug('use shuffledValues to sort the choices...', session.data?.shuffledValues);
34
32
  resolve(compact(currentShuffled.map((v) => choices.find((c) => c[choiceKey] === v))));
35
33
  } else {
36
34
  const shuffledChoices = shuffle(choices);
package/README.md DELETED
@@ -1,5 +0,0 @@
1
- # controller utils
2
-
3
- Some utilities for pie controllers.
4
-
5
- > This package must be able to run server and client side. _Don't add any client specific libraries to this package_.
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;;;;AACA","sourcesContent":["import * as partialScoring from './partial-scoring';\nexport { lockChoices, getShuffledChoices } from './persistence';\nexport { partialScoring };\n"],"file":"index.js"}
@@ -1,33 +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.enabled = void 0;
9
-
10
- var _lodash = _interopRequireDefault(require("lodash"));
11
-
12
- var enabled = function enabled(config, env, defaultValue) {
13
- // if model.partialScoring = false
14
- // - if env.partialScoring = false || env.partialScoring = true => use dichotomous scoring
15
- // else if model.partialScoring = true || undefined
16
- // - if env.partialScoring = false, use dichotomous scoring
17
- // - else if env.partialScoring = true, use partial scoring
18
- config = config || {};
19
- env = env || {};
20
-
21
- if (config.partialScoring === false) {
22
- return false;
23
- }
24
-
25
- if (env.partialScoring === false) {
26
- return false;
27
- }
28
-
29
- return _lodash["default"].isBoolean(defaultValue) ? defaultValue : true;
30
- };
31
-
32
- exports.enabled = enabled;
33
- //# sourceMappingURL=partial-scoring.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/partial-scoring.js"],"names":["enabled","config","env","defaultValue","partialScoring","_","isBoolean"],"mappings":";;;;;;;;;AAAA;;AAEO,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,SAAOC,mBAAEC,SAAF,CAAYH,YAAZ,IAA4BA,YAA5B,GAA2C,IAAlD;AACD,CAlBM","sourcesContent":["import _ from 'lodash';\n\nexport 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 _.isBoolean(defaultValue) ? 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
- var _isNull = _interopRequireDefault(require("lodash/isNull"));
19
-
20
- var _isUndefined = _interopRequireDefault(require("lodash/isUndefined"));
21
-
22
- // eslint-disable-next-line no-console
23
- var lg = function lg(n) {
24
- return console[n].bind(console, 'controller-utils:');
25
- };
26
-
27
- var debug = lg('debug');
28
- var log = lg('log');
29
- var warn = lg('warn');
30
- var error = lg('error');
31
-
32
- var compact = function compact(arr) {
33
- if (Array.isArray(arr)) {
34
- return arr.filter(function (v) {
35
- return !(0, _isNull["default"])(v) && !(0, _isUndefined["default"])(v);
36
- });
37
- }
38
-
39
- return arr;
40
- };
41
-
42
- exports.compact = compact;
43
-
44
- var getShuffledChoices = function getShuffledChoices(choices, session, updateSession, choiceKey) {
45
- return new Promise(function (resolve) {
46
- log('updateSession type: ', (0, _typeof2["default"])(updateSession));
47
- log('session: ', session);
48
- var currentShuffled = compact((session || {}).shuffledValues);
49
-
50
- if (!session) {
51
- // eslint-disable-next-line quotes
52
- warn("unable to save shuffled choices because there's no session.");
53
- resolve(undefined);
54
- } else if (!(0, _isEmpty["default"])(currentShuffled)) {
55
- debug('use shuffledValues to sort the choices...', session.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","getShuffledChoices","choices","session","updateSession","choiceKey","Promise","resolve","currentShuffled","shuffledValues","undefined","map","find","c","shuffledChoices","id","element","JSON","stringify","e","lockChoices","model","env","lockChoiceOrder","role"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;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,CAAhB;AACA,IAAMK,GAAG,GAAGL,EAAE,CAAC,KAAD,CAAd;AACA,IAAMM,IAAI,GAAGN,EAAE,CAAC,MAAD,CAAf;AACA,IAAMO,KAAK,GAAGP,EAAE,CAAC,OAAD,CAAhB;;AAEO,IAAMQ,OAAO,GAAG,SAAVA,OAAU,CAACC,GAAD,EAAS;AAC9B,MAAIC,KAAK,CAACC,OAAN,CAAcF,GAAd,CAAJ,EAAwB;AACtB,WAAOA,GAAG,CAACG,MAAJ,CAAW,UAACC,CAAD;AAAA,aAAO,CAAC,wBAAOA,CAAP,CAAD,I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ACxD,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';\nimport isNull from 'lodash/isNull';\nimport isUndefined from 'lodash/isUndefined';\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) => !isNull(v) && !isUndefined(v));\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 || {}).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.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"}