[M] Move loadAssignments to course
This commit is contained in:
@@ -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
@@ -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};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user