import { AuthService } from '../../core/auth'
import { ConfirmService } from '../../core/confirm'
import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
-import { Subscription } from 'rxjs'
+import { Subject, Subscription } from 'rxjs'
import { ActivatedRoute } from '@angular/router'
import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
pagination: ComponentPagination = {
currentPage: 1,
- itemsPerPage: 30,
+ itemsPerPage: 10,
totalItems: null
}
+ onDataSubject = new Subject<any[]>()
+
private videoPlaylistId: string | number
private paramsSub: Subscription
if (oldPosition > insertAfter) insertAfter--
- this.videoPlaylistService.reorderPlaylist(this.playlist.id, oldPosition, insertAfter)
- .subscribe(
- () => { /* nothing to do */ },
-
- err => this.notifier.error(err.message)
- )
-
const element = this.playlistElements[previousIndex]
this.playlistElements.splice(previousIndex, 1)
this.playlistElements.splice(newIndex, 0, element)
- this.reorderClientPositions()
+ 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()
+ this.reorderClientPositions(oldFirst)
}
onNearOfBottom () {
.subscribe(({ total, data }) => {
this.playlistElements = this.playlistElements.concat(data)
this.pagination.totalItems = total
+
+ this.onDataSubject.next(data)
})
}
})
}
- private reorderClientPositions () {
+ private reorderClientPositions (first?: VideoPlaylistElement) {
+ if (this.playlistElements.length === 0) return
+
+ const oldFirst = first || this.findFirst()
let i = 1
for (const element of this.playlistElements) {
element.position = i
i++
}
+
+ // Reload playlist thumbnail if the first element changed
+ const newFirst = this.findFirst()
+ if (oldFirst && newFirst && oldFirst.id !== newFirst.id) {
+ this.playlist.refreshThumbnail()
+ }
+ }
+
+ private findFirst () {
+ return this.playlistElements.find(e => e.position === 1)
}
}