+ drop (event: CdkDragDrop<any>) {
+ const previousIndex = event.previousIndex
+ const newIndex = event.currentIndex
+
+ if (previousIndex === newIndex) return
+
+ const oldPosition = this.videos[previousIndex].playlistElement.position
+ const insertAfter = newIndex === 0 ? 0 : this.videos[newIndex].playlistElement.position
+
+ this.videoPlaylistService.reorderPlaylist(this.playlist.id, oldPosition, insertAfter)
+ .subscribe(
+ () => { /* nothing to do */ },
+
+ err => this.notifier.error(err.message)
+ )
+
+ const video = this.videos[previousIndex]
+
+ this.videos.splice(previousIndex, 1)
+ this.videos.splice(newIndex, 0, video)
+
+ this.reorderClientPositions()
+ }
+
+ onDragMove (event: CdkDragMove<any>) {
+ this.dragMoveSubject.next(event.pointerPosition.y)
+ }
+
+ checkScroll (pointerY: number) {
+ // FIXME: Uncomment when https://github.com/angular/material2/issues/14098 is fixed
+ // FIXME: Remove when https://github.com/angular/material2/issues/13588 is implemented
+ // if (pointerY < 150) {
+ // window.scrollBy({
+ // left: 0,
+ // top: -20,
+ // behavior: 'smooth'
+ // })
+ //
+ // return
+ // }
+ //
+ // if (window.innerHeight - pointerY <= 50) {
+ // window.scrollBy({
+ // left: 0,
+ // top: 20,
+ // behavior: 'smooth'
+ // })
+ // }
+ }
+