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