src/app/config/app.config.ts
Properties |
Methods |
|
Accessors |
constructor(sysConfig: SysConfig, cts: CustomtextService, expectedApiVersion: string, sanitizer: DomSanitizer)
|
|||||||||||||||
Defined in src/app/config/app.config.ts:67
|
|||||||||||||||
Parameters :
|
appTitle |
Type : string
|
Default value : 'IQB-Testcenter'
|
Defined in src/app/config/app.config.ts:47
|
backgroundBody |
Type : string
|
Defined in src/app/config/app.config.ts:48
|
backgroundBox |
Type : string
|
Defined in src/app/config/app.config.ts:49
|
broadcastingService |
Type : BroadCastingServiceInfo
|
Default value : { status: 'none' }
|
Defined in src/app/config/app.config.ts:46
|
cts |
Type : CustomtextService
|
Default value : null
|
Defined in src/app/config/app.config.ts:59
|
customTexts |
Type : KeyValuePairs
|
Default value : {}
|
Defined in src/app/config/app.config.ts:41
|
detectedApiVersion |
Type : string
|
Default value : ''
|
Defined in src/app/config/app.config.ts:42
|
globalWarningExpiredDay |
Type : string
|
Default value : ''
|
Defined in src/app/config/app.config.ts:55
|
globalWarningExpiredHour |
Type : string
|
Default value : ''
|
Defined in src/app/config/app.config.ts:56
|
globalWarningText |
Type : string
|
Default value : ''
|
Defined in src/app/config/app.config.ts:54
|
introHtml |
Type : string
|
Default value : 'Einführungstext nicht definiert'
|
Defined in src/app/config/app.config.ts:50
|
isValidApiVersion |
Default value : false
|
Defined in src/app/config/app.config.ts:57
|
legalNoticeHtml |
Type : string
|
Default value : 'Impressum/Datenschutz nicht definiert'
|
Defined in src/app/config/app.config.ts:52
|
mainLogo |
Default value : standardLogo
|
Defined in src/app/config/app.config.ts:43
|
sanitizer |
Type : DomSanitizer
|
Default value : null
|
Defined in src/app/config/app.config.ts:58
|
serverTimestamp |
Type : number
|
Default value : 0
|
Defined in src/app/config/app.config.ts:45
|
testConfig |
Type : KeyValuePairs
|
Default value : {}
|
Defined in src/app/config/app.config.ts:44
|
trustedIntroHtml |
Type : SafeUrl
|
Default value : null
|
Defined in src/app/config/app.config.ts:51
|
trustedLegalNoticeHtml |
Type : SafeUrl
|
Default value : null
|
Defined in src/app/config/app.config.ts:53
|
applyBackgroundColors |
applyBackgroundColors()
|
Defined in src/app/config/app.config.ts:149
|
Returns :
void
|
Private Static checkApiVersion |
checkApiVersion(versionToCheck: string, expectedVersion: string)
|
Defined in src/app/config/app.config.ts:154
|
Returns :
boolean
|
getAppConfig |
getAppConfig()
|
Defined in src/app/config/app.config.ts:187
|
Returns :
AppSettings
|
Static isWarningExpired |
isWarningExpired(warningDay: string, warningHour: string)
|
Defined in src/app/config/app.config.ts:180
|
Returns :
boolean
|
setAppConfig | ||||||
setAppConfig(appConfig: AppSettings)
|
||||||
Defined in src/app/config/app.config.ts:114
|
||||||
Parameters :
Returns :
void
|
setCustomTexts | ||||||
setCustomTexts(customTexts: KeyValuePairs)
|
||||||
Defined in src/app/config/app.config.ts:101
|
||||||
Parameters :
Returns :
void
|
warningMessage |
getwarningMessage()
|
Defined in src/app/config/app.config.ts:61
|
import { CustomtextService } from 'iqb-components';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
import customTextsDefault from './custom-texts.json';
import { KeyValuePairs } from '../app.interfaces';
export interface AppSettings {
appTitle: string,
mainLogo: string,
backgroundBody: string,
backgroundBox: string,
introHtml: string,
legalNoticeHtml: string,
globalWarningText: string,
globalWarningExpiredDay: string,
globalWarningExpiredHour: string
}
export interface SysConfig {
customTexts: KeyValuePairs;
version: string;
mainLogo: string;
testConfig: KeyValuePairs;
serverTimestamp: number;
broadcastingService: BroadCastingServiceInfo;
appConfig: AppSettings;
}
export interface BroadCastingServiceInfo {
status: string;
version?: string;
versionExpected?: string;
}
export const localStorageTestConfigKey = 'iqb-tc-c';
export const standardLogo = 'assets/IQB-LogoA.png';
export const standardBackgroundBody = '#003333 linear-gradient(to bottom, #003333, #045659, #0d7b84, #1aa2b2, #2acae5)';
export const standardBackgroundBox = 'lightgray';
export class AppConfig {
customTexts: KeyValuePairs = {};
detectedApiVersion = '';
mainLogo = standardLogo;
testConfig: KeyValuePairs = {};
serverTimestamp = 0;
broadcastingService: BroadCastingServiceInfo = { status: 'none' };
appTitle = 'IQB-Testcenter';
backgroundBody: string;
backgroundBox: string;
introHtml = 'Einführungstext nicht definiert';
trustedIntroHtml: SafeUrl = null;
legalNoticeHtml = 'Impressum/Datenschutz nicht definiert';
trustedLegalNoticeHtml: SafeUrl = null;
globalWarningText = '';
globalWarningExpiredDay = '';
globalWarningExpiredHour = '';
isValidApiVersion = false;
sanitizer: DomSanitizer = null;
cts: CustomtextService = null;
get warningMessage(): string {
if (this.globalWarningExpiredDay) {
return AppConfig.isWarningExpired(this.globalWarningExpiredDay, this.globalWarningExpiredHour) ?
'' : this.globalWarningText;
}
return this.globalWarningText;
}
constructor(
sysConfig: SysConfig,
cts: CustomtextService,
expectedApiVersion: string,
sanitizer: DomSanitizer
) {
this.sanitizer = sanitizer;
this.cts = cts;
if (sysConfig) {
this.customTexts = sysConfig.customTexts;
this.setCustomTexts(sysConfig.customTexts);
this.setAppConfig(sysConfig.appConfig);
this.testConfig = sysConfig.testConfig;
this.serverTimestamp = sysConfig.serverTimestamp;
if (sysConfig.broadcastingService && sysConfig.broadcastingService.status) {
this.broadcastingService = sysConfig.broadcastingService;
}
this.detectedApiVersion = sysConfig.version;
} else {
this.setCustomTexts(null);
this.setAppConfig(null);
}
this.isValidApiVersion = AppConfig.checkApiVersion(this.detectedApiVersion, expectedApiVersion);
if (this.testConfig) {
localStorage.setItem(localStorageTestConfigKey, JSON.stringify(this.testConfig));
} else {
localStorage.removeItem(localStorageTestConfigKey);
}
this.applyBackgroundColors();
}
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);
}
setAppConfig(appConfig: AppSettings): void {
this.appTitle = this.cts.getCustomText('app_title');
if (!this.appTitle) this.appTitle = 'IQB-Testcenter';
this.introHtml = this.cts.getCustomText('app_intro1');
if (this.introHtml) {
this.legalNoticeHtml = this.introHtml;
} else {
this.introHtml = 'Einführungstext nicht definiert';
this.legalNoticeHtml = 'Impressum/Datenschutz nicht definiert';
}
this.mainLogo = standardLogo;
this.backgroundBody = standardBackgroundBody;
this.backgroundBox = standardBackgroundBox;
this.trustedIntroHtml = null;
this.trustedLegalNoticeHtml = null;
this.globalWarningText = '';
this.globalWarningExpiredDay = '';
this.globalWarningExpiredHour = '';
if (appConfig) {
if (appConfig.appTitle) this.appTitle = appConfig.appTitle;
if (appConfig.mainLogo) this.mainLogo = appConfig.mainLogo;
if (appConfig.backgroundBody) this.backgroundBody = appConfig.backgroundBody;
if (appConfig.backgroundBox) this.backgroundBox = appConfig.backgroundBox;
if (appConfig.introHtml) this.introHtml = appConfig.introHtml;
if (appConfig.legalNoticeHtml) this.legalNoticeHtml = appConfig.legalNoticeHtml;
if (appConfig.globalWarningText) this.globalWarningText = appConfig.globalWarningText;
if (appConfig.globalWarningExpiredDay) this.globalWarningExpiredDay = appConfig.globalWarningExpiredDay;
if (appConfig.globalWarningExpiredHour) {
this.globalWarningExpiredHour = appConfig.globalWarningExpiredHour;
}
}
this.trustedIntroHtml = this.sanitizer.bypassSecurityTrustHtml(this.introHtml);
this.trustedLegalNoticeHtml = this.sanitizer.bypassSecurityTrustHtml(this.legalNoticeHtml);
}
applyBackgroundColors(): void {
document.documentElement.style.setProperty('--tc-body-background', this.backgroundBody);
document.documentElement.style.setProperty('--tc-box-background', this.backgroundBox);
}
private static checkApiVersion(versionToCheck: string, expectedVersion: string): boolean {
if (!expectedVersion || !versionToCheck) {
return false;
}
const searchPattern = /\d+/g;
const expectedVersionNumbers = expectedVersion.match(searchPattern);
const reportedVersionNumbers = versionToCheck.match(searchPattern);
if (expectedVersionNumbers && reportedVersionNumbers) {
if (reportedVersionNumbers[0] !== expectedVersionNumbers[0]) {
return false;
}
if (expectedVersionNumbers.length > 1) {
if ((reportedVersionNumbers.length < 2) || +reportedVersionNumbers[1] < +expectedVersionNumbers[1]) {
return false;
}
if ((expectedVersionNumbers.length > 2) && reportedVersionNumbers[1] === expectedVersionNumbers[1]) {
if ((reportedVersionNumbers.length < 3) || +reportedVersionNumbers[2] < +expectedVersionNumbers[2]) {
return false;
}
}
}
return true;
}
return false;
}
static isWarningExpired(warningDay: string, warningHour: string): boolean {
const calcTimePoint = new Date(warningDay);
calcTimePoint.setHours(Number(warningHour));
const now = new Date(Date.now());
return calcTimePoint < now;
}
getAppConfig(): AppSettings {
return {
appTitle: this.appTitle,
mainLogo: this.mainLogo,
backgroundBody: this.backgroundBody,
backgroundBox: this.backgroundBox,
introHtml: this.introHtml,
legalNoticeHtml: this.legalNoticeHtml,
globalWarningText: this.globalWarningText,
globalWarningExpiredDay: this.globalWarningExpiredDay,
globalWarningExpiredHour: this.globalWarningExpiredHour
};
}
}