All files / lib/ext-search/base-ext-search base-ext-search-single-field.component.ts

94.06% Statements 111/118
93.33% Branches 14/15
90% Functions 9/10
94.06% Lines 111/118

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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 1191x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 4369x 4369x 4369x 123x 123x 72x 72x 72x 72x 123x 123x 123x 2327x 2327x 2327x 2327x 2327x 123x 123x 123x 400x 400x 123x 123x 123x 1779x 1779x 1779x 1779x 1779x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 1x 1x 1x 24x 24x 1x 1x 1x 11x 11x 1x 1x 1x             1x 1x 1x 72x 72x   72x 72x 16x 72x 72x 72x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  Directive,
  EventEmitter,
  Input,
  OnDestroy,
  OnInit,
  Output,
} from '@angular/core';
 
import {
  FocusableElementOwner,
  FormControlStatus,
} from '../../utils/util.types';
 
import { BaseExtSearchComponent } from './base-ext-search-field.component';
 
@Directive()
export abstract class BaseExtSearchSingleFieldComponent
  extends BaseExtSearchComponent
  implements FocusableElementOwner, OnInit, OnDestroy
{
  /**
   * Sets the text in the label slot
   */
  @Input({ required: true })
  public label = '';
 
  /**
   * Signals changes of the current status of the component, e.g. also reports errors triggered by internal
   * validation or input handling.
   */
  @Output()
  public readonly onStatusChange: EventEmitter<FormControlStatus> =
    new EventEmitter<FormControlStatus>(true);
 
  /**
   * Optional error message for the slots.
   */
  @Input()
  public get errorMessage(): string {
    return this._errors;
  }
 
  public set errorMessage(value: string) {
    this._errors = value;
    this.onStatusChange.emit(this.combineAllErrorStatuses());
    this.hasExternalError = value.length > 0;
  }
 
  /** @ignore */
  protected get errorMessageId(): string | undefined {
    if (this.errorMessage.length > 0 || this.hasInternalError) {
      return this.errorMessageIdString;
    }
    return undefined;
  }
 
  /** @ignore */
  protected get errorMessageIdString(): string {
    return this._widgetKeys.errorKey;
  }
 
  /** @ignore */
  protected get actualErrorSlots(): 'start' | undefined {
    if (this.hasInternalError || this.hasExternalError) {
      return 'start';
    }
    return undefined;
  }
 
  /** @ignore */
  protected internalError = '';
 
  /** @ignore */
  protected hasInternalError = false;
 
  /** @ignore */
  private hasExternalError = false;
 
  /** @ignore */
  private _errors = '';
 
  /** @ignore */
  protected handleFocusEntered(): void {
    this.onFocusEntered.emit();
  }
 
  /** @ignore */
  protected handleFocusLeft(): void {
    this.onFocusLeft.emit();
  }
 
  /** @ignore */
  protected statusHandler(s: FormControlStatus) {
    this.internalError = s.error ? s.error[0] : '';
    this.hasInternalError = s.error !== undefined;

    const errors: FormControlStatus = this.combineAllErrorStatuses();
    this.onStatusChange.emit(errors);
  }
 
  /** @ignore */
  private combineAllErrorStatuses(): FormControlStatus {
    const errors: FormControlStatus = { error: [] };
    if (this.internalError.length > 0) {
      errors.error?.push(this.internalError);
    }
    if (this.errorMessage.length > 0) {
      errors.error?.push(this.errorMessage);
    }
    return errors;
  }
}