From ae18bc5083cdbf470adcb7c33e987843f05abb5f Mon Sep 17 00:00:00 2001 From: Scott Berg <saberg3@wisc.edu> Date: Thu, 10 Jan 2019 12:30:11 -0600 Subject: [PATCH] Inital drag and drop fix --- src/app/core/data.service.ts | 2 +- .../degree-planner.component.ts | 7 ++++- .../term-container.component.html | 2 +- .../term-container.component.ts | 26 +++++++++---------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/app/core/data.service.ts b/src/app/core/data.service.ts index 7bd43d8..f405d82 100644 --- a/src/app/core/data.service.ts +++ b/src/app/core/data.service.ts @@ -120,7 +120,7 @@ export class DataService { 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) +return this.http.put(this.plannerApiUrl + '/degreePlan/520224/courses/272973?termCode=1176', httpOptions) .pipe(catchError(this.errorHandler)); } diff --git a/src/app/degree-planner/degree-planner.component.ts b/src/app/degree-planner/degree-planner.component.ts index 401774e..d5e870a 100644 --- a/src/app/degree-planner/degree-planner.component.ts +++ b/src/app/degree-planner/degree-planner.component.ts @@ -30,7 +30,12 @@ export class DegreePlannerComponent { termCodes$: any; degreePlannerData: Observable<any>; - constructor(private degreePlannerDataSvc: DegreePlannerDataService, private route: ActivatedRoute, public mediaMatcher: MediaMatcher) { + constructor( + private degreePlannerDataSvc: DegreePlannerDataService, + private dataService: DataService, + private route: ActivatedRoute, + public mediaMatcher: MediaMatcher + ) { this.firstCurrentTerm = null; this.mobileView = mediaMatcher.matchMedia('(max-width: 900px)'); diff --git a/src/app/degree-planner/term-container/term-container.component.html b/src/app/degree-planner/term-container/term-container.component.html index 27e01b4..fa7dc60 100644 --- a/src/app/degree-planner/term-container/term-container.component.html +++ b/src/app/degree-planner/term-container/term-container.component.html @@ -23,7 +23,7 @@ <div cdkDropList id="term-{{termCode}}" [cdkDropListData]="courses" - [cdkDropListConnectedTo]="termCode" + [cdkDropListConnectedTo]="this.dropZones" class="course-list" (cdkDropListDropped)="drop($event)"> diff --git a/src/app/degree-planner/term-container/term-container.component.ts b/src/app/degree-planner/term-container/term-container.component.ts index a072567..7bbccfb 100644 --- a/src/app/degree-planner/term-container/term-container.component.ts +++ b/src/app/degree-planner/term-container/term-container.component.ts @@ -27,6 +27,7 @@ export class TermContainerComponent implements OnInit { @Input() courses: any = []; terms: any[]; + dropZones: any[]; notes: Note[]; myNote: any; termsWithNotes: any[]; @@ -44,6 +45,13 @@ export class TermContainerComponent implements OnInit { ngOnInit() { this.termsWithNotes = this.notes.map(note => note.termCode); + + this.degreePlannerDataSvc.getAllTerms().subscribe(data => { + this.dropZones = data.map(termCode => { + return `term-${termCode}`; + }); + this.dropZones.push('favoriteCourse-dropZone'); + }); } openAddSidenav() { @@ -103,6 +111,10 @@ export class TermContainerComponent implements OnInit { return total; } + getDropZones() { + return []; + } + drop(event: CdkDragDrop<string[]>) { const newTermCode = event.container.id.substr(5, 4); @@ -119,24 +131,12 @@ export class TermContainerComponent implements OnInit { this.dataService.removeFavoriteCourse(event.item.data.subjectCode, event.item.data.courseId) .subscribe(data => {}); - // Move the course into the front end data structure - transferArrayItem(event.previousContainer.data, - event.container.data, - event.previousIndex, - event.currentIndex); - } else if (event.previousContainer.id !== event.container.id) { - // If moving from term to term - // Move the course in the front end data object - transferArrayItem(event.previousContainer.data, - event.container.data, - event.previousIndex, - event.currentIndex); // Tell the API this course updated this.dataService.updateCourseTerm(this.degreePlannerDataSvc.getPlanId(), event.item.data.id, newTermCode) .subscribe( data => { - // TODO Handle errors + this.degreePlannerDataSvc.getDegreePlanDataById(this.degreePlannerDataSvc.getPlanId()); }); } // Do nothing on drop to same term -- GitLab