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