]>
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' | |
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
9 | import { VideoSortField } from '@shared/models' | |
9bf9d2a5 C |
10 | |
11 | @Component({ | |
12 | selector: 'my-videos-trending', | |
67ed6552 C |
13 | styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ], |
14 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html' | |
9bf9d2a5 | 15 | }) |
9af61e84 | 16 | export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy { |
989e526a | 17 | titlePage: string |
9a629c6e | 18 | defaultSort: VideoSortField = '-trending' |
9bf9d2a5 | 19 | |
5c20a455 | 20 | useUserVideoPreferences = true |
3caf77d3 | 21 | |
989e526a | 22 | constructor ( |
34c7f429 | 23 | protected i18n: I18n, |
989e526a | 24 | protected router: Router, |
489290b8 | 25 | protected serverService: ServerService, |
989e526a | 26 | protected route: ActivatedRoute, |
f8b2c1b4 | 27 | protected notifier: Notifier, |
989e526a | 28 | protected authService: AuthService, |
d3217560 | 29 | protected userService: UserService, |
bbe0f064 | 30 | protected screenService: ScreenService, |
d3217560 | 31 | protected storageService: LocalStorageService, |
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 | |
ba430d75 C |
43 | this.serverService.getConfig().subscribe( |
44 | config => { | |
45 | const trendingDays = config.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 | 69 | categoryOneOf: this.categoryOneOf, |
440d39c5 | 70 | languageOneOf: this.languageOneOf, |
5c20a455 | 71 | nsfwPolicy: this.nsfwPolicy, |
440d39c5 | 72 | skipCount: true |
93cae479 C |
73 | } |
74 | ||
75 | return this.hooks.wrapObsFun( | |
76 | this.videoService.getVideos.bind(this.videoService), | |
77 | params, | |
78 | 'common', | |
7663e55a C |
79 | 'filter:api.trending-videos.videos.list.params', |
80 | 'filter:api.trending-videos.videos.list.result' | |
93cae479 | 81 | ) |
9bf9d2a5 | 82 | } |
244e76a5 RK |
83 | |
84 | generateSyndicationList () { | |
d59cba29 | 85 | this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf) |
244e76a5 | 86 | } |
9bf9d2a5 | 87 | } |