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