diff options
Diffstat (limited to 'client/src/app/shared/video-playlist/video-playlist.service.ts')
-rw-r--r-- | client/src/app/shared/video-playlist/video-playlist.service.ts | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/client/src/app/shared/video-playlist/video-playlist.service.ts b/client/src/app/shared/video-playlist/video-playlist.service.ts index da7437507..b93a19356 100644 --- a/client/src/app/shared/video-playlist/video-playlist.service.ts +++ b/client/src/app/shared/video-playlist/video-playlist.service.ts | |||
@@ -18,6 +18,9 @@ import { Account } from '@app/shared/account/account.model' | |||
18 | import { RestService } from '@app/shared/rest' | 18 | import { RestService } from '@app/shared/rest' |
19 | import { VideoExistInPlaylist } from '@shared/models/videos/playlist/video-exist-in-playlist.model' | 19 | import { VideoExistInPlaylist } from '@shared/models/videos/playlist/video-exist-in-playlist.model' |
20 | import { VideoPlaylistReorder } from '@shared/models/videos/playlist/video-playlist-reorder.model' | 20 | import { VideoPlaylistReorder } from '@shared/models/videos/playlist/video-playlist-reorder.model' |
21 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' | ||
22 | import { VideoPlaylistElement as ServerVideoPlaylistElement } from '@shared/models/videos/playlist/video-playlist-element.model' | ||
23 | import { VideoPlaylistElement } from '@app/shared/video-playlist/video-playlist-element.model' | ||
21 | 24 | ||
22 | @Injectable() | 25 | @Injectable() |
23 | export class VideoPlaylistService { | 26 | export class VideoPlaylistService { |
@@ -110,16 +113,16 @@ export class VideoPlaylistService { | |||
110 | ) | 113 | ) |
111 | } | 114 | } |
112 | 115 | ||
113 | updateVideoOfPlaylist (playlistId: number, videoId: number, body: VideoPlaylistElementUpdate) { | 116 | updateVideoOfPlaylist (playlistId: number, playlistElementId: number, body: VideoPlaylistElementUpdate) { |
114 | return this.authHttp.put(VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + playlistId + '/videos/' + videoId, body) | 117 | return this.authHttp.put(VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + playlistId + '/videos/' + playlistElementId, body) |
115 | .pipe( | 118 | .pipe( |
116 | map(this.restExtractor.extractDataBool), | 119 | map(this.restExtractor.extractDataBool), |
117 | catchError(err => this.restExtractor.handleError(err)) | 120 | catchError(err => this.restExtractor.handleError(err)) |
118 | ) | 121 | ) |
119 | } | 122 | } |
120 | 123 | ||
121 | removeVideoFromPlaylist (playlistId: number, videoId: number) { | 124 | removeVideoFromPlaylist (playlistId: number, playlistElementId: number) { |
122 | return this.authHttp.delete(VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + playlistId + '/videos/' + videoId) | 125 | return this.authHttp.delete(VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + playlistId + '/videos/' + playlistElementId) |
123 | .pipe( | 126 | .pipe( |
124 | map(this.restExtractor.extractDataBool), | 127 | map(this.restExtractor.extractDataBool), |
125 | catchError(err => this.restExtractor.handleError(err)) | 128 | catchError(err => this.restExtractor.handleError(err)) |
@@ -139,6 +142,24 @@ export class VideoPlaylistService { | |||
139 | ) | 142 | ) |
140 | } | 143 | } |
141 | 144 | ||
145 | getPlaylistVideos ( | ||
146 | videoPlaylistId: number | string, | ||
147 | componentPagination: ComponentPagination | ||
148 | ): Observable<ResultList<VideoPlaylistElement>> { | ||
149 | const path = VideoPlaylistService.BASE_VIDEO_PLAYLIST_URL + videoPlaylistId + '/videos' | ||
150 | const pagination = this.restService.componentPaginationToRestPagination(componentPagination) | ||
151 | |||
152 | let params = new HttpParams() | ||
153 | params = this.restService.addRestGetParams(params, pagination) | ||
154 | |||
155 | return this.authHttp | ||
156 | .get<ResultList<ServerVideoPlaylistElement>>(path, { params }) | ||
157 | .pipe( | ||
158 | switchMap(res => this.extractVideoPlaylistElements(res)), | ||
159 | catchError(err => this.restExtractor.handleError(err)) | ||
160 | ) | ||
161 | } | ||
162 | |||
142 | doesVideoExistInPlaylist (videoId: number) { | 163 | doesVideoExistInPlaylist (videoId: number) { |
143 | this.videoExistsInPlaylistSubject.next(videoId) | 164 | this.videoExistsInPlaylistSubject.next(videoId) |
144 | 165 | ||
@@ -167,6 +188,23 @@ export class VideoPlaylistService { | |||
167 | .pipe(map(translations => new VideoPlaylist(playlist, translations))) | 188 | .pipe(map(translations => new VideoPlaylist(playlist, translations))) |
168 | } | 189 | } |
169 | 190 | ||
191 | extractVideoPlaylistElements (result: ResultList<ServerVideoPlaylistElement>) { | ||
192 | return this.serverService.localeObservable | ||
193 | .pipe( | ||
194 | map(translations => { | ||
195 | const elementsJson = result.data | ||
196 | const total = result.total | ||
197 | const elements: VideoPlaylistElement[] = [] | ||
198 | |||
199 | for (const elementJson of elementsJson) { | ||
200 | elements.push(new VideoPlaylistElement(elementJson, translations)) | ||
201 | } | ||
202 | |||
203 | return { total, data: elements } | ||
204 | }) | ||
205 | ) | ||
206 | } | ||
207 | |||
170 | private doVideosExistInPlaylist (videoIds: number[]): Observable<VideoExistInPlaylist> { | 208 | private doVideosExistInPlaylist (videoIds: number[]): Observable<VideoExistInPlaylist> { |
171 | const url = VideoPlaylistService.MY_VIDEO_PLAYLIST_URL + 'videos-exist' | 209 | const url = VideoPlaylistService.MY_VIDEO_PLAYLIST_URL + 'videos-exist' |
172 | let params = new HttpParams() | 210 | let params = new HttpParams() |