1
|
import {AfterViewInit, Component, Inject, OnInit, ViewChild} from '@angular/core';
|
2
|
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material';
|
3
|
import {UserProfile} from '../../models/user.model';
|
4
|
import {Calendar} from '../../models/calendar.model';
|
5
|
import {RequestStatus} from '../../enums/common.enum';
|
6
|
import {UserService} from '../../services/api/user.service';
|
7
|
import {DateToolsService} from '../../services/util/date-tools.service';
|
8
|
import {LocalizationService} from '../../localization/localization.service';
|
9
|
import {UsersService} from "../../services/api/users.service";
|
10
|
|
11
|
@Component({
|
12
|
selector: 'app-user-profile',
|
13
|
templateUrl: './user-profile-dialog.component.html',
|
14
|
styleUrls: ['./user-profile-dialog.component.sass']
|
15
|
})
|
16
|
export class UserProfileDialogComponent implements OnInit, AfterViewInit {
|
17
|
@ViewChild('dayPicker', {static: false}) calendar;
|
18
|
|
19
|
private profile: UserProfile;
|
20
|
|
21
|
constructor(
|
22
|
public dialogRef: MatDialogRef<UserProfileDialogComponent>,
|
23
|
@Inject(MAT_DIALOG_DATA) public data: UserProfileDialogData,
|
24
|
private userService: UserService,
|
25
|
private usersService: UsersService,
|
26
|
private dateToolsService: DateToolsService,
|
27
|
private localizationService: LocalizationService
|
28
|
) { }
|
29
|
|
30
|
ngOnInit() {
|
31
|
|
32
|
}
|
33
|
|
34
|
|
35
|
ngAfterViewInit(): void {
|
36
|
this.loadProfile();
|
37
|
this.loadMonthVacation(this.dateToolsService.toStartOfMonth(new Date()));
|
38
|
}
|
39
|
|
40
|
onSelectedMonthChange(monthStart: Date) {
|
41
|
this.loadMonthVacation(monthStart);
|
42
|
}
|
43
|
|
44
|
onCloseClick(): void {
|
45
|
this.dialogRef.close();
|
46
|
}
|
47
|
|
48
|
private loadProfile() {
|
49
|
this.usersService.getUserProfile(this.data.userId)
|
50
|
.subscribe((data: UserProfile) => this.profile = data);
|
51
|
}
|
52
|
|
53
|
private loadMonthVacation(month: Date) {
|
54
|
const fromDate = this.dateToolsService.toStartOfMonth(month);
|
55
|
const toDate = this.dateToolsService.toEndOfMonth(fromDate);
|
56
|
|
57
|
this.userService.getUserCalendarWithOptions(String(this.data.userId), fromDate, toDate, this.localizationService.getCurrentLanguage(), RequestStatus.ACCEPTED)
|
58
|
.subscribe((data: Calendar[]) => {
|
59
|
if (data) {
|
60
|
this.calendar.setVacation(data);
|
61
|
}
|
62
|
});
|
63
|
}
|
64
|
}
|
65
|
|
66
|
export class UserProfileDialogData {
|
67
|
userId: number;
|
68
|
}
|