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';
@Utility({
selector: 'table',
selector: 'table:not([uw-no-check-all])',
})
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)
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');

View File

@ -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

View File

@ -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

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.
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}

View File

@ -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",

View File

@ -4,7 +4,7 @@ $newline never
<section>
<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>
<tr .table__row .table__row--head>
<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
<td .table__td .uw-exam-correct--part-cell>
^{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
<td .table__td #uw-exam-correct__result>
<select>
@ -46,6 +48,8 @@ $newline never
_{MsgExamResultVoided}
<option>
_{MsgExamResultNoShow}
<option value="delete">
_{MsgExamCorrectExamResultDelete}
<td .table__td #uw-exam-correct__result__grade>
<select>
$forall grade <- (toPathPiece <$> examGrades)