]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/videos/video-list/video-trending.component.ts
Use form-control to display box-shadow on form inputs/selects upon focus
[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 { 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 import { HooksService } from '@app/core/plugins/hooks.service'
12 import { UserService } from '@app/shared'
13 import { LocalStorageService } from '@app/shared/misc/storage.service'
14
15 @Component({
16 selector: 'my-videos-trending',
17 styleUrls: [ '../../shared/video/abstract-video-list.scss' ],
18 templateUrl: '../../shared/video/abstract-video-list.html'
19 })
20 export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy {
21 titlePage: string
22 defaultSort: VideoSortField = '-trending'
23
24 useUserVideoLanguagePreferences = true
25
26 constructor (
27 protected i18n: I18n,
28 protected router: Router,
29 protected serverService: ServerService,
30 protected route: ActivatedRoute,
31 protected notifier: Notifier,
32 protected authService: AuthService,
33 protected userService: UserService,
34 protected screenService: ScreenService,
35 protected storageService: LocalStorageService,
36 private videoService: VideoService,
37 private hooks: HooksService
38 ) {
39 super()
40 }
41
42 ngOnInit () {
43 super.ngOnInit()
44
45 this.generateSyndicationList()
46
47 this.serverService.getConfig().subscribe(
48 config => {
49 const trendingDays = config.trending.videos.intervalDays
50
51 if (trendingDays === 1) {
52 this.titlePage = this.i18n('Trending for the last 24 hours')
53 this.titleTooltip = this.i18n('Trending videos are those totalizing the greatest number of views during the last 24 hours')
54 } else {
55 this.titlePage = this.i18n('Trending for the last {{days}} days', { days: trendingDays })
56 this.titleTooltip = this.i18n(
57 'Trending videos are those totalizing the greatest number of views during the last {{days}} days',
58 { days: trendingDays }
59 )
60 }
61 })
62 }
63
64 ngOnDestroy () {
65 super.ngOnDestroy()
66 }
67
68 getVideosObservable (page: number) {
69 const newPagination = immutableAssign(this.pagination, { currentPage: page })
70 const params = {
71 videoPagination: newPagination,
72 sort: this.sort,
73 categoryOneOf: this.categoryOneOf,
74 languageOneOf: this.languageOneOf,
75 skipCount: true
76 }
77
78 return this.hooks.wrapObsFun(
79 this.videoService.getVideos.bind(this.videoService),
80 params,
81 'common',
82 'filter:api.trending-videos.videos.list.params',
83 'filter:api.trending-videos.videos.list.result'
84 )
85 }
86
87 generateSyndicationList () {
88 this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf)
89 }
90 }