]>
Commit | Line | Data |
---|---|---|
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 { VideoFilter } from '../../../../../shared/models/videos/video-query.type' | |
9 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
10 | import { ScreenService } from '@app/shared/misc/screen.service' | |
11 | import { UserRight } from '../../../../../shared/models/users' | |
12 | import { Notifier, ServerService } from '@app/core' | |
13 | import { HooksService } from '@app/core/plugins/hooks.service' | |
14 | ||
15 | @Component({ | |
16 | selector: 'my-videos-local', | |
17 | styleUrls: [ '../../shared/video/abstract-video-list.scss' ], | |
18 | templateUrl: '../../shared/video/abstract-video-list.html' | |
19 | }) | |
20 | export class VideoLocalComponent extends AbstractVideoList implements OnInit, OnDestroy { | |
21 | titlePage: string | |
22 | sort = '-publishedAt' as VideoSortField | |
23 | filter: VideoFilter = 'local' | |
24 | ||
25 | useUserVideoLanguagePreferences = true | |
26 | ||
27 | constructor ( | |
28 | protected i18n: I18n, | |
29 | protected router: Router, | |
30 | protected serverService: ServerService, | |
31 | protected route: ActivatedRoute, | |
32 | protected notifier: Notifier, | |
33 | protected authService: AuthService, | |
34 | protected screenService: ScreenService, | |
35 | private videoService: VideoService, | |
36 | private hooks: HooksService | |
37 | ) { | |
38 | super() | |
39 | ||
40 | this.titlePage = i18n('Local videos') | |
41 | } | |
42 | ||
43 | ngOnInit () { | |
44 | super.ngOnInit() | |
45 | ||
46 | if (this.authService.isLoggedIn()) { | |
47 | const user = this.authService.getUser() | |
48 | this.displayModerationBlock = user.hasRight(UserRight.SEE_ALL_VIDEOS) | |
49 | } | |
50 | ||
51 | this.generateSyndicationList() | |
52 | } | |
53 | ||
54 | ngOnDestroy () { | |
55 | super.ngOnDestroy() | |
56 | } | |
57 | ||
58 | getVideosObservable (page: number) { | |
59 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
60 | const params = { | |
61 | videoPagination: newPagination, | |
62 | sort: this.sort, | |
63 | filter: this.filter, | |
64 | categoryOneOf: this.categoryOneOf, | |
65 | languageOneOf: this.languageOneOf | |
66 | } | |
67 | ||
68 | return this.hooks.wrapObsFun( | |
69 | this.videoService.getVideos.bind(this.videoService), | |
70 | params, | |
71 | 'common', | |
72 | 'filter:api.videos.list.local.params', | |
73 | 'filter:api.videos.list.local.result' | |
74 | ) | |
75 | } | |
76 | ||
77 | generateSyndicationList () { | |
78 | this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, this.filter, this.categoryOneOf) | |
79 | } | |
80 | ||
81 | toggleModerationDisplay () { | |
82 | this.filter = this.filter === 'local' ? 'all-local' as 'all-local' : 'local' as 'local' | |
83 | ||
84 | this.reloadVideos() | |
85 | } | |
86 | } |