File

libs/playground-test-bbs/src/lib/pgr-simple/pgr-simple.component.ts

Extends

AbstractBuildingBlock

Implements

OnInit

Metadata

Index

Properties
Methods
Inputs
Outputs
Accessors

Constructor

constructor(injector: Injector, cdr: ChangeDetectorRef)
Parameters :
Name Type Optional
injector Injector No
cdr ChangeDetectorRef No

Inputs

id
Type : any
Default value : dasherize(this.constructor.name)
Inherited from AbstractBuildingBlock

can be changed during runtime and given as a default by the implemented Building Block

resources
Type : BuildingBlockResources
Inherited from AbstractBuildingBlock

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 inputs:[] to make it available to the template (View Engine limitation).

state
Type : NoArray<BuildingBlockState>
Inherited from AbstractBuildingBlock

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 inputs:[] to make it available to the template (View Engine limitation).

Outputs

completed
Type : EventEmitter
Inherited from AbstractBuildingBlock

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.

Methods

addArrayItem
addArrayItem()
Returns : void
doneBlock
doneBlock()
Returns : void
getForm
getForm()
Inherited from AbstractBuildingBlock
Returns : any
getState
getState()
Inherited from AbstractBuildingBlock
Returns : PgrSimpleState
onPageConnection
onPageConnection()
Inherited from AbstractBuildingBlock
Returns : void
resetBlock
resetBlock()
Returns : void
setResources
setResources(data: PgrSimpleResources)
Inherited from AbstractBuildingBlock
Parameters :
Name Type Optional
data PgrSimpleResources No
Returns : void
setState
setState(data: PgrSimpleState)
Inherited from AbstractBuildingBlock
Parameters :
Name Type Optional
data PgrSimpleState No
Returns : void
setValidationConfiguration
setValidationConfiguration(data: ValidationConfigItem[])
Inherited from AbstractBuildingBlock
Parameters :
Name Type Optional
data ValidationConfigItem[] No
Returns : void
callBusinessEvent
callBusinessEvent(event: string)
Inherited from AbstractBuildingBlock

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 :
Name Type Optional Description
event string No

name of the business event

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
Returns : void
navigate
navigate(type: BUILDING_BLOCK_NAVIGATION_TYPE, payload?: string)
Inherited from AbstractBuildingBlock
Parameters :
Name Type Optional
type BUILDING_BLOCK_NAVIGATION_TYPE No
payload string Yes
Returns : void
onPageDisconnected
onPageDisconnected()
Inherited from AbstractBuildingBlock
Returns : void
revertCompletion
revertCompletion()
Inherited from AbstractBuildingBlock
Returns : void
stateChanged
stateChanged()
Inherited from AbstractBuildingBlock
Returns : void
transformResources
transformResources(data: BuildingBlockResources)
Inherited from AbstractBuildingBlock

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 :
Name Type Optional
data BuildingBlockResources No
transformState
transformState(data: NoArray<BuildingBlockState>)
Inherited from AbstractBuildingBlock

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 :
Name Type Optional
data NoArray<BuildingBlockState> No

Properties

Optional aclFormBinding
Type : FormBindingReturnValue
errorMessage
Default value : new Observable<string>()
form
Default value : 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) })
Optional validationMap
Type : Map<string | ValidationConfig[]>
_aclService
Type : AclService
Inherited from AbstractBuildingBlock
aclTag
Type : AclTag | null
Inherited from AbstractBuildingBlock
businesssEventCall$
Default value : new EventEmitter<BusinessEvent>()
Inherited from AbstractBuildingBlock
Readonly channel
Type : CHANNEL
Inherited from AbstractBuildingBlock
completion$
Default value : new BehaviorSubject(false)
Inherited from AbstractBuildingBlock
connected$
Default value : new Subject<void>()
Inherited from AbstractBuildingBlock

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:

  1. The Building Block is ready (AfterViewInit)
  2. The initial state and resources has been set
disconnected$
Default value : new Subject<void>()
Inherited from AbstractBuildingBlock
Readonly isExpertChannel
Type : boolean
Inherited from AbstractBuildingBlock
Readonly isRetailChannel
Type : boolean
Inherited from AbstractBuildingBlock
loadingStatus$
Default value : this._loadingStatus$ .asObservable() .pipe( scan(accumulateBusinessEvents, []), map(groupEventStatusesByName), distinctUntilChanged(isEqual) )
Inherited from AbstractBuildingBlock
navigateEvent$
Default value : new EventEmitter<BuildingBlockNavigationEvent>()
Inherited from AbstractBuildingBlock
stateChange$
Default value : new BehaviorSubject({} as BuildingBlockState)
Inherited from AbstractBuildingBlock

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

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.

Accessors

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>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""