Newer
Older
import { DataService } from '../../core/data.service';
import { FavoriteCourse } from '../../core/models/favorite-course';
import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
import { DegreePlannerDataService } from '@app/core/service/degree-planner-data.service';
import { ActivatedRoute } from '@angular/router';
selector: 'cse-favorites-container',
templateUrl: './favorites-container.component.html',
styleUrls: ['./favorites-container.component.scss']
export class FavoritesContainerComponent {
termCodes$: any;
constructor(
private route: ActivatedRoute,
private dataService: DataService) {
this.favoriteCourses = route.snapshot.data.requiredData.favorites;
this.termCodes$ = route.snapshot.data.requiredData.termCodes$;
const { container, previousContainer, previousIndex } = event;
// Get the course JSON
const item = event.item.data;
if (event.previousContainer.id !== event.container.id) {
container.data.push(item);
previousContainer.data.splice(previousIndex, 1);
// Add this coruse to the favorites list
this.dataService.saveFavoriteCourse(event.item.data.subjectCode, event.item.data.courseId)
.subscribe(favoriteCourse => {
this.favoriteCourse = favoriteCourse;
});
// Remove this course from the degree plan
this.dataService.removeCourse(this.degreePlannerDataSvc.getPlanId(), event.item.data.id);