@pie-element/rubric 3.0.3 → 3.0.4-next.16

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.
@@ -8,7 +8,7 @@
8
8
  "dependencies": {
9
9
  "@material-ui/core": "^3.9.2",
10
10
  "@pie-framework/pie-configure-events": "^1.3.0",
11
- "@pie-lib/pie-toolbox": "1.1.1",
11
+ "@pie-lib/pie-toolbox": "1.2.0",
12
12
  "debug": "^4.1.1",
13
13
  "react": "^16.8.6",
14
14
  "react-dom": "^16.8.6"
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.model = model;
7
+ exports.validate = validate;
7
8
 
8
9
  function model(model, session, env) {
9
10
  return new Promise(function (resolve) {
@@ -11,4 +12,33 @@ function model(model, session, env) {
11
12
  resolve(env && env.role && env.role === 'instructor' ? modelResult : {});
12
13
  });
13
14
  }
15
+
16
+ function markupToText(s) {
17
+ return (s || '').replace(/(<([^>]+)>)/ig, '');
18
+ }
19
+
20
+ function validate(model, config) {
21
+ var points = model.points;
22
+ var errors = {};
23
+ var pointsDescriptorsErrors = {};
24
+ (points || []).forEach(function (point, index) {
25
+ if (!point || point === '<div></div>') {
26
+ pointsDescriptorsErrors[index] = 'Points descriptors cannot be empty.';
27
+ } else {
28
+ var identicalPointDescr = points.slice(index + 1).some(function (p) {
29
+ return markupToText(p) === markupToText(point);
30
+ });
31
+
32
+ if (identicalPointDescr) {
33
+ pointsDescriptorsErrors[index] = 'Points descriptors should be unique.';
34
+ }
35
+ }
36
+ });
37
+
38
+ if (Object.keys(pointsDescriptorsErrors).length > 0) {
39
+ errors.pointsDescriptorsErrors = pointsDescriptorsErrors;
40
+ }
41
+
42
+ return errors;
43
+ }
14
44
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["model","session","env","Promise","resolve","modelResult","role"],"mappings":";;;;;;;AAAO,SAASA,KAAT,CAAeA,KAAf,EAAsBC,OAAtB,EAA+BC,GAA/B,EAAoC;AACzC,SAAO,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAa;AAC9B,QAAMC,WAAW,GAAG,CAACL,KAAD,GAAS,EAAT,GAAcA,KAAlC;AACAI,IAAAA,OAAO,CAACF,GAAG,IAAIA,GAAG,CAACI,IAAX,IAAmBJ,GAAG,CAACI,IAAJ,KAAa,YAAhC,GAA+CD,WAA/C,GAA6D,EAA9D,CAAP;AACD,GAHM,CAAP;AAID","sourcesContent":["export function model(model, session, env) {\n return new Promise((resolve) => {\n const modelResult = !model ? {} : model;\n resolve(env && env.role && env.role === 'instructor' ? modelResult : {});\n });\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["model","session","env","Promise","resolve","modelResult","role","markupToText","s","replace","validate","config","points","errors","pointsDescriptorsErrors","forEach","point","index","identicalPointDescr","slice","some","p","Object","keys","length"],"mappings":";;;;;;;;AAAO,SAASA,KAAT,CAAeA,KAAf,EAAsBC,OAAtB,EAA+BC,GAA/B,EAAoC;AACzC,SAAO,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAa;AAC9B,QAAMC,WAAW,GAAG,CAACL,KAAD,GAAS,EAAT,GAAcA,KAAlC;AACAI,IAAAA,OAAO,CAACF,GAAG,IAAIA,GAAG,CAACI,IAAX,IAAmBJ,GAAG,CAACI,IAAJ,KAAa,YAAhC,GAA+CD,WAA/C,GAA6D,EAA9D,CAAP;AACD,GAHM,CAAP;AAID;;AAGD,SAASE,YAAT,CAAsBC,CAAtB,EAAyB;AACvB,SAAO,CAACA,CAAC,IAAI,EAAN,EAAUC,OAAV,CAAkB,eAAlB,EAAmC,EAAnC,CAAP;AACD;;AAGM,SAASC,QAAT,CAAmBV,KAAnB,EAA0BW,MAA1B,EAAkC;AACvC,MAAQC,MAAR,GAAmBZ,KAAnB,CAAQY,MAAR;AACA,MAAMC,MAAM,GAAG,EAAf;AACA,MAAMC,uBAAuB,GAAG,EAAhC;AAEA,GAACF,MAAM,IAAI,EAAX,EAAeG,OAAf,CAAuB,UAACC,KAAD,EAAQC,KAAR,EAAkB;AACvC,QAAG,CAACD,KAAD,IAASA,KAAK,KAAK,aAAtB,EAAqC;AACnCF,MAAAA,uBAAuB,CAACG,KAAD,CAAvB,GAAiC,qCAAjC;AACD,KAFD,MAGI;AACF,UAAMC,mBAAmB,GAAGN,MAAM,CAACO,KAAP,CAAaF,KAAK,GAAG,CAArB,EAAwBG,IAAxB,CAA6B,UAAAC,CAAC;AAAA,eAAId,YAAY,CAACc,CAAD,CAAZ,KAAoBd,YAAY,CAACS,KAAD,CAApC;AAAA,OAA9B,CAA5B;;AAEA,UAAIE,mBAAJ,EAAyB;AACvBJ,QAAAA,uBAAuB,CAACG,KAAD,CAAvB,GAAiC,sCAAjC;AACD;AACF;AACF,GAXD;;AAaA,MAAGK,MAAM,CAACC,IAAP,CAAYT,uBAAZ,EAAqCU,MAArC,GAA8C,CAAjD,EAAmD;AACjDX,IAAAA,MAAM,CAACC,uBAAP,GAAiCA,uBAAjC;AACD;;AAED,SAAOD,MAAP;AACD","sourcesContent":["export function model(model, session, env) {\n return new Promise((resolve) => {\n const modelResult = !model ? {} : model;\n resolve(env && env.role && env.role === 'instructor' ? modelResult : {});\n });\n}\n\n\nfunction markupToText(s) {\n return (s || '').replace(/(<([^>]+)>)/ig, '');\n}\n\n\nexport function validate (model, config) {\n const { points } = model;\n const errors = {};\n const pointsDescriptorsErrors = {};\n\n (points || []).forEach((point, index) => {\n if(!point|| point === '<div></div>') {\n pointsDescriptorsErrors[index] = 'Points descriptors cannot be empty.';\n }\n else{\n const identicalPointDescr = points.slice(index + 1).some(p => markupToText(p) === markupToText(point));\n\n if (identicalPointDescr) {\n pointsDescriptorsErrors[index] = 'Points descriptors should be unique.';\n }\n }\n });\n\n if(Object.keys(pointsDescriptorsErrors).length > 0){\n errors.pointsDescriptorsErrors = pointsDescriptorsErrors;\n }\n\n return errors;\n}\n"],"file":"index.js"}
@@ -7,7 +7,7 @@
7
7
  "test": "./node_modules/.bin/jest"
8
8
  },
9
9
  "dependencies": {
10
- "@pie-lib/pie-toolbox": "1.1.1",
10
+ "@pie-lib/pie-toolbox": "1.2.0",
11
11
  "lodash": "^4.17.15"
12
12
  }
13
13
  }
@@ -4,3 +4,34 @@ export function model(model, session, env) {
4
4
  resolve(env && env.role && env.role === 'instructor' ? modelResult : {});
5
5
  });
