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