diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-19 09:24:29 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-25 11:24:11 +0200 |
commit | dd24f1bb0a4b252e5342b251ba36853364da7b8e (patch) | |
tree | 41a9506d07413f056fb90425705e258f96fdc77d /client/src/app/shared/shared-video-miniature/video-filters-header.component.ts | |
parent | 2e80d256cc75b4b02c8efc3d3e4cdf57ddf401a8 (diff) | |
download | PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.gz PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.zst PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.zip |
Add video filters to common video pages
Diffstat (limited to 'client/src/app/shared/shared-video-miniature/video-filters-header.component.ts')
-rw-r--r-- | client/src/app/shared/shared-video-miniature/video-filters-header.component.ts | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/client/src/app/shared/shared-video-miniature/video-filters-header.component.ts b/client/src/app/shared/shared-video-miniature/video-filters-header.component.ts new file mode 100644 index 000000000..99f133e54 --- /dev/null +++ b/client/src/app/shared/shared-video-miniature/video-filters-header.component.ts | |||
@@ -0,0 +1,119 @@ | |||
1 | import * as debug from 'debug' | ||
2 | import { Subscription } from 'rxjs' | ||
3 | import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core' | ||
4 | import { FormBuilder, FormGroup } from '@angular/forms' | ||
5 | import { AuthService } from '@app/core' | ||
6 | import { ServerService } from '@app/core/server/server.service' | ||
7 | import { UserRight } from '@shared/models' | ||
8 | import { NSFWPolicyType } from '@shared/models/videos' | ||
9 | import { PeertubeModalService } from '../shared-main' | ||
10 | import { VideoFilters } from './video-filters.model' | ||
11 | |||
12 | const logger = debug('peertube:videos:VideoFiltersHeaderComponent') | ||
13 | |||
14 | @Component({ | ||
15 | selector: 'my-video-filters-header', | ||
16 | styleUrls: [ './video-filters-header.component.scss' ], | ||
17 | templateUrl: './video-filters-header.component.html' | ||
18 | }) | ||
19 | export class VideoFiltersHeaderComponent implements OnInit, OnDestroy { | ||
20 | @Input() filters: VideoFilters | ||
21 | |||
22 | @Input() displayModerationBlock = false | ||
23 | |||
24 | @Input() defaultSort = '-publishedAt' | ||
25 | @Input() nsfwPolicy: NSFWPolicyType | ||
26 | |||
27 | @Output() filtersChanged = new EventEmitter() | ||
28 | |||
29 | areFiltersCollapsed = true | ||
30 | |||
31 | form: FormGroup | ||
32 | |||
33 | private routeSub: Subscription | ||
34 | |||
35 | constructor ( | ||
36 | private auth: AuthService, | ||
37 | private serverService: ServerService, | ||
38 | private fb: FormBuilder, | ||
39 | private modalService: PeertubeModalService | ||
40 | ) { | ||
41 | } | ||
42 | |||
43 | ngOnInit () { | ||
44 | this.form = this.fb.group({ | ||
45 | sort: [ '' ], | ||
46 | nsfw: [ '' ], | ||
47 | languageOneOf: [ '' ], | ||
48 | categoryOneOf: [ '' ], | ||
49 | scope: [ '' ], | ||
50 | allVideos: [ '' ], | ||
51 | live: [ '' ] | ||
52 | }) | ||
53 | |||
54 | this.patchForm(false) | ||
55 | |||
56 | this.filters.onChange(() => { | ||
57 | this.patchForm(false) | ||
58 | }) | ||
59 | |||
60 | this.form.valueChanges.subscribe(values => { | ||
61 | logger('Loading values from form: %O', values) | ||
62 | |||
63 | this.filters.load(values) | ||
64 | this.filtersChanged.emit() | ||
65 | }) | ||
66 | } | ||
67 | |||
68 | ngOnDestroy () { | ||
69 | if (this.routeSub) this.routeSub.unsubscribe() | ||
70 | } | ||
71 | |||
72 | canSeeAllVideos () { | ||
73 | if (!this.auth.isLoggedIn()) return false | ||
74 | if (!this.displayModerationBlock) return false | ||
75 | |||
76 | return this.auth.getUser().hasRight(UserRight.SEE_ALL_VIDEOS) | ||
77 | } | ||
78 | |||
79 | isTrendingSortEnabled (sort: 'most-viewed' | 'hot' | 'best' | 'most-liked') { | ||
80 | const serverConfig = this.serverService.getHTMLConfig() | ||
81 | |||
82 | const enabled = serverConfig.trending.videos.algorithms.enabled.includes(sort) | ||
83 | |||
84 | // Best is adapted from the user | ||
85 | if (sort === 'best') return enabled && this.auth.isLoggedIn() | ||
86 | |||
87 | return enabled | ||
88 | } | ||
89 | |||
90 | resetFilter (key: string, canRemove: boolean) { | ||
91 | if (!canRemove) return | ||
92 | |||
93 | this.filters.reset(key) | ||
94 | this.patchForm(false) | ||
95 | this.filtersChanged.emit() | ||
96 | } | ||
97 | |||
98 | getFilterTitle (canRemove: boolean) { | ||
99 | if (canRemove) return $localize`Remove this filter` | ||
100 | |||
101 | return '' | ||
102 | } | ||
103 | |||
104 | onAccountSettingsClick (event: Event) { | ||
105 | if (this.auth.isLoggedIn()) return | ||
106 | |||
107 | event.preventDefault() | ||
108 | event.stopPropagation() | ||
109 | |||
110 | this.modalService.openQuickSettingsSubject.next() | ||
111 | } | ||
112 | |||
113 | private patchForm (emitEvent: boolean) { | ||
114 | const defaultValues = this.filters.toFormObject() | ||
115 | this.form.patchValue(defaultValues, { emitEvent }) | ||
116 | |||
117 | logger('Patched form: %O', defaultValues) | ||
118 | } | ||
119 | } | ||