Newer
Older
import { Component } from '@angular/core';
pnogal
committed
import { DataService } from '../core/data.service';
import { DegreePlan } from '../core/models/degree-plan';
import { Term } from '../core/models/term';
import { log } from 'util';
styleUrls: ['./degree-planner.component.scss']
export class DegreePlannerComponent {
degreePlans: DegreePlan[];
selectedDegreePlan: number;
constructor(private dataService: DataService) {
this.dataService.getDegreePlans()
.subscribe(data => {
this.degreePlans = data;
this.selectedDegreePlan = this.degreePlans[0].roadmapId;
});
this.dataService.getDegreePlannerCourseData()
.subscribe(degreePlanCourses => {
this.degreePlanCourses = degreePlanCourses;
if (this.termsByAcademicYear) {
this.updateCourses();
}
this.dataService.getTerms()
.subscribe(terms => {
this.terms = terms;
// Create an empty object to store term data in
// Loop through each term
// Get the 3 digit year code and 1 digit term code
const year = term.termCode.substring(0, 3);
const termCode = term.termCode.substring(3);
// If this year does not exsist in the "termsByAcademicYear" create a new year
// This year has placeholder data for each term in the year
if (!this.termsByAcademicYear[year]) {
this.termsByAcademicYear[year] = {
year: year,
terms: {
2: { termCode: `${year}2`, courses: []},
4: { termCode: `${year}4`, courses: []},
6: { termCode: `${year}6`, courses: []}
// Overwrite the default term with the current term
this.termsByAcademicYear[year].terms[termCode] = {...term, courses: []};
if (this.degreePlanCourses) {
this.updateCourses();
}
pnogal
committed
}
updateCourses() {
for (const term of this.degreePlanCourses) {
// console.log(term);
const yearCode = term.termCode.substring(0, 3);
const termCode = term.termCode.substring(3);
if (this.termsByAcademicYear[yearCode] && this.termsByAcademicYear[yearCode].terms[termCode]) {
this.termsByAcademicYear[yearCode].terms[termCode].courses = term.courses;
}
}
}
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.termCode);
}
}
}
}