]>
Commit | Line | Data |
---|---|---|
1 | import { Subscription } from 'rxjs' | |
2 | import { Component, HostBinding, Inject, OnDestroy, OnInit } from '@angular/core' | |
3 | import { ActivatedRoute, Router } from '@angular/router' | |
4 | import { AuthService, RedirectService } from '@app/core' | |
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' | |
8 | ||
9 | interface VideoTrendingHeaderItem { | |
10 | label: string | |
11 | iconName: GlobalIconName | |
12 | value: string | |
13 | tooltip?: string | |
14 | hidden?: boolean | |
15 | } | |
16 | ||
17 | @Component({ | |
18 | selector: 'video-trending-title-page', | |
19 | styleUrls: [ './video-trending-header.component.scss' ], | |
20 | templateUrl: './video-trending-header.component.html' | |
21 | }) | |
22 | export class VideoTrendingHeaderComponent extends VideoListHeaderComponent implements OnInit, OnDestroy { | |
23 | @HostBinding('class') class = 'title-page title-page-single' | |
24 | ||
25 | buttons: VideoTrendingHeaderItem[] | |
26 | ||
27 | private algorithmChangeSub: Subscription | |
28 | ||
29 | constructor ( | |
30 | @Inject('data') public data: any, | |
31 | private route: ActivatedRoute, | |
32 | private router: Router, | |
33 | private auth: AuthService, | |
34 | private serverService: ServerService, | |
35 | private redirectService: RedirectService | |
36 | ) { | |
37 | super(data) | |
38 | ||
39 | this.buttons = [ | |
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', | |
44 | tooltip: $localize`Videos with the most interactions for recent videos, minus user history`, | |
45 | hidden: true | |
46 | }, | |
47 | { | |
48 | label: $localize`:A variant of Trending videos based on the number of recent interactions:Hot`, | |
49 | iconName: 'flame', | |
50 | value: 'hot', | |
51 | tooltip: $localize`Videos with the most interactions for recent videos`, | |
52 | hidden: true | |
53 | }, | |
54 | { | |
55 | label: $localize`:Main variant of Trending videos based on number of recent views:Views`, | |
56 | iconName: 'trending', | |
57 | value: 'most-viewed', | |
58 | tooltip: $localize`Videos with the most views during the last 24 hours` | |
59 | }, | |
60 | { | |
61 | label: $localize`:A variant of Trending videos based on the number of likes:Likes`, | |
62 | iconName: 'like', | |
63 | value: 'most-liked', | |
64 | tooltip: $localize`Videos that have the most likes` | |
65 | } | |
66 | ] | |
67 | } | |
68 | ||
69 | ngOnInit () { | |
70 | const serverConfig = this.serverService.getHTMLConfig() | |
71 | const algEnabled = serverConfig.trending.videos.algorithms.enabled | |
72 | ||
73 | this.buttons = this.buttons.map(b => { | |
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 | ||
81 | return b | |
82 | }) | |
83 | ||
84 | this.algorithmChangeSub = this.route.queryParams.subscribe( | |
85 | queryParams => { | |
86 | this.data.model = queryParams['alg'] || this.redirectService.getDefaultTrendingAlgorithm() | |
87 | } | |
88 | ) | |
89 | } | |
90 | ||
91 | ngOnDestroy () { | |
92 | if (this.algorithmChangeSub) this.algorithmChangeSub.unsubscribe() | |
93 | } | |
94 | ||
95 | setSort () { | |
96 | const alg = this.data.model !== this.redirectService.getDefaultTrendingAlgorithm() | |
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 | ) | |
108 | } | |
109 | } |