diff options
Diffstat (limited to 'client/src/app/shared/shared-user-settings')
3 files changed, 39 insertions, 20 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 bb9f59070..655b49e18 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,11 +30,11 @@ | |||
30 | </my-help> | 30 | </my-help> |
31 | 31 | ||
32 | <div> | 32 | <div> |
33 | <p-multiSelect | 33 | <my-select-checkbox |
34 | inputId="videoLanguages" [options]="languageItems" formControlName="videoLanguages" [showToggleAll]="true" | 34 | formControlName="videoLanguages" [availableItems]="languageItems" |
35 | [defaultLabel]="getDefaultVideoLanguageLabel()" [selectedItemsLabel]="getSelectedVideoLanguageLabel()" | 35 | [selectableGroup]="true" [selectableGroupAsModel]="true" |
36 | emptyFilterMessage="No results found" i18n-emptyFilterMessage | 36 | > |
37 | ></p-multiSelect> | 37 | </my-select-checkbox > |
38 | </div> | 38 | </div> |
39 | </div> | 39 | </div> |
40 | 40 | ||
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 430250b87..d6a17703a 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,6 +19,10 @@ input[type=submit] { | |||
19 | margin-bottom: 30px; | 19 | margin-bottom: 30px; |
20 | } | 20 | } |
21 | 21 | ||
22 | my-select-checkbox { | ||
23 | @include ng-select(340px); | ||
24 | } | ||
25 | |||
22 | .form-group-select { | 26 | .form-group-select { |
23 | margin-bottom: 30px; | 27 | margin-bottom: 30px; |
24 | } | 28 | } |
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 4e4539936..eb340e24d 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,10 +1,9 @@ | |||
1 | import { pick } from 'lodash-es' | 1 | import { pick } from 'lodash-es' |
2 | import { SelectItem } from 'primeng/api' | ||
3 | import { forkJoin, Subject, Subscription } from 'rxjs' | 2 | import { forkJoin, Subject, Subscription } from 'rxjs' |
4 | import { first } from 'rxjs/operators' | 3 | import { first } from 'rxjs/operators' |
5 | import { Component, Input, OnDestroy, OnInit } from '@angular/core' | 4 | import { Component, Input, OnDestroy, OnInit } from '@angular/core' |
6 | import { AuthService, Notifier, ServerService, User, UserService } from '@app/core' | 5 | import { AuthService, Notifier, ServerService, User, UserService } from '@app/core' |
7 | import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' | 6 | import { FormReactive, FormValidatorService, ItemSelectCheckboxValue, SelectOptionsItem } from '@app/shared/shared-forms' |
8 | import { I18n } from '@ngx-translate/i18n-polyfill' | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
9 | import { UserUpdateMe } from '@shared/models' | 8 | import { UserUpdateMe } from '@shared/models' |
10 | import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' | 9 | import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' |
@@ -20,10 +19,12 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, | |||
20 | @Input() notifyOnUpdate = true | 19 | @Input() notifyOnUpdate = true |
21 | @Input() userInformationLoaded: Subject<any> | 20 | @Input() userInformationLoaded: Subject<any> |
22 | 21 | ||
23 | languageItems: SelectItem[] = [] | 22 | languageItems: SelectOptionsItem[] = [] |
24 | defaultNSFWPolicy: NSFWPolicyType | 23 | defaultNSFWPolicy: NSFWPolicyType |
25 | formValuesWatcher: Subscription | 24 | formValuesWatcher: Subscription |
26 | 25 | ||
26 | private allLanguagesGroup: string | ||
27 | |||
27 | constructor ( | 28 | constructor ( |
28 | protected formValidatorService: FormValidatorService, | 29 | protected formValidatorService: FormValidatorService, |
29 | private authService: AuthService, | 30 | private authService: AuthService, |
@@ -36,6 +37,8 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, | |||
36 | } | 37 | } |
37 | 38 | ||
38 | ngOnInit () { | 39 | ngOnInit () { |
40 | this.allLanguagesGroup = this.i18n('All languages') | ||
41 | |||
39 | let oldForm: any | 42 | let oldForm: any |
40 | 43 | ||
41 | this.buildForm({ | 44 | this.buildForm({ |
@@ -51,13 +54,15 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, | |||
51 | this.serverService.getConfig(), | 54 | this.serverService.getConfig(), |
52 | this.userInformationLoaded.pipe(first()) | 55 | this.userInformationLoaded.pipe(first()) |
53 | ]).subscribe(([ languages, config ]) => { | 56 | ]).subscribe(([ languages, config ]) => { |
54 | this.languageItems = [ { label: this.i18n('Unknown language'), value: '_unknown' } ] | 57 | const group = this.allLanguagesGroup |
58 | |||
59 | this.languageItems = [ { label: this.i18n('Unknown language'), id: '_unknown', group } ] | ||
55 | this.languageItems = this.languageItems | 60 | this.languageItems = this.languageItems |
56 | .concat(languages.map(l => ({ label: l.label, value: l.id }))) | 61 | .concat(languages.map(l => ({ label: l.label, id: l.id, group }))) |
57 | 62 | ||
58 | const videoLanguages = this.user.videoLanguages | 63 | const videoLanguages: ItemSelectCheckboxValue[] = this.user.videoLanguages |
59 | ? this.user.videoLanguages | 64 | ? this.user.videoLanguages.map(l => ({ id: l })) |
60 | : this.languageItems.map(l => l.value) | 65 | : [ { group } ] |
61 | 66 | ||
62 | this.defaultNSFWPolicy = config.instance.defaultNSFWPolicy | 67 | this.defaultNSFWPolicy = config.instance.defaultNSFWPolicy |
63 | 68 | ||
@@ -71,10 +76,12 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, | |||
71 | 76 | ||
72 | if (this.reactiveUpdate) { | 77 | if (this.reactiveUpdate) { |
73 | oldForm = { ...this.form.value } | 78 | oldForm = { ...this.form.value } |
79 | |||
74 | this.formValuesWatcher = this.form.valueChanges.subscribe((formValue: any) => { | 80 | this.formValuesWatcher = this.form.valueChanges.subscribe((formValue: any) => { |
75 | const updatedKey = Object.keys(formValue).find(k => formValue[k] !== oldForm[k]) | 81 | const updatedKey = Object.keys(formValue).find(k => formValue[k] !== oldForm[k]) |
76 | oldForm = { ...this.form.value } | 82 | oldForm = { ...this.form.value } |
77 | this.updateDetails([updatedKey]) | 83 | |
84 | this.updateDetails([ updatedKey ]) | ||
78 | }) | 85 | }) |
79 | } | 86 | } |
80 | }) | 87 | }) |
@@ -91,16 +98,24 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, | |||
91 | const autoPlayNextVideo = this.form.value['autoPlayNextVideo'] | 98 | const autoPlayNextVideo = this.form.value['autoPlayNextVideo'] |
92 | 99 | ||
93 | let videoLanguages: string[] = this.form.value['videoLanguages'] | 100 | let videoLanguages: string[] = this.form.value['videoLanguages'] |
101 | |||
94 | if (Array.isArray(videoLanguages)) { | 102 | if (Array.isArray(videoLanguages)) { |
95 | if (videoLanguages.length === this.languageItems.length) { | 103 | if (videoLanguages.length > 20) { |
96 | videoLanguages = null // null means "All" | 104 | this.notifier.error(this.i18n('Too many languages are enabled. Please enable them all or stay below 20 enabled languages.')) |
97 | } else if (videoLanguages.length > 20) { | ||
98 | this.notifier.error('Too many languages are enabled. Please enable them all or stay below 20 enabled languages.') | ||
99 | return | 105 | return |
100 | } else if (videoLanguages.length === 0) { | 106 | } |
101 | this.notifier.error('You need to enabled at least 1 video language.') | 107 | |
108 | if (videoLanguages.length === 0) { | ||
109 | this.notifier.error(this.i18n('You need to enable at least 1 video language.')) | ||
102 | return | 110 | return |
103 | } | 111 | } |
112 | |||
113 | if ( | ||
114 | videoLanguages.length === this.languageItems.length || | ||
115 | (videoLanguages.length === 1 && videoLanguages[0] === this.allLanguagesGroup) | ||
116 | ) { | ||
117 | videoLanguages = null // null means "All" | ||
118 | } | ||
104 | } | 119 | } |
105 | 120 | ||
106 | let details: UserUpdateMe = { | 121 | let details: UserUpdateMe = { |