]>
Commit | Line | Data |
---|---|---|
e2409062 | 1 | import { Component, OnDestroy, OnInit } from '@angular/core' |
7ccddd7b | 2 | import { I18n } from '@ngx-translate/i18n-polyfill' |
e2409062 | 3 | import { ActivatedRoute, Router } from '@angular/router' |
7ccddd7b JM |
4 | import { AbstractVideoList } from '@app/shared/video/abstract-video-list' |
5 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | |
e2409062 | 6 | import { AuthService, Notifier, ServerService } from '@app/core' |
7ccddd7b JM |
7 | import { Video } from '@shared/models' |
8 | import { VideoBlacklistService } from '@app/shared' | |
9 | import { immutableAssign } from '@app/shared/misc/utils' | |
10 | import { ScreenService } from '@app/shared/misc/screen.service' | |
e2409062 | 11 | import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component' |
7ccddd7b JM |
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 extends AbstractVideoList implements OnInit, OnDestroy { | |
19 | titlePage: string | |
7ccddd7b JM |
20 | checkedVideos: { [ id: number ]: boolean } = {} |
21 | pagination: ComponentPagination = { | |
22 | currentPage: 1, | |
23 | itemsPerPage: 5, | |
24 | totalItems: null | |
25 | } | |
26 | ||
e2409062 C |
27 | miniatureDisplayOptions: MiniatureDisplayOptions = { |
28 | date: true, | |
29 | views: false, | |
30 | by: true, | |
31 | privacyLabel: false, | |
32 | privacyText: true, | |
33 | state: false, | |
34 | blacklistInfo: false, | |
35 | nsfw: true | |
36 | } | |
37 | ||
7ccddd7b JM |
38 | constructor ( |
39 | protected router: Router, | |
40 | protected route: ActivatedRoute, | |
7ccddd7b | 41 | protected notifier: Notifier, |
7ccddd7b JM |
42 | protected authService: AuthService, |
43 | protected screenService: ScreenService, | |
489290b8 C |
44 | protected serverService: ServerService, |
45 | private i18n: I18n, | |
46 | private videoBlacklistService: VideoBlacklistService | |
7ccddd7b JM |
47 | ) { |
48 | super() | |
49 | ||
50 | this.titlePage = this.i18n('Auto-blacklisted videos') | |
51 | } | |
52 | ||
53 | ngOnInit () { | |
54 | super.ngOnInit() | |
55 | } | |
56 | ||
57 | ngOnDestroy () { | |
58 | super.ngOnDestroy() | |
59 | } | |
60 | ||
61 | abortSelectionMode () { | |
62 | this.checkedVideos = {} | |
63 | } | |
64 | ||
65 | isInSelectionMode () { | |
66 | return Object.keys(this.checkedVideos).some(k => this.checkedVideos[k] === true) | |
67 | } | |
68 | ||
69 | getVideosObservable (page: number) { | |
70 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
71 | ||
72 | return this.videoBlacklistService.getAutoBlacklistedAsVideoList(newPagination) | |
73 | } | |
74 | ||
75 | generateSyndicationList () { | |
76 | throw new Error('Method not implemented.') | |
77 | } | |
78 | ||
79 | removeVideoFromBlacklist (entry: Video) { | |
80 | this.videoBlacklistService.removeVideoFromBlacklist(entry.id).subscribe( | |
81 | () => { | |
82 | this.notifier.success(this.i18n('Video {{name}} removed from blacklist.', { name: entry.name })) | |
83 | this.reloadVideos() | |
84 | }, | |
85 | ||
86 | error => this.notifier.error(error.message) | |
87 | ) | |
88 | } | |
89 | ||
90 | removeSelectedVideosFromBlacklist () { | |
91 | const toReleaseVideosIds = Object.keys(this.checkedVideos) | |
92 | .filter(k => this.checkedVideos[ k ] === true) | |
93 | .map(k => parseInt(k, 10)) | |
94 | ||
95 | this.videoBlacklistService.removeVideoFromBlacklist(toReleaseVideosIds).subscribe( | |
96 | () => { | |
97 | this.notifier.success(this.i18n('{{num}} videos removed from blacklist.', { num: toReleaseVideosIds.length })) | |
98 | ||
99 | this.abortSelectionMode() | |
100 | this.reloadVideos() | |
101 | }, | |
102 | ||
103 | error => this.notifier.error(error.message) | |
104 | ) | |
105 | } | |
7ccddd7b | 106 | } |