import { Component, Input, OnInit } from '@angular/core'; import { MatDialog } from '@angular/material'; import { Store, select } from '@ngrx/store'; import { AddCourse, AddSaveForLater, MoveCourseBetweenTerms, } from './../../store/actions/course.actions'; import { getDropableTerms } from '@app/degree-planner/store/selectors'; import { GlobalState } from '@app/core/state'; import { Course } from '@app/core/models/course'; import { DegreePlannerApiService } from '@app/degree-planner/services/api.service'; // tslint:disable-next-line:max-line-length import { CourseDetailsDialogComponent } from '@app/degree-planner/dialogs/course-details-dialog/course-details-dialog.component'; // tslint:disable-next-line:max-line-length import { RemoveCourseConfirmDialogComponent } from '@app/degree-planner/dialogs/remove-course-confirm-dialog/remove-course-confirm-dialog.component'; @Component({ selector: 'cse-course-item', templateUrl: './course-item.component.html', styleUrls: ['./course-item.component.scss'], }) export class CourseItemComponent implements OnInit { @Input() course: Course; @Input() disabled: string; @Input() type: 'saved' | 'course' | 'search'; status; // TODO make this work k thx plz!? visibleTerms: any; constructor( private api: DegreePlannerApiService, public dialog: MatDialog, private store: Store<GlobalState>, ) {} ngOnInit() {} onMenuOpen() { this.store .pipe(select(getDropableTerms)) .subscribe(terms => (this.visibleTerms = terms)); } moveToFavorites(course) { this.store.dispatch( new AddSaveForLater({ courseId: course.courseId, subjectCode: course.subjectCode, title: course.title, catalogNumber: course.catalogNumber, }), ); } addToTerm(course, term) { const { subjectCode, courseId } = course; const termCode = term; this.store.dispatch(new AddCourse({ subjectCode, courseId, termCode })); } switchTerm(course, term) { const { id, termCode: from } = course; const to = term; this.store.dispatch(new MoveCourseBetweenTerms({ to, from, id })); } openCourseDetailsDialog(course) { this.api .getCourseDetails(course.subjectCode, course.courseId) .subscribe(courseDetails => { const dialogRef = this.dialog.open(CourseDetailsDialogComponent, { data: { courseDetails: courseDetails }, }); }); } openRemoveConfirmationDialog() { const dialogRef = this.dialog.open(RemoveCourseConfirmDialogComponent, { data: { course: this.course, type: this.type }, }); } }