Merge branch 'release/v1.3.0' into develop
[oweals/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 { immutableAssign } from '@app/shared/misc/utils'
4 import { AuthService } from '../../core/auth'
5 import { AbstractVideoList } from '../../shared/video/abstract-video-list'
6 import { VideoSortField } from '../../shared/video/sort-field.type'
7 import { VideoService } from '../../shared/video/video.service'
8 import { I18n } from '@ngx-translate/i18n-polyfill'
9 import { ScreenService } from '@app/shared/misc/screen.service'
10 import { Notifier, ServerService } from '@app/core'
11
12 @Component({
13   selector: 'my-videos-trending',
14   styleUrls: [ '../../shared/video/abstract-video-list.scss' ],
15   templateUrl: '../../shared/video/abstract-video-list.html'
16 })
17 export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy {
18   titlePage: string
19   defaultSort: VideoSortField = '-trending'
20
21   constructor (
22     protected i18n: I18n,
23     protected router: Router,
24     protected serverService: ServerService,
25     protected route: ActivatedRoute,
26     protected notifier: Notifier,
27     protected authService: AuthService,
28     protected screenService: ScreenService,
29     private videoService: VideoService
30   ) {
31     super()
32   }
33
34   ngOnInit () {
35     super.ngOnInit()
36
37     this.generateSyndicationList()
38
39     this.serverService.configLoaded.subscribe(
40       () => {
41         const trendingDays = this.serverService.getConfig().trending.videos.intervalDays
42
43         if (trendingDays === 1) {
44           this.titlePage = this.i18n('Trending for the last 24 hours')
45           this.titleTooltip = this.i18n('Trending videos are those totalizing the greatest number of views during the last 24 hours')
46         } else {
47           this.titlePage = this.i18n('Trending for the last {{days}} days', { days: trendingDays })
48           this.titleTooltip = this.i18n(
49             'Trending videos are those totalizing the greatest number of views during the last {{days}} days',
50             { days: trendingDays }
51           )
52         }
53       })
54   }
55
56   ngOnDestroy () {
57     super.ngOnDestroy()
58   }
59
60   getVideosObservable (page: number) {
61     const newPagination = immutableAssign(this.pagination, { currentPage: page })
62     return this.videoService.getVideos(newPagination, this.sort, undefined, this.categoryOneOf)
63   }
64
65   generateSyndicationList () {
66     this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf)
67   }
68 }