Projekt

Obecné

Profil

Stáhnout (2.04 KB) Statistiky
| Větev: | Tag: | Revize:
1 c64ba540 hlavja
import {Component, EventEmitter, Input, OnDestroy, OnInit, Output} from '@angular/core';
2 464309d9 hlavja
import {AuthService} from '../../../auth/services/auth.service';
3 2c5da396 hlavja
import {User} from '../../../auth/models/user';
4
import {Subscription} from 'rxjs';
5 b6006ff4 hlavja
import {Right} from '../../api/endpoints/models/right';
6 278f83f2 Lukáš Moučka
import {Phenomenon} from '../../api/endpoints/models/phenomenon';
7
import {SensorsService} from '../../api/endpoints/services/sensors.service';
8 b5525aef hlavja
import {InsertUnit} from '../../api/endpoints/models/insert-unit';
9
import {InsertSensor} from '../../api/endpoints/models/insert-sensor';
10 464309d9 hlavja
11
@Component({
12
  selector: 'app-nav-bar',
13
  templateUrl: './nav-bar.component.html',
14
  styleUrls: ['./nav-bar.component.scss']
15
})
16 2c5da396 hlavja
export class NavBarComponent implements OnInit, OnDestroy {
17 464309d9 hlavja
18 2c5da396 hlavja
  loggedUser: User;
19
  subscription: Subscription[] = [];
20 b6006ff4 hlavja
  showAddUserPopup = false;
21
  rights: Right[];
22 278f83f2 Lukáš Moučka
  showInsertUnitPopup = false;
23
  phenomenons: Phenomenon[];
24 b5525aef hlavja
  @Output() emitNewUnit: EventEmitter<{unit: InsertUnit, sensors: InsertSensor[]}> =
25 c64ba540 hlavja
    new EventEmitter<{unit: InsertUnit, sensors: InsertSensor[]}>();
26
  @Input() sensorTypes;
27
28 464309d9 hlavja
  constructor(
29 278f83f2 Lukáš Moučka
    private authService: AuthService,
30
    private sensorService: SensorsService
31 464309d9 hlavja
  ) {
32
  }
33
34
  ngOnInit(): void {
35 2c5da396 hlavja
    this.setUser();
36
  }
37
38 cbb91c90 hlavja
  /**
39
   * Get user from state after logged
40
   */
41 2c5da396 hlavja
  setUser(){
42
    this.authService.getUserState().subscribe(res => {
43
      if(res){
44
        this.loggedUser = res;
45
      }
46
    });
47 464309d9 hlavja
  }
48
49 cbb91c90 hlavja
  /**
50
   * Show insert unit popup
51
   */
52 278f83f2 Lukáš Moučka
  insertUnitPopup() {
53
    this.sensorService.getPhenomenons().subscribe(
54
      response => this.phenomenons = response
55
    );
56
    this.showInsertUnitPopup = true;
57
  }
58
59 464309d9 hlavja
  logOut(): void {
60
    this.authService.doLogout();
61
  }
62 2c5da396 hlavja
63 cbb91c90 hlavja
  /**
64
   * Unsubscribe after leaving
65
   */
66 2c5da396 hlavja
  ngOnDestroy(): void {
67
    this.subscription.forEach(subs => subs.unsubscribe());
68
  }
69 b6006ff4 hlavja
70 cbb91c90 hlavja
  /**
71
   * Show add user popup
72
   */
73 b6006ff4 hlavja
  addUser() {
74
    this.showAddUserPopup = true;
75
  }
76 b5525aef hlavja
77 cbb91c90 hlavja
  /**
78
   * Emit inserted unit to add it to units
79
   * @param inserted inserted unit
80
   */
81 b5525aef hlavja
  addUnit(inserted: any) {
82
    this.emitNewUnit.emit(inserted);
83
  }
84 464309d9 hlavja
}