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'
7 import { Notifier, AuthService, ServerService } from '@app/core'
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'
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 extends AbstractVideoList implements OnInit, OnDestroy {
20 checkedVideos: { [ id: number ]: boolean } = {}
21 pagination: ComponentPagination = {
28 protected router: Router,
29 protected route: ActivatedRoute,
30 protected notifier: Notifier,
31 protected authService: AuthService,
32 protected screenService: ScreenService,
33 protected serverService: ServerService,
35 private videoBlacklistService: VideoBlacklistService
39 this.titlePage = this.i18n('Auto-blacklisted videos')
50 abortSelectionMode () {
51 this.checkedVideos = {}
54 isInSelectionMode () {
55 return Object.keys(this.checkedVideos).some(k => this.checkedVideos[k] === true)
58 getVideosObservable (page: number) {
59 const newPagination = immutableAssign(this.pagination, { currentPage: page })
61 return this.videoBlacklistService.getAutoBlacklistedAsVideoList(newPagination)
64 generateSyndicationList () {
65 throw new Error('Method not implemented.')
68 removeVideoFromBlacklist (entry: Video) {
69 this.videoBlacklistService.removeVideoFromBlacklist(entry.id).subscribe(
71 this.notifier.success(this.i18n('Video {{name}} removed from blacklist.', { name: entry.name }))
75 error => this.notifier.error(error.message)
79 removeSelectedVideosFromBlacklist () {
80 const toReleaseVideosIds = Object.keys(this.checkedVideos)
81 .filter(k => this.checkedVideos[ k ] === true)
82 .map(k => parseInt(k, 10))
84 this.videoBlacklistService.removeVideoFromBlacklist(toReleaseVideosIds).subscribe(
86 this.notifier.success(this.i18n('{{num}} videos removed from blacklist.', { num: toReleaseVideosIds.length }))
88 this.abortSelectionMode()
92 error => this.notifier.error(error.message)