]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/video-blacklist/video-blacklist-list/video-blacklist-list.component.ts
Improve follow component routing
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / video-blacklist / video-blacklist-list / video-blacklist-list.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { SortMeta } from 'primeng/components/common/sortmeta'
3 import { NotificationsService } from 'angular2-notifications'
4 import { ConfirmService } from '../../../core'
5 import { RestPagination, RestTable, VideoBlacklistService } from '../../../shared'
6 import { VideoBlacklist } from '../../../../../../shared'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8 import { DropdownAction } from '@app/shared/buttons/action-dropdown.component'
9 import { Video } from '@app/shared/video/video.model'
10
11 @Component({
12 selector: 'my-video-blacklist-list',
13 templateUrl: './video-blacklist-list.component.html',
14 styleUrls: [ './video-blacklist-list.component.scss' ]
15 })
16 export class VideoBlacklistListComponent extends RestTable implements OnInit {
17 blacklist: VideoBlacklist[] = []
18 totalRecords = 0
19 rowsPerPage = 10
20 sort: SortMeta = { field: 'createdAt', order: 1 }
21 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
22
23 videoBlacklistActions: DropdownAction<VideoBlacklist>[] = []
24
25 constructor (
26 private notificationsService: NotificationsService,
27 private confirmService: ConfirmService,
28 private videoBlacklistService: VideoBlacklistService,
29 private i18n: I18n
30 ) {
31 super()
32
33 this.videoBlacklistActions = [
34 {
35 label: this.i18n('Unblacklist'),
36 handler: videoBlacklist => this.removeVideoFromBlacklist(videoBlacklist)
37 }
38 ]
39 }
40
41 ngOnInit () {
42 this.loadSort()
43 }
44
45 getVideoUrl (videoBlacklist: VideoBlacklist) {
46 return Video.buildClientUrl(videoBlacklist.video.uuid)
47 }
48
49 async removeVideoFromBlacklist (entry: VideoBlacklist) {
50 const confirmMessage = this.i18n(
51 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.'
52 )
53
54 const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist'))
55 if (res === false) return
56
57 this.videoBlacklistService.removeVideoFromBlacklist(entry.video.id).subscribe(
58 () => {
59 this.notificationsService.success(
60 this.i18n('Success'),
61 this.i18n('Video {{name}} removed from the blacklist.', { name: entry.video.name })
62 )
63 this.loadData()
64 },
65
66 err => this.notificationsService.error(this.i18n('Error'), err.message)
67 )
68 }
69
70 protected loadData () {
71 this.videoBlacklistService.listBlacklist(this.pagination, this.sort)
72 .subscribe(
73 resultList => {
74 this.blacklist = resultList.data
75 this.totalRecords = resultList.total
76 },
77
78 err => this.notificationsService.error(this.i18n('Error'), err.message)
79 )
80 }
81 }