]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/moderation/video-auto-blacklist-list/video-auto-blacklist-list.component.ts
Refactor video miniatures
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / moderation / video-auto-blacklist-list / video-auto-blacklist-list.component.ts
CommitLineData
e2409062 1import { Component, OnDestroy, OnInit } from '@angular/core'
7ccddd7b 2import { I18n } from '@ngx-translate/i18n-polyfill'
e2409062 3import { ActivatedRoute, Router } from '@angular/router'
7ccddd7b
JM
4import { AbstractVideoList } from '@app/shared/video/abstract-video-list'
5import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
e2409062 6import { AuthService, Notifier, ServerService } from '@app/core'
7ccddd7b
JM
7import { Video } from '@shared/models'
8import { VideoBlacklistService } from '@app/shared'
9import { immutableAssign } from '@app/shared/misc/utils'
10import { ScreenService } from '@app/shared/misc/screen.service'
e2409062 11import { 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})
18export 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}