Projekt

Obecné

Profil

Stáhnout (1.54 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

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

    
25
  onProfileClick(): void {
26
    this.userService.getLoggedUserProfile()
27
      .subscribe((data: UserProfile) => {
28
        this.profile = data;
29

    
30
        this.dialog.open(ProfileSettingsComponent, {
31
          data: {
32
            notification: this.profile.notification
33
          }
34
        }).afterClosed().subscribe(dialogData => {
35
          if (!dialogData.isConfirmed) {
36
            return;
37
          }
38

    
39
          this.userService.putNotificationSettingsWithLanguage(
40
            {
41
              notification: dialogData.notification
42
            },
43
            this.localizationService.getCurrentLanguage()
44
          ).subscribe(() => {
45
            this.userService.getLoggedUserProfile().subscribe((profile: UserProfile) => this.profile = profile);
46
          });
47
        });
48
      });
49
  }
50
}
(3-3/3)