1 |
0e8e77b3
|
Václav Jirák
|
import { Component, ChangeDetectionStrategy, Input, Output, EventEmitter } from '@angular/core';
|
2 |
|
|
import { CalendarView, CalendarEvent } from 'angular-calendar';
|
3 |
18dbad83
|
Václav Jirák
|
import {LocalizationService} from '../localization/localization.service';
|
4 |
0e8e77b3
|
Václav Jirák
|
import {VacationType} from '../enums/common.enum';
|
5 |
0d1b0550
|
Václav Jirák
|
|
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 |
18dbad83
|
Václav Jirák
|
private locale;
|
15 |
0d1b0550
|
Václav Jirák
|
|
16 |
0e8e77b3
|
Václav Jirák
|
private vacationType = VacationType;
|
17 |
|
|
|
18 |
|
|
private currentMonth: number;
|
19 |
|
|
|
20 |
0d1b0550
|
Václav Jirák
|
// Type of calendar (constant)
|
21 |
|
|
view: CalendarView = CalendarView.Month;
|
22 |
|
|
|
23 |
|
|
// Selected date for this component's purpose
|
24 |
0e8e77b3
|
Václav Jirák
|
private viewDate: Date;
|
25 |
|
|
|
26 |
|
|
// Events which are shown in calendar (title = VacationType)
|
27 |
|
|
@Input() events: CalendarEvent[] = [];
|
28 |
0d1b0550
|
Václav Jirák
|
|
29 |
|
|
// EventEmitter informing about changes of selected date
|
30 |
|
|
@Output() selectedDate = new EventEmitter<Date>();
|
31 |
|
|
|
32 |
0e8e77b3
|
Václav Jirák
|
// EventEmitter informing about changes of selected month
|
33 |
|
|
@Output() selectedMonth = new EventEmitter<number>();
|
34 |
|
|
|
35 |
18dbad83
|
Václav Jirák
|
constructor(private localizationService: LocalizationService) {
|
36 |
|
|
this.locale = localizationService.defaultLanguage;
|
37 |
89c98d12
|
Václav Jirák
|
localizationService.currentLanguageSubject
|
38 |
18dbad83
|
Václav Jirák
|
.subscribe((data) => {
|
39 |
|
|
this.locale = data;
|
40 |
|
|
});
|
41 |
0e8e77b3
|
Václav Jirák
|
|
42 |
|
|
this.viewDate = new Date();
|
43 |
|
|
this.currentMonth = this.viewDate.getMonth();
|
44 |
18dbad83
|
Václav Jirák
|
}
|
45 |
|
|
|
46 |
0d1b0550
|
Václav Jirák
|
/**
|
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 |
0e8e77b3
|
Václav Jirák
|
|
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 |
0d1b0550
|
Václav Jirák
|
}
|