Skip to content
Snippets Groups Projects
degree-planner.component.ts 3.34 KiB
Newer Older
import { Component } from '@angular/core';

import { DataService } from '../core/data.service';
import { DegreePlan } from '../core/models/degree-plan';
import { Term } from '../core/models/term';
Paulina Nogal's avatar
Paulina Nogal committed
import { Note } from '../core/models/note';
jvanboxtel@wisc.edu's avatar
jvanboxtel@wisc.edu committed

@Component({
Joe Van Boxtel's avatar
Joe Van Boxtel committed
	selector: 'cse-degree-planner',
jvanboxtel@wisc.edu's avatar
jvanboxtel@wisc.edu committed
	templateUrl: './degree-planner.component.html',
	styleUrls: ['./degree-planner.component.scss']
jvanboxtel@wisc.edu's avatar
jvanboxtel@wisc.edu committed
})
export class DegreePlannerComponent {
	degreePlans: DegreePlan[];
	degreePlanCourses: any[];
	selectedDegreePlan: number;
	terms: Term[];
	termsByAcademicYear: Object;
	subjectsMap: Object;
Paulina Nogal's avatar
Paulina Nogal committed
	notes: Note[];
	firstCurrentTerm: null|string;

jvanboxtel@wisc.edu's avatar
jvanboxtel@wisc.edu committed

	constructor(private dataService: DataService) {
		this.firstCurrentTerm = null;

		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;
					}
jvanboxtel@wisc.edu's avatar
jvanboxtel@wisc.edu committed

				// 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);
				}
			});
		this.dataService.getSubjectsMap()
		.subscribe( subjectsMap => {
			this.subjectsMap = subjectsMap;
		});

		this.dataService.getTerms()
		.subscribe(terms => {});
	// 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) {
		}

		for ( const term of this.degreePlanCourses ) {
			if (term.termCode === termCode) {
				return term.courses;
			}
		}
	getTermDropZone() {
		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);
		return termCodes;
	}

jvanboxtel@wisc.edu's avatar
jvanboxtel@wisc.edu committed
}