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/videos/video-list | |
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/videos/video-list')
12 files changed, 149 insertions, 70 deletions
diff --git a/client/src/app/videos/video-list/index.ts b/client/src/app/videos/video-list/index.ts index b367110ae..af1bd58b7 100644 --- a/client/src/app/videos/video-list/index.ts +++ b/client/src/app/videos/video-list/index.ts | |||
@@ -1,3 +1,4 @@ | |||
1 | export * from './overview' | ||
1 | export * from './video-local.component' | 2 | export * from './video-local.component' |
2 | export * from './video-recently-added.component' | 3 | export * from './video-recently-added.component' |
3 | export * from './video-trending.component' | 4 | export * from './video-trending.component' |
diff --git a/client/src/app/videos/video-list/overview/index.ts b/client/src/app/videos/video-list/overview/index.ts new file mode 100644 index 000000000..e6cfa4802 --- /dev/null +++ b/client/src/app/videos/video-list/overview/index.ts | |||
@@ -0,0 +1,3 @@ | |||
1 | export * from './overview.service' | ||
2 | export * from './video-overview.component' | ||
3 | export * from './videos-overview.model' | ||
diff --git a/client/src/app/videos/video-list/overview/overview.service.ts b/client/src/app/videos/video-list/overview/overview.service.ts new file mode 100644 index 000000000..4458454d5 --- /dev/null +++ b/client/src/app/videos/video-list/overview/overview.service.ts | |||
@@ -0,0 +1,78 @@ | |||
1 | import { forkJoin, Observable, of } from 'rxjs' | ||
2 | import { catchError, map, switchMap, tap } from 'rxjs/operators' | ||
3 | import { HttpClient, HttpParams } from '@angular/common/http' | ||
4 | import { Injectable } from '@angular/core' | ||
5 | import { RestExtractor, ServerService } from '@app/core' | ||
6 | import { immutableAssign } from '@app/helpers' | ||
7 | import { VideoService } from '@app/shared/shared-main' | ||
8 | import { peertubeTranslate, VideosOverview as VideosOverviewServer } from '@shared/models' | ||
9 | import { environment } from '../../../../environments/environment' | ||
10 | import { VideosOverview } from './videos-overview.model' | ||
11 | |||
12 | @Injectable() | ||
13 | export class OverviewService { | ||
14 | static BASE_OVERVIEW_URL = environment.apiUrl + '/api/v1/overviews/' | ||
15 | |||
16 | constructor ( | ||
17 | private authHttp: HttpClient, | ||
18 | private restExtractor: RestExtractor, | ||
19 | private videosService: VideoService, | ||
20 | private serverService: ServerService | ||
21 | ) {} | ||
22 | |||
23 | getVideosOverview (page: number): Observable<VideosOverview> { | ||
24 | let params = new HttpParams() | ||
25 | params = params.append('page', page + '') | ||
26 | |||
27 | return this.authHttp | ||
28 | .get<VideosOverviewServer>(OverviewService.BASE_OVERVIEW_URL + 'videos', { params }) | ||
29 | .pipe( | ||
30 | switchMap(serverVideosOverview => this.updateVideosOverview(serverVideosOverview)), | ||
31 | catchError(err => this.restExtractor.handleError(err)) | ||
32 | ) | ||
33 | } | ||
34 | |||
35 | private updateVideosOverview (serverVideosOverview: VideosOverviewServer): Observable<VideosOverview> { | ||
36 | const observables: Observable<any>[] = [] | ||
37 | const videosOverviewResult: VideosOverview = { | ||
38 | tags: [], | ||
39 | categories: [], | ||
40 | channels: [] | ||
41 | } | ||
42 | |||
43 | // Build videos objects | ||
44 | for (const key of Object.keys(serverVideosOverview)) { | ||
45 | for (const object of serverVideosOverview[ key ]) { | ||
46 | observables.push( | ||
47 | of(object.videos) | ||
48 | .pipe( | ||
49 | switchMap(videos => this.videosService.extractVideos({ total: 0, data: videos })), | ||
50 | map(result => result.data), | ||
51 | tap(videos => { | ||
52 | videosOverviewResult[key].push(immutableAssign(object, { videos })) | ||
53 | }) | ||
54 | ) | ||
55 | ) | ||
56 | } | ||
57 | } | ||
58 | |||
59 | if (observables.length === 0) return of(videosOverviewResult) | ||
60 | |||
61 | return forkJoin(observables) | ||
62 | .pipe( | ||
63 | // Translate categories | ||
64 | switchMap(() => { | ||
65 | return this.serverService.getServerLocale() | ||
66 | .pipe( | ||
67 | tap(translations => { | ||
68 | for (const c of videosOverviewResult.categories) { | ||
69 | c.category.label = peertubeTranslate(c.category.label, translations) | ||
70 | } | ||
71 | }) | ||
72 | ) | ||
73 | }), | ||
74 | map(() => videosOverviewResult) | ||
75 | ) | ||
76 | } | ||
77 | |||
78 | } | ||
diff --git a/client/src/app/videos/video-list/video-overview.component.html b/client/src/app/videos/video-list/overview/video-overview.component.html index ca986c634..ca986c634 100644 --- a/client/src/app/videos/video-list/video-overview.component.html +++ b/client/src/app/videos/video-list/overview/video-overview.component.html | |||
diff --git a/client/src/app/videos/video-list/video-overview.component.scss b/client/src/app/videos/video-list/overview/video-overview.component.scss index c1d10188a..c1d10188a 100644 --- a/client/src/app/videos/video-list/video-overview.component.scss +++ b/client/src/app/videos/video-list/overview/video-overview.component.scss | |||
diff --git a/client/src/app/videos/video-list/video-overview.component.ts b/client/src/app/videos/video-list/overview/video-overview.component.ts index 8ff8400db..b3be1d7b5 100644 --- a/client/src/app/videos/video-list/video-overview.component.ts +++ b/client/src/app/videos/video-list/overview/video-overview.component.ts | |||
@@ -1,11 +1,9 @@ | |||
1 | import { Subject } from 'rxjs' | 1 | import { Subject } from 'rxjs' |
2 | import { Component, OnInit } from '@angular/core' | 2 | import { Component, OnInit } from '@angular/core' |
3 | import { Notifier } from '@app/core' | 3 | import { Notifier, ScreenService, User, UserService } from '@app/core' |
4 | import { User, UserService } from '@app/shared' | 4 | import { Video } from '@app/shared/shared-main' |
5 | import { ScreenService } from '@app/shared/misc/screen.service' | 5 | import { OverviewService } from './overview.service' |
6 | import { OverviewService } from '@app/shared/overview' | 6 | import { VideosOverview } from './videos-overview.model' |
7 | import { VideosOverview } from '@app/shared/overview/videos-overview.model' | ||
8 | import { Video } from '@app/shared/video/video.model' | ||
9 | 7 | ||
10 | @Component({ | 8 | @Component({ |
11 | selector: 'my-video-overview', | 9 | selector: 'my-video-overview', |
diff --git a/client/src/app/videos/video-list/overview/videos-overview.model.ts b/client/src/app/videos/video-list/overview/videos-overview.model.ts new file mode 100644 index 000000000..6765ad9b7 --- /dev/null +++ b/client/src/app/videos/video-list/overview/videos-overview.model.ts | |||
@@ -0,0 +1,20 @@ | |||
1 | import { Video } from '@app/shared/shared-main' | ||
2 | import { VideoChannelSummary, VideoConstant, VideosOverview as VideosOverviewServer } from '@shared/models' | ||
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 | } | ||
diff --git a/client/src/app/videos/video-list/video-local.component.ts b/client/src/app/videos/video-list/video-local.component.ts index 960523cd7..b4c71ac49 100644 --- a/client/src/app/videos/video-list/video-local.component.ts +++ b/client/src/app/videos/video-list/video-local.component.ts | |||
@@ -1,23 +1,17 @@ | |||
1 | import { Component, OnDestroy, OnInit } from '@angular/core' | 1 | import { Component, OnDestroy, OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | 2 | import { ActivatedRoute, Router } from '@angular/router' |
3 | import { immutableAssign } from '@app/shared/misc/utils' | 3 | import { AuthService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' |
4 | import { AuthService } from '../../core/auth' | ||
5 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | ||
6 | import { VideoSortField } from '../../shared/video/sort-field.type' | ||
7 | import { VideoService } from '../../shared/video/video.service' | ||
8 | import { VideoFilter } from '../../../../../shared/models/videos/video-query.type' | ||
9 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
10 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
11 | import { UserRight } from '../../../../../shared/models/users' | ||
12 | import { Notifier, ServerService } from '@app/core' | ||
13 | import { HooksService } from '@app/core/plugins/hooks.service' | 4 | import { HooksService } from '@app/core/plugins/hooks.service' |
14 | import { UserService } from '@app/shared' | 5 | import { immutableAssign } from '@app/helpers' |
15 | import { LocalStorageService } from '@app/shared/misc/storage.service' | 6 | import { VideoService } from '@app/shared/shared-main' |
7 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' | ||
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
9 | import { UserRight, VideoFilter, VideoSortField } from '@shared/models' | ||
16 | 10 | ||
17 | @Component({ | 11 | @Component({ |
18 | selector: 'my-videos-local', | 12 | selector: 'my-videos-local', |
19 | styleUrls: [ '../../shared/video/abstract-video-list.scss' ], | 13 | styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ], |
20 | templateUrl: '../../shared/video/abstract-video-list.html' | 14 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html' |
21 | }) | 15 | }) |
22 | export class VideoLocalComponent extends AbstractVideoList implements OnInit, OnDestroy { | 16 | export class VideoLocalComponent extends AbstractVideoList implements OnInit, OnDestroy { |
23 | titlePage: string | 17 | titlePage: string |
diff --git a/client/src/app/videos/video-list/video-most-liked.component.ts b/client/src/app/videos/video-list/video-most-liked.component.ts index cc91a2330..ca14851bb 100644 --- a/client/src/app/videos/video-list/video-most-liked.component.ts +++ b/client/src/app/videos/video-list/video-most-liked.component.ts | |||
@@ -1,21 +1,17 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | 1 | import { Component, OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | 2 | import { ActivatedRoute, Router } from '@angular/router' |
3 | import { immutableAssign } from '@app/shared/misc/utils' | 3 | import { AuthService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' |
4 | import { AuthService } from '../../core/auth' | ||
5 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | ||
6 | import { VideoSortField } from '../../shared/video/sort-field.type' | ||
7 | import { VideoService } from '../../shared/video/video.service' | ||
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
9 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
10 | import { Notifier, ServerService } from '@app/core' | ||
11 | import { HooksService } from '@app/core/plugins/hooks.service' | 4 | import { HooksService } from '@app/core/plugins/hooks.service' |
12 | import { UserService } from '@app/shared' | 5 | import { immutableAssign } from '@app/helpers' |
13 | import { LocalStorageService } from '@app/shared/misc/storage.service' | 6 | import { VideoService } from '@app/shared/shared-main' |
7 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' | ||
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
9 | import { VideoSortField } from '@shared/models' | ||
14 | 10 | ||
15 | @Component({ | 11 | @Component({ |
16 | selector: 'my-videos-most-liked', | 12 | selector: 'my-videos-most-liked', |
17 | styleUrls: [ '../../shared/video/abstract-video-list.scss' ], | 13 | styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ], |
18 | templateUrl: '../../shared/video/abstract-video-list.html' | 14 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html' |
19 | }) | 15 | }) |
20 | export class VideoMostLikedComponent extends AbstractVideoList implements OnInit { | 16 | export class VideoMostLikedComponent extends AbstractVideoList implements OnInit { |
21 | titlePage: string | 17 | titlePage: string |
diff --git a/client/src/app/videos/video-list/video-recently-added.component.ts b/client/src/app/videos/video-list/video-recently-added.component.ts index 9f57a61e3..c9395133f 100644 --- a/client/src/app/videos/video-list/video-recently-added.component.ts +++ b/client/src/app/videos/video-list/video-recently-added.component.ts | |||
@@ -1,21 +1,17 @@ | |||
1 | import { Component, OnDestroy, OnInit } from '@angular/core' | 1 | import { Component, OnDestroy, OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | 2 | import { ActivatedRoute, Router } from '@angular/router' |
3 | import { immutableAssign } from '@app/shared/misc/utils' | 3 | import { AuthService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' |
4 | import { AuthService } from '../../core/auth' | ||
5 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | ||
6 | import { VideoSortField } from '../../shared/video/sort-field.type' | ||
7 | import { VideoService } from '../../shared/video/video.service' | ||
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
9 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
10 | import { Notifier, ServerService } from '@app/core' | ||
11 | import { HooksService } from '@app/core/plugins/hooks.service' | 4 | import { HooksService } from '@app/core/plugins/hooks.service' |
12 | import { UserService } from '@app/shared' | 5 | import { immutableAssign } from '@app/helpers' |
13 | import { LocalStorageService } from '@app/shared/misc/storage.service' | 6 | import { VideoService } from '@app/shared/shared-main' |
7 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' | ||
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
9 | import { VideoSortField } from '@shared/models' | ||
14 | 10 | ||
15 | @Component({ | 11 | @Component({ |
16 | selector: 'my-videos-recently-added', | 12 | selector: 'my-videos-recently-added', |
17 | styleUrls: [ '../../shared/video/abstract-video-list.scss' ], | 13 | styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ], |
18 | templateUrl: '../../shared/video/abstract-video-list.html' | 14 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html' |
19 | }) | 15 | }) |
20 | export class VideoRecentlyAddedComponent extends AbstractVideoList implements OnInit, OnDestroy { | 16 | export class VideoRecentlyAddedComponent extends AbstractVideoList implements OnInit, OnDestroy { |
21 | titlePage: string | 17 | titlePage: string |
diff --git a/client/src/app/videos/video-list/video-trending.component.ts b/client/src/app/videos/video-list/video-trending.component.ts index 62e0f4e69..10eab18de 100644 --- a/client/src/app/videos/video-list/video-trending.component.ts +++ b/client/src/app/videos/video-list/video-trending.component.ts | |||
@@ -1,21 +1,17 @@ | |||
1 | import { Component, OnDestroy, OnInit } from '@angular/core' | 1 | import { Component, OnDestroy, OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | 2 | import { ActivatedRoute, Router } from '@angular/router' |
3 | import { immutableAssign } from '@app/shared/misc/utils' | 3 | import { AuthService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' |
4 | import { AuthService } from '../../core/auth' | ||
5 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | ||
6 | import { VideoSortField } from '../../shared/video/sort-field.type' | ||
7 | import { VideoService } from '../../shared/video/video.service' | ||
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
9 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
10 | import { Notifier, ServerService } from '@app/core' | ||
11 | import { HooksService } from '@app/core/plugins/hooks.service' | 4 | import { HooksService } from '@app/core/plugins/hooks.service' |
12 | import { UserService } from '@app/shared' | 5 | import { immutableAssign } from '@app/helpers' |
13 | import { LocalStorageService } from '@app/shared/misc/storage.service' | 6 | import { VideoService } from '@app/shared/shared-main' |
7 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' | ||
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
9 | import { VideoSortField } from '@shared/models' | ||
14 | 10 | ||
15 | @Component({ | 11 | @Component({ |
16 | selector: 'my-videos-trending', | 12 | selector: 'my-videos-trending', |
17 | styleUrls: [ '../../shared/video/abstract-video-list.scss' ], | 13 | styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ], |
18 | templateUrl: '../../shared/video/abstract-video-list.html' | 14 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html' |
19 | }) | 15 | }) |
20 | export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy { | 16 | export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy { |
21 | titlePage: string | 17 | titlePage: string |
diff --git a/client/src/app/videos/video-list/video-user-subscriptions.component.ts b/client/src/app/videos/video-list/video-user-subscriptions.component.ts index 036fd8dcb..41ad9b277 100644 --- a/client/src/app/videos/video-list/video-user-subscriptions.component.ts +++ b/client/src/app/videos/video-list/video-user-subscriptions.component.ts | |||
@@ -1,22 +1,18 @@ | |||
1 | import { Component, OnDestroy, OnInit } from '@angular/core' | 1 | import { Component, OnDestroy, OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | 2 | import { ActivatedRoute, Router } from '@angular/router' |
3 | import { immutableAssign } from '@app/shared/misc/utils' | 3 | import { AuthService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' |
4 | import { AuthService } from '../../core/auth' | ||
5 | import { AbstractVideoList } from '../../shared/video/abstract-video-list' | ||
6 | import { VideoSortField } from '../../shared/video/sort-field.type' | ||
7 | import { VideoService } from '../../shared/video/video.service' | ||
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
9 | import { ScreenService } from '@app/shared/misc/screen.service' | ||
10 | import { OwnerDisplayType } from '@app/shared/video/video-miniature.component' | ||
11 | import { Notifier, ServerService } from '@app/core' | ||
12 | import { HooksService } from '@app/core/plugins/hooks.service' | 4 | import { HooksService } from '@app/core/plugins/hooks.service' |
13 | import { UserService } from '@app/shared' | 5 | import { immutableAssign } from '@app/helpers' |
14 | import { LocalStorageService } from '@app/shared/misc/storage.service' | 6 | import { VideoService } from '@app/shared/shared-main' |
7 | import { UserSubscriptionService } from '@app/shared/shared-user-subscription' | ||
8 | import { AbstractVideoList, OwnerDisplayType } from '@app/shared/shared-video-miniature' | ||
9 | import { I18n } from '@ngx-translate/i18n-polyfill' | ||
10 | import { VideoSortField } from '@shared/models' | ||
15 | 11 | ||
16 | @Component({ | 12 | @Component({ |
17 | selector: 'my-videos-user-subscriptions', | 13 | selector: 'my-videos-user-subscriptions', |
18 | styleUrls: [ '../../shared/video/abstract-video-list.scss' ], | 14 | styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ], |
19 | templateUrl: '../../shared/video/abstract-video-list.html' | 15 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html' |
20 | }) | 16 | }) |
21 | export class VideoUserSubscriptionsComponent extends AbstractVideoList implements OnInit, OnDestroy { | 17 | export class VideoUserSubscriptionsComponent extends AbstractVideoList implements OnInit, OnDestroy { |
22 | titlePage: string | 18 | titlePage: string |
@@ -34,6 +30,7 @@ export class VideoUserSubscriptionsComponent extends AbstractVideoList implement | |||
34 | protected userService: UserService, | 30 | protected userService: UserService, |
35 | protected screenService: ScreenService, | 31 | protected screenService: ScreenService, |
36 | protected storageService: LocalStorageService, | 32 | protected storageService: LocalStorageService, |
33 | private userSubscription: UserSubscriptionService, | ||
37 | private videoService: VideoService, | 34 | private videoService: VideoService, |
38 | private hooks: HooksService | 35 | private hooks: HooksService |
39 | ) { | 36 | ) { |
@@ -64,7 +61,7 @@ export class VideoUserSubscriptionsComponent extends AbstractVideoList implement | |||
64 | } | 61 | } |
65 | 62 | ||
66 | return this.hooks.wrapObsFun( | 63 | return this.hooks.wrapObsFun( |
67 | this.videoService.getUserSubscriptionVideos.bind(this.videoService), | 64 | this.userSubscription.getUserSubscriptionVideos.bind(this.userSubscription), |
68 | params, | 65 | params, |
69 | 'common', | 66 | 'common', |
70 | 'filter:api.user-subscriptions-videos.videos.list.params', | 67 | 'filter:api.user-subscriptions-videos.videos.list.params', |