-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp-config.service.ts
More file actions
90 lines (79 loc) · 2.36 KB
/
Copy pathapp-config.service.ts
File metadata and controls
90 lines (79 loc) · 2.36 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { HttpClient } from "@angular/common/http";
import { Injectable } from "@angular/core";
import { timeout } from "rxjs/operators";
import { environment } from "../environments/environment";
import { InjectionToken } from "@angular/core";
export const APP_DYN_CONFIG = new InjectionToken<AppConfigService>(
"app.dyn.config",
);
export interface AppConfig {
production: boolean;
facility: string;
oaiProviderRoute: string;
doiBaseUrl: string;
directMongoAccess: boolean;
accessDataHref: string;
accessInstructions: string;
scicatBaseUrl: string;
logoBanner: string | null;
logoWidth?: string;
retrieveToEmail: RetrieveDestinations | undefined;
lbBaseUrl: string | null;
statusMessage: string;
statusCode: "INFO" | "WARN" | "NONE";
contactEmail: string;
footerMessage?: FooterMessage;
}
export class RetrieveDestinations {
title: string;
option: string;
username: string;
confirmMessage: string | undefined;
}
interface FooterMessage {
text: string;
links: FooterMessageLink[];
}
interface FooterMessageLink {
label: string;
url: string;
}
@Injectable({ providedIn: "root" })
export class AppConfigService {
private appConfig: AppConfig = {} as AppConfig;
constructor(private http: HttpClient) {}
async loadAppConfig(): Promise<void> {
try {
this.appConfig = (await this.http
.get("/config")
.pipe(timeout(2000))
.toPromise()) as AppConfig;
} catch (err) {
console.log("No config available in backend, trying with local config.");
try {
this.appConfig = (await this.http
.get("/assets/config.json")
.toPromise()) as AppConfig;
} catch (err) {
console.log("No config provided, using environment");
this.appConfig = environment as AppConfig;
}
}
// Use old default if not provided
this.appConfig.logoWidth = this.appConfig?.logoWidth ?? "412";
// Parse status-banner related config if exists or set defaults
this.appConfig = {
...this.appConfig,
statusMessage: this.appConfig["statusMessage"] || "",
statusCode: (["INFO", "WARN", "NONE"].includes(
this.appConfig["statusCode"],
)
? this.appConfig["statusCode"]
: "NONE") as "INFO" | "WARN" | "NONE",
contactEmail: this.appConfig["contactEmail"] || "",
};
}
getConfig(): AppConfig {
return this.appConfig;
}
}