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.currentLanguage
|
38
|
.subscribe((data) => {
|
39
|
this.locale = data;
|
40
|
});
|
41
|
|
42
|
this.viewDate = new Date();
|
43
|
this.currentMonth = this.viewDate.getMonth();
|
44
|
console.log(this.currentMonth);
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* Method that is invoked when user clicks on a day.
|
49
|
* Sets selected date and emits event informing about new selected date.
|
50
|
*
|
51
|
* @param date Selected date
|
52
|
*/
|
53
|
private dayClicked({ date }: { date: Date }): void {
|
54
|
this.viewDate = date;
|
55
|
this.selectedDate.emit(date);
|
56
|
}
|
57
|
|
58
|
private setMonth(newMonth: number): void {
|
59
|
this.currentMonth = newMonth % 12;
|
60
|
if (this.currentMonth < 0) {
|
61
|
this.currentMonth = 11;
|
62
|
}
|
63
|
this.selectedMonth.emit(this.currentMonth);
|
64
|
}
|
65
|
}
|