[M] Move course filtering to course-utils.ts
This commit is contained in:
@@ -2,6 +2,7 @@ import {Component, Prop, Vue} from 'vue-property-decorator';
|
|||||||
import GraphOverall from '@/pages/overall/graph-overall/graph-overall';
|
import GraphOverall from '@/pages/overall/graph-overall/graph-overall';
|
||||||
import {Course} from '@/components/app/app';
|
import {Course} from '@/components/app/app';
|
||||||
import {GPAUtils} from '@/utils/gpa-utils';
|
import {GPAUtils} from '@/utils/gpa-utils';
|
||||||
|
import {CourseUtils} from '@/utils/course-utils';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {GraphOverall}
|
components: {GraphOverall}
|
||||||
@@ -20,7 +21,7 @@ export default class Overall extends Vue
|
|||||||
if (this.courses == null) return [];
|
if (this.courses == null) return [];
|
||||||
|
|
||||||
// Filter it
|
// Filter it
|
||||||
let courses: Course[] = this.filterCourses();
|
let courses: Course[] = CourseUtils.getGradedCourses(this.courses);
|
||||||
|
|
||||||
// Compute the column names
|
// Compute the column names
|
||||||
let columns = ['date'];
|
let columns = ['date'];
|
||||||
@@ -108,33 +109,6 @@ export default class Overall extends Vue
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a list of courses that are graphed
|
|
||||||
*/
|
|
||||||
private filterCourses(): Course[]
|
|
||||||
{
|
|
||||||
// Define result
|
|
||||||
let result: Course[] = [];
|
|
||||||
|
|
||||||
// Filter through courses
|
|
||||||
this.courses.forEach(course =>
|
|
||||||
{
|
|
||||||
// Skip future or past courses
|
|
||||||
if (course.status != 'active') return;
|
|
||||||
|
|
||||||
// Skip courses without levels
|
|
||||||
if (course.level == 'None') return;
|
|
||||||
|
|
||||||
// Skip courses without assignments
|
|
||||||
if (course.assignments.length == 0) return;
|
|
||||||
|
|
||||||
// Add it to the list
|
|
||||||
result.push(course);
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is called to get gpa since I can't import another
|
* This function is called to get gpa since I can't import another
|
||||||
* class in the Vue file.
|
* class in the Vue file.
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import {Course} from '@/components/app/app';
|
||||||
|
|
||||||
|
export class CourseUtils
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Return a list of courses that are graphed
|
||||||
|
*
|
||||||
|
* @param original Original course list
|
||||||
|
* @return Course[] Filtered course list
|
||||||
|
*/
|
||||||
|
public static getGradedCourses(original: Course[]): Course[]
|
||||||
|
{
|
||||||
|
// Define result
|
||||||
|
let result: Course[] = [];
|
||||||
|
|
||||||
|
// Filter through courses
|
||||||
|
original.forEach(course =>
|
||||||
|
{
|
||||||
|
// Skip future or past courses
|
||||||
|
if (course.status != 'active') return;
|
||||||
|
|
||||||
|
// Skip courses without levels
|
||||||
|
if (course.level == 'None') return;
|
||||||
|
|
||||||
|
// Skip courses without assignments
|
||||||
|
if (course.assignments.length == 0) return;
|
||||||
|
|
||||||
|
// Add it to the list
|
||||||
|
result.push(course);
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user