+ drop (event: CdkDragDrop<any>) {
+ const previousIndex = event.previousIndex
+ const newIndex = event.currentIndex
+
+ if (previousIndex === newIndex) return
+
+ const oldPosition = this.playlistElements[previousIndex].position
+ let insertAfter = this.playlistElements[newIndex].position
+
+ if (oldPosition > insertAfter) insertAfter--
+
+ const element = this.playlistElements[previousIndex]
+
+ this.playlistElements.splice(previousIndex, 1)
+ this.playlistElements.splice(newIndex, 0, element)
+
+ this.videoPlaylistService.reorderPlaylist(this.playlist.id, oldPosition, insertAfter)
+ .subscribe(
+ () => {
+ this.reorderClientPositions()
+ },
+
+ err => this.notifier.error(err.message)
+ )
+ }
+
+ onElementRemoved (element: VideoPlaylistElement) {
+ const oldFirst = this.findFirst()
+
+ this.playlistElements = this.playlistElements.filter(v => v.id !== element.id)
+ this.reorderClientPositions(oldFirst)
+ }
+