1
|
import {Component} from '@angular/core';
|
2
|
import {MatDialog} from '@angular/material';
|
3
|
import {LocalizationService} from '../localization/localization.service';
|
4
|
import {UserService} from '../services/api/user.service';
|
5
|
import {UserProfile} from '../models/user.model';
|
6
|
import {ProfileSettingsComponent} from '../profile-settings/profile-settings.component';
|
7
|
import {UsersService} from "../services/api/users.service";
|
8
|
|
9
|
@Component({
|
10
|
selector: 'app-header',
|
11
|
templateUrl: './header.component.html',
|
12
|
styleUrls: ['./header.component.sass']
|
13
|
})
|
14
|
export class HeaderComponent {
|
15
|
profile: UserProfile;
|
16
|
language: string;
|
17
|
|
18
|
constructor(
|
19
|
private dialog: MatDialog,
|
20
|
private localizationService: LocalizationService,
|
21
|
private userService: UserService,
|
22
|
private usersService: UsersService
|
23
|
) {
|
24
|
usersService.getLoggedUserProfile()
|
25
|
.subscribe((data: UserProfile) => this.profile = data);
|
26
|
this.language = this.localizationService.getCurrentLanguage();
|
27
|
}
|
28
|
|
29
|
switchLanguage(language: string) {
|
30
|
this.language = this.localizationService.switchLocale(language);
|
31
|
}
|
32
|
onProfileClick(): void {
|
33
|
this.usersService.getLoggedUserProfile()
|
34
|
.subscribe((data: UserProfile) => {
|
35
|
this.profile = data;
|
36
|
|
37
|
this.dialog.open(ProfileSettingsComponent, {
|
38
|
data: {
|
39
|
notification: this.profile.notification
|
40
|
}
|
41
|
}).afterClosed().subscribe(dialogData => {
|
42
|
if (!dialogData || !dialogData.isConfirmed) {
|
43
|
return;
|
44
|
}
|
45
|
|
46
|
this.userService.putNotificationSettingsWithLanguage(
|
47
|
{
|
48
|
notification: dialogData.notification
|
49
|
},
|
50
|
this.localizationService.getCurrentLanguage()
|
51
|
).subscribe(() => {
|
52
|
this.usersService.getLoggedUserProfile().subscribe((profile: UserProfile) => this.profile = profile);
|
53
|
});
|
54
|
});
|
55
|
});
|
56
|
}
|
57
|
}
|