68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import { Component, Input } from '@angular/core';
|
|
import { Entry } from '../../../../shared/models/entry.model';
|
|
import {
|
|
CdkDragDrop,
|
|
CdkDragEnd,
|
|
CdkDragStart,
|
|
moveItemInArray,
|
|
} from '@angular/cdk/drag-drop';
|
|
import {
|
|
animate,
|
|
state,
|
|
style,
|
|
transition,
|
|
trigger,
|
|
} from '@angular/animations';
|
|
import { UserCollectionService } from '../../../../core/services/userCollection.service';
|
|
|
|
@Component({
|
|
selector: 'app-collection-entry-table',
|
|
templateUrl: './collection-entry-table.component.html',
|
|
styleUrl: './collection-entry-table.component.css',
|
|
animations: [
|
|
trigger('animateDestroy', [
|
|
state('void', style({ opacity: '0' })),
|
|
transition('* => void', animate('300ms ease')),
|
|
]),
|
|
],
|
|
})
|
|
export class CollectionEntryTableComponent {
|
|
@Input() entries: Entry[] = [];
|
|
@Input() collectionId: string = '';
|
|
|
|
constructor(private userCollectionService: UserCollectionService) {}
|
|
|
|
refrechEventReceiver() {
|
|
console.log('event recieved');
|
|
}
|
|
|
|
drop(event: CdkDragDrop<any[]>) {
|
|
moveItemInArray(this.entries, event.previousIndex, event.currentIndex);
|
|
|
|
if (event.previousIndex != event.currentIndex) {
|
|
this.userCollectionService
|
|
.updateEntryOrder(
|
|
this.collectionId,
|
|
this.entries[event.currentIndex].id,
|
|
event.currentIndex
|
|
)
|
|
.subscribe({
|
|
next: () => {},
|
|
error: (error) => {
|
|
console.log(`Error changing order of entries!`);
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
dragStart(event: CdkDragStart): void {
|
|
event.source.element.nativeElement.classList.add('custom-dragging-class');
|
|
}
|
|
|
|
dragEnd(event: CdkDragEnd): void {
|
|
event.source.element.nativeElement.classList.remove(
|
|
'custom-dragging-class'
|
|
);
|
|
}
|
|
}
|