@pie-lib/controller-utils 0.2.43-next.0 → 0.2.43-next.105

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.
@@ -94,12 +94,6 @@ var getShuffledChoices = function getShuffledChoices(choices, session, updateSes
94
94
  }
95
95
  });
96
96
  };
97
-
98
- exports.getShuffledChoices = getShuffledChoices;
99
-
100
- var hasShuffledValues = function hasShuffledValues(s) {
101
- return !!(s || {}).shuffledValues;
102
- };
103
97
  /**
104
98
  * If we return:
105
99
  * - true - that means that the order of the choices will be ordinal (as is created in the configure item)
@@ -112,6 +106,8 @@ var hasShuffledValues = function hasShuffledValues(s) {
112
106
  */
113
107
 
114
108
 
109
+ exports.getShuffledChoices = getShuffledChoices;
110
+
115
111
  var lockChoices = function lockChoices(model, session, env) {
116
112
  if (model.lockChoiceOrder) {
117
113
  return true;
@@ -1 +1 @@
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","hasShuffledValues","s","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,G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B,EAAyB;AAClD,MAAID,KAAK,CAACE,eAAV,EAA2B;AACzB,WAAO,IAAP;AACD;;AAEDjC,EAAAA,GAAG,CAAC,mBAAD,EAAsB,qBAAIgC,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';\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\nconst hasShuffledValues = (s) => !!(s || {}).shuffledValues;\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"}
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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AAU;AACV1B,UAAAA,IAAI,CAAC,2CAAD,CAAJ;AACAC,UAAAA,KAAK,CAACyB,CAAD,CAAL;AACD;AACF,OAtBD,MAsBO;AACL1B,QAAAA,IAAI,CAAC,kEAAD,CAAJ;AACD,OA3BI,CA4BL;;;AACAc,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;;AAED/B,EAAAA,GAAG,CAAC,mBAAD,EAAsB,qBAAI8B,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';\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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/controller-utils",
3
- "version": "0.2.43-next.0+2f8c6198",
3
+ "version": "0.2.43-next.105+6f82e209",
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": "2f8c619845b4aa9a1c862b2ac549a975fe0bd13f"
17
+ "gitHead": "6f82e209bcfaede19f4ff2225a17466a617a599e"
18
18
  }
@@ -65,8 +65,6 @@ export const getShuffledChoices = (choices, session, updateSession, choiceKey) =
65
65
  }
66
66
  });
67
67
 
68
- const hasShuffledValues = (s) => !!(s || {}).shuffledValues;
69
-
70
68
  /**
71
69
  * If we return:
72
70
  * - true - that means that the order of the choices will be ordinal (as is created in the configure item)