Projekt

Obecné

Profil

Stáhnout (1.87 KB) Statistiky
| Větev: | Tag: | Revize:
1
import { Component, ChangeDetectionStrategy, Input, Output, EventEmitter } from '@angular/core';
2
import { CalendarView, CalendarEvent } from 'angular-calendar';
3
import {LocalizationService} from '../localization/localization.service';
4
import {VacationType} from '../enums/common.enum';
5

    
6
@Component({
7
  selector: 'app-day-picker',
8
  changeDetection: ChangeDetectionStrategy.OnPush,
9
  styleUrls: ['day-picker.component.sass'],
10
  templateUrl: 'day-picker.component.html'
11
})
12
export class DayPickerComponent {
13

    
14
  private locale;
15

    
16
  private vacationType = VacationType;
17

    
18
  private currentMonth: number;
19

    
20
  // Type of calendar (constant)
21
  view: CalendarView = CalendarView.Month;
22

    
23
  // Selected date for this component's purpose
24
  private viewDate: Date;
25

    
26
  // Events which are shown in calendar (title = VacationType)
27
  @Input() events: CalendarEvent[] = [];
28

    
29
  // EventEmitter informing about changes of selected date
30
  @Output() selectedDate = new EventEmitter<Date>();
31

    
32
  // EventEmitter informing about changes of selected month
33
  @Output() selectedMonth = new EventEmitter<number>();
34

    
35
  constructor(private localizationService: LocalizationService) {
36
    this.locale = localizationService.defaultLanguage;
37
    localizationService.currentLanguageSubject
38
      .subscribe((data) => {
39
        this.locale = data;
40
      });
41

    
42
    this.viewDate = new Date();
43
    this.currentMonth = this.viewDate.getMonth();
44
  }
45

    
46
  /**
47
   * Method that is invoked when user clicks on a day.
48
   * Sets selected date and emits event informing about new selected date.
49
   *
50
   * @param date Selected date
51
   */
52
  private dayClicked({ date }: { date: Date }): void {
53
    this.viewDate = date;
54
    this.selectedDate.emit(date);
55
  }
56

    
57
  private setMonth(newMonth: number): void {
58
    this.currentMonth = newMonth % 12;
59
    if (this.currentMonth < 0) {
60
      this.currentMonth = 11;
61
    }
62
    this.selectedMonth.emit(this.currentMonth);
63
  }
64
}
(3-3/4)