From 9d0181a8a65df99abe4b5156309714c3aa09e567 Mon Sep 17 00:00:00 2001
From: Scott Berg <saberg3@wisc.edu>
Date: Thu, 8 Nov 2018 11:29:01 -0600
Subject: [PATCH] Update data structure for academic years to include terms
 without courses

---
 .../degree-planner.component.html             |  7 ++++++-
 .../degree-planner.component.ts               | 21 +++++++++++++++----
 .../course-item/course-item.component.html    |  3 +--
 .../course-item/course-item.component.scss    |  9 ++++++++
 .../term-container.component.html             |  2 +-
 .../term-container.component.ts               | 11 ++++++++++
 6 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/src/app/degree-planner/degree-planner.component.html b/src/app/degree-planner/degree-planner.component.html
index 2108de7..f9b34c7 100644
--- a/src/app/degree-planner/degree-planner.component.html
+++ b/src/app/degree-planner/degree-planner.component.html
@@ -32,7 +32,12 @@
 						</mat-panel-title>
 					</mat-expansion-panel-header>
 					<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutAlign="start stretch">
-						<app-term-container *ngFor="let term of termsByAcademicYear[year.key].terms" [term]="term" [courses]="getCoursesByTerm(term.termCode)" fxFlex="33%"></app-term-container>
+						<app-term-container 
+							*ngFor="let term of termsByAcademicYear[year.key].terms | keyvalue" 
+							[term]="termsByAcademicYear[year.key].terms[term.key]" 
+							[courses]="getCoursesByTerm(year.key + term.key)" 
+							fxFlex="33%"
+						></app-term-container>
 					</div>
 				</mat-expansion-panel>
 			</mat-accordion>
diff --git a/src/app/degree-planner/degree-planner.component.ts b/src/app/degree-planner/degree-planner.component.ts
index 7365f5e..a78f67c 100644
--- a/src/app/degree-planner/degree-planner.component.ts
+++ b/src/app/degree-planner/degree-planner.component.ts
@@ -33,18 +33,31 @@ export class DegreePlannerComponent {
 		this.dataService.getTerms()
 		.subscribe(terms => {
 			this.terms = terms;
+			// Create an empty object to store term data in
 			this.termsByAcademicYear = {};
+
+			// Loop through each term
 			this.terms.forEach(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.termsByAcademicYear[year]) {
-					this.termsByAcademicYear[year].terms.push(term);
-				} else {
+				// 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: [term]
+						terms: {
+							2: { termCode: `${year}2`},
+							4: { termCode: `${year}4`},
+							6: { termCode: `${year}6`}
+						}
 					};
 				}
+
+				// Overwrite the default term with the current term
+				this.termsByAcademicYear[year].terms[termCode] = term;
+
 			});
 		});
 	}
diff --git a/src/app/degree-planner/shared/course-item/course-item.component.html b/src/app/degree-planner/shared/course-item/course-item.component.html
index c176141..64a8680 100644
--- a/src/app/degree-planner/shared/course-item/course-item.component.html
+++ b/src/app/degree-planner/shared/course-item/course-item.component.html
@@ -1,4 +1,4 @@
-<div class="course-item">
+<div class="course-item {{status}}" [ngClass]="{'disabled': course.pastTerm}">
   <div class="course-row course-info">
     <div class="icon-number-wrapper">
         <p class="course-number">
@@ -10,7 +10,6 @@
             <i *ngSwitchCase="'waitlist'" class="material-icons problem-icon">report_problem</i>
             <i *ngSwitchCase="'incomplete'" class="material-icons error-icon">error</i>
             <i *ngSwitchCase="'likely-offered'" class="material-icons help-icon">help</i>
-            <i *ngSwitchCase="'not-offered'" class="material-icons not-offered">remove</i>
             <i *ngSwitchCase="'favorite'" class="material-icons favorite-icon">favorite_border</i>
         </div>
     </div>
diff --git a/src/app/degree-planner/shared/course-item/course-item.component.scss b/src/app/degree-planner/shared/course-item/course-item.component.scss
index b9a4cad..b816d57 100644
--- a/src/app/degree-planner/shared/course-item/course-item.component.scss
+++ b/src/app/degree-planner/shared/course-item/course-item.component.scss
@@ -70,4 +70,13 @@
 .icon-number-wrapper {
     display: flex;
     align-items: center;
+}
+
+.not-offered {
+    .course-number,
+    .course-credits,
+    .course-title {
+        text-decoration: line-through;
+        opacity: .5;
+    }
 }
\ No newline at end of file
diff --git a/src/app/degree-planner/term-container/term-container.component.html b/src/app/degree-planner/term-container/term-container.component.html
index cdbb4b3..5e7fbd2 100644
--- a/src/app/degree-planner/term-container/term-container.component.html
+++ b/src/app/degree-planner/term-container/term-container.component.html
@@ -1,6 +1,6 @@
 <mat-card class="term-container">
     <div fxLayout="row" fxLayoutAlign="space-between stretch">
-        <h2>{{ term.termCode | getTermDescription }}</h2><p class="text-right semi-bold credits">Credits: 13</p>
+        <h2>{{ term.termCode | getTermDescription }}</h2><p class="text-right semi-bold credits">{{getTotalCredits()}} Credits</p>
     </div>
     <div cdkDropList>
         <app-course-item *ngFor="let course of courses" [course]="course" [status]="'complete'" cdkDrag></app-course-item>
diff --git a/src/app/degree-planner/term-container/term-container.component.ts b/src/app/degree-planner/term-container/term-container.component.ts
index 9a5ed3d..f29680e 100644
--- a/src/app/degree-planner/term-container/term-container.component.ts
+++ b/src/app/degree-planner/term-container/term-container.component.ts
@@ -15,4 +15,15 @@ export class TermContainerComponent {
 	terms: any[];
 
 	constructor() {}
+
+	getTotalCredits() {
+		if (!this.courses) {
+			return '0';
+		}
+		let total = 0;
+		for (const course of this.courses) {
+			total += course.credits;
+		}
+		return total;
+	}
 }
-- 
GitLab