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