]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+videos/video-list/video-trending.component.ts
Migrate to $localize
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / video-list / video-trending.component.ts
1 import { Component, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { AuthService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core'
4 import { HooksService } from '@app/core/plugins/hooks.service'
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 { VideoSortField } from '@shared/models'
9
10 @Component({
11 selector: 'my-videos-trending',
12 styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ],
13 templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html'
14 })
15 export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy {
16 titlePage: string
17 defaultSort: VideoSortField = '-trending'
18
19 useUserVideoPreferences = true
20
21 constructor (
22 protected router: Router,
23 protected serverService: ServerService,
24 protected route: ActivatedRoute,
25 protected notifier: Notifier,
26 protected authService: AuthService,
27 protected userService: UserService,
28 protected screenService: ScreenService,
29 protected storageService: LocalStorageService,
30 private videoService: VideoService,
31 private hooks: HooksService
32 ) {
33 super()
34 }
35
36 ngOnInit () {
37 super.ngOnInit()
38
39 this.generateSyndicationList()
40
41 this.serverService.getConfig().subscribe(
42 config => {
43 const trendingDays = config.trending.videos.intervalDays
44
45 if (trendingDays === 1) {
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`
48 } else {
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`
51 }
52 })
53 }
54
55 ngOnDestroy () {
56 super.ngOnDestroy()
57 }
58
59 getVideosObservable (page: number) {
60 const newPagination = immutableAssign(this.pagination, { currentPage: page })
61 const params = {
62 videoPagination: newPagination,
63 sort: this.sort,
64 categoryOneOf: this.categoryOneOf,
65 languageOneOf: this.languageOneOf,
66 nsfwPolicy: this.nsfwPolicy,
67 skipCount: true
68 }
69
70 return this.hooks.wrapObsFun(
71 this.videoService.getVideos.bind(this.videoService),
72 params,
73 'common',
74 'filter:api.trending-videos.videos.list.params',
75 'filter:api.trending-videos.videos.list.result'
76 )
77 }
78
79 generateSyndicationList () {
80 this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf)
81 }
82 }