Projekt

Obecné

Profil

Stáhnout (1.66 KB) Statistiky
| Větev: | Tag: | Revize:
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

    
8
@Component({
9
  selector: 'app-header',
10
  templateUrl: './header.component.html',
11
  styleUrls: ['./header.component.sass']
12
})
13
export class HeaderComponent {
14
  profile: UserProfile;
15
  language: string;
16

    
17
  constructor(
18
    private dialog: MatDialog,
19
    private localizationService: LocalizationService,
20
    private userService: UserService
21
    ) {
22
    userService.getLoggedUserProfile()
23
      .subscribe((data: UserProfile) => this.profile = data);
24
    this.language = this.localizationService.getCurrentLanguage();
25
  }
26

    
27
  switchLanguage(language: string) {
28
    this.language = this.localizationService.switchLocale(language);
29
  }
30
  onProfileClick(): void {
31
    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
  }
51
}
(3-3/3)