diff options
author | Rigel Kent <sendmemail@rigelk.eu> | 2021-01-22 00:12:44 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-01-28 15:55:34 +0100 |
commit | 5bcbcbe338ef5a1ed14f084311d013fbb25dabcf (patch) | |
tree | b0f6382b30b67f1f7adddaf7d12af9adae0c9f5d /client/src/app/+videos/video-list/trending | |
parent | 7a4994873c0b3394d04e16e877fc7418bc8b146a (diff) | |
download | PeerTube-5bcbcbe338ef5a1ed14f084311d013fbb25dabcf.tar.gz PeerTube-5bcbcbe338ef5a1ed14f084311d013fbb25dabcf.tar.zst PeerTube-5bcbcbe338ef5a1ed14f084311d013fbb25dabcf.zip |
modularize abstract video list header and implement video hotness recommendation variant
Diffstat (limited to 'client/src/app/+videos/video-list/trending')
7 files changed, 351 insertions, 0 deletions
diff --git a/client/src/app/+videos/video-list/trending/index.ts b/client/src/app/+videos/video-list/trending/index.ts new file mode 100644 index 000000000..8bae205a5 --- /dev/null +++ b/client/src/app/+videos/video-list/trending/index.ts | |||
@@ -0,0 +1,4 @@ | |||
1 | export * from './video-trending-header.component' | ||
2 | export * from './video-trending.component' | ||
3 | export * from './video-hot.component' | ||
4 | export * from './video-most-liked.component' | ||
diff --git a/client/src/app/+videos/video-list/trending/video-hot.component.ts b/client/src/app/+videos/video-list/trending/video-hot.component.ts new file mode 100644 index 000000000..1617eb21e --- /dev/null +++ b/client/src/app/+videos/video-list/trending/video-hot.component.ts | |||
@@ -0,0 +1,85 @@ | |||
1 | import { Component, ComponentFactoryResolver, Injector, OnDestroy, OnInit } from '@angular/core' | ||
2 | import { ActivatedRoute, Router } from '@angular/router' | ||
3 | import { AuthService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' | ||
4 | import { HooksService } from '@app/core/plugins/hooks.service' | ||
5 | import { immutableAssign } from '@app/helpers' | ||
6 | import { VideoService } from '@app/shared/shared-main' | ||
7 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' | ||
8 | import { VideoSortField } from '@shared/models' | ||
9 | import { VideoTrendingHeaderComponent } from './video-trending-header.component' | ||
10 | |||
11 | @Component({ | ||
12 | selector: 'my-videos-hot', | ||
13 | styleUrls: [ '../../../shared/shared-video-miniature/abstract-video-list.scss' ], | ||
14 | templateUrl: '../../../shared/shared-video-miniature/abstract-video-list.html' | ||
15 | }) | ||
16 | export class VideoHotComponent extends AbstractVideoList implements OnInit, OnDestroy { | ||
17 | HeaderComponent = VideoTrendingHeaderComponent | ||
18 | titlePage: string | ||
19 | defaultSort: VideoSortField = '-hot' | ||
20 | |||
21 | useUserVideoPreferences = true | ||
22 | |||
23 | constructor ( | ||
24 | protected router: Router, | ||
25 | protected serverService: ServerService, | ||
26 | protected route: ActivatedRoute, | ||
27 | protected notifier: Notifier, | ||
28 | protected authService: AuthService, | ||
29 | protected userService: UserService, | ||
30 | protected screenService: ScreenService, | ||
31 | protected storageService: LocalStorageService, | ||
32 | protected cfr: ComponentFactoryResolver, | ||
33 | private videoService: VideoService, | ||
34 | private hooks: HooksService | ||
35 | ) { | ||
36 | super() | ||
37 | |||
38 | this.headerComponentInjector = this.getInjector() | ||
39 | } | ||
40 | |||
41 | ngOnInit () { | ||
42 | super.ngOnInit() | ||
43 | |||
44 | this.generateSyndicationList() | ||
45 | } | ||
46 | |||
47 | ngOnDestroy () { | ||
48 | super.ngOnDestroy() | ||
49 | } | ||
50 | |||
51 | getVideosObservable (page: number) { | ||
52 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | ||
53 | const params = { | ||
54 | videoPagination: newPagination, | ||
55 | sort: this.sort, | ||
56 | categoryOneOf: this.categoryOneOf, | ||
57 | languageOneOf: this.languageOneOf, | ||
58 | nsfwPolicy: this.nsfwPolicy, | ||
59 | skipCount: true | ||
60 | } | ||
61 | |||
62 | return this.hooks.wrapObsFun( | ||
63 | this.videoService.getVideos.bind(this.videoService), | ||
64 | params, | ||
65 | 'common', | ||
66 | 'filter:api.trending-videos.videos.list.params', | ||
67 | 'filter:api.trending-videos.videos.list.result' | ||
68 | ) | ||
69 | } | ||
70 | |||
71 | generateSyndicationList () { | ||
72 | this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf) | ||
73 | } | ||
74 | |||
75 | getInjector () { | ||
76 | return Injector.create({ | ||
77 | providers: [{ | ||
78 | provide: 'data', | ||
79 | useValue: { | ||
80 | model: this.defaultSort | ||
81 | } | ||
82 | }] | ||
83 | }) | ||
84 | } | ||
85 | } | ||
diff --git a/client/src/app/+videos/video-list/trending/video-most-liked.component.ts b/client/src/app/+videos/video-list/trending/video-most-liked.component.ts new file mode 100644 index 000000000..1781cc6aa --- /dev/null +++ b/client/src/app/+videos/video-list/trending/video-most-liked.component.ts | |||
@@ -0,0 +1,81 @@ | |||
1 | import { Component, ComponentFactoryResolver, Injector, OnInit } from '@angular/core' | ||
2 | import { ActivatedRoute, Router } from '@angular/router' | ||
3 | import { AuthService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' | ||
4 | import { HooksService } from '@app/core/plugins/hooks.service' | ||
5 | import { immutableAssign } from '@app/helpers' | ||
6 | import { VideoService } from '@app/shared/shared-main' | ||
7 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' | ||
8 | import { VideoSortField } from '@shared/models' | ||
9 | import { VideoTrendingHeaderComponent } from './video-trending-header.component' | ||
10 | |||
11 | @Component({ | ||
12 | selector: 'my-videos-most-liked', | ||
13 | styleUrls: [ '../../../shared/shared-video-miniature/abstract-video-list.scss' ], | ||
14 | templateUrl: '../../../shared/shared-video-miniature/abstract-video-list.html' | ||
15 | }) | ||
16 | export class VideoMostLikedComponent extends AbstractVideoList implements OnInit { | ||
17 | HeaderComponent = VideoTrendingHeaderComponent | ||
18 | titlePage: string | ||
19 | defaultSort: VideoSortField = '-likes' | ||
20 | |||
21 | useUserVideoPreferences = true | ||
22 | |||
23 | constructor ( | ||
24 | protected router: Router, | ||
25 | protected serverService: ServerService, | ||
26 | protected route: ActivatedRoute, | ||
27 | protected notifier: Notifier, | ||
28 | protected authService: AuthService, | ||
29 | protected userService: UserService, | ||
30 | protected screenService: ScreenService, | ||
31 | protected storageService: LocalStorageService, | ||
32 | protected cfr: ComponentFactoryResolver, | ||
33 | private videoService: VideoService, | ||
34 | private hooks: HooksService | ||
35 | ) { | ||
36 | super() | ||
37 | |||
38 | this.headerComponentInjector = this.getInjector() | ||
39 | } | ||
40 | |||
41 | ngOnInit () { | ||
42 | super.ngOnInit() | ||
43 | |||
44 | this.generateSyndicationList() | ||
45 | } | ||
46 | |||
47 | getVideosObservable (page: number) { | ||
48 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | ||
49 | const params = { | ||
50 | videoPagination: newPagination, | ||
51 | sort: this.sort, | ||
52 | categoryOneOf: this.categoryOneOf, | ||
53 | languageOneOf: this.languageOneOf, | ||
54 | nsfwPolicy: this.nsfwPolicy, | ||
55 | skipCount: true | ||
56 | } | ||
57 | |||
58 | return this.hooks.wrapObsFun( | ||
59 | this.videoService.getVideos.bind(this.videoService), | ||
60 | params, | ||
61 | 'common', | ||
62 | 'filter:api.most-liked-videos.videos.list.params', | ||
63 | 'filter:api.most-liked-videos.videos.list.result' | ||
64 | ) | ||
65 | } | ||
66 | |||
67 | generateSyndicationList () { | ||
68 | this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf) | ||
69 | } | ||
70 | |||
71 | getInjector () { | ||
72 | return Injector.create({ | ||
73 | providers: [{ | ||
74 | provide: 'data', | ||
75 | useValue: { | ||
76 | model: this.defaultSort | ||
77 | } | ||
78 | }] | ||
79 | }) | ||
80 | } | ||
81 | } | ||
diff --git a/client/src/app/+videos/video-list/trending/video-trending-header.component.html b/client/src/app/+videos/video-list/trending/video-trending-header.component.html new file mode 100644 index 000000000..6319ee6d3 --- /dev/null +++ b/client/src/app/+videos/video-list/trending/video-trending-header.component.html | |||
@@ -0,0 +1,6 @@ | |||
1 | <div class="btn-group btn-group-toggle" ngbRadioGroup name="radioBasic" [(ngModel)]="data.model" (ngModelChange)="setSort()"> | ||
2 | <label *ngFor="let button of buttons" ngbButtonLabel class="btn-light" placement="bottom" [ngbTooltip]="button.tooltip" container="body"> | ||
3 | <my-global-icon [iconName]="button.iconName"></my-global-icon> | ||
4 | <input ngbButton type="radio" [value]="button.value"> {{ button.label }} | ||
5 | </label> | ||
6 | </div> \ No newline at end of file | ||
diff --git a/client/src/app/+videos/video-list/trending/video-trending-header.component.scss b/client/src/app/+videos/video-list/trending/video-trending-header.component.scss new file mode 100644 index 000000000..923a1d67a --- /dev/null +++ b/client/src/app/+videos/video-list/trending/video-trending-header.component.scss | |||
@@ -0,0 +1,17 @@ | |||
1 | .btn-group label { | ||
2 | border: 1px solid transparent; | ||
3 | border-radius: 9999px !important; | ||
4 | padding: 5px 16px; | ||
5 | opacity: .8; | ||
6 | |||
7 | &:not(:first-child) { | ||
8 | margin-left: .5rem; | ||
9 | } | ||
10 | |||
11 | my-global-icon { | ||
12 | position: relative; | ||
13 | top: -2px; | ||
14 | height: 1rem; | ||
15 | margin-right: .1rem; | ||
16 | } | ||
17 | } \ No newline at end of file | ||
diff --git a/client/src/app/+videos/video-list/trending/video-trending-header.component.ts b/client/src/app/+videos/video-list/trending/video-trending-header.component.ts new file mode 100644 index 000000000..125f14e33 --- /dev/null +++ b/client/src/app/+videos/video-list/trending/video-trending-header.component.ts | |||
@@ -0,0 +1,59 @@ | |||
1 | import { Component, Inject } from '@angular/core' | ||
2 | import { Router } from '@angular/router' | ||
3 | import { VideoListHeaderComponent } from '@app/shared/shared-video-miniature' | ||
4 | import { GlobalIconName } from '@app/shared/shared-icons' | ||
5 | import { VideoSortField } from '@shared/models' | ||
6 | |||
7 | interface VideoTrendingHeaderItem { | ||
8 | label: string | ||
9 | iconName: GlobalIconName | ||
10 | value: VideoSortField | ||
11 | path: string | ||
12 | tooltip?: string | ||
13 | } | ||
14 | |||
15 | @Component({ | ||
16 | selector: 'video-trending-title-page', | ||
17 | host: { 'class': 'title-page title-page-single' }, | ||
18 | styleUrls: [ './video-trending-header.component.scss' ], | ||
19 | templateUrl: './video-trending-header.component.html' | ||
20 | }) | ||
21 | export class VideoTrendingHeaderComponent extends VideoListHeaderComponent { | ||
22 | buttons: VideoTrendingHeaderItem[] | ||
23 | |||
24 | constructor ( | ||
25 | @Inject('data') public data: any, | ||
26 | private router: Router | ||
27 | ) { | ||
28 | super(data) | ||
29 | |||
30 | this.buttons = [ | ||
31 | { | ||
32 | label: $localize`:A variant of Trending videos based on the number of recent interactions:Hot`, | ||
33 | iconName: 'flame', | ||
34 | value: '-hot', | ||
35 | path: 'hot', | ||
36 | tooltip: $localize`Videos totalizing the most interactions for recent videos`, | ||
37 | }, | ||
38 | { | ||
39 | label: $localize`:Main variant of Trending videos based on number of recent views:Views`, | ||
40 | iconName: 'trending', | ||
41 | value: '-trending', | ||
42 | path: 'trending', | ||
43 | tooltip: $localize`Videos totalizing the most views during the last 24 hours`, | ||
44 | }, | ||
45 | { | ||
46 | label: $localize`:a variant of Trending videos based on the number of likes:Likes`, | ||
47 | iconName: 'like', | ||
48 | value: '-likes', | ||
49 | path: 'most-liked', | ||
50 | tooltip: $localize`Videos that have the most likes` | ||
51 | } | ||
52 | ] | ||
53 | } | ||
54 | |||
55 | setSort () { | ||
56 | const path = this.buttons.find(b => b.value === this.data.model).path | ||
57 | this.router.navigate([ `/videos/${path}` ]) | ||
58 | } | ||
59 | } | ||
diff --git a/client/src/app/+videos/video-list/trending/video-trending.component.ts b/client/src/app/+videos/video-list/trending/video-trending.component.ts new file mode 100644 index 000000000..e77231586 --- /dev/null +++ b/client/src/app/+videos/video-list/trending/video-trending.component.ts | |||
@@ -0,0 +1,99 @@ | |||
1 | import { Component, ComponentFactoryResolver, Injector, OnDestroy, OnInit } from '@angular/core' | ||
2 | import { ActivatedRoute, Router } from '@angular/router' | ||
3 | import { AuthService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' | ||
4 | import { HooksService } from '@app/core/plugins/hooks.service' | ||
5 | import { immutableAssign } from '@app/helpers' | ||
6 | import { VideoService } from '@app/shared/shared-main' | ||
7 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' | ||
8 | import { VideoSortField } from '@shared/models' | ||
9 | import { VideoTrendingHeaderComponent } from './video-trending-header.component' | ||
10 | |||
11 | @Component({ | ||
12 | selector: 'my-videos-trending', | ||
13 | styleUrls: [ '../../../shared/shared-video-miniature/abstract-video-list.scss' ], | ||
14 | templateUrl: '../../../shared/shared-video-miniature/abstract-video-list.html' | ||
15 | }) | ||
16 | export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy { | ||
17 | HeaderComponent = VideoTrendingHeaderComponent | ||
18 | titlePage: string | ||
19 | defaultSort: VideoSortField = '-trending' | ||
20 | |||
21 | useUserVideoPreferences = true | ||
22 | |||
23 | constructor ( | ||
24 | protected router: Router, | ||
25 | protected serverService: ServerService, | ||
26 | protected route: ActivatedRoute, | ||
27 | protected notifier: Notifier, | ||
28 | protected authService: AuthService, | ||
29 | protected userService: UserService, | ||
30 | protected screenService: ScreenService, | ||
31 | protected storageService: LocalStorageService, | ||
32 | protected cfr: ComponentFactoryResolver, | ||
33 | private videoService: VideoService, | ||
34 | private hooks: HooksService | ||
35 | ) { | ||
36 | super() | ||
37 | |||
38 | this.headerComponentInjector = this.getInjector() | ||
39 | } | ||
40 | |||
41 | ngOnInit () { | ||
42 | super.ngOnInit() | ||
43 | |||
44 | this.generateSyndicationList() | ||
45 | |||
46 | this.serverService.getConfig().subscribe( | ||
47 | config => { | ||
48 | const trendingDays = config.trending.videos.intervalDays | ||
49 | |||
50 | if (trendingDays === 1) { | ||
51 | this.titleTooltip = $localize`Trending videos are those totalizing the greatest number of views during the last 24 hours` | ||
52 | } else { | ||
53 | this.titleTooltip = $localize`Trending videos are those totalizing the greatest number of views during the last ${trendingDays} days` | ||
54 | } | ||
55 | |||
56 | this.headerComponentInjector = this.getInjector() | ||
57 | this.setHeader() | ||
58 | }) | ||
59 | } | ||
60 | |||
61 | ngOnDestroy () { | ||
62 | super.ngOnDestroy() | ||
63 | } | ||
64 | |||
65 | getVideosObservable (page: number) { | ||
66 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | ||
67 | const params = { | ||
68 | videoPagination: newPagination, | ||
69 | sort: this.sort, | ||
70 | categoryOneOf: this.categoryOneOf, | ||
71 | languageOneOf: this.languageOneOf, | ||
72 | nsfwPolicy: this.nsfwPolicy, | ||
73 | skipCount: true | ||
74 | } | ||
75 | |||
76 | return this.hooks.wrapObsFun( | ||
77 | this.videoService.getVideos.bind(this.videoService), | ||
78 | params, | ||
79 | 'common', | ||
80 | 'filter:api.trending-videos.videos.list.params', | ||
81 | 'filter:api.trending-videos.videos.list.result' | ||
82 | ) | ||
83 | } | ||
84 | |||
85 | generateSyndicationList () { | ||
86 | this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf) | ||
87 | } | ||
88 | |||
89 | getInjector () { | ||
90 | return Injector.create({ | ||
91 | providers: [{ | ||
92 | provide: 'data', | ||
93 | useValue: { | ||
94 | model: this.defaultSort | ||
95 | } | ||
96 | }] | ||
97 | }) | ||
98 | } | ||
99 | } | ||