1
|
import {Component, OnInit, ViewChild} from '@angular/core';
|
2
|
import {MatDialog} from '@angular/material';
|
3
|
import {AddVacationDialogComponent} from '../../add-vacation-dialog/add-vacation-dialog.component';
|
4
|
import {UsersService} from '../../services/api/users.service';
|
5
|
import {AuthorizationRequest, VacationRequest} from '../../models/requests.model';
|
6
|
import {UserService} from '../../services/api/user.service';
|
7
|
import {UserProfile} from '../../models/user.model';
|
8
|
import {LocalizationService} from '../../localization/localization.service';
|
9
|
import {RequestStatus, RequestTypes} from '../../enums/common.enum';
|
10
|
import {Calendar} from '../../models/calendar.model';
|
11
|
import {DateToolsService} from '../../services/util/date-tools.service';
|
12
|
|
13
|
@Component({
|
14
|
selector: 'app-employer-dashboard',
|
15
|
templateUrl: './employer-dashboard.component.html',
|
16
|
styleUrls: ['./employer-dashboard.component.sass']
|
17
|
})
|
18
|
export class EmployerDashboardComponent implements OnInit {
|
19
|
@ViewChild('dayPicker') calendar;
|
20
|
|
21
|
private profile: UserProfile;
|
22
|
private authorizationRequests: AuthorizationRequest[];
|
23
|
private vacationRequests: VacationRequest[];
|
24
|
private oncomingVacation: Calendar[];
|
25
|
|
26
|
constructor(
|
27
|
public dialog: MatDialog,
|
28
|
private localizationService: LocalizationService,
|
29
|
private dateToolsService: DateToolsService,
|
30
|
private userService: UserService,
|
31
|
private usersService: UsersService
|
32
|
) { }
|
33
|
|
34
|
ngOnInit() {
|
35
|
this.loadProfile();
|
36
|
this.loadAuthorizationRequests();
|
37
|
this.loadVacationRequests();
|
38
|
this.loadMonthVacation(this.dateToolsService.toStartOfMonth(new Date()));
|
39
|
this.loadOncomingVacation();
|
40
|
}
|
41
|
|
42
|
userApproved(requestId: number, approved: boolean) {
|
43
|
this.requestApproved(requestId, RequestTypes.AUTHORIZATION, approved)
|
44
|
.subscribe(e => this.loadAuthorizationRequests());
|
45
|
}
|
46
|
|
47
|
vacationApproved(requestId: number, approved: boolean) {
|
48
|
this.requestApproved(requestId, RequestTypes.VACATION, approved)
|
49
|
.subscribe(e => this.loadVacationRequests());
|
50
|
}
|
51
|
|
52
|
requestApproved(requestId: number, requestType: RequestTypes, approved: boolean) {
|
53
|
const request = {
|
54
|
id: requestId,
|
55
|
status: approved ? RequestStatus.ACCEPTED : RequestStatus.REJECTED
|
56
|
};
|
57
|
|
58
|
return this.userService.putUserRequestWithLanguage(request, requestType, this.localizationService.getCurrentLanguage());
|
59
|
}
|
60
|
|
61
|
removeVacation(vac: Calendar) {
|
62
|
this.userService.deleteCalendar(vac.id, this.localizationService.getCurrentLanguage())
|
63
|
.subscribe(e => this.loadOncomingVacation());
|
64
|
}
|
65
|
|
66
|
editVacation(vac: Calendar) {
|
67
|
// this.dialog.open(EditVacationDialogComponent, {
|
68
|
// data: {
|
69
|
// vacation: vac
|
70
|
// }
|
71
|
// });
|
72
|
}
|
73
|
|
74
|
onDateSelect( date: Date ) {
|
75
|
this.dialog
|
76
|
.open(AddVacationDialogComponent, {
|
77
|
data: {
|
78
|
fromDate: date
|
79
|
}
|
80
|
})
|
81
|
.afterClosed().subscribe(data => {
|
82
|
if (data && data.isConfirmed) {
|
83
|
// TODO
|
84
|
}
|
85
|
});
|
86
|
}
|
87
|
|
88
|
onSelectedMonthChange(monthStart: Date) {
|
89
|
this.loadMonthVacation(monthStart);
|
90
|
}
|
91
|
|
92
|
private loadProfile() {
|
93
|
this.userService.getLoggedUserProfile()
|
94
|
.subscribe((data: UserProfile) => this.profile = data);
|
95
|
}
|
96
|
|
97
|
private loadAuthorizationRequests() {
|
98
|
this.usersService.getAuthorizationRequestsWithLanguage(this.localizationService.getCurrentLanguage())
|
99
|
.subscribe((data: AuthorizationRequest[]) => this.authorizationRequests = data);
|
100
|
}
|
101
|
|
102
|
private loadVacationRequests() {
|
103
|
this.usersService.getVacationRequestsWithLanguage(this.localizationService.getCurrentLanguage())
|
104
|
.subscribe((data: VacationRequest[]) => this.vacationRequests = data);
|
105
|
}
|
106
|
|
107
|
private loadMonthVacation(month: Date) {
|
108
|
const fromDate = this.dateToolsService.toStartOfMonth(month);
|
109
|
const toDate = this.dateToolsService.toEndOfMonth(fromDate);
|
110
|
|
111
|
this.userService.getLoggedUserCalendarWithOptions(fromDate, toDate, this.localizationService.getCurrentLanguage(), RequestStatus.ACCEPTED)
|
112
|
.subscribe((data: Calendar[]) => {
|
113
|
if (data) {
|
114
|
this.calendar.setVacation(data);
|
115
|
}
|
116
|
});
|
117
|
}
|
118
|
|
119
|
private loadOncomingVacation() {
|
120
|
const fromDate = new Date();
|
121
|
|
122
|
this.userService.getLoggedUserCalendarWithOptions(fromDate, null, this.localizationService.getCurrentLanguage(), null)
|
123
|
.subscribe((data: Calendar[]) => this.oncomingVacation = data);
|
124
|
}
|
125
|
}
|