diff options
Diffstat (limited to 'client/src/app/+my-account/my-account-videos/my-account-videos.component.ts')
-rw-r--r-- | client/src/app/+my-account/my-account-videos/my-account-videos.component.ts | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts b/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts index eed4be01f..afc01073c 100644 --- a/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts +++ b/client/src/app/+my-account/my-account-videos/my-account-videos.component.ts | |||
@@ -12,6 +12,7 @@ import { AbstractVideoList } from '../../shared/video/abstract-video-list' | |||
12 | import { Video } from '../../shared/video/video.model' | 12 | import { Video } from '../../shared/video/video.model' |
13 | import { VideoService } from '../../shared/video/video.service' | 13 | import { VideoService } from '../../shared/video/video.service' |
14 | import { I18n } from '@ngx-translate/i18n-polyfill' | 14 | import { I18n } from '@ngx-translate/i18n-polyfill' |
15 | import { VideoState } from '../../../../../shared/models/videos' | ||
15 | 16 | ||
16 | @Component({ | 17 | @Component({ |
17 | selector: 'my-account-videos', | 18 | selector: 'my-account-videos', |
@@ -59,7 +60,7 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni | |||
59 | } | 60 | } |
60 | 61 | ||
61 | isInSelectionMode () { | 62 | isInSelectionMode () { |
62 | return Object.keys(this.checkedVideos).some(k => this.checkedVideos[k] === true) | 63 | return Object.keys(this.checkedVideos).some(k => this.checkedVideos[ k ] === true) |
63 | } | 64 | } |
64 | 65 | ||
65 | getVideosObservable (page: number) { | 66 | getVideosObservable (page: number) { |
@@ -74,47 +75,68 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni | |||
74 | 75 | ||
75 | async deleteSelectedVideos () { | 76 | async deleteSelectedVideos () { |
76 | const toDeleteVideosIds = Object.keys(this.checkedVideos) | 77 | const toDeleteVideosIds = Object.keys(this.checkedVideos) |
77 | .filter(k => this.checkedVideos[k] === true) | 78 | .filter(k => this.checkedVideos[ k ] === true) |
78 | .map(k => parseInt(k, 10)) | 79 | .map(k => parseInt(k, 10)) |
79 | 80 | ||
80 | const res = await this.confirmService.confirm(`Do you really want to delete ${toDeleteVideosIds.length} videos?`, 'Delete') | 81 | const res = await this.confirmService.confirm( |
82 | this.i18n('Do you really want to delete {{deleteLength}} videos?', { deleteLength: toDeleteVideosIds.length }), | ||
83 | this.i18n('Delete') | ||
84 | ) | ||
81 | if (res === false) return | 85 | if (res === false) return |
82 | 86 | ||
83 | const observables: Observable<any>[] = [] | 87 | const observables: Observable<any>[] = [] |
84 | for (const videoId of toDeleteVideosIds) { | 88 | for (const videoId of toDeleteVideosIds) { |
85 | const o = this.videoService | 89 | const o = this.videoService.removeVideo(videoId) |
86 | .removeVideo(videoId) | ||
87 | .pipe(tap(() => this.spliceVideosById(videoId))) | 90 | .pipe(tap(() => this.spliceVideosById(videoId))) |
88 | 91 | ||
89 | observables.push(o) | 92 | observables.push(o) |
90 | } | 93 | } |
91 | 94 | ||
92 | observableFrom(observables).pipe( | 95 | observableFrom(observables) |
93 | concatAll()) | 96 | .pipe(concatAll()) |
94 | .subscribe( | 97 | .subscribe( |
95 | res => { | 98 | res => { |
96 | this.notificationsService.success('Success', `${toDeleteVideosIds.length} videos deleted.`) | 99 | this.notificationsService.success( |
100 | this.i18n('Success'), | ||
101 | this.i18n('{{deleteLength}} videos deleted.', { deleteLength: toDeleteVideosIds.length }) | ||
102 | ) | ||
103 | |||
97 | this.abortSelectionMode() | 104 | this.abortSelectionMode() |
98 | this.reloadVideos() | 105 | this.reloadVideos() |
99 | }, | 106 | }, |
100 | 107 | ||
101 | err => this.notificationsService.error('Error', err.message) | 108 | err => this.notificationsService.error(this.i18n('Error'), err.message) |
102 | ) | 109 | ) |
103 | } | 110 | } |
104 | 111 | ||
105 | async deleteVideo (video: Video) { | 112 | async deleteVideo (video: Video) { |
106 | const res = await this.confirmService.confirm(`Do you really want to delete ${video.name}?`, 'Delete') | 113 | const res = await this.confirmService.confirm( |
114 | this.i18n('Do you really want to delete {{videoName}}?', { videoName: video.name }), | ||
115 | this.i18n('Delete') | ||
116 | ) | ||
107 | if (res === false) return | 117 | if (res === false) return |
108 | 118 | ||
109 | this.videoService.removeVideo(video.id) | 119 | this.videoService.removeVideo(video.id) |
110 | .subscribe( | 120 | .subscribe( |
111 | status => { | 121 | status => { |
112 | this.notificationsService.success('Success', `Video ${video.name} deleted.`) | 122 | this.notificationsService.success( |
113 | this.reloadVideos() | 123 | this.i18n('Success'), |
114 | }, | 124 | this.i18n('Video {{videoName}} deleted.', { videoName: video.name }) |
125 | ) | ||
126 | this.reloadVideos() | ||
127 | }, | ||
128 | |||
129 | error => this.notificationsService.error(this.i18n('Error'), error.message) | ||
130 | ) | ||
131 | } | ||
115 | 132 | ||
116 | error => this.notificationsService.error('Error', error.message) | 133 | getStateLabel (video: Video) { |
117 | ) | 134 | if (video.state.id === VideoState.PUBLISHED) return this.i18n('Published') |
135 | |||
136 | if (video.state.id === VideoState.TO_TRANSCODE && video.waitTranscoding === true) return this.i18n('Waiting transcoding') | ||
137 | if (video.state.id === VideoState.TO_TRANSCODE) return this.i18n('To transcode') | ||
138 | |||
139 | return this.i18n('Unknown state') | ||
118 | } | 140 | } |
119 | 141 | ||
120 | protected buildVideoHeight () { | 142 | protected buildVideoHeight () { |
@@ -124,7 +146,7 @@ export class MyAccountVideosComponent extends AbstractVideoList implements OnIni | |||
124 | 146 | ||
125 | private spliceVideosById (id: number) { | 147 | private spliceVideosById (id: number) { |
126 | for (const key of Object.keys(this.loadedPages)) { | 148 | for (const key of Object.keys(this.loadedPages)) { |
127 | const videos = this.loadedPages[key] | 149 | const videos = this.loadedPages[ key ] |
128 | const index = videos.findIndex(v => v.id === id) | 150 | const index = videos.findIndex(v => v.id === id) |
129 | 151 | ||
130 | if (index !== -1) { | 152 | if (index !== -1) { |