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

95.17% Statements 138/145
90% Branches 9/10
83.33% Functions 5/6
95.17% Lines 138/145

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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 1461x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 151x 151x 151x 1x 1x 1x 151x 151x 151x 210x 67x 67x         210x 151x 151x 151x 151x 151x 151x 1x 1x 1x 19x 19x 19x 19x 1x 1x 1x 1x 1x 1x 89x 89x 1x 1x 1x       1x 1x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  ChangeDetectorRef,
  Directive,
  EventEmitter,
  Input,
  OnDestroy,
  OnInit,
  Optional,
  Output,
} from '@angular/core';
import { Subscription } from 'rxjs';
 
import {
  FocusableElementOwner,
  Item,
  Key,
  WidgetKeySet,
} from '../../utils/util.types';
 
import { ExtSearchGroupComponent } from '../ext-search-group/ext-search-group.component';
 
export interface GlobalVerticalModeChange {
  newState: boolean;
  onDestroy: boolean;
}
 
@Directive()
export abstract class BaseExtSearchComponent
  implements FocusableElementOwner, OnInit, OnDestroy
{
  /**
   * Items displayed in the settings menu. Button is only shown, when items are existing.
   */
  @Input()
  public settingsMenuItems?: readonly Item[];
 
  /**
   * Sets the settings-menu default item key
   */
  @Input()
  public defaultSettingsKey?: Key;
 
  /**
   * Sets the settings-menu selected item key
   */
  @Input()
  public selectedSettingsKey?: Key;
 
  /**
   * Add remove-button to this component
   */
  @Input()
  public showRemoveButton = false;
 
  /**
   * Event fired when the control gains focus
   */
  @Output()
  public readonly onFocusEntered: EventEmitter<void> = new EventEmitter<void>();
 
  /**
   * Event fired when the control loses focus
   */
  @Output()
  public readonly onFocusLeft: EventEmitter<void> = new EventEmitter<void>();
 
  /**
   * Action that is fired when clicked on item in the settings-menu
   */
  @Output()
  public readonly onSettingsMenuAction: EventEmitter<Item> =
    new EventEmitter<Item>();
 
  /**
   * Action that is fired when clicked on remove-button
   */
  @Output()
  public readonly onRemoveButtonAction: EventEmitter<void> =
    new EventEmitter<void>();
 
  /** @ignore */
  protected globalVerticalMode?: boolean;
 
  /** @ignore */
  private vertModeSubscription?: Subscription;
 
  /** @ignore */
  private internalVerticalMode = false;
 
  /** @ignore */
  protected abstract readonly _widgetKeys: WidgetKeySet;
 
  constructor(
    @Optional() protected extSearchGroup: ExtSearchGroupComponent | null,
    private cdr: ChangeDetectorRef,
  ) {}
 
  /** @ignore */
  public ngOnInit(): void {
    this.vertModeSubscription =
      this.extSearchGroup?._onVerticalModeChange.subscribe(
        verticalModeUpdate => {
          if (verticalModeUpdate.newState != this.globalVerticalMode) {
            this.globalVerticalMode = verticalModeUpdate.newState;
            if (verticalModeUpdate.onDestroy) {
              /**
               * Manually trigger change detection if vertical-mode changes, because an element got removed.
               * Otherwise, would result in an NG0100 error, because change-detection could already run before `_onVerticalModeChange()` is emitted
               */
              this.cdr.detectChanges();
            }
          }
        },
      );
    this.extSearchGroup?._updateGlobalVertState(false);
  }
 
  /** @ignore */
  public ngOnDestroy(): void {
    this.vertModeSubscription?.unsubscribe();
    this.internalVerticalMode = false;
    this.extSearchGroup?._updateGlobalVertState(true);
  }
 
  /**
   * @ignore
   * Returns the internal vertical mode state of the ext-search component
   */
  public _getInternalVerticalMode(): boolean {
    return this.internalVerticalMode;
  }
 
  /** @ignore */
  protected handleVerticalModeChange(value: boolean): void {
    this.internalVerticalMode = value;
    this.extSearchGroup?._updateGlobalVertState(false);
  }
 
  public abstract focusChild(): boolean;
}