All files / lib/calendar/calendar-appointment calendar-appointment.component.ts

95.75% Statements 158/165
92.3% Branches 36/39
100% Functions 7/7
95.75% Lines 158/165

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 1661x 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 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 248x 1695x 1695x 1127x 1695x 142x 739x 98x 739x 142x 739x 186x 1572x     1695x 1695x 248x 248x 248x 1695x 1695x 1695x 931x 931x       1572x 352x 1695x 324x 764x 44x 44x 44x 641x     1695x 1695x 1695x 1695x 1695x 1695x 1695x 1695x 1509x 186x 186x 1695x 1695x 248x 248x 248x 248x 248x 248x 248x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x 17x 4x 4x 13x 13x 17x 17x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  Component,
  ElementRef,
  EventEmitter,
  Input,
  Output,
  ViewChild,
  computed,
  input,
} from '@angular/core';
 
import { Callback, FocusableElementOwner } from '../../utils/util.types';
 
/** Represents days of the week Monday-Sunday */
export type DayOfWeek = 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun';
 
/**
 * Single appointment component for the Calendar component.
 */
@Component({
  selector: 'gc-calendar-appointment',
  templateUrl: './calendar-appointment.component.html',
  styleUrls: [
    '../../utils/styles/reset-button.css',
    './calendar-appointment.component.css',
    '../../utils/styles/patterns.css',
  ],
  standalone: false,
})
export class CalendarAppointmentComponent implements FocusableElementOwner {
  /** @ignore */
  private static readonly dateFormatter = Intl.DateTimeFormat('de-DE', {
    day: 'numeric',
    month: 'long',
    year: 'numeric',
  });
 
  /** Label of the calendar appointment (Primary information). */
  @Input({ required: true })
  label = '';
 
  /** Sublabel of the calendar appointment. (Secondary information) */
  @Input()
  sublabel = '';
 
  /**  Status of the calendar appointment. */
  @Input()
  status: 'scheduled' | 'prebooked' | 'postponed' | 'cancelled' | 'all-day' =
    'scheduled';
 
  /** Decides if the calendar appointment is selected. */
  @Input()
  selected = false;
 
  /** Affects aria readout. If set to true, the appoinment aria-label will be read starting with information that the appointment is today.  */
  @Input()
  isToday = false;
 
  /** Affects aria readout. Decides the day of the week of the calendar appointment.  */
  @Input({ required: true })
  dayOfTheWeek: DayOfWeek = 'mon';
 
  /** Affects aria readout. Decides the start/end time of the calendar appointment.  */
  @Input()
  time: { start: string; end: string } = { start: '00:00', end: '00:00' };
 
  @Input()
  tabIndex = 0;
 
  @Output()
  public readonly onAction: EventEmitter<'open-infobox' | 'open-details'> =
    new EventEmitter<'open-infobox' | 'open-details'>();
 
  @ViewChild('appointmentEl')
  public readonly appointmentEl!: ElementRef<HTMLButtonElement>;
 
  @Input()
  public focusCallback?: Callback;
 
  @Input()
  public keydownCallback?: (event: KeyboardEvent) => void;
 
  /** @ignore */
  protected get statusText(): string {
    switch (this.status) {
      case 'scheduled':
        return 'Terminiert';
      case 'prebooked':
        return 'Vorgemerkt';
      case 'postponed':
        return 'Verlegt';
      case 'cancelled':
        return 'Aufgehoben';
      case 'all-day':
        return 'Ganztägig';
      default:
        this.status satisfies never;
        return '';
    }
  }
 
  /** @ignore */
  protected get ariaLabel(): string {
    const generateDayOfTheWeekText = () => {
      switch (this.dayOfTheWeek) {
        case 'mon':
          return 'Montag';
        case 'tue':
          return 'Dienstag';
        case 'wed':
          return 'Mittwoch';
        case 'thu':
          return 'Donnerstag';
        case 'fri':
          return 'Freitag';
        case 'sat':
          return 'Samstag';
        case 'sun':
          return 'Sonntag';
        default:
          this.dayOfTheWeek satisfies never;
          return '';
      }
    };
 
    const todayText = this.isToday ? 'Heute, ' : '';
    const sublabel = this.sublabel.length > 0 ? ', ' + this.sublabel : '';
    const dayOfTheWeek = generateDayOfTheWeekText();
 
    if (this.status !== 'all-day') {
      return `${todayText}${this.statusText}, ${dayOfTheWeek}, ${this.formattedDate()}, ${this.time.start} Uhr bis ${this.time.end} Uhr, ${this.label}${sublabel}`;
    } else {
      return `${todayText}${this.statusText}, ${dayOfTheWeek}, ${this.formattedDate()}, ${this.label}${sublabel}`;
    }
  }
 
  /** Date of the appointment (e.g. shown in accessible readout), in ISO 8601 format. */
  public readonly date = input.required<string>();
 
  /** @ignore */
  private readonly formattedDate = computed(() =>
    CalendarAppointmentComponent.dateFormatter.format(new Date(this.date())),
  );
 
  /** @ignore */
  public focusChild(): boolean {
    this.appointmentEl.nativeElement.focus();
    return true;
  }
 
  /** @ignore */
  protected onKeydownHandler(event: KeyboardEvent): void {
    if (event.key === 'Enter' || event.key === ' ') {
      event.preventDefault();
      this.onAction.emit(event.shiftKey ? 'open-details' : 'open-infobox');
    } else {
      this.keydownCallback?.(event);
    }
  }
}