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 { Subscription } from 'rxjs'
6 import { Notifier } from '@app/core'
7 import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
8 import { ComponentPagination } 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 private videoChannelSub: Subscription
26 private videoChannel: VideoChannel
29 private notifier: Notifier,
30 private confirmService: ConfirmService,
31 private videoPlaylistService: VideoPlaylistService,
32 private videoChannelService: VideoChannelService
36 // Parent get the video channel for us
37 this.videoChannelSub = this.videoChannelService.videoChannelLoaded
38 .subscribe(videoChannel => {
39 this.videoChannel = videoChannel
40 this.loadVideoPlaylists()
45 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
50 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
52 this.pagination.currentPage += 1
53 this.loadVideoPlaylists()
56 private loadVideoPlaylists () {
57 this.videoPlaylistService.listChannelPlaylists(this.videoChannel)
59 this.videoPlaylists = this.videoPlaylists.concat(res.data)
60 this.pagination.totalItems = res.total