Newer
Older
import { Injectable } from '@angular/core';
import { BehaviorSubject, Subject } from 'rxjs';
import { CustomtextService } from 'iqb-components';
AuthData, KeyValuePairs
import { BackendService } from './backend.service';
import { AppConfig } from './config/app.config';
const localStorageAuthDataKey = 'iqb-tc-a';
const localStorageTestConfigKey = 'iqb-tc-c';
public appError$ = new Subject<AppError>();
public errorReportingSilent = false;
public isSpinnerOn$ = new BehaviorSubject<boolean>(false);
public progressVisualEnabled = true;
public isApiValid = true;

mechtelm
committed
public appConfig: AppConfig = null;
public sysCheckAvailable = false;
public defaultTcHeaderHeight = document.documentElement.style.getPropertyValue('--tc-header-height');
public defaultTcUnitTitleHeight = document.documentElement.style.getPropertyValue('--tc-unit-title-height');
public defaultTcUnitPageNavHeight = document.documentElement.style.getPropertyValue('--tc-unit-page-nav-height');
// set by app.component.ts
public postMessage$ = new Subject<MessageEvent>();
public appWindowHasFocus$ = new Subject<boolean>();
static getAuthData(): AuthData {
let myReturn: AuthData = null;
const storageEntry = localStorage.getItem(localStorageAuthDataKey);
if (storageEntry !== null) {
if (storageEntry.length > 0) {
try {
myReturn = JSON.parse(storageEntry as string);
} catch (e) {
console.warn('corrupt localStorage authData entry');
myReturn = null;

mechtelm
committed
static resetAuthData() {
const storageEntry = localStorage.getItem(localStorageAuthDataKey);
if (storageEntry) {
localStorage.removeItem(localStorageAuthDataKey);
}
}
static getTestConfig(): KeyValuePairs {
let myReturn: KeyValuePairs = null;
const storageEntry = localStorage.getItem(localStorageTestConfigKey);
if (storageEntry !== null) {
if (storageEntry.length > 0) {
try {
myReturn = JSON.parse(storageEntry as string);
} catch (e) {
console.warn('corrupt localStorage testConfig entry');
myReturn = null;

Martin Mechtel
committed
}

Martin Mechtel
committed
}
constructor(
private bs: BackendService,
private cts: CustomtextService

mechtelm
committed
) {
this.appConfig = new AppConfig(cts);
}

mechtelm
committed
}

mechtelm
committed
}
setAuthData(authData: AuthData = null) {
if (authData) {
if (authData.customTexts) {
this.cts.addCustomTexts(authData.customTexts);
}
localStorage.setItem(localStorageAuthDataKey, JSON.stringify(authData));
} else {
localStorage.removeItem(localStorageAuthDataKey);
}
}
setTestConfig(testConfig: KeyValuePairs = null) {
if (testConfig) {
localStorage.setItem(localStorageTestConfigKey, JSON.stringify(testConfig));
localStorage.removeItem(localStorageTestConfigKey);