web/user: add language selection

closes #2041

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer
2022-01-01 15:03:27 +01:00
parent a6373ebb33
commit 0ef8edc9f1
9 changed files with 487 additions and 307 deletions

View File

@ -1,3 +1,5 @@
import { UserSelf } from "@goauthentik/api";
import { me } from "../api/Users";
export enum UserDisplay {
@ -29,6 +31,7 @@ export interface UIConfig {
pagination: {
perPage: number;
};
locale: string;
}
export class DefaultUIConfig implements UIConfig {
@ -49,22 +52,25 @@ export class DefaultUIConfig implements UIConfig {
pagination = {
perPage: 20,
};
locale = "";
}
let globalUiConfig: Promise<UIConfig>;
export function getConfigForUser(user: UserSelf): UIConfig {
const settings = user.settings;
let config = new DefaultUIConfig();
if (!settings) {
return config;
}
config = Object.assign(new DefaultUIConfig(), settings);
return config;
}
export function uiConfig(): Promise<UIConfig> {
if (!globalUiConfig) {
globalUiConfig = me().then((user) => {
const settings = user.user.settings;
let config = new DefaultUIConfig();
if (!settings) {
return config;
}
if ("userInterface" in settings) {
config = Object.assign(new DefaultUIConfig(), settings.userInterface);
}
return config;
return getConfigForUser(user.user);
});
}
return globalUiConfig;