6
6
  }
7
+
8
+
9
+ function markupToText(s) {
10
+ return (s || '').replace(/(<([^>]+)>)/ig, '');
11
+ }
12
+
13
+
14
+ export function validate (model, config) {
15
+ const { points } = model;
16
+ const errors = {};
17
+ const pointsDescriptorsErrors = {};
18
+
19
+ (points || []).forEach((point, index) => {
20
+ if(!point|| point === '<div></div>') {
21
+ pointsDescriptorsErrors[index] = 'Points descriptors cannot be empty.';
22
+ }
23
+ else{
24
+ const identicalPointDescr = points.slice(index + 1).some(p => markupToText(p) === markupToText(point));
25
+
26
+ if (identicalPointDescr) {
27
+ pointsDescriptorsErrors[index] = 'Points descriptors should be unique.';
28
+ }
29
+ }
30
+ });
31
+
32
+ if(Object.keys(pointsDescriptorsErrors).length > 0){
33
+ errors.pointsDescriptorsErrors = pointsDescriptorsErrors;
34
+ }
35
+
36
+ return errors;
37
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/rubric",
3
- "version": "3.0.3",
3
+ "version": "3.0.4-next.16+1d20148ed",
4
4
  "main": "lib/index.js",
5
5
  "module": "src/index.js",
6
6
  "description": "Rubric Scoring Interaction",
@@ -10,12 +10,12 @@
10
10
  },
11
11
  "dependencies": {
12
12
  "@material-ui/core": "^3.9.2",
13
- "@pie-lib/pie-toolbox": "1.1.1",
13
+ "@pie-lib/pie-toolbox": "1.2.0",
14
14
  "prop-types": "^15.7.2"
15
15
  },
16
16
  "author": "pie framework developers",
17
17
  "license": "ISC",
18
- "gitHead": "41ec62fd9015443d35df1370d164c9e605e4d9d6",
18
+ "gitHead": "1d20148ed6abb750252b3cf604080abe71af5194",
19
19
  "scripts": {
20
20
  "postpublish": "../../scripts/postpublish"
21
21
  },