From d9faa0ae9fac7d8b26244c4933838b375fd2eabd Mon Sep 17 00:00:00 2001 From: ievavold <ievavold@wisc.edu> Date: Mon, 17 Jun 2019 10:01:28 -0500 Subject: [PATCH] add types to stepper --- src/app/dars/models/degree-program.ts | 11 +++ .../new-audit-options.component.ts | 70 +++++++++---------- src/app/dars/services/api.service.ts | 10 +-- 3 files changed, 48 insertions(+), 43 deletions(-) diff --git a/src/app/dars/models/degree-program.ts b/src/app/dars/models/degree-program.ts index 697bcad..b007ba5 100644 --- a/src/app/dars/models/degree-program.ts +++ b/src/app/dars/models/degree-program.ts @@ -1,6 +1,17 @@ +import { HonorsOption } from './honors-option'; + export interface DegreeProgram { darsDegreeProgramCode: string; darsInstitutionCode: string; darsInstitutionCodeDescription: string; darsDegreeProgramDescription: string; } + +export interface DegreePrograms { + [darsInstitutionCode: string]: { + darsInstitutionCode: string; + darsInstitutionCodeDescription: string; + programs: DegreeProgram[]; + honorsOptions: HonorsOption[]; + }; +} diff --git a/src/app/dars/new-audit-options/new-audit-options.component.ts b/src/app/dars/new-audit-options/new-audit-options.component.ts index cce8214..f6cad8d 100644 --- a/src/app/dars/new-audit-options/new-audit-options.component.ts +++ b/src/app/dars/new-audit-options/new-audit-options.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit, Inject } from '@angular/core'; import { MatDialogRef, MatSnackBar } from '@angular/material'; import { DarsApiService } from '../services/api.service'; -import { DegreeProgram } from '../models/degree-program'; +import { DegreeProgram, DegreePrograms } from '../models/degree-program'; import { StudentDegreeProgram } from '../models/student-degree-program'; import { Observable } from 'rxjs'; import { Store, select } from '@ngrx/store'; @@ -13,10 +13,11 @@ import { FormBuilder, FormGroup, FormControl, - Validators, - FormArray, AbstractControl, } from '@angular/forms'; +import { HonorsOption } from '../models/honors-option'; +import { DegreePlan } from '@app/core/models/degree-plan'; +import { CourseBase } from '@app/core/models/course'; @Component({ selector: 'cse-new-audit-options', @@ -26,22 +27,21 @@ import { export class NewAuditOptionsComponent implements OnInit { public newAuditForm: FormGroup; public degreeProgram: DegreeProgram; - public degreePrograms: any; + public degreePrograms: DegreePrograms; public programOfStudy: string; public studentDegreeProgram: StudentDegreeProgram[]; - public DARSprograms: any; - public honorsOptions: any; - public courses: any; - public variableCreditCourses: any; + public DARSprograms: DegreeProgram[] = []; + public honorsOptions: HonorsOption[] = []; + public courses: { termCode: string; courses: CourseBase[] }[]; public degreePlans$: Observable<DARSState['degreePlans']>; - public degreePlans: any[]; - public primaryPlan: any[]; + public degreePlans: DegreePlan[]; + public primaryPlan: DegreePlan[]; public primaryPlanId: string; public hasVariableCredits: boolean; - public creditsRange: any[]; + public creditsRange: (CourseBase & { creditRange: number[] })[]; public isLoaded: boolean; public selectedAuditType: string; - public termsToInclude: any[]; + public termsToInclude: { name: string; id: string; value: string }[]; get formArray(): AbstractControl | null { return this.newAuditForm.get('formArray'); } @@ -91,21 +91,11 @@ export class NewAuditOptionsComponent implements OnInit { this.api.getStaticData().subscribe(degreePrograms => { this.degreePrograms = degreePrograms; - this.honorsOptions = []; - this.DARSprograms = []; - for (var school in this.degreePrograms) { - // Get program of study - this.programOfStudy = this.degreePrograms[ - school - ].darsInstitutionCodeDescription; - // Get honors options - if (this.degreePrograms[school].hasOwnProperty('honorsOptions')) { - this.honorsOptions.push(...this.degreePrograms[school].honorsOptions); - } - // Get DARS programs - if (this.degreePrograms[school].hasOwnProperty('programs')) { - this.DARSprograms.push(...this.degreePrograms[school].programs); - } + + for (const institution of Object.values(degreePrograms)) { + this.programOfStudy = institution.darsInstitutionCodeDescription; + this.honorsOptions.push(...institution.honorsOptions); + this.DARSprograms.push(...institution.programs); } }); this.newAuditForm = this.fb.group({ @@ -140,18 +130,22 @@ export class NewAuditOptionsComponent implements OnInit { this.api.getAllCourses(roadmapId).subscribe(courses => { this.courses = courses; this.creditsRange = []; - this.courses ? (this.isLoaded = true) : (this.isLoaded = false); - this.courses.forEach(function(course) { - course.creditMin === course.creditMax - ? (this.hasVariableCredits = false) - : (this.hasVariableCredits = true); + this.isLoaded = true; + this.hasVariableCredits = false; - // Build creditsRange array - course.creditsRange = []; - for (let i = course.creditMin; i <= course.creditMax; i++) { - course.creditsRange.push(i); - } - }, this); + courses.forEach(term => { + term.courses.forEach(course => { + const { creditMin: min, creditMax: max } = course; + if (min !== undefined && max !== undefined && min < max) { + this.hasVariableCredits = true; + const creditRange: number[] = []; + for (let i = min; i <= max; i++) { + creditRange.push(i); + } + this.creditsRange.push({ ...course, creditRange }); + } + }); + }); }); } diff --git a/src/app/dars/services/api.service.ts b/src/app/dars/services/api.service.ts index bcacb62..90bd5d1 100644 --- a/src/app/dars/services/api.service.ts +++ b/src/app/dars/services/api.service.ts @@ -1,14 +1,14 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable, of } from 'rxjs'; -import { DegreeProgram } from '../models/degree-program'; +import { DegreePrograms } from '../models/degree-program'; import { AuditMetadata } from '../models/audit-metadata'; import { StudentDegreeProgram } from '../models/student-degree-program'; import { environment } from './../../../environments/environment'; import { Audit } from '../models/audit/audit'; import { CourseBase } from '@app/core/models/course'; -const auditResponse: any = require('../../../assets/mock-data/audit-response.json'); -const degreeProgramsResponse: any = require('../../../assets/mock-data/degreeprograms-response.json'); +const auditResponse: Audit = require('../../../assets/mock-data/audit-response.json'); +const degreeProgramsResponse: DegreePrograms = require('../../../assets/mock-data/degreeprograms-response.json'); const HTTP_OPTIONS = { headers: new HttpHeaders({ @@ -24,12 +24,12 @@ export class DarsApiService { * Get all degree programs, honors, and institution data. * */ - public getStaticData(): Observable<DegreeProgram[]> { + public getStaticData(): Observable<DegreePrograms> { // Prevents errors locally if (environment.production) { const url = 'http://dev-enroll-app-data.s3-website-us-east-1.amazonaws.com/degreeprograms.json'; - return this.http.get<DegreeProgram[]>(url, HTTP_OPTIONS); + return this.http.get<DegreePrograms>(url, HTTP_OPTIONS); } else { return of(degreeProgramsResponse); } -- GitLab