diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-23 14:10:17 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2020-06-23 16:00:49 +0200 |
commit | 67ed6552b831df66713bac9e672738796128d33f (patch) | |
tree | 59c97d41e0b49d75a90aa3de987968ab9b1ff447 /client/src/app/shared/overview | |
parent | 0c4bacbff53bc732f5a2677d62a6ead7752e2405 (diff) | |
download | PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.gz PeerTube-67ed6552b831df66713bac9e672738796128d33f.tar.zst PeerTube-67ed6552b831df66713bac9e672738796128d33f.zip |
Reorganize client shared modules
Diffstat (limited to 'client/src/app/shared/overview')
-rw-r--r-- | client/src/app/shared/overview/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/shared/overview/overview.service.ts | 79 | ||||
-rw-r--r-- | client/src/app/shared/overview/videos-overview.model.ts | 20 |
3 files changed, 0 insertions, 100 deletions
diff --git a/client/src/app/shared/overview/index.ts b/client/src/app/shared/overview/index.ts deleted file mode 100644 index 2f7e41298..000000000 --- a/client/src/app/shared/overview/index.ts +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | export * from './overview.service' | ||
diff --git a/client/src/app/shared/overview/overview.service.ts b/client/src/app/shared/overview/overview.service.ts deleted file mode 100644 index 6d8af8052..000000000 --- a/client/src/app/shared/overview/overview.service.ts +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | import { catchError, map, switchMap, tap } from 'rxjs/operators' | ||
2 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
3 | import { Injectable } from '@angular/core' | ||
4 | import { forkJoin, Observable, of } from 'rxjs' | ||
5 | import { VideosOverview as VideosOverviewServer, peertubeTranslate } from '../../../../../shared/models' | ||
6 | import { environment } from '../../../environments/environment' | ||
7 | import { RestExtractor } from '../rest/rest-extractor.service' | ||
8 | import { VideosOverview } from '@app/shared/overview/videos-overview.model' | ||
9 | import { VideoService } from '@app/shared/video/video.service' | ||
10 | import { ServerService } from '@app/core' | ||
11 | import { immutableAssign } from '@app/shared/misc/utils' | ||
12 | |||
13 | @Injectable() | ||
14 | export class OverviewService { | ||
15 | static BASE_OVERVIEW_URL = environment.apiUrl + '/api/v1/overviews/' | ||
16 | |||
17 | constructor ( | ||
18 | private authHttp: HttpClient, | ||
19 | private restExtractor: RestExtractor, | ||
20 | private videosService: VideoService, | ||
21 | private serverService: ServerService | ||
22 | ) {} | ||
23 | |||
24 | getVideosOverview (page: number): Observable<VideosOverview> { | ||
25 | let params = new HttpParams() | ||
26 | params = params.append('page', page + '') | ||
27 | |||
28 | return this.authHttp | ||
29 | .get<VideosOverviewServer>(OverviewService.BASE_OVERVIEW_URL + 'videos', { params }) | ||
30 | .pipe( | ||
31 | switchMap(serverVideosOverview => this.updateVideosOverview(serverVideosOverview)), | ||
32 | catchError(err => this.restExtractor.handleError(err)) | ||
33 | ) | ||
34 | } | ||
35 | |||
36 | private updateVideosOverview (serverVideosOverview: VideosOverviewServer): Observable<VideosOverview> { | ||
37 | const observables: Observable<any>[] = [] | ||
38 | const videosOverviewResult: VideosOverview = { | ||
39 | tags: [], | ||
40 | categories: [], | ||
41 | channels: [] | ||
42 | } | ||
43 | |||
44 | // Build videos objects | ||
45 | for (const key of Object.keys(serverVideosOverview)) { | ||
46 | for (const object of serverVideosOverview[ key ]) { | ||
47 | observables.push( | ||
48 | of(object.videos) | ||
49 | .pipe( | ||
50 | switchMap(videos => this.videosService.extractVideos({ total: 0, data: videos })), | ||
51 | map(result => result.data), | ||
52 | tap(videos => { | ||
53 | videosOverviewResult[key].push(immutableAssign(object, { videos })) | ||
54 | }) | ||
55 | ) | ||
56 | ) | ||
57 | } | ||
58 | } | ||
59 | |||
60 | if (observables.length === 0) return of(videosOverviewResult) | ||
61 | |||
62 | return forkJoin(observables) | ||
63 | .pipe( | ||
64 | // Translate categories | ||
65 | switchMap(() => { | ||
66 | return this.serverService.getServerLocale() | ||
67 | .pipe( | ||
68 | tap(translations => { | ||
69 | for (const c of videosOverviewResult.categories) { | ||
70 | c.category.label = peertubeTranslate(c.category.label, translations) | ||
71 | } | ||
72 | }) | ||
73 | ) | ||
74 | }), | ||
75 | map(() => videosOverviewResult) | ||
76 | ) | ||
77 | } | ||
78 | |||
79 | } | ||
diff --git a/client/src/app/shared/overview/videos-overview.model.ts b/client/src/app/shared/overview/videos-overview.model.ts deleted file mode 100644 index 21abe1697..000000000 --- a/client/src/app/shared/overview/videos-overview.model.ts +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | import { VideoChannelSummary, VideoConstant, VideosOverview as VideosOverviewServer } from '../../../../../shared/models' | ||
2 | import { Video } from '@app/shared/video/video.model' | ||
3 | |||
4 | export class VideosOverview implements VideosOverviewServer { | ||
5 | channels: { | ||
6 | channel: VideoChannelSummary | ||
7 | videos: Video[] | ||
8 | }[] | ||
9 | |||
10 | categories: { | ||
11 | category: VideoConstant<number> | ||
12 | videos: Video[] | ||
13 | }[] | ||
14 | |||
15 | tags: { | ||
16 | tag: string | ||
17 | videos: Video[] | ||
18 | }[] | ||
19 | [key: string]: any | ||
20 | } | ||