Skip to content

Commit

Permalink
Merge pull request #470 from uw-it-aca/fix/grade-input
Browse files Browse the repository at this point in the history
Insert chosen grade into grade text input.
  • Loading branch information
jlaney authored Aug 14, 2024
2 parents 285648c + 295c40f commit f342644
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
48 changes: 30 additions & 18 deletions course_grader_vue/components/graderoster/grade/input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@
:id="`grade-${student.item_id}`"
:value="grade"
:disabled="student.is_submitted"
:placeholder="[
incomplete ? 'Enter default grade...' : 'Enter grade...',
]"
:placeholder="gradePlaceholder"
data-bs-toggle="dropdown"
@input="gradeChanged($event.target.value)"
@change="gradeChanged($event.target.value)"
/>
<ul class="dropdown-menu m-0 small overflow-y-auto" style="max-height: 400px;">
<li v-for="g in choices"><a class="dropdown-item small" type="button">{{ g }}</a></li>
<li v-for="opt in actualChoices">
<button
class="dropdown-item small"
type="button"
:value="opt"
@click="gradeChanged(opt)">{{ opt }}</button>
</li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -91,14 +95,18 @@
</span>
</span>
<span role="alert" class="text-danger invalid-grade small">
{{ errorText }}
{{ gradeError }}
</span>
</div>
</template>

<script>
import { updateGrade } from "@/utils/data";
import { normalizeGrade, validateGrade } from "@/utils/grade";
import {
incompleteBlocklist,
normalizeGrade,
validateGrade,
} from "@/utils/grade";
export default {
props: {
Expand All @@ -118,15 +126,17 @@ export default {
},
data() {
return {
incompleteBlocklist: [gettext("x_no_grade_now"), "N", "CR"],
choices: [],
grade: null,
actualChoices: [],
grade: "",
incomplete: false,
writing: false,
errorText: null,
gradeError: "",
};
},
computed: {
gradePlaceholder() {
return this.incomplete ? 'Enter default grade...' : 'Enter grade...';
},
inputIncompleteTitle() {
return this.student.allows_incomplete
? ""
Expand Down Expand Up @@ -156,26 +166,27 @@ export default {
? gettext("x_no_grade_now")
: this.gradeChoices[i];
if (this.incomplete && this.incompleteBlocklist.includes(grade)) {
if (this.incomplete && incompleteBlocklist.includes(grade)) {
continue;
}
valid.push(grade);
}
this.choices = valid;
this.actualChoices = valid;
},
incompleteChanged: function (checked) {
this.incomplete = checked;
this.updateGradeChoices();
this.errorText = validateGrade(
this.grade, this.incomplete, this.choices, this.incompleteBlocklist);
this.gradeError = validateGrade(this.grade, this.incomplete, this.actualChoices);
this.saveGrade();
},
writingChanged: function (checked) {
this.writing = checked;
this.saveGrade();
},
gradeChanged: function (value) {
this.grade = normalizeGrade(value);
this.errorText = validateGrade(
this.grade, this.incomplete, this.choices, this.incompleteBlocklist);
this.gradeError = validateGrade(this.grade, this.incomplete, this.actualChoices);
this.saveGrade();
},
initializeGrade: function () {
this.updateGradeChoices();
Expand All @@ -193,9 +204,10 @@ export default {
this.gradeChoices.includes("N")
) {
this.grade = "N";
} else {
} else if (this.student.grade !== null) {
this.grade = this.student.grade;
}
this.gradeError = validateGrade(this.grade, this.incomplete, this.actualChoices);
},
saveGrade: function () {},
},
Expand Down
7 changes: 6 additions & 1 deletion course_grader_vue/utils/grade.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const incompleteBlocklist = [gettext("x_no_grade_now"), "N", "CR"];

function normalizeGrade(grade) {
grade = grade.trim();
if (grade.match(/^(?:n|nc|p|h|hw|f|hp|i|cr)$/i)) {
Expand All @@ -12,7 +14,7 @@ function normalizeGrade(grade) {
return grade;
}

function validateGrade(grade, incomplete, choices, incompleteBlocklist) {
function validateGrade(grade, incomplete, choices) {
var is_hypenated,
is_cnc,
is_hhppf,
Expand Down Expand Up @@ -86,10 +88,13 @@ function validateGrade(grade, incomplete, choices, incompleteBlocklist) {
} else if (is_hhppf) {
// H/HP/P/F
return gettext("grade_invalid_H_HP_P_F");
} else {
return "Enter a valid grade";
}
}

export {
incompleteBlocklist,
normalizeGrade,
validateGrade,
};

0 comments on commit f342644

Please sign in to comment.