From 014036e4e31f17267e0ad2c82faff163f6064d6c Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Fri, 7 Feb 2020 19:03:27 +0100 Subject: [PATCH] feat(exam-correct): work on delete --- frontend/src/utils/check-all/check-all.js | 2 +- .../src/utils/exam-correct/exam-correct.js | 36 +++++++++++++------ .../src/utils/exam-correct/exam-correct.sass | 15 +++++++- messages/uniworx/de-de-formal.msg | 1 + messages/uniworx/en-eu.msg | 2 ++ package.json | 1 - templates/exam-correct.hamlet | 6 +++- 7 files changed, 49 insertions(+), 14 deletions(-) diff --git a/frontend/src/utils/check-all/check-all.js b/frontend/src/utils/check-all/check-all.js index d196aae51..7922cd3ee 100644 --- a/frontend/src/utils/check-all/check-all.js +++ b/frontend/src/utils/check-all/check-all.js @@ -5,7 +5,7 @@ const CHECKBOX_SELECTOR = '[type="checkbox"]'; const CHECK_ALL_INITIALIZED_CLASS = 'check-all--initialized'; @Utility({ - selector: 'table', + selector: 'table:not([uw-no-check-all])', }) export class CheckAll { diff --git a/frontend/src/utils/exam-correct/exam-correct.js b/frontend/src/utils/exam-correct/exam-correct.js index 2fa50a3bb..5a7ffc9ca 100644 --- a/frontend/src/utils/exam-correct/exam-correct.js +++ b/frontend/src/utils/exam-correct/exam-correct.js @@ -190,6 +190,8 @@ export class ExamCorrect { } } + const result = this._resultSelect.value !== 'none' && this._resultSelect.value; + // abort send if there are no results (after validation) if (Object.keys(results).length <= 0) return; @@ -198,6 +200,8 @@ export class ExamCorrect { results: results, status: STATUS.LOADING, }; + if (results) rowInfo.results = results; + if (result) rowInfo.result = result === 'delete' ? null : result; this._addRow(rowInfo); // clear inputs on validation success @@ -206,8 +210,11 @@ export class ExamCorrect { const body = { user: userId || user, - results: results, }; + if (results) body.results = results; + if (result) body.grade = result === 'result' ? this._resultGradeSelect.value : (result === 'delete' ? null : result); + + console.log('request body', body); this._app.httpClient.post({ url: EXAM_CORRECT_URL_POST, @@ -216,13 +223,13 @@ export class ExamCorrect { }).then( (response) => response.json() ).then( - (response) => this._processResponse(body, response, user, results) + (response) => this._processResponse(body, response, user, undefined, { results: results, result: result }) ).catch((error) => { console.error('Error while processing response', error); }); } - _processResponse(request, response, user, results, targetRow) { + _processResponse(request, response, user, targetRow, ...results) { if (response) { if (response.status === 'no-op') { if (response.users) { @@ -279,6 +286,7 @@ export class ExamCorrect { let newEntry = { users: null, results: null, + result: null, status: STATUS.FAILURE, message: null, date: null, @@ -304,6 +312,7 @@ export class ExamCorrect { timeElem.classList.remove('exam-correct--local-time'); newEntry.users = [response.user]; newEntry.results = response.results; + newEntry.result = response.grade; } // TODO set edit button visibility break; @@ -313,7 +322,8 @@ export class ExamCorrect { if (response.users) { userElem = this._showUserList(row, response.users, results); newEntry.users = response.users; - newEntry.results = results; + newEntry.results = results.partResults; + newEntry.result = results.result; } newEntry.message = response.message || null; break; @@ -322,6 +332,7 @@ export class ExamCorrect { newEntry.users = (response.user && [response.user]) || null; newEntry.results = results; newEntry.message = response.message || null; + newEntry.result = results.result; break; default: // TODO show tooltip with 'invalid response' @@ -418,7 +429,8 @@ export class ExamCorrect { const body = { user: listItem.getAttribute(EXAM_CORRECT_USER_ATTR), - results: results, + results: results.partResults, + grade: results.result, }; this._app.httpClient.post({ @@ -427,10 +439,8 @@ export class ExamCorrect { body: JSON.stringify(body), }).then( (response) => response.json() - ).then((response) => this._processResponse(body, response, userElem.getAttribute(EXAM_CORRECT_USER_ATTR), results, row) - ).catch((error) => { - console.error(error); - }); + ).then((response) => this._processResponse(body, response, userElem.getAttribute(EXAM_CORRECT_USER_ATTR), row, { results: results.partResults, result: results.result }) + ).catch(console.error); } _addRow(rowInfo) { @@ -458,7 +468,7 @@ export class ExamCorrect { userCell.innerHTML = userToHTML(user); userCell.setAttribute(EXAM_CORRECT_USER_ATTR, user); } else { - userCell = this._showUserList(newRow, rowInfo.users, rowInfo.results); + userCell = this._showUserList(newRow, rowInfo.users, { partResults: rowInfo.results, result: rowInfo.result }); } cells.set(this._cIndices.get('user'), userCell); @@ -474,6 +484,12 @@ export class ExamCorrect { } } + const resultCell = document.createElement('TD'); + resultCell.colSpan = 2; + if (rowInfo.result) + resultCell.innerHTML = rowInfo.result; + cells.set(this._cIndices.get('result'), resultCell); + const statusCell = document.createElement('TD'); statusCell.classList.add(EXAM_CORRECT_STATUS_CELL_CLASS); const statusSymbol = document.createElement('I'); diff --git a/frontend/src/utils/exam-correct/exam-correct.sass b/frontend/src/utils/exam-correct/exam-correct.sass index ed764623d..9b5d3658a 100644 --- a/frontend/src/utils/exam-correct/exam-correct.sass +++ b/frontend/src/utils/exam-correct/exam-correct.sass @@ -10,13 +10,26 @@ table[uw-exam-correct] th.uw-exam-correct--user-cell, td.uw-exam-correct--user-cell min-width: 200px + th.uw-exam-correct--part-cell, td.uw-exam-correct--part-cell - width: 85px + width: min-content text-align: center + white-space: nowrap + input width: 70px padding: 4px 8px + .uw-exam-correct--delete-exam-part ~ .fa-trash + opacity: .5 + cursor: pointer + margin-left: 5px + .uw-exam-correct--delete-exam-part ~ .fa-trash:hover + opacity: 1 + .uw-exam-correct--delete-exam-part:checked ~ .fa-trash + opacity: 1 + color: var(--color-error) + td#uw-exam-correct__result width: min-content select diff --git a/messages/uniworx/de-de-formal.msg b/messages/uniworx/de-de-formal.msg index 6d7a40635..e79cff87f 100644 --- a/messages/uniworx/de-de-formal.msg +++ b/messages/uniworx/de-de-formal.msg @@ -1399,6 +1399,7 @@ ExamRegistrationInviteHeading examn@ExamName: Einladung zum Teilnehmer für #{ex ExamRegistrationInviteExplanation: Sie wurden eingeladen, Prüfungsteilnehmer zu sein. ExamCorrectHeading examname@Text: Prüfungsergebnisse für #{examname} eintragen +ExamCorrectExamResultDelete: Prüfungsergebnis löschen ExamCorrectHeadDate: Zeit ExamCorrectHeadParticipant: Teilnehmer diff --git a/messages/uniworx/en-eu.msg b/messages/uniworx/en-eu.msg index 12f3e62eb..8f829c850 100644 --- a/messages/uniworx/en-eu.msg +++ b/messages/uniworx/en-eu.msg @@ -1411,6 +1411,8 @@ ExamCorrectErrorNoMatchingParticipants: This identifier does not match on any ex ExamCorrectErrorPartResultOutOfBounds examPartNumber: Exam part result for #{examPartNumber} ist not greater zero. ExamCorrectErrorPartResultOutOfBoundsMax examPartNumber maxPoints: Exam part result for #{examPartNumber} is not between 0 and #{maxPoints}. +ExamCorrectExamResultDelete: Delete exam result + SubmissionUserInvitationAccepted shn: You now participate in a submission for #{shn} SubmissionUserInvitationDeclined shn: You have declined the invitation to participate in a submission for #{shn} SubmissionUserInviteHeading shn: Invitation to participate in a submission for #{shn} diff --git a/package.json b/package.json index 9b6947436..43d4d1d47 100644 --- a/package.json +++ b/package.json @@ -121,7 +121,6 @@ "core-js": "^3.4.8", "js-cookie": "^2.2.1", "lodash.throttle": "^4.1.1", - "js-cookie": "^2.2.1", "moment": "^2.24.0", "npm": "^6.13.7", "sodium-javascript": "^0.5.5", diff --git a/templates/exam-correct.hamlet b/templates/exam-correct.hamlet index 9a664561d..024de4247 100644 --- a/templates/exam-correct.hamlet +++ b/templates/exam-correct.hamlet @@ -4,7 +4,7 @@ $newline never
- +
@@ -29,6 +29,8 @@ $newline never $forall ExamPart{examPartNumber} <- examParts ^{ptsInput examPartNumber} + +