Browse Source

Consider language from user settings (#1179)

pull/1180/head
Thomas Kaul 2 years ago
committed by GitHub
parent
commit
56bf422407
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      apps/api/src/app/user/update-user-setting.dto.ts
  2. 8
      apps/client/src/app/core/auth.guard.ts
  3. 12
      apps/client/src/app/pages/account/account-page.component.ts
  4. 3
      apps/client/src/app/pages/account/account-page.html
  5. 1
      libs/common/src/lib/interfaces/user-settings.interface.ts

4
apps/api/src/app/user/update-user-setting.dto.ts

@ -9,6 +9,10 @@ export class UpdateUserSettingDto {
@IsOptional() @IsOptional()
isRestrictedView?: boolean; isRestrictedView?: boolean;
@IsString()
@IsOptional()
language?: string;
@IsString() @IsString()
@IsOptional() @IsOptional()
locale?: string; locale?: string;

8
apps/client/src/app/core/auth.guard.ts

@ -72,7 +72,13 @@ export class AuthGuard implements CanActivate {
}) })
) )
.subscribe((user) => { .subscribe((user) => {
if ( const userLanguage = user?.settings?.language;
if (userLanguage && document.documentElement.lang !== userLanguage) {
window.location.href = `../${userLanguage}`;
resolve(false);
return;
} else if (
state.url.startsWith('/home') && state.url.startsWith('/home') &&
user.settings.viewMode === ViewMode.ZEN user.settings.viewMode === ViewMode.ZEN
) { ) {

12
apps/client/src/app/pages/account/account-page.component.ts

@ -149,10 +149,6 @@ export class AccountPageComponent implements OnDestroy, OnInit {
this.update(); this.update();
} }
public onChangeLanguage(aLanguage: string) {
window.location.href = `../${aLanguage}/account`;
}
public onChangeUserSetting(aKey: string, aValue: string) { public onChangeUserSetting(aKey: string, aValue: string) {
this.dataService this.dataService
.putUserSetting({ [aKey]: aValue }) .putUserSetting({ [aKey]: aValue })
@ -167,6 +163,14 @@ export class AccountPageComponent implements OnDestroy, OnInit {
this.user = user; this.user = user;
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
if (aKey === 'language') {
if (aValue) {
window.location.href = `../${aValue}/account`;
} else {
window.location.href = `../`;
}
}
}); });
}); });
} }

3
apps/client/src/app/pages/account/account-page.html

@ -120,8 +120,9 @@
<mat-select <mat-select
name="language" name="language"
[value]="language" [value]="language"
(selectionChange)="onChangeLanguage($event.value)" (selectionChange)="onChangeUserSetting('language', $event.value)"
> >
<mat-option [value]="null"></mat-option>
<mat-option value="de">Deutsch</mat-option> <mat-option value="de">Deutsch</mat-option>
<mat-option value="en">English</mat-option> <mat-option value="en">English</mat-option>
</mat-select> </mat-select>

1
libs/common/src/lib/interfaces/user-settings.interface.ts

@ -3,6 +3,7 @@ import { ViewMode } from '@prisma/client';
export interface UserSettings { export interface UserSettings {
baseCurrency?: string; baseCurrency?: string;
isRestrictedView?: boolean; isRestrictedView?: boolean;
language?: string;
locale: string; locale: string;
viewMode?: ViewMode; viewMode?: ViewMode;
} }

Loading…
Cancel
Save