1
|
import { Component, ChangeDetectionStrategy, Output, EventEmitter } from '@angular/core';
|
2
|
import { CalendarView } from 'angular-calendar';
|
3
|
import {LocalizationService} from '../localization/localization.service';
|
4
|
|
5
|
@Component({
|
6
|
selector: 'app-day-picker',
|
7
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
8
|
styleUrls: ['day-picker.component.sass'],
|
9
|
templateUrl: 'day-picker.component.html'
|
10
|
})
|
11
|
export class DayPickerComponent {
|
12
|
|
13
|
private locale;
|
14
|
|
15
|
// Type of calendar (constant)
|
16
|
view: CalendarView = CalendarView.Month;
|
17
|
|
18
|
// Selected date for this component's purpose
|
19
|
private viewDate: Date = new Date();
|
20
|
|
21
|
// EventEmitter informing about changes of selected date
|
22
|
@Output() selectedDate = new EventEmitter<Date>();
|
23
|
|
24
|
constructor(private localizationService: LocalizationService) {
|
25
|
this.locale = localizationService.defaultLanguage;
|
26
|
localizationService.currentLanguage
|
27
|
.subscribe((data) => {
|
28
|
this.locale = data;
|
29
|
});
|
30
|
}
|
31
|
|
32
|
/**
|
33
|
* Method that is invoked when user clicks on a day.
|
34
|
* Sets selected date and emits event informing about new selected date.
|
35
|
*
|
36
|
* @param date Selected date
|
37
|
*/
|
38
|
private dayClicked({ date }: { date: Date }): void {
|
39
|
this.viewDate = date;
|
40
|
this.selectedDate.emit(date);
|
41
|
}
|
42
|
}
|