Projekt

Obecné

Profil

Stáhnout (1.75 KB) Statistiky
| Větev: | Tag: | Revize:
1 89c98d12 Václav Jirák
import {Component, Inject} from '@angular/core';
2 d9d4877f Václav Jirák
import {MAT_DIALOG_DATA, MatDialogRef, MatSnackBar} from '@angular/material';
3 5d32cbea Václav Jirák
import {TranslateService} from '@ngx-translate/core';
4 89c98d12 Václav Jirák
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 d9d4877f Václav Jirák
    @Inject(MAT_DIALOG_DATA) public data: DefaultSettingsDialogData,
16
    private snackBar: MatSnackBar,
17 5d32cbea Václav Jirák
    private translateService: TranslateService
18 89c98d12 Václav Jirák
  ) {
19
  }
20
21
  onConfirmClick(): void {
22 d9d4877f Václav Jirák
    if (this.everythingFilled()) {
23
      this.dialogRef.close(
24
        {
25
          isConfirmed: true,
26
          notificationDatetime: this.toNotificationDatetime(),
27
          sickDayCount: this.data.sickDayCount
28
        }
29
      );
30 599dd1cf Václav Jirák
    } else {
31 5d32cbea Václav Jirák
      this.translateService.get('error.missingField').subscribe((res: string) => {
32
        this.snackBar.open(res, 'X', { duration: 5000 });
33
      });
34 599dd1cf Václav Jirák
    }
35 89c98d12 Václav Jirák
  }
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 d9d4877f Václav Jirák
  private everythingFilled(): boolean {
56 8860de8e Václav Jirák
    return Boolean(this.data.notificationDate && this.data.notificationTime && this.data.sickDayCount);
57 d9d4877f Václav Jirák
  }
58
59 89c98d12 Václav Jirák
}
60
61
export class DefaultSettingsDialogData {
62
  notificationDate: Date;
63
  notificationTime: string;
64 93fb3695 Václav Jirák
  sickDayCount: number;
65 89c98d12 Václav Jirák
}