]>
Commit | Line | Data |
---|---|---|
1 | import { Component } from '@angular/core' | |
2 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
3 | import { ActivatedRoute, Router } from '@angular/router' | |
4 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | |
5 | import { AuthService, Notifier, ServerService } from '@app/core' | |
6 | import { VideoBlacklistService } from '@app/shared' | |
7 | import { immutableAssign } from '@app/shared/misc/utils' | |
8 | import { ScreenService } from '@app/shared/misc/screen.service' | |
9 | import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component' | |
10 | import { SelectionType } from '@app/shared/video/videos-selection.component' | |
11 | import { Video } from '@app/shared/video/video.model' | |
12 | ||
13 | @Component({ | |
14 | selector: 'my-video-auto-blacklist-list', | |
15 | templateUrl: './video-auto-blacklist-list.component.html', | |
16 | styleUrls: [ './video-auto-blacklist-list.component.scss' ] | |
17 | }) | |
18 | export class VideoAutoBlacklistListComponent { | |
19 | titlePage: string | |
20 | selection: SelectionType = {} | |
21 | miniatureDisplayOptions: MiniatureDisplayOptions = { | |
22 | date: true, | |
23 | views: false, | |
24 | by: true, | |
25 | privacyLabel: false, | |
26 | privacyText: true, | |
27 | state: false, | |
28 | blacklistInfo: false, | |
29 | nsfw: true | |
30 | } | |
31 | pagination: ComponentPagination = { | |
32 | currentPage: 1, | |
33 | itemsPerPage: 5, | |
34 | totalItems: null | |
35 | } | |
36 | videos: Video[] = [] | |
37 | getVideosObservableFunction = this.getVideosObservable.bind(this) | |
38 | ||
39 | constructor ( | |
40 | protected router: Router, | |
41 | protected route: ActivatedRoute, | |
42 | protected notifier: Notifier, | |
43 | protected authService: AuthService, | |
44 | protected screenService: ScreenService, | |
45 | protected serverService: ServerService, | |
46 | private i18n: I18n, | |
47 | private videoBlacklistService: VideoBlacklistService | |
48 | ) { | |
49 | this.titlePage = this.i18n('Auto-blacklisted videos') | |
50 | } | |
51 | ||
52 | getVideosObservable (page: number) { | |
53 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
54 | ||
55 | return this.videoBlacklistService.getAutoBlacklistedAsVideoList(newPagination) | |
56 | } | |
57 | ||
58 | removeVideoFromBlacklist (entry: Video) { | |
59 | this.videoBlacklistService.removeVideoFromBlacklist(entry.id).subscribe( | |
60 | () => { | |
61 | this.notifier.success(this.i18n('Video {{name}} removed from blacklist.', { name: entry.name })) | |
62 | ||
63 | this.videos = this.videos.filter(v => v.id !== entry.id) | |
64 | }, | |
65 | ||
66 | error => this.notifier.error(error.message) | |
67 | ) | |
68 | } | |
69 | ||
70 | removeSelectedVideosFromBlacklist () { | |
71 | const toReleaseVideosIds = Object.keys(this.selection) | |
72 | .filter(k => this.selection[ k ] === true) | |
73 | .map(k => parseInt(k, 10)) | |
74 | ||
75 | this.videoBlacklistService.removeVideoFromBlacklist(toReleaseVideosIds).subscribe( | |
76 | () => { | |
77 | this.notifier.success(this.i18n('{{num}} videos removed from blacklist.', { num: toReleaseVideosIds.length })) | |
78 | ||
79 | this.selection = {} | |
80 | this.videos = this.videos.filter(v => toReleaseVideosIds.includes(v.id) === false) | |
81 | }, | |
82 | ||
83 | error => this.notifier.error(error.message) | |
84 | ) | |
85 | } | |
86 | } |