libs/pfe-connector/src/lib/frame/pfe-frame-top-area.service.ts
Properties |
Methods |
|
constructor(pfeBusinessService: PfeBusinessService, pfeConditionsService: PfeConditionsService, pfeStateService: PfeStateService)
|
||||||||||||
Parameters :
|
Public getNotificationVisibility$ | ||||||
getNotificationVisibility$(visibleIf: string | undefined)
|
||||||
Inherited from
TalyFrameTopAreaService
|
||||||
Defined in
TalyFrameTopAreaService:31
|
||||||
Parameters :
Returns :
Observable<boolean>
|
Public getObservableForStateKey$ | ||||||
getObservableForStateKey$(stateKey: string)
|
||||||
Inherited from
TalyFrameTopAreaService
|
||||||
Defined in
TalyFrameTopAreaService:42
|
||||||
Parameters :
Returns :
Observable<any>
|
networkErrorMessage$ |
Default value : this._networkErrorMessage$.asObservable()
|
Inherited from
TalyFrameTopAreaService
|
Defined in
TalyFrameTopAreaService:19
|
import {
ExpressionCondition,
JSON_PATH_REGEX,
PfeBusinessService,
PfeConditionsService,
PfeStateService
} from '@allianz/ngx-pfe';
import { TalyFrameTopAreaService } from '@allianz/taly-common/frame';
import { Injectable } from '@angular/core';
import { Observable, merge, of } from 'rxjs';
import { map, tap } from 'rxjs/operators';
@Injectable()
export class PfeFrameTopAreaService extends TalyFrameTopAreaService {
constructor(
private pfeBusinessService: PfeBusinessService,
private pfeConditionsService: PfeConditionsService,
private pfeStateService: PfeStateService
) {
super();
this.pfeBusinessService.errorMessage$
.pipe(
tap((message) => {
this._networkErrorMessage$.next(message);
})
)
.subscribe();
}
public getNotificationVisibility$(visibleIf: string | undefined): Observable<boolean> {
if (!visibleIf) {
return of(true);
} else if (JSON_PATH_REGEX.test(visibleIf)) {
return this.getObservableForResolvedPfeExpressionCondition(visibleIf);
} else {
return this.getObservableForStateKey$(visibleIf).pipe(map(Boolean));
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public getObservableForStateKey$(stateKey: string): Observable<any> {
return this.pfeBusinessService.getObservableForExpressionKey(stateKey, true);
}
private getObservableForResolvedPfeExpressionCondition(
expressionCondition: string
): Observable<boolean> {
const condition: ExpressionCondition[] = [{ expression: expressionCondition }];
// get all property keys which are in curly brackets (e.g. "{$.key1} == {$.key2}" => ["$.key1", "$.key2"])
const propertyKeys =
expressionCondition.match(JSON_PATH_REGEX)?.map((match) => match.slice(1, -1)) || [];
return merge(
...propertyKeys.map((key) => this.pfeBusinessService.getObservableForExpressionKey(key, true))
).pipe(
map(() =>
this.pfeConditionsService.evaluateConditions(condition, this.pfeStateService.getFullState())
)
);
}
}