All files / lib/dynamic-form-action dynamic-form-action-base.ts

100% Statements 20/20
100% Branches 6/6
100% Functions 16/16
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55                          1x           23x 23x     72x 11x   6x 2x   2x 2x   39x 2x 2x 2x     28x       5x 2x       3x     4x 2x 2x    
import { Directive, DoCheck } from '@angular/core';
import { Observable } from 'rxjs';
import { DynamicFormElement } from '../dynamic-form-element/dynamic-form-element';
import { DynamicFormElementBase } from '../dynamic-form-element/dynamic-form-element-base';
import { DynamicForm } from '../dynamic-form/dynamic-form';
import { DynamicFormDefinition } from '../dynamic-form/dynamic-form-definition';
import { DynamicFormTemplate } from '../dynamic-form/dynamic-form-template';
import { DynamicFormAction } from './dynamic-form-action';
import { DynamicFormActionDefinition } from './dynamic-form-action-definition';
import { DynamicFormActionTemplate } from './dynamic-form-action-template';
import { DynamicFormActionService } from './dynamic-form-action.service';
 
@Directive()
export abstract class DynamicFormActionBase<
  Template extends DynamicFormActionTemplate = DynamicFormActionTemplate,
  Definition extends DynamicFormActionDefinition<Template> = DynamicFormActionDefinition<Template>,
  Action extends DynamicFormAction<Template, Definition> = DynamicFormAction<Template, Definition>
> extends DynamicFormElementBase<Template, Definition, Action> implements DoCheck {
 
  constructor(protected actionService: DynamicFormActionService) {
    super();
  }
 
  get action(): Action { return this.element; }
  set action(action: Action) { this.element = action; }
 
  get dialogOpen(): boolean { return this.action.dialogOpen; }
  get dialogOpen$(): Observable<boolean> { return this.action.dialogOpenChanges; }
 
  get dialogDefinition(): DynamicFormDefinition { return this.action.dialogDefinition; }
  get dialogTemplate(): DynamicFormTemplate { return this.action.dialogTemplate; }
 
  get dialog(): DynamicForm { return this.action.dialog; }
  get dialogChildren(): DynamicFormElement[] { return this.action.dialogChildren; }
  get dialogHeaderActions(): DynamicFormAction[] { return this.action.dialogHeaderActions; }
  get dialogFooterActions(): DynamicFormAction[] { return this.action.dialogFooterActions; }
 
  ngDoCheck(): void {
    return this.dialog && this.dialogOpen && this.dialog.check();
  }
 
  handleEvent($event: Event): void {
    if (this.dialog) {
      return this.dialogOpen
        ? this.actionService.handle(this.action, $event)
        : this.openDialog();
    }
    return this.actionService.handle(this.action, $event);
  }
 
  openDialog(): void { this.action.openDialog(); }
  closeDialog(): void { this.action.closeDialog(); }
  toggleDialog(): void { this.action.toggleDialog(); }
}