All files / lib/confirmation-banner confirmation-banner.component.ts

89.51% Statements 128/143
91.66% Branches 22/24
83.33% Functions 10/12
89.51% Lines 128/143

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 1441x 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 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 22x 23x 23x 23x 22x 22x 23x 23x 23x 1x 1x 1x 1x 1x 1x 23x 23x 22x 22x 22x 22x 22x 22x 1x 1x               1x 1x 1x 6x 6x 1x 1x 1x 13x 1x 12x 4x 13x 13x 1x 1x 1x 10x   10x 10x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x           1x 1x 1x 3x 2x 2x 2x     2x 2x 2x 2x 2x 3x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  Component,
  ElementRef,
  EventEmitter,
  Input,
  Output,
  ViewChild,
} from '@angular/core';
 
import { LinkEvent } from '../utils/event.types';
import { Consumer, FocusableElementOwner } from '../utils/util.types';
 
const CREATED_MESSAGE = 'Erfolgreich angelegt';
 
/**
 * A Confirmation-banner is used to inform the user about a successful action
 */
@Component({
  selector: 'gc-confirmation-banner',
  templateUrl: './confirmation-banner.component.html',
  styleUrls: [
    '../utils/styles/reset-button.css',
    './confirmation-banner.component.css',
  ],
  standalone: false,
})
export class ConfirmationBannerComponent implements FocusableElementOwner {
  /**
   * URL that the user will be sent to on click.
   */
  @Input()
  public url = '';
 
  /**
   * Optional handler to customize handling of navigation requests
   */
  @Input()
  public linkHandler?: Consumer<LinkEvent>;
 
  /**
   * Event emitted when banner gets closed
   */
  @Output()
  public readonly onClose: EventEmitter<void> = new EventEmitter<void>();
 
  /** @ignore */
  @ViewChild('link')
  protected _linkElement?: ElementRef<HTMLAnchorElement>;
 
  /**
   * Text that is shown as the link
   */
  @Input()
  public get text(): string {
    return this._text;
  }
 
  public set text(val: string) {
    this._text = val;
 
    if (!this.text.includes(':')) {
      this._displayedText = `${CREATED_MESSAGE}: ${val}`;
      console.warn(
        `For compat reasons "${CREATED_MESSAGE}: " has been prepended to the text. Please change your code to pass the full message to display`,
      );
    } else {
      this._displayedText = val;
    }
  }
 
  /** @ignore */
  protected _displayedText = '';
 
  /** @ignore */
  private _text = '';
 
  public focusChild(): boolean {
    if (this._linkElement) {
      this._linkElement.nativeElement.focus();
      return true;
    } else {
      return false;
    }
  }
 
  /** @ignore */
  protected _impl_closeBanner(): void {
    this.onClose.emit();
  }
 
  /** @ignore */
  protected _linkOnKeydown(event: KeyboardEvent) {
    if (this._linkElement && event.key === ' ') {
      this._linkElement.nativeElement.click();
    } else if (event.key === 'Escape') {
      this._impl_closeBanner();
    }
  }
 
  /** @ignore */
  protected _buttonOnKeydown(event: KeyboardEvent) {
    if (event.key === 'Escape') {
      this._impl_closeBanner();
    }
  }
 
  /**
   * @ignore
   */
  protected _handleClick() {
    return this._internalHandleClick(true);
  }
 
  /**
   * @ignore
   */
  protected _handleAuxClick(event: MouseEvent) {
    if (event.button === 1) {
      return this._internalHandleClick(false);
    }
    return true;
  }
 
  /** @ignore */
  private _internalHandleClick(replace: boolean): boolean {
    if (this.linkHandler && this.url) {
      try {
        this.linkHandler({ linkInfo: this.url, replace });
      } catch (e) {
        console.error('Failed to execute link handler', e);
      }
 
      return false;
    }
 
    return true;
  }
}