aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+admin/moderation/video-auto-blacklist-list/video-auto-blacklist-list.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-04 10:44:18 +0200
committerChocobozzz <me@florianbigard.com>2019-04-05 10:53:08 +0200
commit693263e936763a851e3c8c020e3739def8bd4eca (patch)
tree7fd333fcf76edbc24f3daf4a78e47ff55f048b04 /client/src/app/+admin/moderation/video-auto-blacklist-list/video-auto-blacklist-list.component.ts
parent9ba1d64b1ac77304d9ffb1b3432a90ea00ff3281 (diff)
downloadPeerTube-693263e936763a851e3c8c020e3739def8bd4eca.tar.gz
PeerTube-693263e936763a851e3c8c020e3739def8bd4eca.tar.zst
PeerTube-693263e936763a851e3c8c020e3739def8bd4eca.zip
Refactor videos selection components
Diffstat (limited to 'client/src/app/+admin/moderation/video-auto-blacklist-list/video-auto-blacklist-list.component.ts')
-rw-r--r--client/src/app/+admin/moderation/video-auto-blacklist-list/video-auto-blacklist-list.component.ts56
1 files changed, 18 insertions, 38 deletions
diff --git a/client/src/app/+admin/moderation/video-auto-blacklist-list/video-auto-blacklist-list.component.ts b/client/src/app/+admin/moderation/video-auto-blacklist-list/video-auto-blacklist-list.component.ts
index d66a6dcae..fb2962b47 100644
--- a/client/src/app/+admin/moderation/video-auto-blacklist-list/video-auto-blacklist-list.component.ts
+++ b/client/src/app/+admin/moderation/video-auto-blacklist-list/video-auto-blacklist-list.component.ts
@@ -1,29 +1,23 @@
1import { Component, OnDestroy, OnInit } from '@angular/core' 1import { Component } from '@angular/core'
2import { I18n } from '@ngx-translate/i18n-polyfill' 2import { I18n } from '@ngx-translate/i18n-polyfill'
3import { ActivatedRoute, Router } from '@angular/router' 3import { ActivatedRoute, Router } from '@angular/router'
4import { AbstractVideoList } from '@app/shared/video/abstract-video-list'
5import { ComponentPagination } from '@app/shared/rest/component-pagination.model' 4import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
6import { AuthService, Notifier, ServerService } from '@app/core' 5import { AuthService, Notifier, ServerService } from '@app/core'
7import { Video } from '@shared/models'
8import { VideoBlacklistService } from '@app/shared' 6import { VideoBlacklistService } from '@app/shared'
9import { immutableAssign } from '@app/shared/misc/utils' 7import { immutableAssign } from '@app/shared/misc/utils'
10import { ScreenService } from '@app/shared/misc/screen.service' 8import { ScreenService } from '@app/shared/misc/screen.service'
11import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component' 9import { MiniatureDisplayOptions } from '@app/shared/video/video-miniature.component'
10import { SelectionType } from '@app/shared/video/videos-selection.component'
11import { Video } from '@app/shared/video/video.model'
12 12
13@Component({ 13@Component({
14 selector: 'my-video-auto-blacklist-list', 14 selector: 'my-video-auto-blacklist-list',
15 templateUrl: './video-auto-blacklist-list.component.html', 15 templateUrl: './video-auto-blacklist-list.component.html',
16 styleUrls: [ './video-auto-blacklist-list.component.scss' ] 16 styleUrls: [ './video-auto-blacklist-list.component.scss' ]
17}) 17})
18export class VideoAutoBlacklistListComponent extends AbstractVideoList implements OnInit, OnDestroy { 18export class VideoAutoBlacklistListComponent {
19 titlePage: string 19 titlePage: string
20 checkedVideos: { [ id: number ]: boolean } = {} 20 selection: SelectionType = {}
21 pagination: ComponentPagination = {
22 currentPage: 1,
23 itemsPerPage: 5,
24 totalItems: null
25 }
26
27 miniatureDisplayOptions: MiniatureDisplayOptions = { 21 miniatureDisplayOptions: MiniatureDisplayOptions = {
28 date: true, 22 date: true,
29 views: false, 23 views: false,
@@ -34,6 +28,13 @@ export class VideoAutoBlacklistListComponent extends AbstractVideoList implement
34 blacklistInfo: false, 28 blacklistInfo: false,
35 nsfw: true 29 nsfw: true
36 } 30 }
31 pagination: ComponentPagination = {
32 currentPage: 1,
33 itemsPerPage: 5,
34 totalItems: null
35 }
36 videos: Video[] = []
37 getVideosObservableFunction = this.getVideosObservable.bind(this)
37 38
38 constructor ( 39 constructor (
39 protected router: Router, 40 protected router: Router,
@@ -45,42 +46,21 @@ export class VideoAutoBlacklistListComponent extends AbstractVideoList implement
45 private i18n: I18n, 46 private i18n: I18n,
46 private videoBlacklistService: VideoBlacklistService 47 private videoBlacklistService: VideoBlacklistService
47 ) { 48 ) {
48 super()
49
50 this.titlePage = this.i18n('Auto-blacklisted videos') 49 this.titlePage = this.i18n('Auto-blacklisted videos')
51 } 50 }
52 51
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) { 52 getVideosObservable (page: number) {
70 const newPagination = immutableAssign(this.pagination, { currentPage: page }) 53 const newPagination = immutableAssign(this.pagination, { currentPage: page })
71 54
72 return this.videoBlacklistService.getAutoBlacklistedAsVideoList(newPagination) 55 return this.videoBlacklistService.getAutoBlacklistedAsVideoList(newPagination)
73 } 56 }
74 57
75 generateSyndicationList () {
76 throw new Error('Method not implemented.')
77 }
78
79 removeVideoFromBlacklist (entry: Video) { 58 removeVideoFromBlacklist (entry: Video) {
80 this.videoBlacklistService.removeVideoFromBlacklist(entry.id).subscribe( 59 this.videoBlacklistService.removeVideoFromBlacklist(entry.id).subscribe(
81 () => { 60 () => {
82 this.notifier.success(this.i18n('Video {{name}} removed from blacklist.', { name: entry.name })) 61 this.notifier.success(this.i18n('Video {{name}} removed from blacklist.', { name: entry.name }))
83 this.reloadVideos() 62
63 this.videos = this.videos.filter(v => v.id !== entry.id)
84 }, 64 },
85 65
86 error => this.notifier.error(error.message) 66 error => this.notifier.error(error.message)
@@ -88,16 +68,16 @@ export class VideoAutoBlacklistListComponent extends AbstractVideoList implement
88 } 68 }
89 69
90 removeSelectedVideosFromBlacklist () { 70 removeSelectedVideosFromBlacklist () {
91 const toReleaseVideosIds = Object.keys(this.checkedVideos) 71 const toReleaseVideosIds = Object.keys(this.selection)
92 .filter(k => this.checkedVideos[ k ] === true) 72 .filter(k => this.selection[ k ] === true)
93 .map(k => parseInt(k, 10)) 73 .map(k => parseInt(k, 10))
94 74
95 this.videoBlacklistService.removeVideoFromBlacklist(toReleaseVideosIds).subscribe( 75 this.videoBlacklistService.removeVideoFromBlacklist(toReleaseVideosIds).subscribe(
96 () => { 76 () => {
97 this.notifier.success(this.i18n('{{num}} videos removed from blacklist.', { num: toReleaseVideosIds.length })) 77 this.notifier.success(this.i18n('{{num}} videos removed from blacklist.', { num: toReleaseVideosIds.length }))
98 78
99 this.abortSelectionMode() 79 this.selection = {}
100 this.reloadVideos() 80 this.videos = this.videos.filter(v => toReleaseVideosIds.includes(v.id) === false)
101 }, 81 },
102 82
103 error => this.notifier.error(error.message) 83 error => this.notifier.error(error.message)