From feabc336c1e88041a04c496d7470ed3b47b0ab67 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Tue, 1 Oct 2019 18:29:50 -0400 Subject: [PATCH] [+] Create method to check course gradings --- src/components/app/app.ts | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/components/app/app.ts b/src/components/app/app.ts index a972e82..13b3cdc 100644 --- a/src/components/app/app.ts +++ b/src/components/app/app.ts @@ -7,6 +7,7 @@ import JsonUtils from '@/utils/json-utils'; import pWaitFor from 'p-wait-for'; import {HttpUtils} from '@/utils/http-utils'; import {CourseUtils} from '@/utils/course-utils'; +import {GPAUtils} from '@/utils/gpa-utils'; /** * Objects of this interface represent assignment grades. @@ -184,6 +185,67 @@ export default class App extends Vue return true; } + /** + * Check the courses' grading algorithms. (Total-average or percent-type) + */ + private checkGradingAlgorithms() + { + // Loop through all the courses + for (const course of this.filteredCourses) + { + // Check if total-average grade is the same with percent-type grade + if (course.numericGrade == GPAUtils.getTotalMeanAverage(course)) + { + course.grading.method = 'TOTAL_AVERAGE'; + } + else + { + // Request grading scheme for this course + this.http.post('/grading', {assignments_id: course.assignmentsId}).then(response => + { + // Check success + if (response.success) + { + // Add it to course + course.grading = response.data; + } + else + { + // Show error message TODO: Show it properly + alert(response.data) + } + }) + .catch(alert) + } + } + + // Wait for done + pWaitFor(() => this.isGradingReady()).then(() => + { + // When the assignments are ready + // TODO: Display loading + this.assignmentsReady = true; + }) + } + + /** + * Are grading algorithms ready or not. + * + * @returns boolean Ready or not + */ + private isGradingReady(): boolean + { + for (const course of this.filteredCourses) + { + if (course.grading.method == undefined) + { + return false; + } + } + + return true; + } + /** * This is called when a navigation tab is clicked *