Skip to content

Commit 51871ae

Browse files
Address code review feedback - fix auto-uncheck and add constants
Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
1 parent 74f4ba7 commit 51871ae

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

cadmin/templates/cadmin/homework_submissions.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ <h2>{{ homework.title }} - Submissions</h2>
8383
</div>
8484

8585
<script>
86+
const MISSING_SCORE_VALUE = -999; // Used for sorting when score is missing
87+
8688
function sortTable() {
8789
const table = document.getElementById('submissionsTable');
8890
const tbody = table.querySelector('tbody');
@@ -102,8 +104,8 @@ <h2>{{ homework.title }} - Submissions</h2>
102104
} else if (sortBy === 'score') {
103105
aVal = a.cells[2].textContent.trim();
104106
bVal = b.cells[2].textContent.trim();
105-
aVal = aVal === '-' ? -999 : parseFloat(aVal);
106-
bVal = bVal === '-' ? -999 : parseFloat(bVal);
107+
aVal = aVal === '-' ? MISSING_SCORE_VALUE : parseFloat(aVal);
108+
bVal = bVal === '-' ? MISSING_SCORE_VALUE : parseFloat(bVal);
107109
return bVal - aVal; // Descending
108110
}
109111
return 0;

cadmin/templates/cadmin/project_submission_edit.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,13 @@ <h4>Overall Results</h4>
187187
totalField.value = total;
188188
}
189189

190-
// Auto-check "passed" if total >= passing threshold
191-
if (passedCheckbox && total >= passingThreshold) {
192-
passedCheckbox.checked = true;
190+
// Auto-check or uncheck "passed" based on total score vs passing threshold
191+
if (passedCheckbox) {
192+
if (total >= passingThreshold) {
193+
passedCheckbox.checked = true;
194+
} else {
195+
passedCheckbox.checked = false;
196+
}
193197
}
194198

195199
return total;

cadmin/templates/cadmin/project_submissions.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ <h2>{{ project.title }} - Submissions</h2>
111111
{% endif %}
112112

113113
<script>
114+
const MISSING_SCORE_VALUE = -999; // Used for sorting when score is missing
115+
114116
function copyEmails() {
115117
const emails = [
116118
{% for submission in submissions %}
@@ -155,14 +157,14 @@ <h2>{{ project.title }} - Submissions</h2>
155157
} else if (sortBy === 'project_score') {
156158
aVal = a.cells[2].textContent.trim();
157159
bVal = b.cells[2].textContent.trim();
158-
aVal = aVal === '-' ? -999 : parseFloat(aVal);
159-
bVal = bVal === '-' ? -999 : parseFloat(bVal);
160+
aVal = aVal === '-' ? MISSING_SCORE_VALUE : parseFloat(aVal);
161+
bVal = bVal === '-' ? MISSING_SCORE_VALUE : parseFloat(bVal);
160162
return bVal - aVal; // Descending
161163
} else if (sortBy === 'total_score') {
162164
aVal = a.cells[3].textContent.trim();
163165
bVal = b.cells[3].textContent.trim();
164-
aVal = aVal === '-' ? -999 : parseFloat(aVal);
165-
bVal = bVal === '-' ? -999 : parseFloat(bVal);
166+
aVal = aVal === '-' ? MISSING_SCORE_VALUE : parseFloat(aVal);
167+
bVal = bVal === '-' ? MISSING_SCORE_VALUE : parseFloat(bVal);
166168
return bVal - aVal; // Descending
167169
}
168170
return 0;

0 commit comments

Comments
 (0)