1 import { Component, OnInit } from '@angular/core'
2 import { Notifier } from '@app/core'
3 import { AuthService } from '../../core/auth'
4 import { ConfirmService } from '../../core/confirm'
5 import { User } from '@app/shared'
6 import { flatMap } from 'rxjs/operators'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8 import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
9 import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
10 import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
11 import { VideoPlaylistType } from '@shared/models'
12 import { Subject } from 'rxjs'
15 selector: 'my-account-video-playlists',
16 templateUrl: './my-account-video-playlists.component.html',
17 styleUrls: [ './my-account-video-playlists.component.scss' ]
19 export class MyAccountVideoPlaylistsComponent implements OnInit {
20 videoPlaylists: VideoPlaylist[] = []
22 pagination: ComponentPagination = {
28 onDataSubject = new Subject<any[]>()
33 private authService: AuthService,
34 private notifier: Notifier,
35 private confirmService: ConfirmService,
36 private videoPlaylistService: VideoPlaylistService,
41 this.user = this.authService.getUser()
43 this.loadVideoPlaylists()
46 async deleteVideoPlaylist (videoPlaylist: VideoPlaylist) {
47 const res = await this.confirmService.confirm(
49 'Do you really want to delete {{playlistDisplayName}}?',
50 { playlistDisplayName: videoPlaylist.displayName }
54 if (res === false) return
56 this.videoPlaylistService.removeVideoPlaylist(videoPlaylist)
59 this.videoPlaylists = this.videoPlaylists
60 .filter(p => p.id !== videoPlaylist.id)
62 this.notifier.success(
63 this.i18n('Playlist {{playlistDisplayName}} deleted.', { playlistDisplayName: videoPlaylist.displayName })
67 error => this.notifier.error(error.message)
71 isRegularPlaylist (playlist: VideoPlaylist) {
72 return playlist.type.id === VideoPlaylistType.REGULAR
77 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return
79 this.pagination.currentPage += 1
80 this.loadVideoPlaylists()
83 private loadVideoPlaylists () {
84 this.authService.userInformationLoaded
86 return this.videoPlaylistService.listAccountPlaylists(this.user.account, this.pagination, '-updatedAt')
89 this.videoPlaylists = this.videoPlaylists.concat(res.data)
90 this.pagination.totalItems = res.total
92 this.onDataSubject.next(res.data)