]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/account/account-videos/account-videos.component.ts
Begin to add avatar to actors
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account-videos / account-videos.component.ts
CommitLineData
f3aaa9a9 1import { Component, OnInit } from '@angular/core'
be447678 2import { ActivatedRoute, Router } from '@angular/router'
202f6b6c 3import { NotificationsService } from 'angular2-notifications'
ce0e281d
C
4import 'rxjs/add/observable/from'
5import 'rxjs/add/operator/concatAll'
6import { Observable } from 'rxjs/Observable'
b2731bff 7import { AuthService } from '../../core/auth'
332542bc 8import { ConfirmService } from '../../core/confirm'
be447678 9import { AbstractVideoList } from '../../shared/video/abstract-video-list'
332542bc 10import { Video } from '../../shared/video/video.model'
202f6b6c
C
11import { VideoService } from '../../shared/video/video.service'
12
13@Component({
14 selector: 'my-account-videos',
15 templateUrl: './account-videos.component.html',
16 styleUrls: [ './account-videos.component.scss' ]
17})
f3aaa9a9 18export class AccountVideosComponent extends AbstractVideoList implements OnInit {
202f6b6c
C
19 titlePage = 'My videos'
20 currentRoute = '/account/videos'
ce0e281d 21 checkedVideos: { [ id: number ]: boolean } = {}
202f6b6c
C
22
23 constructor (protected router: Router,
24 protected route: ActivatedRoute,
b2731bff 25 protected authService: AuthService,
202f6b6c 26 protected notificationsService: NotificationsService,
332542bc 27 protected confirmService: ConfirmService,
202f6b6c
C
28 private videoService: VideoService) {
29 super()
30 }
31
32 ngOnInit () {
33 super.ngOnInit()
34 }
35
ce0e281d
C
36 abortSelectionMode () {
37 this.checkedVideos = {}
38 }
39
40 isInSelectionMode () {
41 return Object.keys(this.checkedVideos).some(k => this.checkedVideos[k] === true)
42 }
43
202f6b6c
C
44 getVideosObservable () {
45 return this.videoService.getMyVideos(this.pagination, this.sort)
46 }
332542bc 47
ce0e281d
C
48 deleteSelectedVideos () {
49 const toDeleteVideosIds = Object.keys(this.checkedVideos)
50 .filter(k => this.checkedVideos[k] === true)
51 .map(k => parseInt(k, 10))
52
53 this.confirmService.confirm(`Do you really want to delete ${toDeleteVideosIds.length} videos?`, 'Delete').subscribe(
54 res => {
55 if (res === false) return
56
57 const observables: Observable<any>[] = []
58 for (const videoId of toDeleteVideosIds) {
59 const o = this.videoService
60 .removeVideo(videoId)
61 .do(() => this.spliceVideosById(videoId))
62
63 observables.push(o)
64 }
65
66 Observable.from(observables)
67 .concatAll()
68 .subscribe(
69 res => this.notificationsService.success('Success', `${toDeleteVideosIds.length} videos deleted.`),
70
c5911fd3 71 err => this.notificationsService.error('Error', err.message)
ce0e281d
C
72 )
73 }
74 )
75 }
76
332542bc
C
77 deleteVideo (video: Video) {
78 this.confirmService.confirm(`Do you really want to delete ${video.name}?`, 'Delete').subscribe(
79 res => {
80 if (res === false) return
81
82 this.videoService.removeVideo(video.id)
83 .subscribe(
84 status => {
85 this.notificationsService.success('Success', `Video ${video.name} deleted.`)
ce0e281d 86 this.spliceVideosById(video.id)
332542bc
C
87 },
88
c5911fd3 89 error => this.notificationsService.error('Error', error.message)
332542bc
C
90 )
91 }
92 )
93 }
ce0e281d
C
94
95 private spliceVideosById (id: number) {
96 const index = this.videos.findIndex(v => v.id === id)
97 this.videos.splice(index, 1)
98 }
202f6b6c 99}