Skip to content
Snippets Groups Projects
Commit d9faa0ae authored by Isaac Evavold's avatar Isaac Evavold
Browse files

add types to stepper

parent 07698876
No related branches found
No related tags found
No related merge requests found
import { HonorsOption } from './honors-option';
export interface DegreeProgram { export interface DegreeProgram {
darsDegreeProgramCode: string; darsDegreeProgramCode: string;
darsInstitutionCode: string; darsInstitutionCode: string;
darsInstitutionCodeDescription: string; darsInstitutionCodeDescription: string;
darsDegreeProgramDescription: string; darsDegreeProgramDescription: string;
} }
export interface DegreePrograms {
[darsInstitutionCode: string]: {
darsInstitutionCode: string;
darsInstitutionCodeDescription: string;
programs: DegreeProgram[];
honorsOptions: HonorsOption[];
};
}
import { Component, OnInit, Inject } from '@angular/core'; import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MatSnackBar } from '@angular/material'; import { MatDialogRef, MatSnackBar } from '@angular/material';
import { DarsApiService } from '../services/api.service'; 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 { StudentDegreeProgram } from '../models/student-degree-program';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { Store, select } from '@ngrx/store'; import { Store, select } from '@ngrx/store';
...@@ -13,10 +13,11 @@ import { ...@@ -13,10 +13,11 @@ import {
FormBuilder, FormBuilder,
FormGroup, FormGroup,
FormControl, FormControl,
Validators,
FormArray,
AbstractControl, AbstractControl,
} from '@angular/forms'; } 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({ @Component({
selector: 'cse-new-audit-options', selector: 'cse-new-audit-options',
...@@ -26,22 +27,21 @@ import { ...@@ -26,22 +27,21 @@ import {
export class NewAuditOptionsComponent implements OnInit { export class NewAuditOptionsComponent implements OnInit {
public newAuditForm: FormGroup; public newAuditForm: FormGroup;
public degreeProgram: DegreeProgram; public degreeProgram: DegreeProgram;
public degreePrograms: any; public degreePrograms: DegreePrograms;
public programOfStudy: string; public programOfStudy: string;
public studentDegreeProgram: StudentDegreeProgram[]; public studentDegreeProgram: StudentDegreeProgram[];
public DARSprograms: any; public DARSprograms: DegreeProgram[] = [];
public honorsOptions: any; public honorsOptions: HonorsOption[] = [];
public courses: any; public courses: { termCode: string; courses: CourseBase[] }[];
public variableCreditCourses: any;
public degreePlans$: Observable<DARSState['degreePlans']>; public degreePlans$: Observable<DARSState['degreePlans']>;
public degreePlans: any[]; public degreePlans: DegreePlan[];
public primaryPlan: any[]; public primaryPlan: DegreePlan[];
public primaryPlanId: string; public primaryPlanId: string;
public hasVariableCredits: boolean; public hasVariableCredits: boolean;
public creditsRange: any[]; public creditsRange: (CourseBase & { creditRange: number[] })[];
public isLoaded: boolean; public isLoaded: boolean;
public selectedAuditType: string; public selectedAuditType: string;
public termsToInclude: any[]; public termsToInclude: { name: string; id: string; value: string }[];
get formArray(): AbstractControl | null { get formArray(): AbstractControl | null {
return this.newAuditForm.get('formArray'); return this.newAuditForm.get('formArray');
} }
...@@ -91,21 +91,11 @@ export class NewAuditOptionsComponent implements OnInit { ...@@ -91,21 +91,11 @@ export class NewAuditOptionsComponent implements OnInit {
this.api.getStaticData().subscribe(degreePrograms => { this.api.getStaticData().subscribe(degreePrograms => {
this.degreePrograms = degreePrograms; this.degreePrograms = degreePrograms;
this.honorsOptions = [];
this.DARSprograms = []; for (const institution of Object.values(degreePrograms)) {
for (var school in this.degreePrograms) { this.programOfStudy = institution.darsInstitutionCodeDescription;
// Get program of study this.honorsOptions.push(...institution.honorsOptions);
this.programOfStudy = this.degreePrograms[ this.DARSprograms.push(...institution.programs);
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);
}
} }
}); });
this.newAuditForm = this.fb.group({ this.newAuditForm = this.fb.group({
...@@ -140,18 +130,22 @@ export class NewAuditOptionsComponent implements OnInit { ...@@ -140,18 +130,22 @@ export class NewAuditOptionsComponent implements OnInit {
this.api.getAllCourses(roadmapId).subscribe(courses => { this.api.getAllCourses(roadmapId).subscribe(courses => {
this.courses = courses; this.courses = courses;
this.creditsRange = []; this.creditsRange = [];
this.courses ? (this.isLoaded = true) : (this.isLoaded = false); this.isLoaded = true;
this.courses.forEach(function(course) { this.hasVariableCredits = false;
course.creditMin === course.creditMax
? (this.hasVariableCredits = false)
: (this.hasVariableCredits = true);
// Build creditsRange array courses.forEach(term => {
course.creditsRange = []; term.courses.forEach(course => {
for (let i = course.creditMin; i <= course.creditMax; i++) { const { creditMin: min, creditMax: max } = course;
course.creditsRange.push(i); if (min !== undefined && max !== undefined && min < max) {
} this.hasVariableCredits = true;
}, this); const creditRange: number[] = [];
for (let i = min; i <= max; i++) {
creditRange.push(i);
}
this.creditsRange.push({ ...course, creditRange });
}
});
});
}); });
} }
......
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, of } from 'rxjs'; import { Observable, of } from 'rxjs';
import { DegreeProgram } from '../models/degree-program'; import { DegreePrograms } from '../models/degree-program';
import { AuditMetadata } from '../models/audit-metadata'; import { AuditMetadata } from '../models/audit-metadata';
import { StudentDegreeProgram } from '../models/student-degree-program'; import { StudentDegreeProgram } from '../models/student-degree-program';
import { environment } from './../../../environments/environment'; import { environment } from './../../../environments/environment';
import { Audit } from '../models/audit/audit'; import { Audit } from '../models/audit/audit';
import { CourseBase } from '@app/core/models/course'; import { CourseBase } from '@app/core/models/course';
const auditResponse: any = require('../../../assets/mock-data/audit-response.json'); const auditResponse: Audit = require('../../../assets/mock-data/audit-response.json');
const degreeProgramsResponse: any = require('../../../assets/mock-data/degreeprograms-response.json'); const degreeProgramsResponse: DegreePrograms = require('../../../assets/mock-data/degreeprograms-response.json');
const HTTP_OPTIONS = { const HTTP_OPTIONS = {
headers: new HttpHeaders({ headers: new HttpHeaders({
...@@ -24,12 +24,12 @@ export class DarsApiService { ...@@ -24,12 +24,12 @@ export class DarsApiService {
* Get all degree programs, honors, and institution data. * Get all degree programs, honors, and institution data.
* *
*/ */
public getStaticData(): Observable<DegreeProgram[]> { public getStaticData(): Observable<DegreePrograms> {
// Prevents errors locally // Prevents errors locally
if (environment.production) { if (environment.production) {
const url = const url =
'http://dev-enroll-app-data.s3-website-us-east-1.amazonaws.com/degreeprograms.json'; '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 { } else {
return of(degreeProgramsResponse); return of(degreeProgramsResponse);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment