All files / lib/alert-dialog alert-dialog.component.ts

94.64% Statements 159/168
80% Branches 12/15
75% Functions 6/8
94.64% Lines 159/168

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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 1691x 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 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 74x 74x 74x 74x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 572x 572x 1x 1x 1x         1x 1x 1x 21x 21x   21x 1x 1x 1x 174x 174x 174x 174x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  Component,
  EventEmitter,
  Input,
  Output,
  QueryList,
  ViewChild,
  ViewChildren,
} from '@angular/core';
 
import { LinkEvent } from '../utils/event.types';
import { FocusableElementOwner, Item } from '../utils/util.types';
 
import { ButtonComponent } from '../button/button.component';
 
export type AlertContent =
  | { type: 'formattedText'; content: string }
  | {
      type: 'link';
      text: string;
      url: string;
      handler?: (evt: LinkEvent) => void;
    }
  | string;
 
let UNIQUE_ID = 0;
 
/**
 * `gc-alert-dialog` are windows containing contextual information, tasks, or workflows.
 */
@Component({
  selector: 'gc-alert-dialog',
  templateUrl: './alert-dialog.component.html',
  styleUrls: ['./alert-dialog.component.css'],
})
export class AlertDialogComponent implements FocusableElementOwner {
  /**
   * Label displayed in the header
   */
  @Input()
  public label = '';
 
  /**
   * Description displayed in the header.
   * Can contain a string or an array of strings, formatted text, and/or links
   * If an array is provided, each entry is rendered in a separate div element
   */
  @Input()
  public description: string | AlertContent[] = '';
 
  /**
   * Variant of the alert dialog
   */
  @Input()
  public variant: 'info' | 'warning' = 'info';
 
  /**
   * Actions shown in the alert dialog
   */
  @Input()
  public actions: readonly Item[] = [];
 
  /**
   * Primary action shown in the alert dialog
   */
  @Input()
  public primaryAction!: Item;
 
  /**
   * Whether message is focusable in the alert dialog
   * @deprecated
   */
  @Input()
  public isMessageFocusable = false;
 
  /**
   * Event emitted when an item is selected
   */
  @Output()
  public readonly onItemAction: EventEmitter<Item> = new EventEmitter<Item>();
 
  /**
   * @ignore
   */
  @ViewChild('primaryButton', { read: ButtonComponent })
  private primaryButton?: ButtonComponent;
 
  /**
   * @ignore
   */
  @ViewChildren('button', { read: ButtonComponent })
  private buttons?: QueryList<ButtonComponent>;
 
  /**
   * @ignore
   */
  public readonly _labelId: string;
 
  /**
   * @ignore
   */
  public readonly _descId: string;
 
  /**
   * @ignore
   */
  protected readonly _id: string;
 
  constructor() {
    this._id = 'gc-alert-' + (UNIQUE_ID++).toString();
    this._labelId = this._id + '-label';
    this._descId = this._id + '-desc';
  }
 
  public focusChild(): boolean {
    if (this.buttons) {
      const firstNonDisabledButton = this.buttons.find(btn => !btn.disabled);
 
      if (this.primaryButton && !this.primaryButton.disabled) {
        return this.primaryButton.focusChild();
      } else if (firstNonDisabledButton) {
        return firstNonDisabledButton.focusChild();
      } else {
        return false;
      }
    }
 
    return false;
  }
 
  /**
   * @ignore
   */
  protected _handleHeaderAction(item: Item): void {
    this.onItemAction.emit(item);
  }
 
  /** @ignore */
  protected _isSingleValuedDescription() {
    return typeof this.description === 'string';
  }
 
  /** @ignore */
  protected _singleValueDescription(): string {
    return typeof this.description === 'string'
      ? this.description
      : 'ERROR: multi valued';
  }
 
  /** @ignore */
  protected _multiValueDescription(): AlertContent[] {
    return typeof this.description !== 'string'
      ? this.description
      : ['ERROR: single valued'];
  }
 
  /** @ignore */
  protected _isFormattedType(
    content: AlertContent | string,
  ): content is Exclude<AlertContent, string> {
    return typeof content !== 'string';
  }
}