diff --git a/src/app/app.component.html b/src/app/app.component.html index 01dffade9637ae09ce42ba292abc93a041e0d3df..08abe4f4bc58cea6e9d3c55a8287ce0f30e0f818 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -22,13 +22,14 @@ <mat-form-field> <input matInput placeholder="Subject" [matAutocomplete]="auto" formControlName='coursesInput' required> - <mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn"> - <mat-option *ngFor="let course of (courses | async)" [value]="course.textSuggest"> + <mat-autocomplete #auto="matAutocomplete"> + <mat-option *ngFor="let course of (courses | async)" [(value)]="course.textSuggest"> <span>{{ course.textSuggest }} </span> </mat-option> </mat-autocomplete> - <mat-error *ngIf="coursesInput.invalid">Please select an existing Subject or 'All'.</mat-error> + <!-- <mat-error *ngIf="coursesInput.invalid">Please select an existing Subject or 'All'.</mat-error> --> </mat-form-field> + <mat-form-field class="example-full-width"> <input matInput placeholder="Keyword, number" value=""> </mat-form-field> diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 0eb325523e76dd2aa8c7082faf1d2f42bd1b7256..c8b4c94995225472186b399705c409f3ad4a228d 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -22,9 +22,9 @@ export class AppComponent implements OnInit { selectedDegreePlan: number; courses: Observable<any>; coursesForm: FormGroup; - coursesInput: any; - + coursesInput = {}; @ViewChild('rightAddCourse') public rightAddCourse: MatSidenav; + constructor( public dialog: MatDialog, private route: ActivatedRoute, @@ -33,19 +33,21 @@ export class AppComponent implements OnInit { private api: DegreePlannerApiService) { this.coursesInput = new FormControl('', [Validators.required]); this.selectedDegreePlan = 520224; + this.coursesForm = this.fb.group({ + coursesInput: null + }); + // Uncomment following code when working on Course Search form in +Add Course + // It will need to be modified to fix error: TS2531: Object is possibly 'null' + // this.courses = this.coursesForm.get('coursesInput').valueChanges + // .pipe( + // debounceTime(300), + // switchMap(value => this.api.autocomplete(value)), + // tap(x => console.log( x)) + // ); } ngOnInit() { this.sidenavService.setSidenav(this.rightAddCourse); - this.coursesForm = this.fb.group({ - coursesInput: null - }); - this.courses = this.coursesForm.get('coursesInput').valueChanges - .pipe( - debounceTime(300), - switchMap(value => this.api.autocomplete(value)), - tap(x => console.log( x)) - ); } openCourseDetailsDialog(course) { diff --git a/src/app/app.module.ts b/src/app/app.module.ts index ff8e08e1111a77aebe2e6bbe676e13c73a8ab6ca..19dd85ab5b3ad88c6fd3c2e158e0558213fe9741 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -6,7 +6,6 @@ import { StoreModule } from '@ngrx/store'; import { StoreDevtoolsModule } from '@ngrx/store-devtools'; import { EffectsModule } from '@ngrx/effects'; -import { DataService } from './core/data.service'; import { AppRoutingModule } from './app.routing.module'; import { AppComponent } from './app.component'; import { CoreModule } from '@app/core/core.module'; @@ -41,7 +40,7 @@ import { CourseDetailsDialogComponent } from './degree-planner/dialogs/course-de HeaderComponent ], entryComponents: [CourseDetailsDialogComponent], - providers: [ SidenavService, DataService ], + providers: [ SidenavService ], bootstrap: [ AppComponent ], schemas: [ CUSTOM_ELEMENTS_SCHEMA ] }) diff --git a/src/app/core/data.service.ts b/src/app/core/data.service.ts deleted file mode 100644 index e840ed93a86aab3ead1e325aa97b3ee46a8bffec..0000000000000000000000000000000000000000 --- a/src/app/core/data.service.ts +++ /dev/null @@ -1,130 +0,0 @@ -import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import { throwError, Observable, forkJoin } from 'rxjs'; -import { catchError, map } from 'rxjs/operators'; -import { ConfigService } from './config.service'; -import { Course } from './models/course'; -import { DegreePlan } from './models/degree-plan'; -import { Term } from './models/term'; -import { SavedForLaterCourse } from './models/saved-for-later-course'; -import { CourseDetails } from './models/course-details'; -import { Note } from './models/note'; - -const httpOptions = { - headers: new HttpHeaders({ - 'Content-Type': 'application/json' - }) -}; - -@Injectable() -export class DataService { - private plannerApiUrl: string; - private searchApiUrl: string; - - constructor(private http: HttpClient, private configService: ConfigService) { - this.plannerApiUrl = this.configService.apiPlannerUrl; - this.searchApiUrl = this.configService.apiSearchUrl; - } - - getAllPlanData(roadmapId: number) { - return forkJoin( - this.getDegreePlannerCourseData(roadmapId), - this.getTerms() - ); - } - - getDegreePlans(): Observable<DegreePlan[]> { - return this.http.get<DegreePlan[]>(this.plannerApiUrl + '/degreePlan') - .pipe(catchError(this.errorHandler)); - } - - getDegreePlannerCourseData(roadmapId: number): Observable<Course[]> { - return this.http.get<Course[]>(this.plannerApiUrl + '/degreePlan/' + roadmapId + '/courses') - .pipe(catchError(this.errorHandler)); - } - - getDegreePlannerCourseData2(roadmapId: number): Observable<Course> { - return this.http.get<Course>(this.plannerApiUrl + '/degreePlan/' + roadmapId + '/courses') - .pipe(catchError(this.errorHandler)); - } - - getTerms(): Observable<Term[]> { - return this.http.get<Term[]>(this.searchApiUrl + '/terms') - .pipe(catchError(this.errorHandler)); - } - - getCourseDetails(termCode: string, subjectCode: string, courseId: string): Observable<CourseDetails[]> { - return this.http.get<CourseDetails[]>(this.searchApiUrl + '/course/0000/' + subjectCode + '/' + courseId, httpOptions) - .pipe(catchError(this.errorHandler)); - } - - getSubjectsMap(): Observable<Object> { - return this.http.get(this.searchApiUrl + '/subjectsMap/0000', httpOptions) - .pipe(catchError(this.errorHandler)); - } - - getFavoriteCourses(): Observable<SavedForLaterCourse[]> { - return this.http.get<SavedForLaterCourse[]>(this.plannerApiUrl + '/favorites') - .pipe(catchError(this.errorHandler)); - } - - getAllNotes(planId: number): Observable<Note[]> { - return this.http.get<Note[]>(this.plannerApiUrl + '/degreePlan/' + planId + '/notes') - .pipe(catchError(this.errorHandler)); - } - - getNote(planId, noteId): Observable<Note[]> { - return this.http.get<Note[]>(this.plannerApiUrl + '/degreePlan/' + planId + '/notes/' + noteId) - .pipe(catchError(this.errorHandler)); - } - - updateNote(planId, note): Observable<Note[]> { - return this.http.put<Note[]>(this.plannerApiUrl + '/degreePlan/' + planId + '/notes/' + note.id, note, httpOptions) - .pipe(catchError(this.errorHandler)); - } - - createNote(planId, note): Observable<Note[]> { - return this.http.post<Note[]>(this.plannerApiUrl + '/degreePlan/' + planId + '/notes/', note, httpOptions) - .pipe(catchError(this.errorHandler)); - } - - removeNote(planId, noteId): Observable<Note[]> { - return this.http.delete<Note[]>(this.plannerApiUrl + '/degreePlan/' + planId + '/notes/' + noteId, httpOptions) - .pipe(catchError(this.errorHandler)); - } - - saveFavoriteCourse(subjectCode: string, courseId: string): Observable<SavedForLaterCourse> { - return this.http.post<SavedForLaterCourse>(this.plannerApiUrl + '/favorites/' + subjectCode + '/' + courseId, httpOptions) - .pipe(catchError(this.errorHandler)); - } - - removeFavoriteCourse(subjectCode, courseId): Observable<SavedForLaterCourse> { - return this.http.delete<SavedForLaterCourse>(this.plannerApiUrl + '/favorites/' + subjectCode + '/' + courseId, httpOptions) - .pipe(catchError(this.errorHandler)); - } - - addCourse(planId, subjectCode, courseId, termCode) { - return this.http.post(this.plannerApiUrl + '/degreePlan/' + planId + '/courses', {subjectCode, courseId, termCode }, httpOptions) - .pipe(catchError(this.errorHandler)); - } - - removeCourse(planId, recordId) { - return this.http.delete(this.plannerApiUrl + '/degreePlan/' + planId + '/courses/' + recordId, httpOptions) - .pipe(catchError(this.errorHandler)); - } - - updateCourseTerm(planId, recordId, termCode): Observable<Course> { - return this.http.put<Course>(this.plannerApiUrl + '/degreePlan/' + planId + '/courses/' + recordId + '?termCode=' + termCode, httpOptions) - .pipe(catchError(this.errorHandler)); - } - -test() { -// return this.http.delete(this.plannerApiUrl + '/degreePlan/519260/courses/259445', httpOptions) -return this.http.put(this.plannerApiUrl + '/degreePlan/519260/courses/259465?termCode=1174', httpOptions) - .pipe(catchError(this.errorHandler)); -} - - private errorHandler(error: HttpErrorResponse) { - return throwError(error || 'Server Error'); - } -} diff --git a/src/app/degree-planner/degree-planner.component.spec.ts b/src/app/degree-planner/degree-planner.component.spec.ts index 130639ca3afb2a239bc073d65a84119af0bcbcb5..81079aa584f7fb868935dc6816f998384787c7da 100644 --- a/src/app/degree-planner/degree-planner.component.spec.ts +++ b/src/app/degree-planner/degree-planner.component.spec.ts @@ -8,7 +8,6 @@ import { SharedModule } from '@app/shared/shared.module'; import { CoreModule } from '@app/core/core.module'; import { DegreePlannerComponent } from './degree-planner.component'; -import { DataService } from '@app/core/data.service'; import { HttpClientModule } from '@angular/common/http'; import { MAT_DIALOG_DATA } from '@angular/material'; @@ -21,7 +20,7 @@ describe('DegreePlannerComponent', () => { TestBed.configureTestingModule({ imports: [RouterTestingModule, HttpClientModule, CoreModule, SharedModule, BrowserAnimationsModule], declarations: [DegreePlannerComponent], - providers: [DataService, SidenavService, { provide: MAT_DIALOG_DATA }], + providers: [SidenavService, { provide: MAT_DIALOG_DATA }], schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); })); diff --git a/src/app/degree-planner/dialogs/notes-dialog/notes-dialog.component.spec.ts b/src/app/degree-planner/dialogs/notes-dialog/notes-dialog.component.spec.ts index 90681cd8a6c03e846ea683204db82d5ac7157bd1..8b588a67b641b873d586149c7a0b1ce0e525cfee 100644 --- a/src/app/degree-planner/dialogs/notes-dialog/notes-dialog.component.spec.ts +++ b/src/app/degree-planner/dialogs/notes-dialog/notes-dialog.component.spec.ts @@ -3,7 +3,6 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { SharedModule } from '@app/shared/shared.module'; import { CoreModule } from '@app/core/core.module'; -import { DataService } from '@app/core/data.service'; import { HttpClientModule } from '@angular/common/http'; import { NotesDialogComponent } from './notes-dialog.component'; import { MAT_DIALOG_DATA, MatDialogRef, MatInputModule } from '@angular/material'; @@ -15,7 +14,7 @@ describe('NotesDialogComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ imports: [HttpClientModule, CoreModule, SharedModule, MatInputModule, BrowserAnimationsModule], - providers: [DataService, { provide: MAT_DIALOG_DATA, useValue: {} }, { provide: MatDialogRef, useValue: {} }], + providers: [{ provide: MAT_DIALOG_DATA, useValue: {} }, { provide: MatDialogRef, useValue: {} }], declarations: [ NotesDialogComponent ] }) .compileComponents(); diff --git a/src/app/degree-planner/favorites-container/favorites-container.component.spec.ts b/src/app/degree-planner/favorites-container/favorites-container.component.spec.ts index b2e31961878ac43293dadbb158f1caadf8d8b47a..a8566faeea7b45467026045a01f5662cc2934093 100644 --- a/src/app/degree-planner/favorites-container/favorites-container.component.spec.ts +++ b/src/app/degree-planner/favorites-container/favorites-container.component.spec.ts @@ -1,5 +1,4 @@ import { HttpClientModule } from '@angular/common/http'; -import { DataService } from '@app/core/data.service'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { SharedModule } from '@app/shared/shared.module'; @@ -15,7 +14,7 @@ describe('SavedForLaterContainerComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ imports: [HttpClientModule, CoreModule, SharedModule, DragDropModule], - providers: [DataService], + providers: [], declarations: [SavedForLaterContainerComponent, CourseItemComponent] }).compileComponents(); })); diff --git a/src/app/degree-planner/term-container/term-container.component.spec.ts b/src/app/degree-planner/term-container/term-container.component.spec.ts index f37e4741ccd29460070b1b329fa10bbb878e84f9..c4d56cbfe461224df98f22da99acfee3603efc71 100644 --- a/src/app/degree-planner/term-container/term-container.component.spec.ts +++ b/src/app/degree-planner/term-container/term-container.component.spec.ts @@ -6,7 +6,6 @@ import { RouterTestingModule } from '@angular/router/testing'; import { SharedModule } from '@app/shared/shared.module'; import { CoreModule } from '@app/core/core.module'; -import { DataService } from '@app/core/data.service'; import { HttpClient, HttpClientModule } from '@angular/common/http'; import { TermContainerComponent } from './term-container.component'; @@ -21,7 +20,7 @@ describe('TermContainerComponent', () => { TestBed.configureTestingModule({ imports: [RouterTestingModule, HttpClientModule, CoreModule, SharedModule], declarations: [TermContainerComponent], - providers: [DataService, SidenavService], + providers: [SidenavService], schemas: [NO_ERRORS_SCHEMA] }) .compileComponents();