1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ConfirmService } from '../../core/confirm'
3 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
4 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
5 import { Subject, Subscription } from 'rxjs'
6 import { Notifier } from '@app/core'
7 import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
8 import { ComponentPagination, hasMoreItems } from '@app/shared/rest/component-pagination.model'
9 import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
12 selector: 'my-video-channel-playlists',
13 templateUrl: './video-channel-playlists.component.html',
14 styleUrls: [ './video-channel-playlists.component.scss' ]
16 export class VideoChannelPlaylistsComponent implements OnInit, OnDestroy {
17 videoPlaylists: VideoPlaylist[] = []
19 pagination: ComponentPagination = {
25 onDataSubject = new Subject<any[]>()
27 private videoChannelSub: Subscription
28 private videoChannel: VideoChannel
31 private notifier: Notifier,
32 private confirmService: ConfirmService,
33 private videoPlaylistService: VideoPlaylistService,
34 private videoChannelService: VideoChannelService
38 // Parent get the video channel for us
39 this.videoChannelSub = this.videoChannelService.videoChannelLoaded
40 .subscribe(videoChannel => {
41 this.videoChannel = videoChannel
42 this.loadVideoPlaylists()
47 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
51 if (!hasMoreItems(this.pagination)) return
53 this.pagination.currentPage += 1
54 this.loadVideoPlaylists()
57 private loadVideoPlaylists () {
58 this.videoPlaylistService.listChannelPlaylists(this.videoChannel, this.pagination)
60 this.videoPlaylists = this.videoPlaylists.concat(res.data)
61 this.pagination.totalItems = res.total
63 this.onDataSubject.next(res.data)