aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-user-settings/user-video-settings.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-08-11 16:07:53 +0200
committerChocobozzz <me@florianbigard.com>2020-08-11 16:18:42 +0200
commit52c4976fcf4ee255a3af68ff9778e4f5c4f84bd4 (patch)
tree887d2b6106548ad23cf016d82baf1977198027d9 /client/src/app/shared/shared-user-settings/user-video-settings.component.ts
parent3d25d5de33d8aa0ba00d7514522b25d22bf0e0a1 (diff)
downloadPeerTube-52c4976fcf4ee255a3af68ff9778e4f5c4f84bd4.tar.gz
PeerTube-52c4976fcf4ee255a3af68ff9778e4f5c4f84bd4.tar.zst
PeerTube-52c4976fcf4ee255a3af68ff9778e4f5c4f84bd4.zip
Use ng select for multiselect
Diffstat (limited to 'client/src/app/shared/shared-user-settings/user-video-settings.component.ts')
-rw-r--r--client/src/app/shared/shared-user-settings/user-video-settings.component.ts45
1 files changed, 30 insertions, 15 deletions
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 @@
1import { pick } from 'lodash-es' 1import { pick } from 'lodash-es'
2import { SelectItem } from 'primeng/api'
3import { forkJoin, Subject, Subscription } from 'rxjs' 2import { forkJoin, Subject, Subscription } from 'rxjs'
4import { first } from 'rxjs/operators' 3import { first } from 'rxjs/operators'
5import { Component, Input, OnDestroy, OnInit } from '@angular/core' 4import { Component, Input, OnDestroy, OnInit } from '@angular/core'
6import { AuthService, Notifier, ServerService, User, UserService } from '@app/core' 5import { AuthService, Notifier, ServerService, User, UserService } from '@app/core'
7import { FormReactive, FormValidatorService } from '@app/shared/shared-forms' 6import { FormReactive, FormValidatorService, ItemSelectCheckboxValue, SelectOptionsItem } from '@app/shared/shared-forms'
8import { I18n } from '@ngx-translate/i18n-polyfill' 7import { I18n } from '@ngx-translate/i18n-polyfill'
9import { UserUpdateMe } from '@shared/models' 8import { UserUpdateMe } from '@shared/models'
10import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' 9import { 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 = {