aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos/video-list/video-trending.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+videos/video-list/video-trending.component.ts')
-rw-r--r--client/src/app/+videos/video-list/video-trending.component.ts87
1 files changed, 87 insertions, 0 deletions
diff --git a/client/src/app/+videos/video-list/video-trending.component.ts b/client/src/app/+videos/video-list/video-trending.component.ts
new file mode 100644
index 000000000..10eab18de
--- /dev/null
+++ b/client/src/app/+videos/video-list/video-trending.component.ts
@@ -0,0 +1,87 @@
1import { Component, OnDestroy, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router'
3import { AuthService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core'
4import { HooksService } from '@app/core/plugins/hooks.service'
5import { immutableAssign } from '@app/helpers'
6import { VideoService } from '@app/shared/shared-main'
7import { AbstractVideoList } from '@app/shared/shared-video-miniature'
8import { I18n } from '@ngx-translate/i18n-polyfill'
9import { VideoSortField } from '@shared/models'
10
11@Component({
12 selector: 'my-videos-trending',
13 styleUrls: [ '../../shared/shared-video-miniature/abstract-video-list.scss' ],
14 templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html'
15})
16export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy {
17 titlePage: string
18 defaultSort: VideoSortField = '-trending'
19
20 useUserVideoPreferences = true
21
22 constructor (
23 protected i18n: I18n,
24 protected router: Router,
25 protected serverService: ServerService,
26 protected route: ActivatedRoute,
27 protected notifier: Notifier,
28 protected authService: AuthService,
29 protected userService: UserService,
30 protected screenService: ScreenService,
31 protected storageService: LocalStorageService,
32 private videoService: VideoService,
33 private hooks: HooksService
34 ) {
35 super()
36 }
37
38 ngOnInit () {
39 super.ngOnInit()
40
41 this.generateSyndicationList()
42
43 this.serverService.getConfig().subscribe(
44 config => {
45 const trendingDays = config.trending.videos.intervalDays
46
47 if (trendingDays === 1) {
48 this.titlePage = this.i18n('Trending for the last 24 hours')
49 this.titleTooltip = this.i18n('Trending videos are those totalizing the greatest number of views during the last 24 hours')
50 } else {
51 this.titlePage = this.i18n('Trending for the last {{days}} days', { days: trendingDays })
52 this.titleTooltip = this.i18n(
53 'Trending videos are those totalizing the greatest number of views during the last {{days}} days',
54 { days: trendingDays }
55 )
56 }
57 })
58 }
59
60 ngOnDestroy () {
61 super.ngOnDestroy()
62 }
63
64 getVideosObservable (page: number) {
65 const newPagination = immutableAssign(this.pagination, { currentPage: page })
66 const params = {
67 videoPagination: newPagination,
68 sort: this.sort,
69 categoryOneOf: this.categoryOneOf,
70 languageOneOf: this.languageOneOf,
71 nsfwPolicy: this.nsfwPolicy,
72 skipCount: true
73 }
74
75 return this.hooks.wrapObsFun(
76 this.videoService.getVideos.bind(this.videoService),
77 params,
78 'common',
79 'filter:api.trending-videos.videos.list.params',
80 'filter:api.trending-videos.videos.list.result'
81 )
82 }
83
84 generateSyndicationList () {
85 this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf)
86 }
87}