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