-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathServerContext.ts
71 lines (65 loc) · 2.06 KB
/
ServerContext.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
class User {
id: number;
username: string;
isSuperuser: boolean;
constructor(user: any) {
this.id = user.id;
this.username = user.username;
this.isSuperuser = user.isSuperuser;
}
}
const FlagKey = {
0: "webhook",
} as const;
type FlagKey = typeof FlagKey[keyof typeof FlagKey];
/**
* Context continued from server side to succeed information only server side can know.
* Currently, it's passed via django_context in index.html.
* ref. ~/templates/frontend/index.html
*/
export class ServerContext {
loginNext: string;
version: string;
title: string;
subTitle: string;
noteDesc: string;
noteLink: string;
user?: User;
singleSignOnLoginUrl?: string;
legacyUiDisabled?: boolean;
passwordResetDisabled?: boolean;
checkTermService?: boolean;
termsOfServiceUrl?: string;
extendedGeneralParameters: { [key: string]: any };
extendedHeaderMenus: {
name: string;
children: { name: string; url: string }[];
}[];
headerColor?: string;
flags: Record<FlagKey, boolean>;
private static _instance: ServerContext | undefined;
constructor(context: any) {
this.loginNext = context.next;
this.title = context.title;
this.subTitle = context.subtitle;
this.noteDesc = context.note_desc;
this.noteLink = context.note_link;
this.version = context.version;
this.user = context.user ? new User(context.user) : undefined;
this.singleSignOnLoginUrl = context.singleSignOnLoginUrl;
this.legacyUiDisabled = context.legacyUiDisabled;
this.passwordResetDisabled = context.password_reset_disabled;
this.checkTermService = context.checkTermService;
this.termsOfServiceUrl = context.termsOfServiceUrl;
this.extendedGeneralParameters = context.extendedGeneralParameters;
this.extendedHeaderMenus = context.extendedHeaderMenus;
this.headerColor = context.headerColor;
this.flags = context.flags ?? { webhook: true };
}
static getInstance() {
if ((window as any).django_context) {
this._instance = new ServerContext((window as any).django_context);
}
return this._instance;
}
}