]>
Commit | Line | Data |
---|---|---|
9af61e84 | 1 | import { Component, OnDestroy, OnInit } from '@angular/core' |
9bf9d2a5 | 2 | import { ActivatedRoute, Router } from '@angular/router' |
67ed6552 | 3 | import { AuthService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core' |
93cae479 | 4 | import { HooksService } from '@app/core/plugins/hooks.service' |
67ed6552 C |
5 | import { immutableAssign } from '@app/helpers' |
6 | import { VideoService } from '@app/shared/shared-main' | |
7 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' | |
67ed6552 | 8 | import { VideoSortField } from '@shared/models' |
9bf9d2a5 C |
9 | |
10 | @Component({ | |
11 | selector: 'my-videos-trending', | |
67ed6552 C |
12 | styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ], |
13 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html' | |
9bf9d2a5 | 14 | }) |
9af61e84 | 15 | export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy { |
989e526a | 16 | titlePage: string |
9a629c6e | 17 | defaultSort: VideoSortField = '-trending' |
9bf9d2a5 | 18 | |
5c20a455 | 19 | useUserVideoPreferences = true |
3caf77d3 | 20 | |
989e526a C |
21 | constructor ( |
22 | protected router: Router, | |
489290b8 | 23 | protected serverService: ServerService, |
989e526a | 24 | protected route: ActivatedRoute, |
f8b2c1b4 | 25 | protected notifier: Notifier, |
989e526a | 26 | protected authService: AuthService, |
d3217560 | 27 | protected userService: UserService, |
bbe0f064 | 28 | protected screenService: ScreenService, |
d3217560 | 29 | protected storageService: LocalStorageService, |
93cae479 C |
30 | private videoService: VideoService, |
31 | private hooks: HooksService | |
989e526a | 32 | ) { |
9bf9d2a5 C |
33 | super() |
34 | } | |
35 | ||
36 | ngOnInit () { | |
37 | super.ngOnInit() | |
cc1561f9 | 38 | |
244e76a5 | 39 | this.generateSyndicationList() |
7b95f313 | 40 | |
ba430d75 C |
41 | this.serverService.getConfig().subscribe( |
42 | config => { | |
43 | const trendingDays = config.trending.videos.intervalDays | |
7b95f313 | 44 | |
572b8e02 | 45 | if (trendingDays === 1) { |
66357162 C |
46 | this.titlePage = $localize`Trending for the last 24 hours` |
47 | this.titleTooltip = $localize`Trending videos are those totalizing the greatest number of views during the last 24 hours` | |
572b8e02 | 48 | } else { |
66357162 C |
49 | this.titlePage = `Trending for the last ${trendingDays} days` |
50 | this.titleTooltip = `Trending videos are those totalizing the greatest number of views during the last ${trendingDays} days` | |
572b8e02 C |
51 | } |
52 | }) | |
9bf9d2a5 C |
53 | } |
54 | ||
9af61e84 C |
55 | ngOnDestroy () { |
56 | super.ngOnDestroy() | |
57 | } | |
58 | ||
0cd4344f C |
59 | getVideosObservable (page: number) { |
60 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
93cae479 | 61 | const params = { |
3caf77d3 C |
62 | videoPagination: newPagination, |
63 | sort: this.sort, | |
3caf77d3 | 64 | categoryOneOf: this.categoryOneOf, |
440d39c5 | 65 | languageOneOf: this.languageOneOf, |
5c20a455 | 66 | nsfwPolicy: this.nsfwPolicy, |
440d39c5 | 67 | skipCount: true |
93cae479 C |
68 | } |
69 | ||
70 | return this.hooks.wrapObsFun( | |
71 | this.videoService.getVideos.bind(this.videoService), | |
72 | params, | |
73 | 'common', | |
7663e55a C |
74 | 'filter:api.trending-videos.videos.list.params', |
75 | 'filter:api.trending-videos.videos.list.result' | |
93cae479 | 76 | ) |
9bf9d2a5 | 77 | } |
244e76a5 RK |
78 | |
79 | generateSyndicationList () { | |
d59cba29 | 80 | this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf) |
244e76a5 | 81 | } |
9bf9d2a5 | 82 | } |