Skip to content
Snippets Groups Projects
Commit ae18bc50 authored by Scott Berg's avatar Scott Berg
Browse files

Inital drag and drop fix

parent 0db1ba2b
No related branches found
No related tags found
No related merge requests found
...@@ -120,7 +120,7 @@ export class DataService { ...@@ -120,7 +120,7 @@ export class DataService {
test() { test() {
// return this.http.delete(this.plannerApiUrl + '/degreePlan/519260/courses/259445', httpOptions) // 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)); .pipe(catchError(this.errorHandler));
} }
......
...@@ -30,7 +30,12 @@ export class DegreePlannerComponent { ...@@ -30,7 +30,12 @@ export class DegreePlannerComponent {
termCodes$: any; termCodes$: any;
degreePlannerData: Observable<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.firstCurrentTerm = null;
this.mobileView = mediaMatcher.matchMedia('(max-width: 900px)'); this.mobileView = mediaMatcher.matchMedia('(max-width: 900px)');
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<div cdkDropList <div cdkDropList
id="term-{{termCode}}" id="term-{{termCode}}"
[cdkDropListData]="courses" [cdkDropListData]="courses"
[cdkDropListConnectedTo]="termCode" [cdkDropListConnectedTo]="this.dropZones"
class="course-list" class="course-list"
(cdkDropListDropped)="drop($event)"> (cdkDropListDropped)="drop($event)">
......
...@@ -27,6 +27,7 @@ export class TermContainerComponent implements OnInit { ...@@ -27,6 +27,7 @@ export class TermContainerComponent implements OnInit {
@Input() courses: any = []; @Input() courses: any = [];
terms: any[]; terms: any[];
dropZones: any[];
notes: Note[]; notes: Note[];
myNote: any; myNote: any;
termsWithNotes: any[]; termsWithNotes: any[];
...@@ -44,6 +45,13 @@ export class TermContainerComponent implements OnInit { ...@@ -44,6 +45,13 @@ export class TermContainerComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.termsWithNotes = this.notes.map(note => note.termCode); 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() { openAddSidenav() {
...@@ -103,6 +111,10 @@ export class TermContainerComponent implements OnInit { ...@@ -103,6 +111,10 @@ export class TermContainerComponent implements OnInit {
return total; return total;
} }
getDropZones() {
return [];
}
drop(event: CdkDragDrop<string[]>) { drop(event: CdkDragDrop<string[]>) {
const newTermCode = event.container.id.substr(5, 4); const newTermCode = event.container.id.substr(5, 4);
...@@ -119,24 +131,12 @@ export class TermContainerComponent implements OnInit { ...@@ -119,24 +131,12 @@ export class TermContainerComponent implements OnInit {
this.dataService.removeFavoriteCourse(event.item.data.subjectCode, event.item.data.courseId) this.dataService.removeFavoriteCourse(event.item.data.subjectCode, event.item.data.courseId)
.subscribe(data => {}); .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) { } 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 // Tell the API this course updated
this.dataService.updateCourseTerm(this.degreePlannerDataSvc.getPlanId(), event.item.data.id, newTermCode) this.dataService.updateCourseTerm(this.degreePlannerDataSvc.getPlanId(), event.item.data.id, newTermCode)
.subscribe( data => { .subscribe( data => {
// TODO Handle errors this.degreePlannerDataSvc.getDegreePlanDataById(this.degreePlannerDataSvc.getPlanId());
}); });
} }
// Do nothing on drop to same term // Do nothing on drop to same term
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment