aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/account/account-videos/account-videos.component.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-12-06 15:07:17 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-12-06 15:07:17 +0100
commitce0e281d46a7b574dcccb47958743656532bd312 (patch)
treeb2d26aef176f39ebdf37e5e7c28d6f6fb905bf10 /client/src/app/account/account-videos/account-videos.component.ts
parent7d763d97497df1bbf7a01f61aa916d99a1338a33 (diff)
downloadPeerTube-ce0e281d46a7b574dcccb47958743656532bd312.tar.gz
PeerTube-ce0e281d46a7b574dcccb47958743656532bd312.tar.zst
PeerTube-ce0e281d46a7b574dcccb47958743656532bd312.zip
Client bulk delete
Diffstat (limited to 'client/src/app/account/account-videos/account-videos.component.ts')
-rw-r--r--client/src/app/account/account-videos/account-videos.component.ts49
1 files changed, 47 insertions, 2 deletions
diff --git a/client/src/app/account/account-videos/account-videos.component.ts b/client/src/app/account/account-videos/account-videos.component.ts
index 9c2cc2404..5f12cfce0 100644
--- a/client/src/app/account/account-videos/account-videos.component.ts
+++ b/client/src/app/account/account-videos/account-videos.component.ts
@@ -1,6 +1,9 @@
1import { Component, OnInit } from '@angular/core' 1import { Component, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router' 2import { ActivatedRoute, Router } from '@angular/router'
3import { NotificationsService } from 'angular2-notifications' 3import { NotificationsService } from 'angular2-notifications'
4import 'rxjs/add/observable/from'
5import 'rxjs/add/operator/concatAll'
6import { Observable } from 'rxjs/Observable'
4import { ConfirmService } from '../../core/confirm' 7import { ConfirmService } from '../../core/confirm'
5import { AbstractVideoList } from '../../shared/video/abstract-video-list' 8import { AbstractVideoList } from '../../shared/video/abstract-video-list'
6import { Video } from '../../shared/video/video.model' 9import { Video } from '../../shared/video/video.model'
@@ -14,6 +17,7 @@ import { VideoService } from '../../shared/video/video.service'
14export class AccountVideosComponent extends AbstractVideoList implements OnInit { 17export class AccountVideosComponent extends AbstractVideoList implements OnInit {
15 titlePage = 'My videos' 18 titlePage = 'My videos'
16 currentRoute = '/account/videos' 19 currentRoute = '/account/videos'
20 checkedVideos: { [ id: number ]: boolean } = {}
17 21
18 constructor (protected router: Router, 22 constructor (protected router: Router,
19 protected route: ActivatedRoute, 23 protected route: ActivatedRoute,
@@ -27,10 +31,47 @@ export class AccountVideosComponent extends AbstractVideoList implements OnInit
27 super.ngOnInit() 31 super.ngOnInit()
28 } 32 }
29 33
34 abortSelectionMode () {
35 this.checkedVideos = {}
36 }
37
38 isInSelectionMode () {
39 return Object.keys(this.checkedVideos).some(k => this.checkedVideos[k] === true)
40 }
41
30 getVideosObservable () { 42 getVideosObservable () {
31 return this.videoService.getMyVideos(this.pagination, this.sort) 43 return this.videoService.getMyVideos(this.pagination, this.sort)
32 } 44 }
33 45
46 deleteSelectedVideos () {
47 const toDeleteVideosIds = Object.keys(this.checkedVideos)
48 .filter(k => this.checkedVideos[k] === true)
49 .map(k => parseInt(k, 10))
50
51 this.confirmService.confirm(`Do you really want to delete ${toDeleteVideosIds.length} videos?`, 'Delete').subscribe(
52 res => {
53 if (res === false) return
54
55 const observables: Observable<any>[] = []
56 for (const videoId of toDeleteVideosIds) {
57 const o = this.videoService
58 .removeVideo(videoId)
59 .do(() => this.spliceVideosById(videoId))
60
61 observables.push(o)
62 }
63
64 Observable.from(observables)
65 .concatAll()
66 .subscribe(
67 res => this.notificationsService.success('Success', `${toDeleteVideosIds.length} videos deleted.`),
68
69 err => this.notificationsService.error('Error', err.text)
70 )
71 }
72 )
73 }
74
34 deleteVideo (video: Video) { 75 deleteVideo (video: Video) {
35 this.confirmService.confirm(`Do you really want to delete ${video.name}?`, 'Delete').subscribe( 76 this.confirmService.confirm(`Do you really want to delete ${video.name}?`, 'Delete').subscribe(
36 res => { 77 res => {
@@ -40,8 +81,7 @@ export class AccountVideosComponent extends AbstractVideoList implements OnInit
40 .subscribe( 81 .subscribe(
41 status => { 82 status => {
42 this.notificationsService.success('Success', `Video ${video.name} deleted.`) 83 this.notificationsService.success('Success', `Video ${video.name} deleted.`)
43 const index = this.videos.findIndex(v => v.id === video.id) 84 this.spliceVideosById(video.id)
44 this.videos.splice(index, 1)
45 }, 85 },
46 86
47 error => this.notificationsService.error('Error', error.text) 87 error => this.notificationsService.error('Error', error.text)
@@ -49,4 +89,9 @@ export class AccountVideosComponent extends AbstractVideoList implements OnInit
49 } 89 }
50 ) 90 )
51 } 91 }
92
93 private spliceVideosById (id: number) {
94 const index = this.videos.findIndex(v => v.id === id)
95 this.videos.splice(index, 1)
96 }
52} 97}