]>
Commit | Line | Data |
---|---|---|
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' | |
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 | ||
25 | onDataSubject = new Subject<any[]>() | |
26 | ||
27 | private videoChannelSub: Subscription | |
28 | private videoChannel: VideoChannel | |
29 | ||
30 | constructor ( | |
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 () { | |
51 | if (!hasMoreItems(this.pagination)) return | |
52 | ||
53 | this.pagination.currentPage += 1 | |
54 | this.loadVideoPlaylists() | |
55 | } | |
56 | ||
57 | private loadVideoPlaylists () { | |
58 | this.videoPlaylistService.listChannelPlaylists(this.videoChannel, this.pagination) | |
59 | .subscribe(res => { | |
60 | this.videoPlaylists = this.videoPlaylists.concat(res.data) | |
61 | this.pagination.totalItems = res.total | |
62 | ||
63 | this.onDataSubject.next(res.data) | |
64 | }) | |
65 | } | |
66 | } |