From ba430d7516bc5b1324b60571ba7594460969b7fb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 18 Dec 2019 15:31:54 +0100 Subject: Lazy load static objects --- .../my-account-change-email.component.ts | 43 +++++++++++----------- .../my-account-interface-settings.component.ts | 10 ++++- ...y-account-notification-preferences.component.ts | 10 +++-- .../my-account-video-settings.component.ts | 6 +-- .../my-account-video-channel-update.component.ts | 10 ++++- .../my-account-video-playlist-create.component.ts | 13 +++---- .../my-account-video-playlist-update.component.ts | 14 ++++--- client/src/app/+my-account/my-account.component.ts | 16 ++++++-- .../shared/actor-avatar-info.component.ts | 17 +++++++-- 9 files changed, 86 insertions(+), 53 deletions(-) (limited to 'client/src/app/+my-account') diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts index ec7cf935c..9d406805f 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts +++ b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts @@ -6,6 +6,7 @@ import { FormValidatorService } from '@app/shared/forms/form-validators/form-val import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service' import { User } from '../../../../../../shared' import { tap } from 'rxjs/operators' +import { forkJoin } from 'rxjs' @Component({ selector: 'my-account-change-email', @@ -45,29 +46,29 @@ export class MyAccountChangeEmailComponent extends FormReactive implements OnIni const password = this.form.value[ 'password' ] const email = this.form.value[ 'new-email' ] - this.userService.changeEmail(password, email) - .pipe( - tap(() => this.authService.refreshUserInformation()) - ) - .subscribe( - () => { - this.form.reset() + forkJoin([ + this.serverService.getConfig(), + this.userService.changeEmail(password, email) + ]).pipe(tap(() => this.authService.refreshUserInformation())) + .subscribe( + ([ config ]) => { + this.form.reset() - if (this.serverService.getConfig().signup.requiresEmailVerification) { - this.success = this.i18n('Please check your emails to verify your new email.') - } else { - this.success = this.i18n('Email updated.') - } - }, - - err => { - if (err.status === 401) { - this.error = this.i18n('You current password is invalid.') - return - } + if (config.signup.requiresEmailVerification) { + this.success = this.i18n('Please check your emails to verify your new email.') + } else { + this.success = this.i18n('Email updated.') + } + }, - this.error = err.message + err => { + if (err.status === 401) { + this.error = this.i18n('You current password is invalid.') + return } - ) + + this.error = err.message + } + ) } } diff --git a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts b/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts index 5ec1c9f8f..441f89f10 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts +++ b/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts @@ -1,6 +1,6 @@ import { Component, Input, OnInit } from '@angular/core' import { Notifier, ServerService } from '@app/core' -import { UserUpdateMe } from '../../../../../../shared' +import { ServerConfig, UserUpdateMe } from '../../../../../../shared' import { AuthService } from '../../../core' import { FormReactive, User, UserService } from '../../../shared' import { I18n } from '@ngx-translate/i18n-polyfill' @@ -16,6 +16,8 @@ export class MyAccountInterfaceSettingsComponent extends FormReactive implements @Input() user: User = null @Input() userInformationLoaded: Subject + private serverConfig: ServerConfig + constructor ( protected formValidatorService: FormValidatorService, private authService: AuthService, @@ -28,11 +30,15 @@ export class MyAccountInterfaceSettingsComponent extends FormReactive implements } get availableThemes () { - return this.serverService.getConfig().theme.registered + return this.serverConfig.theme.registered .map(t => t.name) } ngOnInit () { + this.serverConfig = this.serverService.getTmpConfig() + this.serverService.getConfig() + .subscribe(config => this.serverConfig = config) + this.buildForm({ theme: null }) diff --git a/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts b/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts index 76fabb19d..6ba1a1020 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts +++ b/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts @@ -21,7 +21,7 @@ export class MyAccountNotificationPreferencesComponent implements OnInit { webNotifications: { [ id in keyof UserNotificationSetting ]: boolean } = {} as any labelNotifications: { [ id in keyof UserNotificationSetting ]: string } = {} as any rightNotifications: { [ id in keyof Partial ]: UserRight } = {} as any - emailEnabled: boolean + emailEnabled = false private savePreferences = debounce(this.savePreferencesImpl.bind(this), 500) @@ -31,7 +31,6 @@ export class MyAccountNotificationPreferencesComponent implements OnInit { private serverService: ServerService, private notifier: Notifier ) { - this.labelNotifications = { newVideoFromSubscription: this.i18n('New video from your subscriptions'), newCommentOnMyVideo: this.i18n('New comment on your video'), @@ -55,11 +54,14 @@ export class MyAccountNotificationPreferencesComponent implements OnInit { newInstanceFollower: UserRight.MANAGE_SERVER_FOLLOW, autoInstanceFollowing: UserRight.MANAGE_CONFIGURATION } - - this.emailEnabled = this.serverService.getConfig().email.enabled } ngOnInit () { + this.serverService.getConfig() + .subscribe(config => { + this.emailEnabled = config.email.enabled + }) + this.userInformationLoaded.subscribe(() => this.loadNotificationSettings()) } diff --git a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts index 99eee23b8..a66159b3f 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts +++ b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts @@ -41,11 +41,9 @@ export class MyAccountVideoSettingsComponent extends FormReactive implements OnI }) forkJoin([ - this.serverService.videoLanguagesLoaded.pipe(first()), + this.serverService.getVideoLanguages(), this.userInformationLoaded.pipe(first()) - ]).subscribe(() => { - const languages = this.serverService.getVideoLanguages() - + ]).subscribe(([ languages ]) => { this.languageItems = [ { label: this.i18n('Unknown language'), value: '_unknown' } ] this.languageItems = this.languageItems .concat(languages.map(l => ({ label: l.label, value: l.id }))) diff --git a/client/src/app/+my-account/my-account-video-channels/my-account-video-channel-update.component.ts b/client/src/app/+my-account/my-account-video-channels/my-account-video-channel-update.component.ts index 081e956d2..9c948b367 100644 --- a/client/src/app/+my-account/my-account-video-channels/my-account-video-channel-update.component.ts +++ b/client/src/app/+my-account/my-account-video-channels/my-account-video-channel-update.component.ts @@ -9,6 +9,7 @@ import { VideoChannel } from '@app/shared/video-channel/video-channel.model' import { I18n } from '@ngx-translate/i18n-polyfill' import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' import { VideoChannelValidatorsService } from '@app/shared/forms/form-validators/video-channel-validators.service' +import { ServerConfig } from '@shared/models' @Component({ selector: 'my-account-video-channel-update', @@ -21,6 +22,7 @@ export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelE private paramsSub: Subscription private oldSupportField: string + private serverConfig: ServerConfig constructor ( protected formValidatorService: FormValidatorService, @@ -37,6 +39,10 @@ export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelE } ngOnInit () { + this.serverConfig = this.serverService.getTmpConfig() + this.serverService.getConfig() + .subscribe(config => this.serverConfig = config) + this.buildForm({ 'display-name': this.videoChannelValidatorsService.VIDEO_CHANNEL_DISPLAY_NAME, description: this.videoChannelValidatorsService.VIDEO_CHANNEL_DESCRIPTION, @@ -109,11 +115,11 @@ export class MyAccountVideoChannelUpdateComponent extends MyAccountVideoChannelE } get maxAvatarSize () { - return this.serverService.getConfig().avatar.file.size.max + return this.serverConfig.avatar.file.size.max } get avatarExtensions () { - return this.serverService.getConfig().avatar.file.extensions.join(',') + return this.serverConfig.avatar.file.extensions.join(',') } isCreation () { diff --git a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts index 8aed8b513..e47e5f980 100644 --- a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts +++ b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts @@ -47,15 +47,14 @@ export class MyAccountVideoPlaylistCreateComponent extends MyAccountVideoPlaylis populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) .catch(err => console.error('Cannot populate user video channels.', err)) - this.serverService.videoPlaylistPrivaciesLoaded.subscribe( - () => { - this.videoPlaylistPrivacies = this.serverService.getVideoPlaylistPrivacies() + this.serverService.getVideoPlaylistPrivacies() + .subscribe(videoPlaylistPrivacies => { + this.videoPlaylistPrivacies = videoPlaylistPrivacies - this.form.patchValue({ - privacy: VideoPlaylistPrivacy.PRIVATE + this.form.patchValue({ + privacy: VideoPlaylistPrivacy.PRIVATE + }) }) - } - ) } formValidated () { diff --git a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-update.component.ts b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-update.component.ts index 917ad7258..2f85cdd96 100644 --- a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-update.component.ts +++ b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-update.component.ts @@ -1,7 +1,7 @@ import { Component, OnDestroy, OnInit } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' import { AuthService, Notifier, ServerService } from '@app/core' -import { Subscription } from 'rxjs' +import { forkJoin, Subscription } from 'rxjs' import { I18n } from '@ngx-translate/i18n-polyfill' import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' import { MyAccountVideoPlaylistEdit } from '@app/+my-account/my-account-video-playlists/my-account-video-playlist-edit' @@ -56,13 +56,17 @@ export class MyAccountVideoPlaylistUpdateComponent extends MyAccountVideoPlaylis this.paramsSub = this.route.params .pipe( map(routeParams => routeParams['videoPlaylistId']), - switchMap(videoPlaylistId => this.videoPlaylistService.getVideoPlaylist(videoPlaylistId)), - delayWhen(() => this.serverService.videoPlaylistPrivaciesLoaded) + switchMap(videoPlaylistId => { + return forkJoin([ + this.videoPlaylistService.getVideoPlaylist(videoPlaylistId), + this.serverService.getVideoPlaylistPrivacies() + ]) + }) ) .subscribe( - videoPlaylistToUpdate => { - this.videoPlaylistPrivacies = this.serverService.getVideoPlaylistPrivacies() + ([ videoPlaylistToUpdate, videoPlaylistPrivacies]) => { this.videoPlaylistToUpdate = videoPlaylistToUpdate + this.videoPlaylistPrivacies = videoPlaylistPrivacies this.hydrateFormFromPlaylist() }, diff --git a/client/src/app/+my-account/my-account.component.ts b/client/src/app/+my-account/my-account.component.ts index d98d06f8e..05dcf522d 100644 --- a/client/src/app/+my-account/my-account.component.ts +++ b/client/src/app/+my-account/my-account.component.ts @@ -1,20 +1,28 @@ -import { Component } from '@angular/core' +import { Component, OnInit } from '@angular/core' import { ServerService } from '@app/core' import { I18n } from '@ngx-translate/i18n-polyfill' import { TopMenuDropdownParam } from '@app/shared/menu/top-menu-dropdown.component' +import { ServerConfig } from '@shared/models' @Component({ selector: 'my-my-account', templateUrl: './my-account.component.html', styleUrls: [ './my-account.component.scss' ] }) -export class MyAccountComponent { +export class MyAccountComponent implements OnInit { menuEntries: TopMenuDropdownParam[] = [] + private serverConfig: ServerConfig + constructor ( private serverService: ServerService, private i18n: I18n - ) { + ) { } + + ngOnInit (): void { + this.serverConfig = this.serverService.getTmpConfig() + this.serverService.getConfig() + .subscribe(config => this.serverConfig = config) const libraryEntries: TopMenuDropdownParam = { label: this.i18n('My library'), @@ -91,7 +99,7 @@ export class MyAccountComponent { } isVideoImportEnabled () { - const importConfig = this.serverService.getConfig().import.videos + const importConfig = this.serverConfig.import.videos return importConfig.http.enabled || importConfig.torrent.enabled } diff --git a/client/src/app/+my-account/shared/actor-avatar-info.component.ts b/client/src/app/+my-account/shared/actor-avatar-info.component.ts index 0289a66c3..101dfa556 100644 --- a/client/src/app/+my-account/shared/actor-avatar-info.component.ts +++ b/client/src/app/+my-account/shared/actor-avatar-info.component.ts @@ -1,26 +1,35 @@ -import { Component, ElementRef, EventEmitter, Input, Output, ViewChild } from '@angular/core' +import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' import { ServerService } from '../../core/server' import { VideoChannel } from '@app/shared/video-channel/video-channel.model' import { Account } from '@app/shared/account/account.model' import { Notifier } from '@app/core' +import { ServerConfig } from '@shared/models' @Component({ selector: 'my-actor-avatar-info', templateUrl: './actor-avatar-info.component.html', styleUrls: [ './actor-avatar-info.component.scss' ] }) -export class ActorAvatarInfoComponent { +export class ActorAvatarInfoComponent implements OnInit { @ViewChild('avatarfileInput', { static: false }) avatarfileInput: ElementRef @Input() actor: VideoChannel | Account @Output() avatarChange = new EventEmitter() + private serverConfig: ServerConfig + constructor ( private serverService: ServerService, private notifier: Notifier ) {} + ngOnInit (): void { + this.serverConfig = this.serverService.getTmpConfig() + this.serverService.getConfig() + .subscribe(config => this.serverConfig = config) + } + onAvatarChange () { const avatarfile = this.avatarfileInput.nativeElement.files[ 0 ] if (avatarfile.size > this.maxAvatarSize) { @@ -35,10 +44,10 @@ export class ActorAvatarInfoComponent { } get maxAvatarSize () { - return this.serverService.getConfig().avatar.file.size.max + return this.serverConfig.avatar.file.size.max } get avatarExtensions () { - return this.serverService.getConfig().avatar.file.extensions.join(',') + return this.serverConfig.avatar.file.extensions.join(',') } } -- cgit v1.2.3