]>
Commit | Line | Data |
---|---|---|
2989628b | 1 | import { Subscription } from 'rxjs' |
ba5d4a84 RK |
2 | import { Component, HostBinding, Inject, OnDestroy, OnInit } from '@angular/core' |
3 | import { ActivatedRoute, Router } from '@angular/router' | |
e6ea0cac | 4 | import { AuthService, RedirectService } from '@app/core' |
2989628b C |
5 | import { ServerService } from '@app/core/server/server.service' |
6 | import { GlobalIconName } from '@app/shared/shared-icons' | |
7 | import { VideoListHeaderComponent } from '@app/shared/shared-video-miniature' | |
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, |
aea0b0e7 C |
34 | private serverService: ServerService, |
35 | private redirectService: RedirectService | |
5bcbcbe3 RK |
36 | ) { |
37 | super(data) | |
38 | ||
39 | this.buttons = [ | |
3d4e112d RK |
40 | { |
41 | label: $localize`:A variant of Trending videos based on the number of recent interactions, minus user history:Best`, | |
42 | iconName: 'award', | |
43 | value: 'best', | |
8795d6f2 | 44 | tooltip: $localize`Videos with the most interactions for recent videos, minus user history`, |
3d4e112d RK |
45 | hidden: true |
46 | }, | |
5bcbcbe3 RK |
47 | { |
48 | label: $localize`:A variant of Trending videos based on the number of recent interactions:Hot`, | |
49 | iconName: 'flame', | |
ba5d4a84 | 50 | value: 'hot', |
8795d6f2 | 51 | tooltip: $localize`Videos with the most interactions for recent videos`, |
3da68f0a | 52 | hidden: true |
5bcbcbe3 RK |
53 | }, |
54 | { | |
55 | label: $localize`:Main variant of Trending videos based on number of recent views:Views`, | |
56 | iconName: 'trending', | |
ba5d4a84 | 57 | value: 'most-viewed', |
8795d6f2 | 58 | tooltip: $localize`Videos with the most views during the last 24 hours` |
5bcbcbe3 RK |
59 | }, |
60 | { | |
3da68f0a | 61 | label: $localize`:A variant of Trending videos based on the number of likes:Likes`, |
5bcbcbe3 | 62 | iconName: 'like', |
ba5d4a84 | 63 | value: 'most-liked', |
5bcbcbe3 RK |
64 | tooltip: $localize`Videos that have the most likes` |
65 | } | |
66 | ] | |
67 | } | |
68 | ||
3da68f0a | 69 | ngOnInit () { |
2989628b C |
70 | const serverConfig = this.serverService.getHTMLConfig() |
71 | const algEnabled = serverConfig.trending.videos.algorithms.enabled | |
e6ea0cac | 72 | |
2989628b C |
73 | this.buttons = this.buttons.map(b => { |
74 | b.hidden = !algEnabled.includes(b.value) | |
e6ea0cac | 75 | |
2989628b C |
76 | // Best is adapted by the user history so |
77 | if (b.value === 'best' && !this.auth.isLoggedIn()) { | |
78 | b.hidden = true | |
79 | } | |
e6ea0cac | 80 | |
2989628b C |
81 | return b |
82 | }) | |
ba5d4a84 RK |
83 | |
84 | this.algorithmChangeSub = this.route.queryParams.subscribe( | |
85 | queryParams => { | |
aea0b0e7 | 86 | this.data.model = queryParams['alg'] || this.redirectService.getDefaultTrendingAlgorithm() |
ba5d4a84 RK |
87 | } |
88 | ) | |
3da68f0a RK |
89 | } |
90 | ||
ba5d4a84 RK |
91 | ngOnDestroy () { |
92 | if (this.algorithmChangeSub) this.algorithmChangeSub.unsubscribe() | |
3da68f0a RK |
93 | } |
94 | ||
5bcbcbe3 | 95 | setSort () { |
aea0b0e7 | 96 | const alg = this.data.model !== this.redirectService.getDefaultTrendingAlgorithm() |
ba5d4a84 RK |
97 | ? this.data.model |
98 | : undefined | |
99 | ||
100 | this.router.navigate( | |
101 | [], | |
102 | { | |
103 | relativeTo: this.route, | |
104 | queryParams: { alg }, | |
105 | queryParamsHandling: 'merge' | |
106 | } | |
107 | ) | |
5bcbcbe3 RK |
108 | } |
109 | } |