]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/account/account-videos/account-videos.component.ts
Update dependencies
[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 } = {}
234b535d
C
22 pagination = {
23 currentPage: 1,
24 itemsPerPage: 10,
25 totalItems: null
26 }
202f6b6c
C
27
28 constructor (protected router: Router,
29 protected route: ActivatedRoute,
b2731bff 30 protected authService: AuthService,
202f6b6c 31 protected notificationsService: NotificationsService,
332542bc 32 protected confirmService: ConfirmService,
202f6b6c
C
33 private videoService: VideoService) {
34 super()
35 }
36
37 ngOnInit () {
38 super.ngOnInit()
39 }
40
ce0e281d
C
41 abortSelectionMode () {
42 this.checkedVideos = {}
43 }
44
45 isInSelectionMode () {
46 return Object.keys(this.checkedVideos).some(k => this.checkedVideos[k] === true)
47 }
48
202f6b6c
C
49 getVideosObservable () {
50 return this.videoService.getMyVideos(this.pagination, this.sort)
51 }
332542bc 52
ce0e281d
C
53 deleteSelectedVideos () {
54 const toDeleteVideosIds = Object.keys(this.checkedVideos)
55 .filter(k => this.checkedVideos[k] === true)
56 .map(k => parseInt(k, 10))
57
58 this.confirmService.confirm(`Do you really want to delete ${toDeleteVideosIds.length} videos?`, 'Delete').subscribe(
59 res => {
60 if (res === false) return
61
62 const observables: Observable<any>[] = []
63 for (const videoId of toDeleteVideosIds) {
64 const o = this.videoService
65 .removeVideo(videoId)
66 .do(() => this.spliceVideosById(videoId))
67
68 observables.push(o)
69 }
70
71 Observable.from(observables)
72 .concatAll()
73 .subscribe(
74 res => this.notificationsService.success('Success', `${toDeleteVideosIds.length} videos deleted.`),
75
c5911fd3 76 err => this.notificationsService.error('Error', err.message)
ce0e281d
C
77 )
78 }
79 )
80 }
81
332542bc
C
82 deleteVideo (video: Video) {
83 this.confirmService.confirm(`Do you really want to delete ${video.name}?`, 'Delete').subscribe(
84 res => {
85 if (res === false) return
86
87 this.videoService.removeVideo(video.id)
88 .subscribe(
89 status => {
90 this.notificationsService.success('Success', `Video ${video.name} deleted.`)
ce0e281d 91 this.spliceVideosById(video.id)
332542bc
C
92 },
93
c5911fd3 94 error => this.notificationsService.error('Error', error.message)
332542bc
C
95 )
96 }
97 )
98 }
ce0e281d
C
99
100 private spliceVideosById (id: number) {
101 const index = this.videos.findIndex(v => v.id === id)
102 this.videos.splice(index, 1)
103 }
202f6b6c 104}