feat(exam-correct): work on delete

This commit is contained in:
Sarah Vaupel 2020-02-07 19:03:27 +01:00
parent c8edbb395b
commit 014036e4e3
7 changed files with 49 additions and 14 deletions

View File

@ -5,7 +5,7 @@ const CHECKBOX_SELECTOR = '[type="checkbox"]';
const CHECK_ALL_INITIALIZED_CLASS = 'check-all--initialized'; const CHECK_ALL_INITIALIZED_CLASS = 'check-all--initialized';
@Utility({ @Utility({
selector: 'table', selector: 'table:not([uw-no-check-all])',
}) })
export class CheckAll { export class CheckAll {

View File

@ -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) // abort send if there are no results (after validation)
if (Object.keys(results).length <= 0) return; if (Object.keys(results).length <= 0) return;
@ -198,6 +200,8 @@ export class ExamCorrect {
results: results, results: results,
status: STATUS.LOADING, status: STATUS.LOADING,
}; };
if (results) rowInfo.results = results;
if (result) rowInfo.result = result === 'delete' ? null : result;
this._addRow(rowInfo); this._addRow(rowInfo);
// clear inputs on validation success // clear inputs on validation success
@ -206,8 +210,11 @@ export class ExamCorrect {
const body = { const body = {
user: userId || user, 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({ this._app.httpClient.post({
url: EXAM_CORRECT_URL_POST, url: EXAM_CORRECT_URL_POST,
@ -216,13 +223,13 @@ export class ExamCorrect {
}).then( }).then(
(response) => response.json() (response) => response.json()
).then( ).then(
(response) => this._processResponse(body, response, user, results) (response) => this._processResponse(body, response, user, undefined, { results: results, result: result })
).catch((error) => { ).catch((error) => {
console.error('Error while processing response', error); console.error('Error while processing response', error);
}); });
} }
_processResponse(request, response, user, results, targetRow) { _processResponse(request, response, user, targetRow, ...results) {
if (response) { if (response) {
if (response.status === 'no-op') { if (response.status === 'no-op') {
if (response.users) { if (response.users) {
@ -279,6 +286,7 @@ export class ExamCorrect {
let newEntry = { let newEntry = {
users: null, users: null,
results: null, results: null,
result: null,
status: STATUS.FAILURE, status: STATUS.FAILURE,
message: null, message: null,
date: null, date: null,
@ -304,6 +312,7 @@ export class ExamCorrect {
timeElem.classList.remove('exam-correct--local-time'); timeElem.classList.remove('exam-correct--local-time');
newEntry.users = [response.user]; newEntry.users = [response.user];
newEntry.results = response.results; newEntry.results = response.results;
newEntry.result = response.grade;
} }
// TODO set edit button visibility // TODO set edit button visibility
break; break;
@ -313,7 +322,8 @@ export class ExamCorrect {
if (response.users) { if (response.users) {
userElem = this._showUserList(row, response.users, results); userElem = this._showUserList(row, response.users, results);
newEntry.users = response.users; newEntry.users = response.users;
newEntry.results = results; newEntry.results = results.partResults;
newEntry.result = results.result;
} }
newEntry.message = response.message || null; newEntry.message = response.message || null;
break; break;
@ -322,6 +332,7 @@ export class ExamCorrect {
newEntry.users = (response.user && [response.user]) || null; newEntry.users = (response.user && [response.user]) || null;
newEntry.results = results; newEntry.results = results;
newEntry.message = response.message || null; newEntry.message = response.message || null;
newEntry.result = results.result;
break; break;
default: default:
// TODO show tooltip with 'invalid response' // TODO show tooltip with 'invalid response'
@ -418,7 +429,8 @@ export class ExamCorrect {
const body = { const body = {
user: listItem.getAttribute(EXAM_CORRECT_USER_ATTR), user: listItem.getAttribute(EXAM_CORRECT_USER_ATTR),
results: results, results: results.partResults,
grade: results.result,
}; };
this._app.httpClient.post({ this._app.httpClient.post({
@ -427,10 +439,8 @@ export class ExamCorrect {
body: JSON.stringify(body), body: JSON.stringify(body),
}).then( }).then(
(response) => response.json() (response) => response.json()
).then((response) => this._processResponse(body, response, userElem.getAttribute(EXAM_CORRECT_USER_ATTR), results, row) ).then((response) => this._processResponse(body, response, userElem.getAttribute(EXAM_CORRECT_USER_ATTR), row, { results: results.partResults, result: results.result })
).catch((error) => { ).catch(console.error);
console.error(error);
});
} }
_addRow(rowInfo) { _addRow(rowInfo) {
@ -458,7 +468,7 @@ export class ExamCorrect {
userCell.innerHTML = userToHTML(user); userCell.innerHTML = userToHTML(user);
userCell.setAttribute(EXAM_CORRECT_USER_ATTR, user); userCell.setAttribute(EXAM_CORRECT_USER_ATTR, user);
} else { } 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); 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'); const statusCell = document.createElement('TD');
statusCell.classList.add(EXAM_CORRECT_STATUS_CELL_CLASS); statusCell.classList.add(EXAM_CORRECT_STATUS_CELL_CLASS);
const statusSymbol = document.createElement('I'); const statusSymbol = document.createElement('I');

View File

@ -10,13 +10,26 @@ table[uw-exam-correct]
th.uw-exam-correct--user-cell, td.uw-exam-correct--user-cell th.uw-exam-correct--user-cell, td.uw-exam-correct--user-cell
min-width: 200px min-width: 200px
th.uw-exam-correct--part-cell, td.uw-exam-correct--part-cell th.uw-exam-correct--part-cell, td.uw-exam-correct--part-cell
width: 85px width: min-content
text-align: center text-align: center
white-space: nowrap
input input
width: 70px width: 70px
padding: 4px 8px 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 td#uw-exam-correct__result
width: min-content width: min-content
select select

View File

@ -1399,6 +1399,7 @@ ExamRegistrationInviteHeading examn@ExamName: Einladung zum Teilnehmer für #{ex
ExamRegistrationInviteExplanation: Sie wurden eingeladen, Prüfungsteilnehmer zu sein. ExamRegistrationInviteExplanation: Sie wurden eingeladen, Prüfungsteilnehmer zu sein.
ExamCorrectHeading examname@Text: Prüfungsergebnisse für #{examname} eintragen ExamCorrectHeading examname@Text: Prüfungsergebnisse für #{examname} eintragen
ExamCorrectExamResultDelete: Prüfungsergebnis löschen
ExamCorrectHeadDate: Zeit ExamCorrectHeadDate: Zeit
ExamCorrectHeadParticipant: Teilnehmer ExamCorrectHeadParticipant: Teilnehmer

View File

@ -1411,6 +1411,8 @@ ExamCorrectErrorNoMatchingParticipants: This identifier does not match on any ex
ExamCorrectErrorPartResultOutOfBounds examPartNumber: Exam part result for #{examPartNumber} ist not greater zero. 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}. 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} SubmissionUserInvitationAccepted shn: You now participate in a submission for #{shn}
SubmissionUserInvitationDeclined shn: You have declined the invitation to 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} SubmissionUserInviteHeading shn: Invitation to participate in a submission for #{shn}

View File

@ -121,7 +121,6 @@
"core-js": "^3.4.8", "core-js": "^3.4.8",
"js-cookie": "^2.2.1", "js-cookie": "^2.2.1",
"lodash.throttle": "^4.1.1", "lodash.throttle": "^4.1.1",
"js-cookie": "^2.2.1",
"moment": "^2.24.0", "moment": "^2.24.0",
"npm": "^6.13.7", "npm": "^6.13.7",
"sodium-javascript": "^0.5.5", "sodium-javascript": "^0.5.5",

View File

@ -4,7 +4,7 @@ $newline never
<section> <section>
<div uw-hide-columns="exam-correct" .scrolltable .scrolltable--bordered> <div uw-hide-columns="exam-correct" .scrolltable .scrolltable--bordered>
<table .table .table--striped .table--hover uw-exam-correct=#{toPathPiece examCorrectIdent} uw-sort-table=exam-correct-#{toPathPiece examCorrectIdent}> <table .table .table--striped .table--hover uw-exam-correct=#{toPathPiece examCorrectIdent} uw-sort-table=exam-correct-#{toPathPiece examCorrectIdent} uw-no-check-all>
<thead> <thead>
<tr .table__row .table__row--head> <tr .table__row .table__row--head>
<th .table__th .uw-exam-correct--date-cell uw-exam-correct-header="date" uw-hide-column-header="date"> <th .table__th .uw-exam-correct--date-cell uw-exam-correct-header="date" uw-hide-column-header="date">
@ -29,6 +29,8 @@ $newline never
$forall ExamPart{examPartNumber} <- examParts $forall ExamPart{examPartNumber} <- examParts
<td .table__td .uw-exam-correct--part-cell> <td .table__td .uw-exam-correct--part-cell>
^{ptsInput examPartNumber} ^{ptsInput examPartNumber}
<input #exam-correct__#{examPartNumber}--delete type="checkbox" style="display:none" uw-no-checkbox .uw-exam-correct--delete-exam-part>
<label for=exam-correct__#{examPartNumber}--delete .fas .fa-fw .fa-trash>
$if mayEditResults $if mayEditResults
<td .table__td #uw-exam-correct__result> <td .table__td #uw-exam-correct__result>
<select> <select>
@ -46,6 +48,8 @@ $newline never
_{MsgExamResultVoided} _{MsgExamResultVoided}
<option> <option>
_{MsgExamResultNoShow} _{MsgExamResultNoShow}
<option value="delete">
_{MsgExamCorrectExamResultDelete}
<td .table__td #uw-exam-correct__result__grade> <td .table__td #uw-exam-correct__result__grade>
<select> <select>
$forall grade <- (toPathPiece <$> examGrades) $forall grade <- (toPathPiece <$> examGrades)