Projekt

Obecné

Profil

Stáhnout (1.66 KB) Statistiky
| Větev: | Tag: | Revize:
1 1b7df50a Hung Hoang
import {Component} from '@angular/core';
2
import {MatDialog} from '@angular/material';
3 3fcf8b67 Hung Hoang
import {LocalizationService} from '../localization/localization.service';
4 696f3358 Václav Jirák
import {UserService} from '../services/api/user.service';
5
import {UserProfile} from '../models/user.model';
6 9cc55d8d Václav Jirák
import {ProfileSettingsComponent} from "../profile-settings/profile-settings.component";
7 37333849 Václav Jirák
8
@Component({
9
  selector: 'app-header',
10
  templateUrl: './header.component.html',
11
  styleUrls: ['./header.component.sass']
12
})
13
export class HeaderComponent {
14 696f3358 Václav Jirák
  profile: UserProfile;
15 230804d9 Václav Jirák
  language: string;
16 9c7b1b63 Václav Jirák
17
  constructor(
18
    private dialog: MatDialog,
19 696f3358 Václav Jirák
    private localizationService: LocalizationService,
20
    private userService: UserService
21 9c7b1b63 Václav Jirák
    ) {
22 696f3358 Václav Jirák
    userService.getLoggedUserProfile()
23
      .subscribe((data: UserProfile) => this.profile = data);
24 230804d9 Václav Jirák
    this.language = this.localizationService.getCurrentLanguage();
25 9c7b1b63 Václav Jirák
  }
26 37333849 Václav Jirák
27 230804d9 Václav Jirák
  switchLanguage(language: string) {
28
    this.language = this.localizationService.switchLocale(language);
29
  }
30 37333849 Václav Jirák
  onProfileClick(): void {
31 9cc55d8d Václav Jirák
    this.userService.getLoggedUserProfile()
32
      .subscribe((data: UserProfile) => {
33
        this.profile = data;
34
35
        this.dialog.open(ProfileSettingsComponent, {
36
          data: {
37
            notification: this.profile.notification
38
          }
39
        }).afterClosed().subscribe(dialogData => {
40
          this.userService.putNotificationSettingsWithLanguage(
41
            {
42
              notification: dialogData.notification
43
            },
44
            this.localizationService.getCurrentLanguage()
45
          ).subscribe(() => {
46
            this.userService.getLoggedUserProfile().subscribe((profile: UserProfile) => this.profile = profile);
47
          });
48
        });
49
      });
50 37333849 Václav Jirák
  }
51
}