Projekt

Obecné

Profil

Stáhnout (1.85 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 7479e470 Hung Hoang
import {ProfileSettingsComponent} from '../profile-settings/profile-settings.component';
7 d2799ca5 Jakub Danek
import {UsersService} from "../services/api/users.service";
8 37333849 Václav Jirák
9
@Component({
10
  selector: 'app-header',
11
  templateUrl: './header.component.html',
12
  styleUrls: ['./header.component.sass']
13
})
14
export class HeaderComponent {
15 696f3358 Václav Jirák
  profile: UserProfile;
16 230804d9 Václav Jirák
  language: string;
17 9c7b1b63 Václav Jirák
18
  constructor(
19
    private dialog: MatDialog,
20 696f3358 Václav Jirák
    private localizationService: LocalizationService,
21 d2799ca5 Jakub Danek
    private userService: UserService,
22
    private usersService: UsersService
23 9c7b1b63 Václav Jirák
    ) {
24 d2799ca5 Jakub Danek
    usersService.getLoggedUserProfile()
25 696f3358 Václav Jirák
      .subscribe((data: UserProfile) => this.profile = data);
26 230804d9 Václav Jirák
    this.language = this.localizationService.getCurrentLanguage();
27 9c7b1b63 Václav Jirák
  }
28 37333849 Václav Jirák
29 230804d9 Václav Jirák
  switchLanguage(language: string) {
30
    this.language = this.localizationService.switchLocale(language);
31
  }
32 37333849 Václav Jirák
  onProfileClick(): void {
33 d2799ca5 Jakub Danek
    this.usersService.getLoggedUserProfile()
34 9cc55d8d Václav Jirák
      .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 7ddbcffc Václav Jirák
          if (!dialogData || !dialogData.isConfirmed) {
43 7479e470 Hung Hoang
            return;
44
          }
45
46 9cc55d8d Václav Jirák
          this.userService.putNotificationSettingsWithLanguage(
47
            {
48
              notification: dialogData.notification
49
            },
50
            this.localizationService.getCurrentLanguage()
51
          ).subscribe(() => {
52 d2799ca5 Jakub Danek
            this.usersService.getLoggedUserProfile().subscribe((profile: UserProfile) => this.profile = profile);
53 9cc55d8d Václav Jirák
          });
54
        });
55
      });
56 37333849 Václav Jirák
  }
57
}