]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+my-account/my-account-videos/my-account-videos.component.ts
Set thumbnail height
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-videos / my-account-videos.component.ts
CommitLineData
489290b8
C
1import { concat, Observable } from 'rxjs'
2import { tap, toArray } from 'rxjs/operators'
3import { Component, Inject, LOCALE_ID, OnDestroy, OnInit, ViewChild } from '@angular/core'
be447678 4import { ActivatedRoute, Router } from '@angular/router'
0cd4344f
C
5import { immutableAssign } from '@app/shared/misc/utils'
6import { ComponentPagination } from '@app/shared/rest/component-pagination.model'
489290b8 7import { Notifier, ServerService } from '@app/core'
b2731bff 8import { AuthService } from '../../core/auth'
332542bc 9import { ConfirmService } from '../../core/confirm'
be447678 10import { AbstractVideoList } from '../../shared/video/abstract-video-list'
332542bc 11import { Video } from '../../shared/video/video.model'
202f6b6c 12import { VideoService } from '../../shared/video/video.service'
b1d40cff 13import { I18n } from '@ngx-translate/i18n-polyfill'
bbe0f064
C
14import { VideoPrivacy, VideoState } from '../../../../../shared/models/videos'
15import { ScreenService } from '@app/shared/misc/screen.service'
74d63469 16import { VideoChangeOwnershipComponent } from './video-change-ownership/video-change-ownership.component'
202f6b6c
C
17
18@Component({
19 selector: 'my-account-videos',
4bb6886d
C
20 templateUrl: './my-account-videos.component.html',
21 styleUrls: [ './my-account-videos.component.scss' ]
202f6b6c 22})
4bb6886d 23export class MyAccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy {
489290b8
C
24 @ViewChild('videoChangeOwnershipModal') videoChangeOwnershipModal: VideoChangeOwnershipComponent
25
b1d40cff 26 titlePage: string
ce0e281d 27 checkedVideos: { [ id: number ]: boolean } = {}
0cd4344f 28 pagination: ComponentPagination = {
234b535d 29 currentPage: 1,
2e78e268 30 itemsPerPage: 5,
234b535d
C
31 totalItems: null
32 }
202f6b6c 33
b1d40cff
C
34 constructor (
35 protected router: Router,
489290b8 36 protected serverService: ServerService,
b1d40cff
C
37 protected route: ActivatedRoute,
38 protected authService: AuthService,
f8b2c1b4 39 protected notifier: Notifier,
bbe0f064 40 protected screenService: ScreenService,
489290b8 41 private i18n: I18n,
308c4275 42 private confirmService: ConfirmService,
bbe0f064
C
43 private videoService: VideoService,
44 @Inject(LOCALE_ID) private localeId: string
b1d40cff 45 ) {
202f6b6c 46 super()
b1d40cff
C
47
48 this.titlePage = this.i18n('My videos')
202f6b6c
C
49 }
50
51 ngOnInit () {
52 super.ngOnInit()
53 }
54
9af61e84
C
55 ngOnDestroy () {
56 super.ngOnDestroy()
57 }
58
ce0e281d
C
59 abortSelectionMode () {
60 this.checkedVideos = {}
61 }
62
63 isInSelectionMode () {
c199c427 64 return Object.keys(this.checkedVideos).some(k => this.checkedVideos[ k ] === true)
ce0e281d
C
65 }
66
0cd4344f
C
67 getVideosObservable (page: number) {
68 const newPagination = immutableAssign(this.pagination, { currentPage: page })
69
70 return this.videoService.getMyVideos(newPagination, this.sort)
202f6b6c 71 }
332542bc 72
244e76a5
RK
73 generateSyndicationList () {
74 throw new Error('Method not implemented.')
75 }
76
1f30a185 77 async deleteSelectedVideos () {
ce0e281d 78 const toDeleteVideosIds = Object.keys(this.checkedVideos)
c199c427 79 .filter(k => this.checkedVideos[ k ] === true)
2186386c 80 .map(k => parseInt(k, 10))
ce0e281d 81
2186386c
C
82 const res = await this.confirmService.confirm(
83 this.i18n('Do you really want to delete {{deleteLength}} videos?', { deleteLength: toDeleteVideosIds.length }),
84 this.i18n('Delete')
85 )
1f30a185
C
86 if (res === false) return
87
88 const observables: Observable<any>[] = []
89 for (const videoId of toDeleteVideosIds) {
2186386c 90 const o = this.videoService.removeVideo(videoId)
489290b8 91 .pipe(tap(() => this.removeVideoFromArray(videoId)))
1f30a185
C
92
93 observables.push(o)
94 }
95
489290b8
C
96 concat(...observables)
97 .pipe(toArray())
1f30a185 98 .subscribe(
489290b8 99 () => {
f8b2c1b4 100 this.notifier.success(this.i18n('{{deleteLength}} videos deleted.', { deleteLength: toDeleteVideosIds.length }))
2186386c 101
06be7ed0 102 this.abortSelectionMode()
1f30a185
C
103 },
104
f8b2c1b4 105 err => this.notifier.error(err.message)
1f30a185 106 )
ce0e281d
C
107 }
108
1f30a185 109 async deleteVideo (video: Video) {
2186386c
C
110 const res = await this.confirmService.confirm(
111 this.i18n('Do you really want to delete {{videoName}}?', { videoName: video.name }),
112 this.i18n('Delete')
113 )
1f30a185
C
114 if (res === false) return
115
116 this.videoService.removeVideo(video.id)
2186386c 117 .subscribe(
f8b2c1b4
C
118 () => {
119 this.notifier.success(this.i18n('Video {{videoName}} deleted.', { videoName: video.name }))
2186386c
C
120 this.reloadVideos()
121 },
122
f8b2c1b4 123 error => this.notifier.error(error.message)
2186386c
C
124 )
125 }
1f30a185 126
74d63469
GR
127 changeOwnership (event: Event, video: Video) {
128 event.preventDefault()
129 this.videoChangeOwnershipModal.show(video)
130 }
131
2186386c 132 getStateLabel (video: Video) {
bbe0f064
C
133 let suffix: string
134
135 if (video.privacy.id !== VideoPrivacy.PRIVATE && video.state.id === VideoState.PUBLISHED) {
136 suffix = this.i18n('Published')
137 } else if (video.scheduledUpdate) {
138 const updateAt = new Date(video.scheduledUpdate.updateAt.toString()).toLocaleString(this.localeId)
139 suffix = this.i18n('Publication scheduled on ') + updateAt
140 } else if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) {
141 suffix = this.i18n('Waiting transcoding')
142 } else if (video.state.id === VideoState.TO_TRANSCODE) {
143 suffix = this.i18n('To transcode')
ed31c059
C
144 } else if (video.state.id === VideoState.TO_IMPORT) {
145 suffix = this.i18n('To import')
bbe0f064
C
146 } else {
147 return ''
148 }
2186386c 149
bbe0f064 150 return ' - ' + suffix
332542bc 151 }
ce0e281d 152
489290b8
C
153 private removeVideoFromArray (id: number) {
154 this.videos = this.videos.filter(v => v.id !== id)
ce0e281d 155 }
202f6b6c 156}