diff options
author | Chocobozzz <me@florianbigard.com> | 2021-08-25 11:42:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-08-25 11:42:30 +0200 |
commit | fdec51e3846d50e3375612a6820ed3ab0b5fcd25 (patch) | |
tree | 17283e85a6794c9e8fe3f5d4478a406d8d188425 /client/src/app/shared/shared-user-settings | |
parent | 59c8902a57991be29f0aacac1642389fb770c6ed (diff) | |
parent | dd24f1bb0a4b252e5342b251ba36853364da7b8e (diff) | |
download | PeerTube-fdec51e3846d50e3375612a6820ed3ab0b5fcd25.tar.gz PeerTube-fdec51e3846d50e3375612a6820ed3ab0b5fcd25.tar.zst PeerTube-fdec51e3846d50e3375612a6820ed3ab0b5fcd25.zip |
Merge branch 'feature/video-filters' into develop
Diffstat (limited to 'client/src/app/shared/shared-user-settings')
3 files changed, 24 insertions, 78 deletions
diff --git a/client/src/app/shared/shared-user-settings/user-video-settings.component.html b/client/src/app/shared/shared-user-settings/user-video-settings.component.html index a49e11485..bc9dd0f7f 100644 --- a/client/src/app/shared/shared-user-settings/user-video-settings.component.html +++ b/client/src/app/shared/shared-user-settings/user-video-settings.component.html | |||
@@ -30,12 +30,7 @@ | |||
30 | </my-help> | 30 | </my-help> |
31 | 31 | ||
32 | <div> | 32 | <div> |
33 | <my-select-checkbox | 33 | <my-select-languages formControlName="videoLanguages"></my-select-languages> |
34 | formControlName="videoLanguages" [availableItems]="languageItems" | ||
35 | [selectableGroup]="true" [selectableGroupAsModel]="true" | ||
36 | i18n-placeholder placeholder="Add a new language" | ||
37 | > | ||
38 | </my-select-checkbox > | ||
39 | </div> | 34 | </div> |
40 | </div> | 35 | </div> |
41 | 36 | ||
diff --git a/client/src/app/shared/shared-user-settings/user-video-settings.component.scss b/client/src/app/shared/shared-user-settings/user-video-settings.component.scss index 4b007b691..c4f6020d4 100644 --- a/client/src/app/shared/shared-user-settings/user-video-settings.component.scss +++ b/client/src/app/shared/shared-user-settings/user-video-settings.component.scss | |||
@@ -19,7 +19,7 @@ input[type=submit] { | |||
19 | margin-bottom: 30px; | 19 | margin-bottom: 30px; |
20 | } | 20 | } |
21 | 21 | ||
22 | my-select-checkbox { | 22 | my-select-languages { |
23 | @include responsive-width(340px); | 23 | @include responsive-width(340px); |
24 | 24 | ||
25 | display: block; | 25 | display: block; |
diff --git a/client/src/app/shared/shared-user-settings/user-video-settings.component.ts b/client/src/app/shared/shared-user-settings/user-video-settings.component.ts index 5d6e11c04..0cd889a8a 100644 --- a/client/src/app/shared/shared-user-settings/user-video-settings.component.ts +++ b/client/src/app/shared/shared-user-settings/user-video-settings.component.ts | |||
@@ -1,12 +1,11 @@ | |||
1 | import { pick } from 'lodash-es' | 1 | import { pick } from 'lodash-es' |
2 | import { forkJoin, Subject, Subscription } from 'rxjs' | 2 | import { Subject, Subscription } from 'rxjs' |
3 | import { first } from 'rxjs/operators' | 3 | import { first } from 'rxjs/operators' |
4 | import { Component, Input, OnDestroy, OnInit } from '@angular/core' | 4 | import { Component, Input, OnDestroy, OnInit } from '@angular/core' |
5 | import { AuthService, Notifier, ServerService, User, UserService } from '@app/core' | 5 | import { AuthService, Notifier, ServerService, User, UserService } from '@app/core' |
6 | import { FormReactive, FormValidatorService, ItemSelectCheckboxValue } from '@app/shared/shared-forms' | 6 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' |
7 | import { UserUpdateMe } from '@shared/models' | 7 | import { UserUpdateMe } from '@shared/models' |
8 | import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' | 8 | import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' |
9 | import { SelectOptionsItem } from '../../../types/select-options-item.model' | ||
10 | 9 | ||
11 | @Component({ | 10 | @Component({ |
12 | selector: 'my-user-video-settings', | 11 | selector: 'my-user-video-settings', |
@@ -19,12 +18,9 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, | |||
19 | @Input() notifyOnUpdate = true | 18 | @Input() notifyOnUpdate = true |
20 | @Input() userInformationLoaded: Subject<any> | 19 | @Input() userInformationLoaded: Subject<any> |
21 | 20 | ||
22 | languageItems: SelectOptionsItem[] = [] | ||
23 | defaultNSFWPolicy: NSFWPolicyType | 21 | defaultNSFWPolicy: NSFWPolicyType |
24 | formValuesWatcher: Subscription | 22 | formValuesWatcher: Subscription |
25 | 23 | ||
26 | private allLanguagesGroup: string | ||
27 | |||
28 | constructor ( | 24 | constructor ( |
29 | protected formValidatorService: FormValidatorService, | 25 | protected formValidatorService: FormValidatorService, |
30 | private authService: AuthService, | 26 | private authService: AuthService, |
@@ -36,8 +32,6 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, | |||
36 | } | 32 | } |
37 | 33 | ||
38 | ngOnInit () { | 34 | ngOnInit () { |
39 | this.allLanguagesGroup = $localize`All languages` | ||
40 | |||
41 | this.buildForm({ | 35 | this.buildForm({ |
42 | nsfwPolicy: null, | 36 | nsfwPolicy: null, |
43 | webTorrentEnabled: null, | 37 | webTorrentEnabled: null, |
@@ -46,33 +40,23 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, | |||
46 | videoLanguages: null | 40 | videoLanguages: null |
47 | }) | 41 | }) |
48 | 42 | ||
49 | forkJoin([ | 43 | this.userInformationLoaded.pipe(first()) |
50 | this.serverService.getVideoLanguages(), | 44 | .subscribe( |
51 | this.userInformationLoaded.pipe(first()) | 45 | () => { |
52 | ]).subscribe(([ languages ]) => { | 46 | const serverConfig = this.serverService.getHTMLConfig() |
53 | const group = this.allLanguagesGroup | 47 | this.defaultNSFWPolicy = serverConfig.instance.defaultNSFWPolicy |
54 | 48 | ||
55 | this.languageItems = [ { label: $localize`Unknown language`, id: '_unknown', group } ] | 49 | this.form.patchValue({ |
56 | this.languageItems = this.languageItems | 50 | nsfwPolicy: this.user.nsfwPolicy || this.defaultNSFWPolicy, |
57 | .concat(languages.map(l => ({ label: l.label, id: l.id, group }))) | 51 | webTorrentEnabled: this.user.webTorrentEnabled, |
58 | 52 | autoPlayVideo: this.user.autoPlayVideo === true, | |
59 | const videoLanguages: ItemSelectCheckboxValue[] = this.user.videoLanguages | 53 | autoPlayNextVideo: this.user.autoPlayNextVideo, |
60 | ? this.user.videoLanguages.map(l => ({ id: l })) | 54 | videoLanguages: this.user.videoLanguages |
61 | : [ { group } ] | 55 | }) |
62 | 56 | ||
63 | const serverConfig = this.serverService.getHTMLConfig() | 57 | if (this.reactiveUpdate) this.handleReactiveUpdate() |
64 | this.defaultNSFWPolicy = serverConfig.instance.defaultNSFWPolicy | 58 | } |
65 | 59 | ) | |
66 | this.form.patchValue({ | ||
67 | nsfwPolicy: this.user.nsfwPolicy || this.defaultNSFWPolicy, | ||
68 | webTorrentEnabled: this.user.webTorrentEnabled, | ||
69 | autoPlayVideo: this.user.autoPlayVideo === true, | ||
70 | autoPlayNextVideo: this.user.autoPlayNextVideo, | ||
71 | videoLanguages | ||
72 | }) | ||
73 | |||
74 | if (this.reactiveUpdate) this.handleReactiveUpdate() | ||
75 | }) | ||
76 | } | 60 | } |
77 | 61 | ||
78 | ngOnDestroy () { | 62 | ngOnDestroy () { |
@@ -85,23 +69,15 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, | |||
85 | const autoPlayVideo = this.form.value['autoPlayVideo'] | 69 | const autoPlayVideo = this.form.value['autoPlayVideo'] |
86 | const autoPlayNextVideo = this.form.value['autoPlayNextVideo'] | 70 | const autoPlayNextVideo = this.form.value['autoPlayNextVideo'] |
87 | 71 | ||
88 | let videoLanguagesForm = this.form.value['videoLanguages'] | 72 | const videoLanguages = this.form.value['videoLanguages'] |
89 | 73 | ||
90 | if (Array.isArray(videoLanguagesForm)) { | 74 | if (Array.isArray(videoLanguages)) { |
91 | if (videoLanguagesForm.length > 20) { | 75 | if (videoLanguages.length > 20) { |
92 | this.notifier.error($localize`Too many languages are enabled. Please enable them all or stay below 20 enabled languages.`) | 76 | this.notifier.error($localize`Too many languages are enabled. Please enable them all or stay below 20 enabled languages.`) |
93 | return | 77 | return |
94 | } | 78 | } |
95 | |||
96 | // Automatically use "All languages" if the user did not select any language | ||
97 | if (videoLanguagesForm.length === 0) { | ||
98 | videoLanguagesForm = [ this.allLanguagesGroup ] | ||
99 | this.form.patchValue({ videoLanguages: [ { group: this.allLanguagesGroup } ] }) | ||
100 | } | ||
101 | } | 79 | } |
102 | 80 | ||
103 | const videoLanguages = this.buildLanguagesFromForm(videoLanguagesForm) | ||
104 | |||
105 | let details: UserUpdateMe = { | 81 | let details: UserUpdateMe = { |
106 | nsfwPolicy, | 82 | nsfwPolicy, |
107 | webTorrentEnabled, | 83 | webTorrentEnabled, |
@@ -123,31 +99,6 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, | |||
123 | return this.updateAnonymousProfile(details) | 99 | return this.updateAnonymousProfile(details) |
124 | } | 100 | } |
125 | 101 | ||
126 | private buildLanguagesFromForm (videoLanguages: ItemSelectCheckboxValue[]) { | ||
127 | if (!Array.isArray(videoLanguages)) return undefined | ||
128 | |||
129 | // null means "All" | ||
130 | if (videoLanguages.length === this.languageItems.length) return null | ||
131 | |||
132 | if (videoLanguages.length === 1) { | ||
133 | const videoLanguage = videoLanguages[0] | ||
134 | |||
135 | if (typeof videoLanguage === 'string') { | ||
136 | if (videoLanguage === this.allLanguagesGroup) return null | ||
137 | } else { | ||
138 | if (videoLanguage.group === this.allLanguagesGroup) return null | ||
139 | } | ||
140 | } | ||
141 | |||
142 | return videoLanguages.map(l => { | ||
143 | if (typeof l === 'string') return l | ||
144 | |||
145 | if (l.group) return l.group | ||
146 | |||
147 | return l.id + '' | ||
148 | }) | ||
149 | } | ||
150 | |||
151 | private handleReactiveUpdate () { | 102 | private handleReactiveUpdate () { |
152 | let oldForm = { ...this.form.value } | 103 | let oldForm = { ...this.form.value } |
153 | 104 | ||