1
|
import {Component, Inject} from '@angular/core';
|
2
|
import {MAT_DIALOG_DATA, MatDialogRef, MatSnackBar} from '@angular/material';
|
3
|
import {VacationType} from '../enums/common.enum';
|
4
|
import {FormControl} from '@angular/forms';
|
5
|
import {DateFormatterService} from '../services/util/date-formatter.service';
|
6
|
|
7
|
@Component({
|
8
|
selector: 'app-add-days-off-dialog',
|
9
|
templateUrl: './add-vacation-dialog.component.html',
|
10
|
styleUrls: ['./add-vacation-dialog.component.sass']
|
11
|
})
|
12
|
export class AddVacationDialogComponent {
|
13
|
MINUTE_STEP = 15;
|
14
|
|
15
|
vacationType = VacationType;
|
16
|
|
17
|
selectedVacationType: VacationType;
|
18
|
|
19
|
dateFormControl: FormControl = new FormControl();
|
20
|
|
21
|
constructor(
|
22
|
public dialogRef: MatDialogRef<AddVacationDialogComponent>,
|
23
|
@Inject(MAT_DIALOG_DATA) public data: AddVacationDialogData,
|
24
|
private snackBar: MatSnackBar,
|
25
|
private dateFormatterService: DateFormatterService
|
26
|
) {
|
27
|
if (this.data.fromTime == null) {
|
28
|
this.data.fromTime = '08:00';
|
29
|
}
|
30
|
if (data.toTime == null) {
|
31
|
this.data.toTime = '16:00';
|
32
|
}
|
33
|
|
34
|
this.dateFormControl.setValue(data.date);
|
35
|
}
|
36
|
|
37
|
onConfirmClick(): void {
|
38
|
if (this.selectedVacationType == null) {
|
39
|
this.snackBar.open('Nevybrán typ volna', 'Zavřít', { duration: 5000 });
|
40
|
} else {
|
41
|
let data;
|
42
|
const formattedDate = this.dateFormatterService.formatDate(this.data.date);
|
43
|
|
44
|
if (this.selectedVacationType === VacationType.VACATION) {
|
45
|
data = {
|
46
|
isConfirmed: true,
|
47
|
vacationType: this.selectedVacationType,
|
48
|
date: formattedDate,
|
49
|
fromTime: this.data.fromTime,
|
50
|
toTime: this.data.toTime
|
51
|
};
|
52
|
} else {
|
53
|
data = {
|
54
|
isConfirmed: true,
|
55
|
vacationType: this.selectedVacationType,
|
56
|
date: formattedDate
|
57
|
};
|
58
|
}
|
59
|
|
60
|
this.dialogRef.close(data);
|
61
|
}
|
62
|
}
|
63
|
|
64
|
onCloseClick(): void {
|
65
|
this.dialogRef.close({
|
66
|
isConfirmed: false
|
67
|
});
|
68
|
}
|
69
|
|
70
|
}
|
71
|
|
72
|
export interface AddVacationDialogData {
|
73
|
date: Date;
|
74
|
fromTime: string; // 'HH:mm' format
|
75
|
toTime: string; // 'HH:mm' format
|
76
|
}
|