]>
Commit | Line | Data |
---|---|---|
bce47964 | 1 | import { Component, OnDestroy, OnInit } from '@angular/core' |
bce47964 C |
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' | |
ad453580 | 5 | import { Subject, Subscription } from 'rxjs' |
bce47964 C |
6 | import { Notifier } from '@app/core' |
7 | import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model' | |
c8487f3f | 8 | import { ComponentPagination, hasMoreItems } from '@app/shared/rest/component-pagination.model' |
bce47964 C |
9 | import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service' |
10 | ||
11 | @Component({ | |
12 | selector: 'my-video-channel-playlists', | |
13 | templateUrl: './video-channel-playlists.component.html', | |
14 | styleUrls: [ './video-channel-playlists.component.scss' ] | |
15 | }) | |
16 | export class VideoChannelPlaylistsComponent implements OnInit, OnDestroy { | |
17 | videoPlaylists: VideoPlaylist[] = [] | |
18 | ||
19 | pagination: ComponentPagination = { | |
20 | currentPage: 1, | |
21 | itemsPerPage: 20, | |
22 | totalItems: null | |
23 | } | |
24 | ||
ad453580 C |
25 | onDataSubject = new Subject<any[]>() |
26 | ||
bce47964 C |
27 | private videoChannelSub: Subscription |
28 | private videoChannel: VideoChannel | |
29 | ||
30 | constructor ( | |
bce47964 C |
31 | private notifier: Notifier, |
32 | private confirmService: ConfirmService, | |
33 | private videoPlaylistService: VideoPlaylistService, | |
34 | private videoChannelService: VideoChannelService | |
35 | ) {} | |
36 | ||
37 | ngOnInit () { | |
38 | // Parent get the video channel for us | |
39 | this.videoChannelSub = this.videoChannelService.videoChannelLoaded | |
40 | .subscribe(videoChannel => { | |
41 | this.videoChannel = videoChannel | |
42 | this.loadVideoPlaylists() | |
43 | }) | |
44 | } | |
45 | ||
46 | ngOnDestroy () { | |
47 | if (this.videoChannelSub) this.videoChannelSub.unsubscribe() | |
48 | } | |
49 | ||
50 | onNearOfBottom () { | |
c8487f3f | 51 | if (!hasMoreItems(this.pagination)) return |
bce47964 C |
52 | |
53 | this.pagination.currentPage += 1 | |
54 | this.loadVideoPlaylists() | |
55 | } | |
56 | ||
57 | private loadVideoPlaylists () { | |
ad453580 | 58 | this.videoPlaylistService.listChannelPlaylists(this.videoChannel, this.pagination) |
bce47964 C |
59 | .subscribe(res => { |
60 | this.videoPlaylists = this.videoPlaylists.concat(res.data) | |
61 | this.pagination.totalItems = res.total | |
ad453580 C |
62 | |
63 | this.onDataSubject.next(res.data) | |
bce47964 C |
64 | }) |
65 | } | |
66 | } |