]>
Commit | Line | Data |
---|---|---|
ba5d4a84 RK |
1 | import { Component, HostBinding, Inject, OnDestroy, OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | |
5bcbcbe3 RK |
3 | import { VideoListHeaderComponent } from '@app/shared/shared-video-miniature' |
4 | import { GlobalIconName } from '@app/shared/shared-icons' | |
3da68f0a | 5 | import { ServerService } from '@app/core/server/server.service' |
ba5d4a84 | 6 | import { Subscription } from 'rxjs' |
e6ea0cac | 7 | import { AuthService, RedirectService } from '@app/core' |
5bcbcbe3 RK |
8 | |
9 | interface VideoTrendingHeaderItem { | |
10 | label: string | |
11 | iconName: GlobalIconName | |
ba5d4a84 | 12 | value: string |
5bcbcbe3 | 13 | tooltip?: string |
3da68f0a | 14 | hidden?: boolean |
5bcbcbe3 RK |
15 | } |
16 | ||
17 | @Component({ | |
18 | selector: 'video-trending-title-page', | |
5bcbcbe3 RK |
19 | styleUrls: [ './video-trending-header.component.scss' ], |
20 | templateUrl: './video-trending-header.component.html' | |
21 | }) | |
ba5d4a84 RK |
22 | export class VideoTrendingHeaderComponent extends VideoListHeaderComponent implements OnInit, OnDestroy { |
23 | @HostBinding('class') class = 'title-page title-page-single' | |
24 | ||
5bcbcbe3 RK |
25 | buttons: VideoTrendingHeaderItem[] |
26 | ||
ba5d4a84 RK |
27 | private algorithmChangeSub: Subscription |
28 | ||
5bcbcbe3 RK |
29 | constructor ( |
30 | @Inject('data') public data: any, | |
ba5d4a84 | 31 | private route: ActivatedRoute, |
3da68f0a | 32 | private router: Router, |
e6ea0cac | 33 | private auth: AuthService, |
3da68f0a | 34 | private serverService: ServerService |
5bcbcbe3 RK |
35 | ) { |
36 | super(data) | |
37 | ||
38 | this.buttons = [ | |
3d4e112d RK |
39 | { |
40 | label: $localize`:A variant of Trending videos based on the number of recent interactions, minus user history:Best`, | |
41 | iconName: 'award', | |
42 | value: 'best', | |
8795d6f2 | 43 | tooltip: $localize`Videos with the most interactions for recent videos, minus user history`, |
3d4e112d RK |
44 | hidden: true |
45 | }, | |
5bcbcbe3 RK |
46 | { |
47 | label: $localize`:A variant of Trending videos based on the number of recent interactions:Hot`, | |
48 | iconName: 'flame', | |
ba5d4a84 | 49 | value: 'hot', |
8795d6f2 | 50 | tooltip: $localize`Videos with the most interactions for recent videos`, |
3da68f0a | 51 | hidden: true |
5bcbcbe3 RK |
52 | }, |
53 | { | |
54 | label: $localize`:Main variant of Trending videos based on number of recent views:Views`, | |
55 | iconName: 'trending', | |
ba5d4a84 | 56 | value: 'most-viewed', |
8795d6f2 | 57 | tooltip: $localize`Videos with the most views during the last 24 hours` |
5bcbcbe3 RK |
58 | }, |
59 | { | |
3da68f0a | 60 | label: $localize`:A variant of Trending videos based on the number of likes:Likes`, |
5bcbcbe3 | 61 | iconName: 'like', |
ba5d4a84 | 62 | value: 'most-liked', |
5bcbcbe3 RK |
63 | tooltip: $localize`Videos that have the most likes` |
64 | } | |
65 | ] | |
66 | } | |
67 | ||
3da68f0a RK |
68 | ngOnInit () { |
69 | this.serverService.getConfig() | |
70 | .subscribe(config => { | |
e6ea0cac C |
71 | const algEnabled = config.trending.videos.algorithms.enabled |
72 | ||
ba5d4a84 | 73 | this.buttons = this.buttons.map(b => { |
e6ea0cac C |
74 | b.hidden = !algEnabled.includes(b.value) |
75 | ||
76 | // Best is adapted by the user history so | |
77 | if (b.value === 'best' && !this.auth.isLoggedIn()) { | |
78 | b.hidden = true | |
79 | } | |
80 | ||
ba5d4a84 RK |
81 | return b |
82 | }) | |
3da68f0a | 83 | }) |
ba5d4a84 RK |
84 | |
85 | this.algorithmChangeSub = this.route.queryParams.subscribe( | |
86 | queryParams => { | |
87 | const algorithm = queryParams['alg'] | |
88 | if (algorithm) { | |
89 | this.data.model = algorithm | |
90 | } else { | |
91 | this.data.model = RedirectService.DEFAULT_TRENDING_ALGORITHM | |
92 | } | |
93 | } | |
94 | ) | |
3da68f0a RK |
95 | } |
96 | ||
ba5d4a84 RK |
97 | ngOnDestroy () { |
98 | if (this.algorithmChangeSub) this.algorithmChangeSub.unsubscribe() | |
3da68f0a RK |
99 | } |
100 | ||
5bcbcbe3 | 101 | setSort () { |
ba5d4a84 RK |
102 | const alg = this.data.model !== RedirectService.DEFAULT_TRENDING_ALGORITHM |
103 | ? this.data.model | |
104 | : undefined | |
105 | ||
106 | this.router.navigate( | |
107 | [], | |
108 | { | |
109 | relativeTo: this.route, | |
110 | queryParams: { alg }, | |
111 | queryParamsHandling: 'merge' | |
112 | } | |
113 | ) | |
5bcbcbe3 RK |
114 | } |
115 | } |