1 |
f8b40fd5
|
Hung Hoang
|
import {Component, EventEmitter, Inject, OnInit, Output} from '@angular/core';
|
2 |
|
|
import {MAT_DIALOG_DATA, MatDialogRef, MatSnackBar} from '@angular/material';
|
3 |
79d7de40
|
Hung Hoang
|
import {UserType} from '../../enums/common.enum';
|
4 |
f8b40fd5
|
Hung Hoang
|
import {UserProfile} from '../../models/user.model';
|
5 |
|
|
import {UserSettings} from '../../models/settings.model';
|
6 |
5d32cbea
|
Václav Jirák
|
import {TranslateService} from '@ngx-translate/core';
|
7 |
79d7de40
|
Hung Hoang
|
|
8 |
|
|
|
9 |
|
|
@Component({
|
10 |
|
|
selector: 'app-edit-employee-dialog',
|
11 |
|
|
templateUrl: './edit-employee-dialog.component.html',
|
12 |
|
|
styleUrls: ['./edit-employee-dialog.component.sass']
|
13 |
|
|
})
|
14 |
|
|
export class EditEmployeeDialogComponent implements OnInit {
|
15 |
f8b40fd5
|
Hung Hoang
|
readonly _userTypes: string[] = ['EMPLOYER', 'EMPLOYEE'];
|
16 |
79d7de40
|
Hung Hoang
|
private _sickDaysCount: number;
|
17 |
6496dcfb
|
Václav Jirák
|
private _addVacationHoursCount: number;
|
18 |
79d7de40
|
Hung Hoang
|
private _userType: UserType;
|
19 |
f8b40fd5
|
Hung Hoang
|
private readonly _userId: number;
|
20 |
6496dcfb
|
Václav Jirák
|
|
21 |
f8b40fd5
|
Hung Hoang
|
@Output() postUserSettings = new EventEmitter<UserSettings>();
|
22 |
79d7de40
|
Hung Hoang
|
|
23 |
|
|
constructor(public dialogRef: MatDialogRef<EditEmployeeDialogComponent>,
|
24 |
f8b40fd5
|
Hung Hoang
|
@Inject(MAT_DIALOG_DATA) public data: UserProfile,
|
25 |
5d32cbea
|
Václav Jirák
|
private snackBar: MatSnackBar,
|
26 |
|
|
private translateService: TranslateService
|
27 |
|
|
) {
|
28 |
93fb3695
|
Václav Jirák
|
this._sickDaysCount = data.sickDayCount;
|
29 |
6496dcfb
|
Václav Jirák
|
this._addVacationHoursCount = 0;
|
30 |
f8b40fd5
|
Hung Hoang
|
this._userType = data.role;
|
31 |
|
|
this._userId = data.id;
|
32 |
79d7de40
|
Hung Hoang
|
}
|
33 |
|
|
|
34 |
|
|
ngOnInit() {
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
onConfirmClick(): void {
|
38 |
6496dcfb
|
Václav Jirák
|
if (this._sickDaysCount == null || this._addVacationHoursCount == null || this._userType == null) {
|
39 |
5d32cbea
|
Václav Jirák
|
this.translateService.get('error.missingField').subscribe((res: string) => {
|
40 |
|
|
this.snackBar.open(res, 'X', { duration: 5000 });
|
41 |
|
|
});
|
42 |
f8b40fd5
|
Hung Hoang
|
} else {
|
43 |
|
|
this.postUserSettings.emit({
|
44 |
|
|
id: this._userId,
|
45 |
|
|
role: this._userType,
|
46 |
93fb3695
|
Václav Jirák
|
sickDayCount: this._sickDaysCount,
|
47 |
6496dcfb
|
Václav Jirák
|
vacationCount: this._addVacationHoursCount
|
48 |
f8b40fd5
|
Hung Hoang
|
});
|
49 |
|
|
|
50 |
|
|
this.dialogRef.close();
|
51 |
|
|
}
|
52 |
79d7de40
|
Hung Hoang
|
}
|
53 |
|
|
|
54 |
|
|
onCloseClick(): void {
|
55 |
|
|
this.dialogRef.close();
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
}
|