]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/account/account-videos/account-videos.component.ts
Fix changelog bullet points
[github/Chocobozzz/PeerTube.git] / client / src / app / account / account-videos / account-videos.component.ts
CommitLineData
9af61e84 1import { Component, OnInit, OnDestroy } from '@angular/core'
be447678 2import { ActivatedRoute, Router } from '@angular/router'
2a2c19df 3import { Location } from '@angular/common'
0cd4344f
C
4import { immutableAssign } from '@app/shared/misc/utils'
5import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
202f6b6c 6import { NotificationsService } from 'angular2-notifications'
ce0e281d
C
7import 'rxjs/add/observable/from'
8import 'rxjs/add/operator/concatAll'
9import { Observable } from 'rxjs/Observable'
b2731bff 10import { AuthService } from '../../core/auth'
332542bc 11import { ConfirmService } from '../../core/confirm'
be447678 12import { AbstractVideoList } from '../../shared/video/abstract-video-list'
332542bc 13import { Video } from '../../shared/video/video.model'
202f6b6c
C
14import { VideoService } from '../../shared/video/video.service'
15
16@Component({
17 selector: 'my-account-videos',
18 templateUrl: './account-videos.component.html',
19 styleUrls: [ './account-videos.component.scss' ]
20})
9af61e84 21export class AccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy {
202f6b6c
C
22 titlePage = 'My videos'
23 currentRoute = '/account/videos'
ce0e281d 24 checkedVideos: { [ id: number ]: boolean } = {}
0cd4344f 25 pagination: ComponentPagination = {
234b535d 26 currentPage: 1,
2e78e268 27 itemsPerPage: 5,
234b535d
C
28 totalItems: null
29 }
202f6b6c 30
9af61e84
C
31 protected baseVideoWidth = -1
32 protected baseVideoHeight = 155
33
202f6b6c
C
34 constructor (protected router: Router,
35 protected route: ActivatedRoute,
b2731bff 36 protected authService: AuthService,
202f6b6c 37 protected notificationsService: NotificationsService,
332542bc 38 protected confirmService: ConfirmService,
2a2c19df 39 protected location: Location,
202f6b6c
C
40 private videoService: VideoService) {
41 super()
42 }
43
44 ngOnInit () {
45 super.ngOnInit()
cc1561f9
C
46
47 // this.generateSyndicationList()
202f6b6c
C
48 }
49
9af61e84
C
50 ngOnDestroy () {
51 super.ngOnDestroy()
52 }
53
ce0e281d
C
54 abortSelectionMode () {
55 this.checkedVideos = {}
56 }
57
58 isInSelectionMode () {
59 return Object.keys(this.checkedVideos).some(k => this.checkedVideos[k] === true)
60 }
61
0cd4344f
C
62 getVideosObservable (page: number) {
63 const newPagination = immutableAssign(this.pagination, { currentPage: page })
64
65 return this.videoService.getMyVideos(newPagination, this.sort)
202f6b6c 66 }
332542bc 67
244e76a5
RK
68 generateSyndicationList () {
69 throw new Error('Method not implemented.')
70 }
71
1f30a185 72 async deleteSelectedVideos () {
ce0e281d
C
73 const toDeleteVideosIds = Object.keys(this.checkedVideos)
74 .filter(k => this.checkedVideos[k] === true)
75 .map(k => parseInt(k, 10))
76
1f30a185
C
77 const res = await this.confirmService.confirm(`Do you really want to delete ${toDeleteVideosIds.length} videos?`, 'Delete')
78 if (res === false) return
79
80 const observables: Observable<any>[] = []
81 for (const videoId of toDeleteVideosIds) {
82 const o = this.videoService
83 .removeVideo(videoId)
84 .do(() => this.spliceVideosById(videoId))
85
86 observables.push(o)
87 }
88
89 Observable.from(observables)
90 .concatAll()
91 .subscribe(
92 res => {
93 this.notificationsService.success('Success', `${toDeleteVideosIds.length} videos deleted.`)
94 this.buildVideoPages()
95 },
96
97 err => this.notificationsService.error('Error', err.message)
98 )
ce0e281d
C
99 }
100
1f30a185
C
101 async deleteVideo (video: Video) {
102 const res = await this.confirmService.confirm(`Do you really want to delete ${video.name}?`, 'Delete')
103 if (res === false) return
104
105 this.videoService.removeVideo(video.id)
106 .subscribe(
107 status => {
108 this.notificationsService.success('Success', `Video ${video.name} deleted.`)
109 this.spliceVideosById(video.id)
110 this.buildVideoPages()
111 },
112
113 error => this.notificationsService.error('Error', error.message)
114 )
332542bc 115 }
ce0e281d 116
a86887a4
C
117 protected buildVideoHeight () {
118 // In account videos, the video height is fixed
119 return this.baseVideoHeight
120 }
121
ce0e281d 122 private spliceVideosById (id: number) {
0cd4344f
C
123 for (const key of Object.keys(this.loadedPages)) {
124 const videos = this.loadedPages[key]
125 const index = videos.findIndex(v => v.id === id)
126
127 if (index !== -1) {
128 videos.splice(index, 1)
129 return
130 }
131 }
ce0e281d 132 }
202f6b6c 133}