src/app/maindata.service.ts
Properties |
Methods |
Accessors |
constructor(expectedApiVersion: string, cts: CustomtextService)
|
|||||||||
Defined in src/app/maindata.service.ts:67
|
|||||||||
Parameters :
|
Static getAuthData |
getAuthData()
|
Defined in src/app/maindata.service.ts:37
|
Returns :
AuthData
|
Static getTestConfig |
getTestConfig()
|
Defined in src/app/maindata.service.ts:53
|
Returns :
KeyValuePairs
|
resetAuthData |
resetAuthData()
|
Defined in src/app/maindata.service.ts:95
|
Returns :
void
|
setAuthData | ||||||||
setAuthData(authData: AuthData)
|
||||||||
Defined in src/app/maindata.service.ts:83
|
||||||||
Parameters :
Returns :
void
|
setSpinnerOff |
setSpinnerOff()
|
Defined in src/app/maindata.service.ts:79
|
Returns :
void
|
setSpinnerOn |
setSpinnerOn()
|
Defined in src/app/maindata.service.ts:75
|
Returns :
void
|
setTestConfig | ||||||||
setTestConfig(testConfig: KeyValuePairs)
|
||||||||
Defined in src/app/maindata.service.ts:103
|
||||||||
Parameters :
Returns :
void
|
_authData$ |
Default value : new Subject<AuthData>()
|
Defined in src/app/maindata.service.ts:19
|
appConfig |
Type : AppConfig
|
Default value : null
|
Defined in src/app/maindata.service.ts:27
|
appError$ |
Default value : new ReplaySubject<AppError>(1)
|
Defined in src/app/maindata.service.ts:18
|
appSubTitle$ |
Default value : new BehaviorSubject<string>('')
|
Defined in src/app/maindata.service.ts:30
|
appTitle$ |
Default value : new BehaviorSubject<string>('IQB-Testcenter')
|
Defined in src/app/maindata.service.ts:29
|
appWindowHasFocus$ |
Default value : new Subject<boolean>()
|
Defined in src/app/maindata.service.ts:35
|
errorReportingSilent |
Default value : false
|
Defined in src/app/maindata.service.ts:24
|
globalWarning |
Type : string
|
Default value : ''
|
Defined in src/app/maindata.service.ts:31
|
isSpinnerOn$ |
Default value : new BehaviorSubject<boolean>(false)
|
Defined in src/app/maindata.service.ts:25
|
postMessage$ |
Default value : new Subject<MessageEvent>()
|
Defined in src/app/maindata.service.ts:34
|
progressVisualEnabled |
Default value : true
|
Defined in src/app/maindata.service.ts:26
|
sysCheckAvailable |
Default value : false
|
Defined in src/app/maindata.service.ts:28
|
authData$ |
getauthData$()
|
Defined in src/app/maindata.service.ts:20
|
import { Inject, Injectable } from '@angular/core';
import {
BehaviorSubject, Observable, ReplaySubject, Subject
} from 'rxjs';
import { CustomtextService } from 'iqb-components';
import {
AppError,
AuthData, KeyValuePairs
} from './app.interfaces';
import { AppConfig, localStorageTestConfigKey } from './config/app.config';
const localStorageAuthDataKey = 'iqb-tc-a';
@Injectable({
providedIn: 'root'
})
export class MainDataService {
appError$ = new ReplaySubject<AppError>(1);
_authData$ = new Subject<AuthData>();
get authData$(): Observable<AuthData> {
return this._authData$.asObservable();
}
errorReportingSilent = false;
isSpinnerOn$ = new BehaviorSubject<boolean>(false);
progressVisualEnabled = true;
appConfig: AppConfig = null;
sysCheckAvailable = false;
appTitle$ = new BehaviorSubject<string>('IQB-Testcenter');
appSubTitle$ = new BehaviorSubject<string>('');
globalWarning = '';
// set by app.component.ts
postMessage$ = new Subject<MessageEvent>();
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;
}
}
}
return myReturn;
}
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;
}
}
}
return myReturn;
}
constructor(
@Inject('API_VERSION_EXPECTED') readonly expectedApiVersion: string,
private cts: CustomtextService
) {
}
setSpinnerOn(): void {
this.isSpinnerOn$.next(true);
}
setSpinnerOff(): void {
this.isSpinnerOn$.next(false);
}
setAuthData(authData: AuthData = null): void {
this._authData$.next(authData);
if (authData) {
if (authData.customTexts) {
this.cts.addCustomTexts(authData.customTexts);
}
localStorage.setItem(localStorageAuthDataKey, JSON.stringify(authData));
} else {
localStorage.removeItem(localStorageAuthDataKey);
}
}
resetAuthData(): void {
const storageEntry = localStorage.getItem(localStorageAuthDataKey);
if (storageEntry) {
localStorage.removeItem(localStorageAuthDataKey);
}
this._authData$.next(MainDataService.getAuthData());
}
setTestConfig(testConfig: KeyValuePairs = null): void {
if (testConfig) {
localStorage.setItem(localStorageTestConfigKey, JSON.stringify(testConfig));
} else {
localStorage.removeItem(localStorageTestConfigKey);
}
this._authData$.next(MainDataService.getAuthData());
}
}