Newer
Older
import { Observable } from 'rxjs';
import { groupBy, reduce, toArray, mergeMap, flatMap, tap, switchMap, mergeAll, map, first} from 'rxjs/operators';
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
pnogal
committed
import { DataService } from '../core/data.service';
import { DegreePlan } from '../core/models/degree-plan';
import { DegreePlannerDataService } from './../core/service/degree-planner-data.service';
import { MediaMatcher } from '@angular/cdk/layout';
import { FavoriteCourse } from '../core/models/favorite-course';
styleUrls: ['./degree-planner.component.scss']
export class DegreePlannerComponent {
degreePlans: DegreePlan[];
selectedDegreePlan: number;
notes$: Observable<Note[]>;
firstCurrentTerm: null|string;
favoriteCourses: FavoriteCourse[];
termCodes$: any;
constructor(
private degreePlannerDataSvc: DegreePlannerDataService,
private dataService: DataService,
private route: ActivatedRoute,
public mediaMatcher: MediaMatcher
) {
this.firstCurrentTerm = null;
this.mobileView = mediaMatcher.matchMedia('(max-width: 900px)');
this.degreePlans = route.snapshot.data.requiredData.degreePlans;
this.selectedDegreePlan = this.degreePlans[0].roadmapId;
this.coursesData$ = this.degreePlannerDataSvc.getDegreePlanDataById(this.selectedDegreePlan);
this.degreePlannerDataSvc.getAllNotes().subscribe(notes => { route.snapshot.data.requiredData.notes = notes; });
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// this.coursesData$.subscribe(x => console.log(x));
// this.dataService.getDegreePlans()
// .subscribe(plans => {
// this.degreePlans = plans;
// this.selectedDegreePlan = this.degreePlans[0].roadmapId;
// this.dataService.getAllPlanData(this.selectedDegreePlan)
// .subscribe(data => {
// // Seperate the data from the forked API calls
// this.degreePlanCourses = data[0];
// this.terms = data[1];
// // Loop over the current terms and determine the current / future terms
// for (const term of this.terms) {
// if (this.firstCurrentTerm === null || parseInt(term.termCode, 10) < parseInt(this.firstCurrentTerm, 10)) {
// this.firstCurrentTerm = term.termCode;
// }
// }
// // Create the global data object
// this.termsByAcademicYear = {};
// // Loop over all the courses, creating a placeholder year if one doesn't exsist
// for (const course of this.degreePlanCourses) {
// // Get the 3 digit year code and 1 digit term code
// const year = course.termCode.substring(0, 3);
// const termCode = course.termCode.substring(3);
// // Create and add a placeholder year to the data object
// if (!this.termsByAcademicYear[year]) {
// this.termsByAcademicYear[year] = this.getYearObject(year);
// }
// // Add the course to the proper year > term
// this.termsByAcademicYear[year].terms[termCode].courses.push(course);
// }
// console.log('termsByAcademicYear', this.termsByAcademicYear);
// });
// });
pnogal
committed
}
// Create a new year object to be used in this.termsByAcademicYear
getYearObject(yearCode) {
const year = {
year: yearCode,
terms: {}
};
for (const termCode of ['2', '4', '6']) {
year.terms[termCode] = {
termCode: `${yearCode}${termCode}`,
courses: [],
pastTerm: (this.firstCurrentTerm && parseInt(this.firstCurrentTerm, 10) > parseInt(`${yearCode}${termCode}`, 10)) ? true : false
};
}
}
getCoursesByTerm(termCode) {
if (!this.degreePlanCourses) {
return [];
}
for ( const term of this.degreePlanCourses ) {
if (term.termCode === termCode) {
return term.courses;
}
}
return [];
if (!this.degreePlanCourses) {
return false;
}
const termCodes = [
'favoriteCourse-dropZone'
];
for (const yearCode in this.termsByAcademicYear) {
if (this.termsByAcademicYear[yearCode]) {
const year = this.termsByAcademicYear[yearCode];
for (const termKey in year.terms) {
if (year.terms[termKey]) {
const term = year.terms[termKey];
termCodes.push('term-' + term.termCode);
}
}
}
}
// console.log(termCodes);