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