]>
Commit | Line | Data |
---|---|---|
792dbaf0 GS |
1 | import { Component, OnInit } from '@angular/core' |
2 | import { SortMeta } from 'primeng/components/common/sortmeta' | |
3 | ||
4 | import { NotificationsService } from 'angular2-notifications' | |
5 | ||
6 | import { ConfirmService } from '../../../core' | |
35bf0c83 | 7 | import { VideoBlacklistService, RestTable, RestPagination } from '../../../shared' |
792dbaf0 GS |
8 | import { BlacklistedVideo } from '../../../../../../shared' |
9 | ||
10 | @Component({ | |
35bf0c83 C |
11 | selector: 'my-video-blacklist-list', |
12 | templateUrl: './video-blacklist-list.component.html', | |
792dbaf0 GS |
13 | styleUrls: [] |
14 | }) | |
35bf0c83 | 15 | export class VideoBlacklistListComponent extends RestTable implements OnInit { |
792dbaf0 GS |
16 | blacklist: BlacklistedVideo[] = [] |
17 | totalRecords = 0 | |
18 | rowsPerPage = 10 | |
ab998f7b | 19 | sort: SortMeta = { field: 'createdAt', order: 1 } |
792dbaf0 GS |
20 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
21 | ||
22 | constructor ( | |
23 | private notificationsService: NotificationsService, | |
24 | private confirmService: ConfirmService, | |
35bf0c83 | 25 | private videoBlacklistService: VideoBlacklistService |
792dbaf0 GS |
26 | ) { |
27 | super() | |
28 | } | |
29 | ||
30 | ngOnInit () { | |
ab998f7b | 31 | this.loadSort() |
792dbaf0 GS |
32 | } |
33 | ||
1f30a185 | 34 | async removeVideoFromBlacklist (entry: BlacklistedVideo) { |
ab998f7b | 35 | const confirmMessage = 'Do you really want to remove this video from the blacklist ? It will be available again in the videos list.' |
792dbaf0 | 36 | |
ab998f7b | 37 | const res = await this.confirmService.confirm(confirmMessage, 'Unblacklist') |
1f30a185 | 38 | if (res === false) return |
792dbaf0 | 39 | |
1f30a185 C |
40 | this.videoBlacklistService.removeVideoFromBlacklist(entry.videoId).subscribe( |
41 | () => { | |
42 | this.notificationsService.success('Success', `Video ${entry.name} removed from the blacklist.`) | |
43 | this.loadData() | |
44 | }, | |
792dbaf0 | 45 | |
1f30a185 | 46 | err => this.notificationsService.error('Error', err.message) |
792dbaf0 GS |
47 | ) |
48 | } | |
49 | ||
50 | protected loadData () { | |
35bf0c83 | 51 | this.videoBlacklistService.listBlacklist(this.pagination, this.sort) |
792dbaf0 GS |
52 | .subscribe( |
53 | resultList => { | |
54 | this.blacklist = resultList.data | |
55 | this.totalRecords = resultList.total | |
56 | }, | |
57 | ||
58 | err => this.notificationsService.error('Error', err.message) | |
59 | ) | |
60 | } | |
61 | } |