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'
14 selector: 'my-video-auto-blacklist-list',
15 templateUrl: './video-auto-blacklist-list.component.html',
16 styleUrls: [ './video-auto-blacklist-list.component.scss' ]
18 export class VideoAutoBlacklistListComponent {
20 selection: SelectionType = {}
21 miniatureDisplayOptions: MiniatureDisplayOptions = {
31 pagination: ComponentPagination = {
37 getVideosObservableFunction = this.getVideosObservable.bind(this)
40 protected router: Router,
41 protected route: ActivatedRoute,
42 protected notifier: Notifier,
43 protected authService: AuthService,
44 protected screenService: ScreenService,
45 protected serverService: ServerService,
47 private videoBlacklistService: VideoBlacklistService
49 this.titlePage = this.i18n('Auto-blacklisted videos')
52 getVideosObservable (page: number) {
53 const newPagination = immutableAssign(this.pagination, { currentPage: page })
55 return this.videoBlacklistService.getAutoBlacklistedAsVideoList(newPagination)
58 removeVideoFromBlacklist (entry: Video) {
59 this.videoBlacklistService.removeVideoFromBlacklist(entry.id).subscribe(
61 this.notifier.success(this.i18n('Video {{name}} removed from blacklist.', { name: entry.name }))
63 this.videos = this.videos.filter(v => v.id !== entry.id)
66 error => this.notifier.error(error.message)
70 removeSelectedVideosFromBlacklist () {
71 const toReleaseVideosIds = Object.keys(this.selection)
72 .filter(k => this.selection[ k ] === true)
73 .map(k => parseInt(k, 10))
75 this.videoBlacklistService.removeVideoFromBlacklist(toReleaseVideosIds).subscribe(
77 this.notifier.success(this.i18n('{{num}} videos removed from blacklist.', { num: toReleaseVideosIds.length }))
80 this.videos = this.videos.filter(v => toReleaseVideosIds.includes(v.id) === false)
83 error => this.notifier.error(error.message)