From 3caf77d3b11f2dbc12e52d665183d36604c1dab9 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 19 Jun 2019 14:55:58 +0200 Subject: Add language filters in user preferences --- .../my-account-video-settings.component.html | 15 +++++ .../my-account-video-settings.component.ts | 64 ++++++++++++++++++---- 2 files changed, 68 insertions(+), 11 deletions(-) (limited to 'client/src/app/+my-account/my-account-settings/my-account-video-settings') diff --git a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html index 049119fa8..2796dd2db 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html +++ b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html @@ -15,6 +15,21 @@ +
+ + + +
+ +
+
+
+ languageItems: SelectItem[] = [] + constructor ( protected formValidatorService: FormValidatorService, private authService: AuthService, private notifier: Notifier, private userService: UserService, + private serverService: ServerService, private i18n: I18n ) { super() @@ -30,31 +35,60 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI this.buildForm({ nsfwPolicy: null, webTorrentEnabled: null, - autoPlayVideo: null + autoPlayVideo: null, + videoLanguages: null }) - this.userInformationLoaded.subscribe(() => { - this.form.patchValue({ - nsfwPolicy: this.user.nsfwPolicy, - webTorrentEnabled: this.user.webTorrentEnabled, - autoPlayVideo: this.user.autoPlayVideo === true - }) - }) + this.serverService.videoLanguagesLoaded + .pipe(switchMap(() => this.userInformationLoaded)) + .subscribe(() => { + const languages = this.serverService.getVideoLanguages() + + this.languageItems = [ { label: this.i18n('Unknown language'), value: '_unknown' } ] + this.languageItems = this.languageItems + .concat(languages.map(l => ({ label: l.label, value: l.id }))) + + const videoLanguages = this.user.videoLanguages + ? this.user.videoLanguages + : this.languageItems.map(l => l.value) + + this.form.patchValue({ + nsfwPolicy: this.user.nsfwPolicy, + webTorrentEnabled: this.user.webTorrentEnabled, + autoPlayVideo: this.user.autoPlayVideo === true, + videoLanguages + }) + }) } updateDetails () { const nsfwPolicy = this.form.value['nsfwPolicy'] const webTorrentEnabled = this.form.value['webTorrentEnabled'] const autoPlayVideo = this.form.value['autoPlayVideo'] + + let videoLanguages: string[] = this.form.value['videoLanguages'] + if (Array.isArray(videoLanguages)) { + if (videoLanguages.length === this.languageItems.length) { + videoLanguages = null // null means "All" + } else if (videoLanguages.length > 20) { + this.notifier.error('Too many languages are enabled. Please enable them all or stay below 20 enabled languages.') + return + } else if (videoLanguages.length === 0) { + this.notifier.error('You need to enabled at least 1 video language.') + return + } + } + const details: UserUpdateMe = { nsfwPolicy, webTorrentEnabled, - autoPlayVideo + autoPlayVideo, + videoLanguages } this.userService.updateMyProfile(details).subscribe( () => { - this.notifier.success(this.i18n('Information updated.')) + this.notifier.success(this.i18n('Video settings updated.')) this.authService.refreshUserInformation() }, @@ -62,4 +96,12 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI err => this.notifier.error(err.message) ) } + + getDefaultVideoLanguageLabel () { + return this.i18n('No language') + } + + getSelectedVideoLanguageLabel () { + return this.i18n('{{\'{0} languages selected') + } } -- cgit v1.2.3