1
|
import {Component, Inject} from '@angular/core';
|
2
|
import {MAT_DIALOG_DATA, MatDialogRef, MatSnackBar} from '@angular/material';
|
3
|
import {TranslateService} from '@ngx-translate/core';
|
4
|
|
5
|
@Component({
|
6
|
selector: 'app-default-settings',
|
7
|
templateUrl: './default-settings-dialog.component.html',
|
8
|
styleUrls: ['./default-settings.component.sass']
|
9
|
})
|
10
|
export class DefaultSettingsDialogComponent {
|
11
|
MINUTE_STEP = 15;
|
12
|
|
13
|
constructor(
|
14
|
public dialogRef: MatDialogRef<DefaultSettingsDialogComponent>,
|
15
|
@Inject(MAT_DIALOG_DATA) public data: DefaultSettingsDialogData,
|
16
|
private snackBar: MatSnackBar,
|
17
|
private translateService: TranslateService
|
18
|
) {
|
19
|
}
|
20
|
|
21
|
onConfirmClick(): void {
|
22
|
if (this.everythingFilled()) {
|
23
|
this.dialogRef.close(
|
24
|
{
|
25
|
isConfirmed: true,
|
26
|
notificationDatetime: this.toNotificationDatetime(),
|
27
|
sickDayCount: this.data.sickDayCount
|
28
|
}
|
29
|
);
|
30
|
} else {
|
31
|
this.translateService.get('error.missingField').subscribe((res: string) => {
|
32
|
this.snackBar.open(res, 'X', { duration: 5000 });
|
33
|
});
|
34
|
}
|
35
|
}
|
36
|
|
37
|
onCloseClick(): void {
|
38
|
this.dialogRef.close({
|
39
|
isConfirmed: false
|
40
|
});
|
41
|
}
|
42
|
|
43
|
private toNotificationDatetime(): Date {
|
44
|
const splittedTime = this.data.notificationTime.split(':');
|
45
|
|
46
|
return new Date(
|
47
|
this.data.notificationDate.getFullYear(),
|
48
|
this.data.notificationDate.getMonth(),
|
49
|
this.data.notificationDate.getDate(),
|
50
|
Number(splittedTime[0]),
|
51
|
Number(splittedTime[1])
|
52
|
);
|
53
|
}
|
54
|
|
55
|
private everythingFilled(): boolean {
|
56
|
return Boolean(this.data.notificationDate && this.data.notificationTime && this.data.sickDayCount);
|
57
|
}
|
58
|
|
59
|
}
|
60
|
|
61
|
export class DefaultSettingsDialogData {
|
62
|
notificationDate: Date;
|
63
|
notificationTime: string;
|
64
|
sickDayCount: number;
|
65
|
}
|