From e4dbb21c1de84f8006204044fc8e5cc3c511b1ff Mon Sep 17 00:00:00 2001 From: Jim Laney Date: Tue, 20 Aug 2024 16:35:00 -0700 Subject: [PATCH] save grades --- .../components/graderoster/grade/input.vue | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/course_grader_vue/components/graderoster/grade/input.vue b/course_grader_vue/components/graderoster/grade/input.vue index 3eb381d..5581320 100644 --- a/course_grader_vue/components/graderoster/grade/input.vue +++ b/course_grader_vue/components/graderoster/grade/input.vue @@ -143,6 +143,7 @@ export default { writing: false, gradeError: "", menuOpen: false, + inprogress_save: false, }; }, computed: { @@ -213,7 +214,6 @@ export default { this.menuOpen = false; }, initializeGrade: function () { - this.updateGradeChoices(); if (this.student.allows_incomplete) { this.incomplete = this.student.has_incomplete; } @@ -224,20 +224,56 @@ export default { this.grade = gettext("x_no_grade_now"); } else if ( this.student.grade === null && - !this.student.has_incomplete && + !this.has_incomplete && this.gradeChoices.includes("N") ) { this.grade = "N"; } else if (this.student.grade !== null) { this.grade = this.student.grade; } + this.updateGradeChoices(); this.gradeError = validateGrade( this.grade, this.incomplete, this.actualChoices ); }, - saveGrade: function () {}, + saveGrade: function () { + var put_data = { + student_id: this.student.student_id, + is_incomplete: this.incomplete, + is_writing: this.writing, + grade: this.grade, + no_grade_now: this.grade === gettext("x_no_grade_now"), + }; + + // Prevent duplicate PATCH requests + if (!this.inprogress_save) { + this.inprogress_save = true; + + this.updateGrade(this.student.grade_url, put_data) + .then((response) => { + return response.data; + }) + .then((data) => { + this.grade = data.grade; + this.incomplete = data.is_incomplete; + this.is_writing = data.is_writing; + this.gradeError = validateGrade( + this.grade, + this.incomplete, + this.actualChoices + ); + }) + .catch((error) => { + console.log(error.message); + this.gradeError = error.message; + }) + .finally(() => { + this.inprogress_save = false; + }); + } + }, }, created() { this.initializeGrade();