Skip to content
Snippets Groups Projects
Commit 9334ee46 authored by mechtelm's avatar mechtelm
Browse files

Change appConfig data model

The API will send the appConfig as key value pairing, so we need some transform procedures. The getAppConfig function prepares for super user setting edit.
parent 1f72836f
No related branches found
No related tags found
No related merge requests found
Pipeline #19287 failed
...@@ -10,14 +10,7 @@ export interface SysConfig { ...@@ -10,14 +10,7 @@ export interface SysConfig {
testConfig: KeyValuePairs; testConfig: KeyValuePairs;
serverTimestamp: number; serverTimestamp: number;
broadcastingService: BroadCastingServiceInfo; broadcastingService: BroadCastingServiceInfo;
app_title: string; appConfig: Map<string, string>;
background_body: string;
background_box: string;
intro_html: string;
impressum_html: string;
global_warning: string;
global_warning_expired_day: Date;
global_warning_expired_hour: number;
} }
export interface BroadCastingServiceInfo { export interface BroadCastingServiceInfo {
...@@ -43,9 +36,11 @@ export class AppConfig { ...@@ -43,9 +36,11 @@ export class AppConfig {
impressum_html = 'Impressum/Datenschutz nicht definiert'; impressum_html = 'Impressum/Datenschutz nicht definiert';
trusted_impressum_html: SafeUrl = null; trusted_impressum_html: SafeUrl = null;
global_warning = ''; global_warning = '';
global_warning_expired_day: Date; global_warning_expired_day = '';
global_warning_expired_hour: number; global_warning_expired_hour = '';
isValidApiVersion = false; isValidApiVersion = false;
sanitizer: DomSanitizer = null;
cts: CustomtextService = null;
constructor( constructor(
sysConfig: SysConfig, sysConfig: SysConfig,
...@@ -53,55 +48,103 @@ export class AppConfig { ...@@ -53,55 +48,103 @@ export class AppConfig {
expectedApiVersion: string, expectedApiVersion: string,
sanitizer: DomSanitizer sanitizer: DomSanitizer
) { ) {
const ctSettings = {}; this.sanitizer = sanitizer;
Object.keys(customTextsDefault).forEach(k => { this.cts = cts;
ctSettings[k] = customTextsDefault[k].defaultvalue;
if (k === 'app_title') this.app_title = customTextsDefault[k].defaultvalue;
if (k === 'app_intro1') {
this.intro_html = customTextsDefault[k].defaultvalue;
this.impressum_html = customTextsDefault[k].defaultvalue;
}
});
if (sysConfig) { if (sysConfig) {
Object.keys(sysConfig.customTexts).forEach(k => { this.setCustomTexts(sysConfig.customTexts);
ctSettings[k] = sysConfig.customTexts[k]; this.setAppConfig(sysConfig.appConfig);
if (k === 'app_title') this.app_title = sysConfig.customTexts[k];
if (k === 'app_intro1') {
this.intro_html = sysConfig.customTexts[k];
this.impressum_html = sysConfig.customTexts[k];
}
});
if (sysConfig.app_title) this.app_title = sysConfig.app_title;
if (sysConfig.mainLogo) this.mainLogo = sysConfig.mainLogo;
if (sysConfig.background_body) {
this.background_body = sysConfig.background_body;
document.documentElement.style.setProperty('--tc-body-background', this.background_body);
}
if (sysConfig.background_box) {
this.background_box = sysConfig.background_box;
document.documentElement.style.setProperty('--tc-box-background', this.background_box);
}
this.isValidApiVersion = AppConfig.checkApiVersion(sysConfig.version, expectedApiVersion);
this.detectedApiVersion = sysConfig.version;
if (sysConfig.intro_html) this.intro_html = sysConfig.intro_html;
if (sysConfig.impressum_html) this.impressum_html = sysConfig.impressum_html;
this.global_warning = sysConfig.global_warning;
this.global_warning_expired_day = sysConfig.global_warning_expired_day;
this.global_warning_expired_hour = sysConfig.global_warning_expired_hour;
this.testConfig = sysConfig.testConfig; this.testConfig = sysConfig.testConfig;
this.serverTimestamp = sysConfig.serverTimestamp; this.serverTimestamp = sysConfig.serverTimestamp;
if (sysConfig.broadcastingService && sysConfig.broadcastingService.status) { if (sysConfig.broadcastingService && sysConfig.broadcastingService.status) {
this.broadcastingService = sysConfig.broadcastingService; this.broadcastingService = sysConfig.broadcastingService;
} }
this.detectedApiVersion = sysConfig.version;
} else {
this.setCustomTexts(null);
this.setAppConfig(null);
} }
cts.addCustomTexts(ctSettings); this.isValidApiVersion = AppConfig.checkApiVersion(this.detectedApiVersion, expectedApiVersion);
this.trusted_intro_html = sanitizer.bypassSecurityTrustHtml(this.intro_html);
this.trusted_impressum_html = sanitizer.bypassSecurityTrustHtml(this.impressum_html);
if (this.testConfig) { if (this.testConfig) {
localStorage.setItem(localStorageTestConfigKey, JSON.stringify(this.testConfig)); localStorage.setItem(localStorageTestConfigKey, JSON.stringify(this.testConfig));
} else { } else {
localStorage.removeItem(localStorageTestConfigKey); localStorage.removeItem(localStorageTestConfigKey);
} }
this.applyBackgroundColors();
}
private setCustomTexts(customTexts: KeyValuePairs): void {
const ctSettings = {};
Object.keys(customTextsDefault).forEach(k => {
ctSettings[k] = customTextsDefault[k].defaultvalue;
});
if (customTexts) {
Object.keys(customTexts).forEach(k => {
ctSettings[k] = customTexts[k];
});
}
this.cts.addCustomTexts(ctSettings);
}
private setAppConfig(appConfig: Map<string, string>): void {
this.app_title = this.cts.getCustomText('app_title');
if (!this.app_title) this.app_title = 'IQB-Testcenter';
this.intro_html = this.cts.getCustomText('app_intro1');
if (this.intro_html) {
this.impressum_html = this.intro_html;
} else {
this.intro_html = 'Einführungstext nicht definiert';
this.impressum_html = 'Impressum/Datenschutz nicht definiert';
}
this.mainLogo = 'assets/IQB-LogoA.png';
this.background_body = '';
this.background_box = '';
this.trusted_intro_html = null;
this.trusted_impressum_html = null;
this.global_warning = '';
this.global_warning_expired_day = '';
this.global_warning_expired_hour = '';
if (appConfig) {
Object.keys(appConfig).forEach(k => {
switch (k) {
case 'app_title':
this.app_title = appConfig[k];
break;
case 'mainLogo':
this.mainLogo = appConfig[k];
break;
case 'background_body':
this.background_body = appConfig[k];
break;
case 'background_box':
this.background_box = appConfig[k];
break;
case 'intro_html':
this.intro_html = appConfig[k];
break;
case 'impressum_html':
this.impressum_html = appConfig[k];
break;
case 'global_warning':
this.global_warning = appConfig[k];
break;
case 'global_warning_expired_day':
this.global_warning_expired_day = appConfig[k];
break;
case 'global_warning_expired_hour':
this.global_warning_expired_hour = appConfig[k];
break;
default:
console.warn(`unknown key in appConfig "${k}"`);
}
});
}
this.trusted_intro_html = this.sanitizer.bypassSecurityTrustHtml(this.intro_html);
this.trusted_impressum_html = this.sanitizer.bypassSecurityTrustHtml(this.impressum_html);
}
private applyBackgroundColors(): void {
document.documentElement.style.setProperty('--tc-body-background', this.background_body);
document.documentElement.style.setProperty('--tc-box-background', this.background_box);
} }
private static checkApiVersion(versionToCheck: string, expectedVersion: string): boolean { private static checkApiVersion(versionToCheck: string, expectedVersion: string): boolean {
...@@ -139,4 +182,18 @@ export class AppConfig { ...@@ -139,4 +182,18 @@ export class AppConfig {
} }
return this.global_warning; return this.global_warning;
} }
getAppConfig(): Map<string, string> {
const appConfig = new Map<string, string>();
appConfig.set('app_title', this.app_title);
appConfig.set('mainLogo', this.mainLogo);
appConfig.set('background_body', this.background_body);
appConfig.set('background_box', this.background_box);
appConfig.set('intro_html', this.intro_html);
appConfig.set('impressum_html', this.impressum_html);
appConfig.set('global_warning', this.global_warning);
appConfig.set('global_warning_expired_day', this.global_warning_expired_day);
appConfig.set('global_warning_expired_hour', this.global_warning_expired_hour);
return appConfig;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment