libs/playground-test-bbs/src/lib/pgr-simple/pgr-simple.component.ts
providers |
createBuildingBlockProvider(forwardRef(() => PgrSimpleComponent))
|
selector | bb-pgr-simple |
templateUrl | pgr-simple.component.html |
Properties |
|
Methods |
Inputs |
Outputs |
Accessors |
constructor(injector: Injector, cdr: ChangeDetectorRef)
|
|||||||||
Parameters :
|
id | |
Type : any
|
|
Default value : dasherize(this.constructor.name)
|
|
Inherited from
AbstractBuildingBlock
|
|
Defined in
AbstractBuildingBlock:135
|
|
can be changed during runtime and given as a default by the implemented Building Block |
resources | |
Type : BuildingBlockResources
|
|
Inherited from
AbstractBuildingBlock
|
|
Defined in
AbstractBuildingBlock:215
|
|
The method will be called by the facade
and is marked as an @Input. Derived Building Blocks need to list
the input in the @Component decorator under |
state | |
Type : NoArray<BuildingBlockState>
|
|
Inherited from
AbstractBuildingBlock
|
|
Defined in
AbstractBuildingBlock:265
|
|
The method will be called by the facade
and is marked as an @Input. Derived Building Blocks need to list
the input in the @Component decorator under |
completed | |
Type : EventEmitter
|
|
Inherited from
AbstractBuildingBlock
|
|
Defined in
AbstractBuildingBlock:152
|
|
Mark this Building Block as complete. That way a workflow engine can determine the overall completion state of any given pages. This method can be actively triggered by the user (say a button is clicked) or indirectly by a form being changed. The author of a Building Block needs to make sure that this function is called during the lifetime of a Building Block. If the Building Block is purely presentational this method can be called during initialization. |
addArrayItem |
addArrayItem()
|
Returns :
void
|
doneBlock |
doneBlock()
|
Returns :
void
|
getForm |
getForm()
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:105
|
Returns :
any
|
getState |
getState()
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:101
|
Returns :
PgrSimpleState
|
onPageConnection |
onPageConnection()
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:109
|
Returns :
void
|
resetBlock |
resetBlock()
|
Returns :
void
|
setResources | ||||||
setResources(data: PgrSimpleResources)
|
||||||
Inherited from
AbstractBuildingBlock
|
||||||
Defined in
AbstractBuildingBlock:93
|
||||||
Parameters :
Returns :
void
|
setState | ||||||
setState(data: PgrSimpleState)
|
||||||
Inherited from
AbstractBuildingBlock
|
||||||
Defined in
AbstractBuildingBlock:97
|
||||||
Parameters :
Returns :
void
|
setValidationConfiguration | ||||||
setValidationConfiguration(data: ValidationConfigItem[])
|
||||||
Inherited from
AbstractBuildingBlock
|
||||||
Defined in
AbstractBuildingBlock:86
|
||||||
Parameters :
Returns :
void
|
callBusinessEvent | ||||||||
callBusinessEvent(event: string)
|
||||||||
Inherited from
AbstractBuildingBlock
|
||||||||
Defined in
AbstractBuildingBlock:101
|
||||||||
This method creates a Deferred object for the business event given. This will have a newly created promise and their executor parameters resolve & reject. This deferred object is then emitted along with the business event name The Store Integration(Facade) can then decide when to resolve or reject the underlying promise based on the service activator call attached to the business event. call's status.
Parameters :
Returns :
Promise<>
the promise from the deferred. The building block can then be notified on the respective service activator call's status. |
commitCompletion |
commitCompletion()
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:156
|
Returns :
void
|
navigate | |||||||||
navigate(type: BUILDING_BLOCK_NAVIGATION_TYPE, payload?: string)
|
|||||||||
Inherited from
AbstractBuildingBlock
|
|||||||||
Defined in
AbstractBuildingBlock:119
|
|||||||||
Parameters :
Returns :
void
|
onPageDisconnected |
onPageDisconnected()
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:179
|
Returns :
void
|
revertCompletion |
revertCompletion()
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:161
|
Returns :
void
|
stateChanged |
stateChanged()
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:236
|
Returns :
void
|
transformResources | ||||||
transformResources(data: BuildingBlockResources)
|
||||||
Inherited from
AbstractBuildingBlock
|
||||||
Defined in
AbstractBuildingBlock:205
|
||||||
Override if you need to pre process the incoming resource data and if you want to establish some default values. The return value will arrive in setResources and stored in the 'resources' variable. Needs to match the Resource Generic of the given Building Block
Parameters :
Returns :
BuildingBlockResources
|
transformState | ||||||
transformState(data: NoArray<BuildingBlockState>)
|
||||||
Inherited from
AbstractBuildingBlock
|
||||||
Defined in
AbstractBuildingBlock:255
|
||||||
Override if you need to pre process the incoming state data and if you want to establish some default values. The return value will arrive in setState and stored in the 'state' variable. Needs to match the State Generic of the given Building Block
Parameters :
Returns :
NoArray<BuildingBlockState>
|
Optional aclFormBinding |
Type : FormBindingReturnValue
|
errorMessage |
Default value : new Observable<string>()
|
Optional validationMap |
Type : Map<string | ValidationConfig[]>
|
_aclService |
Type : AclService
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:57
|
aclTag |
Type : AclTag | null
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:58
|
businesssEventCall$ |
Default value : new EventEmitter<BusinessEvent>()
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:64
|
Readonly channel |
Type : CHANNEL
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:60
|
completion$ |
Default value : new BehaviorSubject(false)
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:154
|
connected$ |
Default value : new Subject<void>()
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:175
|
Lifecycle Event called once the Building Block is connected to the page. This can only happen when the Building Block is embed in a Building Block Page This is not intended to be used standalone. At this point you can be sure that:
|
disconnected$ |
Default value : new Subject<void>()
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:178
|
Readonly isExpertChannel |
Type : boolean
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:62
|
Readonly isRetailChannel |
Type : boolean
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:61
|
loadingStatus$ |
Default value : this._loadingStatus$
.asObservable()
.pipe(
scan(accumulateBusinessEvents, []),
map(groupEventStatusesByName),
distinctUntilChanged(isEqual)
)
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:317
|
navigateEvent$ |
Default value : new EventEmitter<BuildingBlockNavigationEvent>()
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:65
|
stateChange$ |
Default value : new BehaviorSubject({} as BuildingBlockState)
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:235
|
Call this function to grab the current state and forward it any time your internal state is ready to be forwarded. It's a BehaviorSubject to always deliver the latest state on subscription. TODO: Evaluate if a multicast could help maintaining an more coordiated data stream |
trackForm$ |
Default value : new EventEmitter<UntypedFormGroup>()
|
Inherited from
AbstractBuildingBlock
|
Defined in
AbstractBuildingBlock:74
|
Can be used to add automatic tracking to a form. Keep in mind that the form that is returned by getForm() is tracked automatically during the initialization. This only has to be called if there are other forms that should be tracked or if the form is created after the initialization. |
arrayItems |
getarrayItems()
|
import { FormBindingReturnValue, autoFormBindingFactory } from '@allianz/taly-acl/form-support';
import {
AbstractBuildingBlock,
ValidationConfig,
ValidationConfigItem,
applyValidationConfig,
createBuildingBlockProvider
} from '@allianz/taly-core';
import {
ChangeDetectorRef,
Component,
DestroyRef,
Injector,
OnInit,
forwardRef,
inject
} from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { FormArray, FormControl, FormGroup, UntypedFormArray } from '@angular/forms';
import { Observable } from 'rxjs';
import { distinctUntilChanged } from 'rxjs/operators';
import { PgrSimpleResources, PgrSimpleState } from './pgr-simple.model';
@Component({
selector: 'bb-pgr-simple',
templateUrl: 'pgr-simple.component.html',
providers: [createBuildingBlockProvider(forwardRef(() => PgrSimpleComponent))],
standalone: false
})
export class PgrSimpleComponent
extends AbstractBuildingBlock<PgrSimpleState, PgrSimpleResources>
implements OnInit
{
form = new FormGroup({
person: new FormGroup({
firstName: new FormControl('', { nonNullable: true }),
lastName: new FormControl('')
}),
date: new FormControl(),
boolean: new FormControl(true),
items: new FormArray([this.createFormArrayItem()]),
minValue: new FormControl(''),
validNumber: new FormControl(''),
done: new FormControl(false)
});
errorMessage = new Observable<string>();
aclFormBinding?: FormBindingReturnValue;
validationMap?: Map<string, ValidationConfig[]>;
private destroyRef = inject(DestroyRef);
constructor(injector: Injector, private cdr: ChangeDetectorRef) {
super(injector);
}
override ngOnInit(): void {
this.setupFormChangesSubscriptions();
this.setupAclBinding();
}
private setupAclBinding(): void {
this.aclFormBinding = autoFormBindingFactory()(this.acl, this.form);
this.aclFormBinding.stream$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe();
}
private setupFormChangesSubscriptions(): void {
this.form.valueChanges
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => this.stateChanged());
this.form.statusChanges
.pipe(takeUntilDestroyed(this.destroyRef), distinctUntilChanged())
.subscribe(() => this.checkCompletion());
}
private checkCompletion(): void {
if (this.form.valid || this.form.disabled) {
this.commitCompletion();
} else {
this.revertCompletion();
}
}
override setValidationConfiguration(data: ValidationConfigItem[]): void {
this.validationMap = applyValidationConfig(this.form, data);
this.errorMessage = this.validationMap?.get('validNumber')?.[0]
?.errorMessage as Observable<string>;
this.cdr.markForCheck();
}
override setResources(data: PgrSimpleResources): void {
console.log('The Building Block PgrSimple received the following resources:', data);
}
override setState(data: PgrSimpleState): void {
this.form.patchValue(data);
}
override getState(): PgrSimpleState {
return this.form.getRawValue();
}
override getForm() {
return this.form;
}
override onPageConnection(): void {
console.log('The Building Block PgrSimple got connected to the page');
this.checkCompletion();
}
doneBlock() {
this.form.patchValue({ done: true });
this.commitCompletion();
}
resetBlock() {
this.form.patchValue({ done: false });
this.stateChanged();
this.checkCompletion();
}
get arrayItems() {
return this.form.get('items') as UntypedFormArray;
}
addArrayItem() {
this.arrayItems.push(this.createFormArrayItem());
}
private createFormArrayItem() {
return new FormGroup({
id: new FormControl('')
});
}
}
<form [formGroup]="form">
<div nxLayout="grid nopadding">
<div nxRow [rowJustify]="isExpertChannel ? 'start' : 'center'">
<div [nxCol]="isExpertChannel ? '12,12,6' : '12,12,8'">
<taly-headline i18n *aclTag="'headline'" data-testid="headline"
>The Simple Building Block Headline</taly-headline
>
<div nxCopytext>
It contains a complicated form and even has an asset:
<img src="assets/Heart.svg" alt="Heart image" />
</div>
<div nxRow *aclTag="'person'" formGroupName="person" data-testid="person">
<div nxCol="12,12,6">
<nx-formfield
*aclTag="'first-name'"
i18n-label="@@pgr-simple.first-name"
label="First Name"
optionalLabel="Optional"
>
<input
nxInput
placeholder="Enter first name"
i18n-placeholder="@@pgr-simple.first-name-placeholder"
data-testid="person/first-name"
formControlName="firstName"
/>
<taly-validation-errors
nxFormfieldError
[errorMessages]="validationMap?.get('person.firstName')"
[controlErrors]="form.get('person.firstName')?.errors"
>
</taly-validation-errors>
</nx-formfield>
</div>
<div nxCol="12,12,6">
<nx-formfield
*aclTag="'last-name'"
i18n-label="@@pgr-simple.last-name"
label="Last Name"
optionalLabel="Optional"
>
<input
nxInput
placeholder="Enter last name"
i18n-placeholder="@@pgr-simple.last-name-placeholder"
data-testid="person/last-name"
formControlName="lastName"
/>
<taly-validation-errors
nxFormfieldError
[errorMessages]="validationMap?.get('person.lastName')"
[controlErrors]="form.get('person.lastName')?.errors"
>
</taly-validation-errors>
</nx-formfield>
</div>
</div>
<nx-formfield label="Enter Date" *aclTag="'date'" optionalLabel="Optional">
<input nxDatefield nxInput formControlName="date" [datepicker]="dp" />
<nx-datepicker-toggle [for]="dp" nxFormfieldSuffix></nx-datepicker-toggle>
<nx-datepicker #dp></nx-datepicker>
<taly-validation-errors
nxFormfieldError
[errorMessages]="validationMap?.get('date')"
[controlErrors]="form.get('date')?.errors"
>
</taly-validation-errors>
</nx-formfield>
<nx-checkbox
formControlName="boolean"
*aclTag="'boolean'"
data-testid="boolean"
optionalLabel="Optional"
>
Should this be checked?
</nx-checkbox>
<taly-validation-errors
nxFormfieldError
[errorMessages]="validationMap?.get('boolean')"
[controlErrors]="form.get('boolean')?.errors"
>
</taly-validation-errors>
<taly-headline i18n *aclTag="'form-array-headline'">Form Array</taly-headline>
<ng-container formArrayName="items" *aclTag="'items'">
<ng-container *ngFor="let arrayControl of arrayItems.controls; let i = index">
<div [formGroupName]="i" *aclTag="i + ''">
<nx-formfield label="FormArray Item ID" *aclTag="'id'" optionalLabel="Optional">
<input nxInput formControlName="id" />
<taly-validation-errors
nxFormfieldError
[errorMessages]="validationMap?.get('items.*.id')"
[controlErrors]="arrayControl.get('id')?.errors"
>
</taly-validation-errors>
</nx-formfield>
</div>
</ng-container>
</ng-container>
<button
*aclTag="'add-array-item-button'"
nxButton="secondary small"
type="button"
class="nx-margin-bottom-m"
(click)="addArrayItem()"
>
Add array item
</button>
<nx-formfield
label="Minimum value of the field below"
*aclTag="'min-value'"
data-testid="minValue"
optionalLabel="Optional"
>
<input nxInput formControlName="minValue" />
</nx-formfield>
<nx-formfield
*aclTag="'valid-number'"
label="Enter a value greater than or equal to the field above. 👆"
optionalLabel="Optional"
>
<input nxInput formControlName="validNumber" />
<taly-validation-errors
nxFormfieldError
[errorMessages]="validationMap?.get('validNumber')"
[controlErrors]="form.get('validNumber')?.errors"
>
</taly-validation-errors>
</nx-formfield>
<ng-container *aclTag="'done-button'">
<button
nxButton="secondary small"
class="nx-margin-bottom-0"
*ngIf="!form.value.done"
(click)="doneBlock()"
>
Mark as "complete"
</button>
<ng-container *ngIf="form.value.done">
<button nxButton="secondary small" class="nx-margin-bottom-0" (click)="resetBlock()">
Reset "complete" state
</button>
✅
</ng-container>
</ng-container>
<ng-container *talyFrameSmallPrint><div>A non-index Footprint</div></ng-container>
<ng-container *talyFrameSmallPrint="2"><div>2nd index Footprint</div></ng-container>
<ng-container *talyFrameSmallPrint><div>B non-index Footprint</div></ng-container>
<ng-container *ngIf="form.value.done"
><ng-container *talyFrameSmallPrint="1"
><div>1st index Footprint</div></ng-container
></ng-container
>
</div>
</div>
</div>
</form>