1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { AuthService } from '../../core/auth'
3 import { ConfirmService } from '../../core/confirm'
4 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
5 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
6 import { flatMap } from 'rxjs/operators'
7 import { Subscription } from 'rxjs'
8 import { Notifier } from '@app/core'
9 import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
10 import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
11 import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
14 selector: 'my-video-channel-playlists',
15 templateUrl: './video-channel-playlists.component.html',
16 styleUrls: [ './video-channel-playlists.component.scss' ]
18 export class VideoChannelPlaylistsComponent implements OnInit, OnDestroy {
19 videoPlaylists: VideoPlaylist[] = []
21 pagination: ComponentPagination = {
27 private videoChannelSub: Subscription
28 private videoChannel: VideoChannel
31 private authService: AuthService,
32 private notifier: Notifier,
33 private confirmService: ConfirmService,
34 private videoPlaylistService: VideoPlaylistService,
35 private videoChannelService: VideoChannelService
39 // Parent get the video channel for us
40 this.videoChannelSub = this.videoChannelService.videoChannelLoaded
41 .subscribe(videoChannel => {
42 this.videoChannel = videoChannel
43 this.loadVideoPlaylists()
48 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
53 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
55 this.pagination.currentPage += 1
56 this.loadVideoPlaylists()
59 private loadVideoPlaylists () {
60 this.authService.userInformationLoaded
61 .pipe(flatMap(() => this.videoPlaylistService.listChannelPlaylists(this.videoChannel)))
63 this.videoPlaylists = this.videoPlaylists.concat(res.data)
64 this.pagination.totalItems = res.total