Skip to content
Snippets Groups Projects
app.component.ts 2.74 KiB
Newer Older
import { DataService } from './core/data.service';
pnogal's avatar
pnogal committed
import { FormBuilder, FormGroup } from '@angular/forms';
import { SidenavService } from './core/service/sidenav.service';
import { Component, ViewChild, OnInit } from '@angular/core';
import { MatSidenav } from '@angular/material';
import { ActivatedRoute } from '@angular/router';
import { DegreePlannerDataService } from './core/service/degree-planner-data.service';
pnogal's avatar
pnogal committed
import { Observable } from 'rxjs';
import { debounceTime, switchMap, tap } from 'rxjs/operators';
import { MatDialog } from '@angular/material';
import { CourseDetailsDialogComponent } from './degree-planner/dialogs/course-details-dialog/course-details-dialog.component';
import { ErrorStateMatcher } from '@angular/material/core';
import { FormControl, FormGroupDirective, NgForm, Validators } from '@angular/forms';
jvanboxtel@wisc.edu's avatar
jvanboxtel@wisc.edu committed

@Component({
pnogal's avatar
pnogal committed
    selector: 'cse-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.scss']
jvanboxtel@wisc.edu's avatar
jvanboxtel@wisc.edu committed
})
pnogal's avatar
pnogal committed

export class AppComponent implements OnInit {
pnogal's avatar
pnogal committed
    coursesData$: any;
    selectedDegreePlan: number;
    courses: Observable<any>;
    coursesForm: FormGroup;
    coursesInput: any;
pnogal's avatar
pnogal committed
    @ViewChild('rightAddCourse') public rightAddCourse: MatSidenav;
    constructor(
        public dialog: MatDialog,
        private dataService: DataService,
        private route: ActivatedRoute,
        private sidenavService: SidenavService,
        private degreePlannerDataSvc: DegreePlannerDataService,
        private fb: FormBuilder) {
            this.coursesInput = new FormControl('', [Validators.required]);
            this.selectedDegreePlan = 520224;
            this.coursesData$ = this.degreePlannerDataSvc.getDegreePlanDataById(this.selectedDegreePlan);
    }
pnogal's avatar
pnogal committed
    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.dataService.autocomplete(value)),
                tap(x => console.log( x))
            );
    }
pnogal's avatar
pnogal committed
    openCourseDetailsDialog(course) {
        this.dataService.getCourseDetails(course.termCode, course.payload.subject.subjectCode, course.payload.courseId)
        .subscribe(courseDetails => {
            const dialogRef = this.dialog.open(CourseDetailsDialogComponent, {
                data: { courseDetails: courseDetails }
            });
        });
    }

}
document.addEventListener('WebComponentsReady', function() {
pnogal's avatar
pnogal committed
    const customEvent = new CustomEvent('myuw-login', {
        detail: {
            person: {
            // 'firstName': 'Bucky'
            }
        }
    });
    document.dispatchEvent(customEvent);