]>
Commit | Line | Data |
---|---|---|
5bcbcbe3 | 1 | import { Component, ComponentFactoryResolver, Injector, 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' |
5bcbcbe3 | 9 | import { VideoTrendingHeaderComponent } from './video-trending-header.component' |
9bf9d2a5 C |
10 | |
11 | @Component({ | |
12 | selector: 'my-videos-trending', | |
5bcbcbe3 RK |
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 { |
5bcbcbe3 | 17 | HeaderComponent = VideoTrendingHeaderComponent |
989e526a | 18 | titlePage: string |
9a629c6e | 19 | defaultSort: VideoSortField = '-trending' |
9bf9d2a5 | 20 | |
5c20a455 | 21 | useUserVideoPreferences = true |
3caf77d3 | 22 | |
989e526a C |
23 | constructor ( |
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, |
5bcbcbe3 | 32 | protected cfr: ComponentFactoryResolver, |
93cae479 C |
33 | private videoService: VideoService, |
34 | private hooks: HooksService | |
989e526a | 35 | ) { |
9bf9d2a5 | 36 | super() |
5bcbcbe3 RK |
37 | |
38 | this.headerComponentInjector = this.getInjector() | |
9bf9d2a5 C |
39 | } |
40 | ||
41 | ngOnInit () { | |
42 | super.ngOnInit() | |
cc1561f9 | 43 | |
244e76a5 | 44 | this.generateSyndicationList() |
7b95f313 | 45 | |
ba430d75 C |
46 | this.serverService.getConfig().subscribe( |
47 | config => { | |
48 | const trendingDays = config.trending.videos.intervalDays | |
7b95f313 | 49 | |
572b8e02 | 50 | if (trendingDays === 1) { |
66357162 | 51 | this.titleTooltip = $localize`Trending videos are those totalizing the greatest number of views during the last 24 hours` |
5bcbcbe3 RK |
52 | } else { |
53 | this.titleTooltip = $localize`Trending videos are those totalizing the greatest number of views during the last ${trendingDays} days` | |
572b8e02 | 54 | } |
f19a9e4b | 55 | |
5bcbcbe3 RK |
56 | this.headerComponentInjector = this.getInjector() |
57 | this.setHeader() | |
572b8e02 | 58 | }) |
9bf9d2a5 C |
59 | } |
60 | ||
9af61e84 C |
61 | ngOnDestroy () { |
62 | super.ngOnDestroy() | |
63 | } | |
64 | ||
0cd4344f C |
65 | getVideosObservable (page: number) { |
66 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
93cae479 | 67 | const params = { |
3caf77d3 C |
68 | videoPagination: newPagination, |
69 | sort: this.sort, | |
3caf77d3 | 70 | categoryOneOf: this.categoryOneOf, |
440d39c5 | 71 | languageOneOf: this.languageOneOf, |
5c20a455 | 72 | nsfwPolicy: this.nsfwPolicy, |
440d39c5 | 73 | skipCount: true |
93cae479 C |
74 | } |
75 | ||
76 | return this.hooks.wrapObsFun( | |
77 | this.videoService.getVideos.bind(this.videoService), | |
78 | params, | |
79 | 'common', | |
7663e55a C |
80 | 'filter:api.trending-videos.videos.list.params', |
81 | 'filter:api.trending-videos.videos.list.result' | |
93cae479 | 82 | ) |
9bf9d2a5 | 83 | } |
244e76a5 RK |
84 | |
85 | generateSyndicationList () { | |
d59cba29 | 86 | this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf) |
244e76a5 | 87 | } |
5bcbcbe3 RK |
88 | |
89 | getInjector () { | |
90 | return Injector.create({ | |
91 | providers: [{ | |
92 | provide: 'data', | |
93 | useValue: { | |
94 | model: this.defaultSort | |
95 | } | |
96 | }] | |
97 | }) | |
98 | } | |
9bf9d2a5 | 99 | } |