@universis/evaluations 1.0.25 → 1.0.27
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/dist/config/models/ClassInstructorEvaluationEvent.json +1 -1
- package/dist/config/models/CourseClassEvaluationEvent.json +89 -4
- package/dist/config/models/EvaluationAccessToken.json +19 -1
- package/dist/config/models/EvaluationDocument.json +17 -1
- package/dist/config/models/EvaluationEvent.json +13 -0
- package/dist/config/models/GenerateCourseClassTokenAction.json +57 -0
- package/dist/config/models/SendCourseClassTokenAction.json +52 -0
- package/dist/listeners/access-token-listener.js +76 -0
- package/dist/listeners/access-token-listener.js.map +1 -0
- package/dist/listeners/class-event-listener.js +184 -0
- package/dist/listeners/class-event-listener.js.map +1 -0
- package/dist/locales/el.json +3 -1
- package/dist/models/class-instructor-evaluation-event-model.js +1 -5
- package/dist/models/class-instructor-evaluation-event-model.js.map +1 -1
- package/dist/models/course-class-evaluation-event-model.js +340 -0
- package/dist/models/course-class-evaluation-event-model.js.map +1 -0
- package/dist/models/evaluation-event-model.js +200 -12
- package/dist/models/evaluation-event-model.js.map +1 -1
- package/package.json +1 -1
- package/src/config/models/ClassInstructorEvaluationEvent.json +1 -1
- package/src/config/models/CourseClassEvaluationEvent.json +89 -4
- package/src/config/models/EvaluationAccessToken.json +19 -1
- package/src/config/models/EvaluationDocument.json +17 -1
- package/src/config/models/EvaluationEvent.json +13 -0
- package/src/config/models/GenerateCourseClassTokenAction.json +57 -0
- package/src/config/models/SendCourseClassTokenAction.json +52 -0
- package/src/listeners/access-token-listener.js +75 -0
- package/src/listeners/class-event-listener.js +183 -0
- package/src/locales/el.json +3 -1
- package/src/models/class-instructor-evaluation-event-model.js +1 -5
- package/src/models/course-class-evaluation-event-model.js +339 -0
- package/src/models/evaluation-event-model.js +204 -16
|
@@ -77,6 +77,49 @@ _data.EdmMapping.func('Current', 'EvaluationEvent'), _dec3 =
|
|
|
77
77
|
|
|
78
78
|
|
|
79
79
|
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
80
123
|
|
|
81
124
|
|
|
82
125
|
|
|
@@ -181,6 +224,62 @@ _data.EdmMapping.func('form', 'Object'), _dec4 =
|
|
|
181
224
|
|
|
182
225
|
|
|
183
226
|
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
184
283
|
|
|
185
284
|
|
|
186
285
|
|
|
@@ -450,6 +549,11 @@ _data.EdmMapping.func('FormAttributesSummary', _data.EdmType.CollectionOf('Objec
|
|
|
450
549
|
|
|
451
550
|
|
|
452
551
|
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
453
557
|
|
|
454
558
|
|
|
455
559
|
|
|
@@ -465,8 +569,10 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
465
569
|
*/static async getCurrent(context) {// get evaluation key
|
|
466
570
|
const token = await EvaluationAccessToken.inspect(context, context.user && context.user.authenticationToken);if (token.active === false) {throw new _common.HttpTokenExpiredError(context.__('Evaluation access token has been expired or is invalid.'));} // get evaluation event
|
|
467
571
|
// get current date
|
|
468
|
-
let evaluationEvent = await context.model('EvaluationEvent').where('id').equal(token.sub).expand('eventStatus').silent().getTypedItem();if (evaluationEvent == null) {throw new _common.HttpNotFoundError('The specified evaluation cannot be found');}if (evaluationEvent.eventStatus) {if (evaluationEvent.eventStatus.alternateName !== 'EventOpened') {throw new _common.DataError('E_CLOSED_EVENT', context.__('The course evaluation has been closed and is no longer available'));}} // check dates
|
|
469
|
-
const currentDate = new Date().setHours(0, 0, 0, 0);const startDate = evaluationEvent.startDate.setHours(0, 0, 0, 0);const endDate = evaluationEvent.endDate.setHours(0, 0, 0, 0);if (currentDate < startDate) {throw new _common.DataError('E_NOT_STARTED', context.__('Evaluation period for this course has not been started yet'));}if (currentDate > endDate) {throw new _common.DataError('E_EXPIRED', context.__('Evaluation period for this course has been expired'));}
|
|
572
|
+
let evaluationEvent = await context.model('EvaluationEvent').where('id').equal(token.sub).expand('eventStatus', 'subEvents').silent().getTypedItem();if (evaluationEvent == null) {throw new _common.HttpNotFoundError('The specified evaluation cannot be found');}if (evaluationEvent.eventStatus) {if (evaluationEvent.eventStatus.alternateName !== 'EventOpened') {throw new _common.DataError('E_CLOSED_EVENT', context.__('The course evaluation has been closed and is no longer available'));}} // check dates
|
|
573
|
+
const currentDate = new Date().setHours(0, 0, 0, 0);const startDate = evaluationEvent.startDate.setHours(0, 0, 0, 0);const endDate = evaluationEvent.endDate.setHours(0, 0, 0, 0);if (currentDate < startDate) {throw new _common.DataError('E_NOT_STARTED', context.__('Evaluation period for this course has not been started yet'));}if (currentDate > endDate) {throw new _common.DataError('E_EXPIRED', context.__('Evaluation period for this course has been expired'));}let courseClass;let courseClassTitle;switch (evaluationEvent.additionalType) {case 'ClassInstructorEvaluationEvent':const event = await context.model('ClassInstructorEvaluationEvent').where('id').equal(token.sub).expand({ name: 'courseClassInstructor', options: { $expand: 'courseClass($expand=course,year,period,locale),instructor' } }).silent().getTypedItem();courseClass = event.courseClassInstructor.courseClass;const instructor = event.courseClassInstructor.instructor;courseClassTitle = courseClass.locale && courseClass.locale.title || courseClass.title;evaluationEvent.courseClass = `${courseClass.course.displayCode}-${courseClassTitle} (${courseClass.year.alternateName}-${courseClass.period.name}) `;evaluationEvent.instructor = `${instructor.familyName} ${instructor.givenName}`;break;case 'CourseClassEvaluationEvent':const courseEvent = await context.model('CourseClassEvaluationEvent').where('id').equal(token.sub).expand({ name: 'courseClass', options: { $expand: 'course,year,period,locale,instructors($expand=instructor)' } }).silent().getTypedItem();courseClass = courseEvent.courseClass;courseClassTitle = courseClass.locale && courseClass.locale.title || courseClass.title;evaluationEvent.courseClass = `${courseClass.course.displayCode}-${courseClassTitle} (${courseClass.year.alternateName}-${courseClass.period.name}) `; // check if child evaluation tokens
|
|
574
|
+
const instructorTokens = await context.model('EvaluationAccessToken').where('parentToken').equal(token.access_token).silent().getAllItems();if (instructorTokens && instructorTokens.length > 0) {evaluationEvent.subEvents = [];for (let i = 0; i < instructorTokens.length; i++) {const instructorToken = await EvaluationAccessToken.inspect(context, instructorTokens[i].access_token);if (instructorToken.active) {// load evaluation event for getting instructor name
|
|
575
|
+
const subEvent = await context.model('ClassInstructorEvaluationEvent').where('id').equal(instructorTokens[i].evaluationEvent).and('superEvent').equal(evaluationEvent.id).and('eventStatus/alternateName').equal('EventOpened').select('id', 'courseClassInstructor/instructor/familyName as familyName', 'courseClassInstructor/instructor/givenName as givenName').silent().getItem();if (subEvent) {subEvent.instructor = `${subEvent.familyName} ${subEvent.givenName}`;subEvent.access_token = instructorTokens[i].access_token;evaluationEvent.subEvents.push(subEvent);}}}}break;case 'default':evaluationEvent = await evaluationEvent.silent().getAdditionalObject();break;}return evaluationEvent;}async getForm() {const form = await this.property('evaluationDocument').getItem();const service = this.context.getApplication().getService(function PrivateContentService() {}); /**
|
|
470
576
|
* @type {string}
|
|
471
577
|
*/const formPath = await new Promise((resolve, reject) => {service.resolvePhysicalPath(this.context, form, (err, physicalPath) => {if (err) {return reject(err);}return resolve(physicalPath);});});const readFileAsync = _util.default.promisify(_fs.default.readFile);let content = await readFileAsync(formPath);if (content == null) {throw new _common.HttpNotFoundError('Evaluation form cannot be found');}let buffer = Buffer.from(content, 'base64');let result;result = JSON.parse(buffer.toString('utf8'));try {result.properties = result.properties || {};Object.assign(result.properties, { name: form.resultType, _id: form.id, _event: this.id }); // post-processing
|
|
472
578
|
let shouldUpgrade = true;let model = this.context.model(form.resultType);if (model != null) {shouldUpgrade = (0, _semver.lt)(model.version, form.version);}if (shouldUpgrade) {// load for inspector
|
|
@@ -483,13 +589,17 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
483
589
|
const thisModel = dataConfiguration.model(this.getModel().name);model.privileges.push.apply(model.privileges, [{ "mask": 15, "type": "global" }, { "mask": 1, "type": "global", "account": "Administrators" }]); // add extra privileges
|
|
484
590
|
if (Array.isArray(thisModel.resultPrivileges)) {model.privileges.push.apply(model.privileges, thisModel.resultPrivileges);}dataConfiguration.setModelDefinition(model); // add entity set
|
|
485
591
|
const builder = this.context.getApplication().getService(_data.ODataModelBuilder);builder.addEntitySet(model.name, model.name);if (model.hidden) {builder.removeEntitySet(model.name);} // update version
|
|
486
|
-
form.version = model.version;await this.context.model('EvaluationDocument').silent().save(form);}
|
|
592
|
+
form.version = model.version;await this.context.model('EvaluationDocument').silent().save(form);} // check if event has sub events and append form to result
|
|
593
|
+
if (this.subEvents && this.subEvents.length) {// get first subEvent for
|
|
594
|
+
const subEvent = this.context.model('EvaluationEvent').convert(this.subEvents[0]);const subResult = await subEvent.getForm(); // add select boxes for each instructor
|
|
595
|
+
if (this.subEvents.length > 1) {const label = this.context.__('Select at least one instructor to evaluate');const selectInstructorsComponent = { "label": label, "optionsLabelPosition": "right", "tableView": false, "key": "instructors", "type": "selectboxes", "input": true, "inputType": "checkbox", "validate": { "required": true } };this.subEvents.sort((a, b) => a.instructor < b.instructor ? -1 : 1);selectInstructorsComponent.values = this.subEvents.map((x) => {x.label = x.instructor;x.value = x.id;return x;});result.components.push(selectInstructorsComponent);const headerComponent = subResult.components[0];headerComponent.customConditional = "show =(data && data.instructors[row.id])";headerComponent.refreshOn = "instructors";} // create panel
|
|
596
|
+
const repeaterComponent = { "label": " ", "disableAddingRemovingRows": true, "reorder": false, "customClass": "border-0", "addAnotherPosition": "bottom", "layoutFixed": false, "enableRowGroups": false, "initEmpty": false, "hideLabel": true, "tableView": false, "key": "subEvents", "type": "datagrid", "input": true, "components": [] };repeaterComponent.components.push.apply(repeaterComponent.components, subResult.components);result.components.push(repeaterComponent);}return result;} catch (err) {_common.TraceUtils.error(`Error while decoding evaluation form ${form.id} content.`);_common.TraceUtils.error(err);throw new _common.HttpServerError('An error occurred while decoding evaluation form.');}}async getResults() {const form = await this.getForm();return this.context.model(form.properties.name).where('evaluationEvent').equal(this.id).prepare();}async getAccessTokens() {return this.context.model('EvaluationAccessToken').where('evaluationEvent').equal(this.id).prepare();}async getFormAttributes() {/**
|
|
487
597
|
* @type {DataContext|*}
|
|
488
598
|
*/const context = this.context;const results = await this.getFormResults(context, this.getId(), null);return results.responses;}async getFormAttributesSummary() {/**
|
|
489
599
|
* @type {DataContext|*}
|
|
490
600
|
*/const context = this.context;const eventModel = this.getModel().name;const results = await this.getFormResults(context, this.getId(), null);let q = this.context.model(eventModel).where('id').equal(this.getId()).expand({ 'name': 'tokens', 'options': { '$select': 'evaluationEvent,count(evaluationEvent) as total,used', '$groupby': 'evaluationEvent,used' } }, 'organizer');if (eventModel === 'ClassInstructorEvaluationEvent') {q = this.context.model(eventModel).where('id').equal(this.getId()).expand({ 'name': 'tokens', 'options': { '$select': 'evaluationEvent,count(evaluationEvent) as total,used', '$groupby': 'evaluationEvent,used' } }, { 'name': 'courseClassInstructor', 'options': { '$expand': 'courseClass($expand=year,period,course($expand=department)),instructor' } });}results.event = await q.getItem();if (results.event == null) {throw new _common.DataNotFoundError('Evaluation event not found.');} // count used tokens of event
|
|
491
601
|
if (results.event.tokens) {const usedTokens = results.event.tokens && results.event.tokens.find((x) => {return x.used === true;});results.event.tokensUsed = usedTokens ? usedTokens.total : 0;} // get avg of questions avg
|
|
492
|
-
results.event.responsesAvg =
|
|
602
|
+
const avg = this.getAvgValues(context, results);results.event.responsesAvg = avg.responsesAvg;results.event.questionsAvg = avg.questionsAvg;return results;}async getFormResults(context, id, events) {const result = [];const evaluationEvents = [];if (id) {evaluationEvents.push(id);} else {if (Array.isArray(events) && events.length) {evaluationEvents.push.apply(evaluationEvents, events.map((x) => {return x.id || x;}));}}if (evaluationEvents.length === 0) {throw new _common.DataError('Evaluation events not supplied.');}const form = await this.getForm();this.setParentLegend(form); // get model attributes
|
|
493
603
|
/**
|
|
494
604
|
* @type {DataConfigurationStrategy|*}
|
|
495
605
|
*/const dataConfiguration = context.getApplication().getConfiguration().getStrategy(_data.DataConfigurationStrategy);const dataTypes = dataConfiguration.dataTypes;const q = context.model(form.properties.name).asQueryable();const selectArguments = [];const model = dataConfiguration.model(form.properties.name);const attributes = model.fields;let totalResponses = 0;const summaryValues = [];const currentLocale = context.locale;const settings = form.settings && form.settings.i18n;const translations = settings && settings[currentLocale] || {};attributes.forEach((attribute) => {const key = this.findByKey(form.components, attribute.name);if (key) {attribute = Object.assign(attribute, { name: attribute.name, label: key.label });attribute.isNumber = false;attribute.legend = key.customProperties && key.customProperties.legend;if (Object.prototype.hasOwnProperty.call(dataTypes, attribute.type)) {attribute.isNumber = dataTypes[attribute.type].type === 'number';}selectArguments.push(`${attribute.name}`); // clear std,avg and responses from model attribute
|
|
@@ -500,7 +610,7 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
500
610
|
summaryValues.map((x) => {x.total = 0;return x;});const showResults = await this.showResults(context); // check if zero values should be excluded
|
|
501
611
|
const ignoreZeroValues = context.getConfiguration().getSourceAt('settings/evaluation/ignoreZeroValues') || false;if (selectArguments.length && showResults === true) {const responses = await q.select.apply(q, selectArguments).where('evaluationEvent').in(evaluationEvents).silent().getAllItems();for (let i = 0; i < result.length; i++) {const qElement = result[i];qElement.responses = [];if (qElement.isNumber) {// remove zero values from responses avg and std
|
|
502
612
|
const sample = responses.filter((x) => {if (ignoreZeroValues) {return x[qElement.name] != 0;}return true;}); // add mean value and standard deviation
|
|
503
|
-
qElement.std = sample.length ? math.std(sample.map((x) => {return x[qElement.name];})) : 0;qElement.avg = sample.length ? math.mean(sample.map((x) => {return x[qElement.name];})) : 0;qElement.numberOfResponses = sample.length;summaryValues.forEach((radioValue) => {const result = responses.filter((y) => {return y[qElement.name] == radioValue.value;}).length;radioValue.total += result;totalResponses += result;});} else {qElement.responses = responses.map((x) => {return x[qElement.name];});}}}const results = {};results.responses = result;results.summaryValues = [];results.summaryValues.push.apply(results.summaryValues, summaryValues.map((x) => {x.totalResponses = totalResponses;return x;}));return results;}async showResults(context) {// this is a custom way to get permissions based on eventStatus and user groups
|
|
613
|
+
qElement.std = sample.length ? math.std(sample.map((x) => {return x[qElement.name];})) : 0;qElement.avg = sample.length ? math.mean(sample.map((x) => {return x[qElement.name];})) : 0;qElement.numberOfResponses = sample.length;summaryValues.forEach((radioValue) => {const result = responses.filter((y) => {return y[qElement.name] == radioValue.value;}).length;radioValue.total += result;totalResponses += result;});qElement.responses = responses.map((x) => {if (x[qElement.name] > 0 && ignoreZeroValues || !ignoreZeroValues) {return x[qElement.name];}});} else {qElement.responses = responses.map((x) => {return x[qElement.name];});}}}const results = {};results.responses = result;results.summaryValues = [];results.summaryValues.push.apply(results.summaryValues, summaryValues.map((x) => {x.totalResponses = totalResponses;return x;}));return results;}async showResults(context) {// this is a custom way to get permissions based on eventStatus and user groups
|
|
504
614
|
let showResults = true;let found = false;const eventStatusesResults = context.getConfiguration().getSourceAt('settings/evaluation/results/statuses') || [];const groupsAllowed = context.getConfiguration().getSourceAt('settings/evaluation/results/groupsAllowed') || [];if (eventStatusesResults.length > 0) {// check if eventStatus is allowed
|
|
505
615
|
if (groupsAllowed.length > 0) {// but first check if user belongs to allowed groups
|
|
506
616
|
const userName = context.interactiveUser ? context.interactiveUser.name : context.user.name;const user = await context.model('User').where('name').equal(userName).expand('groups').getItem();found = user.groups.some((r) => groupsAllowed.indexOf(r.name) >= 0);}if (!found) {const evaluationEvent = await context.model('EvaluationEvent').where('id').equal(this.getId()).select('id', 'eventStatus/alternateName as eventStatus').getItem();if (evaluationEvent == null) {throw new _common.HttpNotFoundError('The specified evaluation cannot be found');}showResults = eventStatusesResults.findIndex((x) => {return x === evaluationEvent.eventStatus;}) >= 0;}}return showResults;}findByKey(array, key) {for (let index = 0; index < array.length; index++) {const element = array[index];if (element.key === key) {return element;} else {if (element.components) {const found = this.findByKey(element.components, key);if (found) {return found;}}}}}setParentLegend(component) {if (Array.isArray(component.components)) {component.components.forEach((item) => {if (component.legend) {item.customProperties = item.customProperties || {};item.customProperties.legend = component.legend;}this.setParentLegend(item);});}}async evaluate(data) {const token = await EvaluationAccessToken.inspect(this.context, this.context.user.authenticationToken);if (token.active === false) {throw new _common.HttpTokenExpiredError('Evaluation access token has been expired or is invalid.');}if (this.id !== token.sub) {throw new _common.HttpBadRequestError('Evaluation access token is invalid');} // get evaluation form
|
|
@@ -508,8 +618,23 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
508
618
|
if (form == null) {throw new _common.HttpNotFoundError('Evaluation form cannot be found');} // get evaluation document
|
|
509
619
|
const evaluationDocument = await this.context.model(_evaluationDocumentModel.default).where('id').equal(form.properties._id).silent().getItem();if (evaluationDocument == null) {throw new _common.HttpNotFoundError('Evaluation document cannot be found');} // assign defaults
|
|
510
620
|
Object.assign(data, { evaluationEvent: this.id, evaluationDocument: evaluationDocument.id }); // and finally append evaluation
|
|
511
|
-
await this.context.model(evaluationDocument.resultType).on('after.save', (event, callback) => {const context = event.model.context;context.model(EvaluationAccessToken).where('access_token').equal(context.user && context.user.authenticationToken).silent().getItem().then((token) => {if (token == null) {throw new _common.HttpTokenExpiredError('Evaluation token is required');}
|
|
512
|
-
|
|
621
|
+
await this.context.model(evaluationDocument.resultType).on('after.save', (event, callback) => {const context = event.model.context;context.model(EvaluationAccessToken).where('access_token').equal(context.user && context.user.authenticationToken).silent().getItem().then(async (token) => {if (token == null) {throw new _common.HttpTokenExpiredError('Evaluation token is required');} // check if subEvents have been evaluated
|
|
622
|
+
const subEvents = event.target.subEvents;if (subEvents && subEvents.length) {// evaluate each sub event
|
|
623
|
+
for (let i = 0; i < subEvents.length; i++) {context.user.authenticationToken = subEvents[i].access_token;const subEvent = context.model('EvaluationEvent').convert(subEvents[i].id);delete subEvents[i].id;if (subEvents.length > 1 && event.target.instructors) {// check if instructor has been evaluated
|
|
624
|
+
if (event.target.instructors[subEvent.id] === true) {await subEvent.evaluate(subEvents[i]);}} else {await subEvent.evaluate(subEvents[i]);}}}return context.model(EvaluationAccessToken).silent().save({ access_token: token.access_token, expires: new Date(0), // set epoch date
|
|
625
|
+
used: true });}).then(() => {
|
|
626
|
+
return callback();
|
|
627
|
+
}).catch((err) => {
|
|
628
|
+
_common.TraceUtils.error('An error occurred while submitting evaluation');
|
|
629
|
+
return callback(err);
|
|
630
|
+
});
|
|
631
|
+
}).silent().save(data);
|
|
632
|
+
return data;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
static async generateTokens(context, generateOptions) {
|
|
636
|
+
let items = [];
|
|
637
|
+
if (Array.isArray(generateOptions)) {
|
|
513
638
|
let n = 0;
|
|
514
639
|
let newItems;
|
|
515
640
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -577,7 +702,32 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
577
702
|
// refresh mailer
|
|
578
703
|
const mailer = (0, _mailer.getMailer)(context); // maybe investigate why this has to be refreshed.
|
|
579
704
|
// pop an access token
|
|
580
|
-
|
|
705
|
+
let access_token;
|
|
706
|
+
const studentMetadata = context.getConfiguration().getSourceAt('settings/evaluation/useStudentInfoAtMetadata') || false;
|
|
707
|
+
// student metadata contains student identifiers only if setting useStudentInfoAtMetadata is true
|
|
708
|
+
// otherwise only semester and registrationType are stored
|
|
709
|
+
const metadata = {
|
|
710
|
+
id: studentMetadata ? student.id : null,
|
|
711
|
+
student: studentMetadata ? student.student : null,
|
|
712
|
+
semester: student.semester,
|
|
713
|
+
registrationType: student.registrationType };
|
|
714
|
+
|
|
715
|
+
if (studentMetadata) {
|
|
716
|
+
// try to find access token for specific student
|
|
717
|
+
access_token = tokens.find((x) => {
|
|
718
|
+
return x.metadata && x.metadata.student === student.id;
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
if (!access_token) {
|
|
722
|
+
access_token = tokens.pop();
|
|
723
|
+
// update metadata
|
|
724
|
+
} else
|
|
725
|
+
{
|
|
726
|
+
//
|
|
727
|
+
_common.TraceUtils.log('test');
|
|
728
|
+
}
|
|
729
|
+
access_token.metadata = metadata;
|
|
730
|
+
|
|
581
731
|
// send message
|
|
582
732
|
await new Promise((resolve) => {
|
|
583
733
|
mailer.transporter(transporter).
|
|
@@ -585,7 +735,7 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
585
735
|
subject(subject).
|
|
586
736
|
to(student.email).
|
|
587
737
|
send(Object.assign(evaluationEvent, {
|
|
588
|
-
access_token }),
|
|
738
|
+
access_token: access_token.access_token }),
|
|
589
739
|
(err) => {
|
|
590
740
|
if (err) {
|
|
591
741
|
try {
|
|
@@ -600,8 +750,9 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
600
750
|
succeeded.push(access_token);
|
|
601
751
|
// update successfully sent token
|
|
602
752
|
return context.model('EvaluationAccessToken').silent().save({
|
|
603
|
-
access_token: access_token, // access_token is primary
|
|
753
|
+
access_token: access_token.access_token, // access_token is primary
|
|
604
754
|
sent: true,
|
|
755
|
+
metadata: access_token.metadata,
|
|
605
756
|
$state: 2 }).
|
|
606
757
|
then((χ) => {
|
|
607
758
|
return resolve();
|
|
@@ -629,7 +780,7 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
629
780
|
description: tokenInfo.total === failed.length ? context.__('Sending tokens failed for all students') : null };
|
|
630
781
|
|
|
631
782
|
// and save
|
|
632
|
-
return context.model(
|
|
783
|
+
return context.model(action.additionalType).silent().save(sendTokensAction).then((item) => {
|
|
633
784
|
EvaluationEvent.sendSse(user, context, evaluationEvent.id, message, sendTokensAction.description ? { message: sendTokensAction.description } : null);
|
|
634
785
|
}).catch((err) => {
|
|
635
786
|
_common.TraceUtils.error(err);
|
|
@@ -662,7 +813,7 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
662
813
|
description: tokenInfo.total === failed.length ? context.__('Sending tokens failed for all students') : null };
|
|
663
814
|
|
|
664
815
|
// and save
|
|
665
|
-
return context.model(
|
|
816
|
+
return context.model(action.additionalType).silent().save(sendTokensAction).then((tokenAction) => {
|
|
666
817
|
EvaluationEvent.sendSse(user, context, evaluationEvent.id, message, err);
|
|
667
818
|
}).catch((err) => {
|
|
668
819
|
_common.TraceUtils.error(err);
|
|
@@ -703,6 +854,43 @@ _data.EdmMapping.action('Evaluate', 'Object'), _dec(_class = (_class2 = class Ev
|
|
|
703
854
|
|
|
704
855
|
}
|
|
705
856
|
}
|
|
857
|
+
}
|
|
858
|
+
getAvgValues(context, results)
|
|
859
|
+
{
|
|
860
|
+
const avg = {
|
|
861
|
+
responsesAvg: 0,
|
|
862
|
+
questionsAvg: 0 };
|
|
863
|
+
|
|
864
|
+
// get avg of questions avg
|
|
865
|
+
const ignoreZeroValues = context.getConfiguration().getSourceAt('settings/evaluation/ignoreZeroValues') || false;
|
|
866
|
+
// filter only numbers
|
|
867
|
+
const filteredResults = results.responses.filter((x) => {
|
|
868
|
+
return !!x.isNumber;
|
|
869
|
+
});
|
|
870
|
+
// filter avg values
|
|
871
|
+
const filteredByValueResults = filteredResults.
|
|
872
|
+
filter((x) => {
|
|
873
|
+
return ignoreZeroValues && x.avg > 0 || !ignoreZeroValues;
|
|
874
|
+
});
|
|
875
|
+
avg.responsesAvg = filteredByValueResults.length ? math.mean(filteredByValueResults.
|
|
876
|
+
map((x) => {
|
|
877
|
+
return x.avg;
|
|
878
|
+
})) : 0;
|
|
879
|
+
|
|
880
|
+
// get all answers
|
|
881
|
+
const questionResults = filteredResults.length ? filteredResults.reduce((prev, curr) => {
|
|
882
|
+
if (curr.responses) {
|
|
883
|
+
prev.push(...curr.responses.filter((y) => {
|
|
884
|
+
return y !== undefined;
|
|
885
|
+
}).map((y) => {
|
|
886
|
+
return y;
|
|
887
|
+
}));
|
|
888
|
+
}
|
|
889
|
+
return prev;
|
|
890
|
+
}, []) : [];
|
|
891
|
+
|
|
892
|
+
avg.questionsAvg = questionResults.length ? math.mean(questionResults) : 0;
|
|
893
|
+
return avg;
|
|
706
894
|
}}, (_applyDecoratedDescriptor(_class2, "getCurrent", [_dec2], Object.getOwnPropertyDescriptor(_class2, "getCurrent"), _class2), _applyDecoratedDescriptor(_class2.prototype, "getForm", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "getForm"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getResults", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "getResults"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getAccessTokens", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "getAccessTokens"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getFormAttributes", [_dec6], Object.getOwnPropertyDescriptor(_class2.prototype, "getFormAttributes"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "getFormAttributesSummary", [_dec7], Object.getOwnPropertyDescriptor(_class2.prototype, "getFormAttributesSummary"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "evaluate", [_dec8, _dec9], Object.getOwnPropertyDescriptor(_class2.prototype, "evaluate"), _class2.prototype)), _class2)) || _class);
|
|
707
895
|
|
|
708
896
|
module.exports = EvaluationEvent;
|