[M] Move loadAssignments to course

This commit is contained in:
Hykilpikonna
2019-11-06 18:13:24 -05:00
parent 1e91cec8d2
commit 6f5c4f3a09
2 changed files with 44 additions and 33 deletions
+1 -32
View File
@@ -150,38 +150,7 @@ export default class App extends Vue
// Check success
if (response.success)
{
// Load assignments
// Parse json and filter it
course.assignments = JsonUtils.filterAssignments(response.data);
// Sort by date (Latest is at 0)
course.assignments.sort((a, b) => b.date.getTime() - a.date.getTime());
// Filter assignments into terms
let termAssignments: Assignment[][] = [[], [], [], []];
let currentTerm = 0;
// Loop through it by time order
for (let i = course.assignments.length - 1; i >= 0; i--)
{
let a = course.assignments[i];
// On to the next term
if (currentTerm < 3 && a.date > Constants.TERMS[currentTerm + 1])
{
currentTerm ++;
// Check again
i++;
continue;
}
// Push data
termAssignments[currentTerm].push(a);
}
// Set computed data
course.computed = {termAssignments: termAssignments, allYearGrade: -1};
course.loadAssignments(response.data);
}
else throw new Error(response.data);
})
+43 -1
View File
@@ -1,4 +1,6 @@
import {Assignment} from '@/components/app/app';
import JsonUtils from '@/utils/json-utils';
import Constants from '@/constants';
export default class Course
{
@@ -39,7 +41,6 @@ export default class Course
this.name = courseJson.name;
this.teacherName = courseJson.teacherName;
this.status = courseJson.status;
this.assignments = courseJson.assignments;
this.letterGrade = courseJson.letterGrade;
this.numericGrade = courseJson.numericGrade;
@@ -49,4 +50,45 @@ export default class Course
this.grading = courseJson.grading;
}
/**
* Load in assignments data
*
* @param data Assignments data
*/
loadAssignments(data: any)
{
// Load assignments
// Parse json and filter it
this.assignments = JsonUtils.filterAssignments(data);
// Sort by date (Latest is at 0)
this.assignments.sort((a, b) => b.date.getTime() - a.date.getTime());
// Filter assignments into terms
let termAssignments: Assignment[][] = [[], [], [], []];
let currentTerm = 0;
// Loop through it by time order
for (let i = this.assignments.length - 1; i >= 0; i--)
{
let a = this.assignments[i];
// On to the next term
if (currentTerm < 3 && a.date > Constants.TERMS[currentTerm + 1])
{
currentTerm ++;
// Check again
i++;
continue;
}
// Push data
termAssignments[currentTerm].push(a);
}
// Set computed data
this.computed = {termAssignments: termAssignments, allYearGrade: -1};
}
}