All files / lib/internal/wizard-stepper/wizard-stepper-horizontal wizard-stepper-horizontal.component.ts

88.83% Statements 175/197
92.85% Branches 26/28
85% Functions 17/20
88.83% Lines 175/197

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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 1981x 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 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 2513x 2513x 2513x 19x 19x 27x 27x 19x 19x 444x 444x 444x 19x 19x 19x 19x 19x 19x 19x 333x 333x 19x 19x 19x 222x 222x 222x 222x 222x 222x 222x 222x 222x 19x 19x 19x 19x 19x 19x 1x 1x 1x 1x 1x     1x 1x 19x 19x 1x 1x 19x 19x 1x 1x 1998x 1998x 1x 1x     1x 1x 222x 222x 222x 222x 222x 222x 222x 222x 222x 222x 1x 1x 4x 4x 4x 4x 4x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 4x 4x 4x 1x 1x 1x 14x 14x 14x 14x 14x 14x 14x 14x 14x 1x 1x 1x 95x 95x 1x 1x 1x                                     1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  Component,
  ElementRef,
  EventEmitter,
  Input,
  Output,
  ViewChild,
} from '@angular/core';
 
import { IndexedItem, textToLine } from '../../../utils/internal-utils';
import { Item, Key, WidgetKeySet } from '../../../utils/util.types';
import { createWidgetKeySet, itemTrack } from '../../../utils/utilities';
 
import {
  KeyFocusTarget,
  LegacyBasePickerComponent,
} from '../../../picker/legacy-base-picker.component';
import { SelectionEvent } from '../../listbox.directive';
 
@Component({
  selector: 'gc-wizard-stepper-horizontal',
  templateUrl: './wizard-stepper-horizontal.component.html',
  styleUrls: [
    './../../../utils/styles/reset-button.css',
    './wizard-stepper-horizontal.component.css',
  ],
  standalone: false,
})
export class WizardStepperHorizontalComponent extends LegacyBasePickerComponent<
  Item,
  Item
> {
  /** Inform about the change of the selection state */
  @Output()
  public readonly valueChange: EventEmitter<Item> = new EventEmitter<Item>();
 
  @Input()
  public selectableItems: readonly Item[] = [];
 
  @Input()
  public controlledId = '';
 
  @Input()
  public invalidItemKeys: ReadonlySet<Key> = new Set();
 
  @ViewChild('button')
  public button!: ElementRef<HTMLButtonElement>;
 
  @ViewChild('wizardStepperContainer')
  private containerElement!: ElementRef<HTMLDivElement>;
 
  /**
   * The value represents the selected value
   */
  @Input()
  public get value(): Item | undefined {
    return this.storage.selected;
  }
 
  public set value(value: Item | undefined) {
    this.storage.selected = value;
  }
 
  @Input()
  public override get items(): readonly Item[] {
    return super.items;
  }
 
  public override set items(items: readonly Item[]) {
    super.items = items;
  }
 
  /** @ignore */
  public get _listboxId(): string {
    return this._widgetKeys.baseKey + '-lb';
  }
 
  /** @ignore */
  public get _ariaControls(): string | undefined {
    const idList = [
      this._impl_drawerOpen ? this._listboxId : '',
      this.controlledId,
    ]
      .join(' ')
      .trim();
 
    return idList ? idList : undefined;
  }
 
  public readonly _widgetKeys: WidgetKeySet = createWidgetKeySet(
    'gc-wizard-stepper-horizontal',
  );
 
  public _hasFocus = false;
 
  /**
   * @ignore
   */
  public _processItemText(text: string) {
    return textToLine(text, 32, '<br>');
  }
 
  public getAnker(): ElementRef<HTMLElement> {
    return this.button;
  }
 
  public getScrollTarget(): ElementRef<HTMLElement> | undefined {
    return this.containerElement;
  }
 
  public _isSelected(item: IndexedItem<Item>): boolean {
    return item.value === this.value;
  }
 
  public _isSelectable(key: Key): boolean {
    return this.selectableItems.some(i => i.key === key);
  }
 
  public _getAriaMessage(): string {
    const itemIndex = this.items.findIndex(i => i.key === this.value?.key);
    return (
      'Arbeitsschritt ' +
      (itemIndex !== -1 ? itemIndex + 1 : 1).toString() +
      ' von ' +
      this.items.length.toString() +
      (this.invalidItemKeys.size > 0 ? this.getInvalidStepIndexes() : '') +
      '.'
    );
  }
 
  public _onSelect(event: SelectionEvent): void {
    const item = this.storage.indexItems.find(i => i.key === event.key);
    if (item && !this.disabledItems.has(item.key)) {
      this._impl_onSelect(item.key);
    }
  }
 
  /** @ignore */
  public _impl_onSelect(key: Key): void {
    if (!this._isDisabled(key)) {
      const value = this.storage.getValueByKey(key);
      if (value != undefined) {
        this._impl_handleChange(value);
        this._impl_close(true);
      }
    }
  }
 
  /** @ignore */
  public _impl_handleChange(value: Item): void {
    this.value = value;
    this.valueChange.emit(value);
  }
 
  /** @ignore */
  protected _impl_onOpen(focusItem: KeyFocusTarget): KeyFocusTarget {
    // always open selected value if set
    if (this.value != undefined) {
      const key = this.storage.getItemByValue(this.value)?.key;
      if (key != undefined) {
        focusItem = key;
      }
    }
    return focusItem;
  }
 
  /** @ignore */
  protected _itemTrackBy(item: Item): string {
    return itemTrack(item);
  }
 
  /** @ignore */
  private getInvalidStepIndexes() {
    let invalidItemsAriaText = ' - Fehlerhafte Eingaben in Schritt ';
    const invalidStepIndexes: number[] = [];
    this.invalidItemKeys.forEach(value => {
      invalidStepIndexes.push(this.items.findIndex(i => i.key === value));
    });
    invalidStepIndexes.forEach((stepIndex, idx) => {
      const stringifiedIndex = (stepIndex + 1).toString();
      if (idx === 0) {
        invalidItemsAriaText += stringifiedIndex;
      } else {
        invalidItemsAriaText +=
          idx === invalidStepIndexes.length - 1
            ? ` und ${stringifiedIndex}`
            : `, ${stringifiedIndex}`;
      }
    });
    return invalidItemsAriaText;
  }
}