Projekt

Obecné

Profil

Stáhnout (2.04 KB) Statistiky
| Větev: | Tag: | Revize:
1
import {Component, EventEmitter, Input, OnDestroy, OnInit, Output} from '@angular/core';
2
import {AuthService} from '../../../auth/services/auth.service';
3
import {User} from '../../../auth/models/user';
4
import {Subscription} from 'rxjs';
5
import {Right} from '../../api/endpoints/models/right';
6
import {Phenomenon} from '../../api/endpoints/models/phenomenon';
7
import {SensorsService} from '../../api/endpoints/services/sensors.service';
8
import {InsertUnit} from '../../api/endpoints/models/insert-unit';
9
import {InsertSensor} from '../../api/endpoints/models/insert-sensor';
10

    
11
@Component({
12
  selector: 'app-nav-bar',
13
  templateUrl: './nav-bar.component.html',
14
  styleUrls: ['./nav-bar.component.scss']
15
})
16
export class NavBarComponent implements OnInit, OnDestroy {
17

    
18
  loggedUser: User;
19
  subscription: Subscription[] = [];
20
  showAddUserPopup = false;
21
  rights: Right[];
22
  showInsertUnitPopup = false;
23
  phenomenons: Phenomenon[];
24
  @Output() emitNewUnit: EventEmitter<{unit: InsertUnit, sensors: InsertSensor[]}> =
25
    new EventEmitter<{unit: InsertUnit, sensors: InsertSensor[]}>();
26
  @Input() sensorTypes;
27

    
28
  constructor(
29
    private authService: AuthService,
30
    private sensorService: SensorsService
31
  ) {
32
  }
33

    
34
  ngOnInit(): void {
35
    this.setUser();
36
  }
37

    
38
  /**
39
   * Get user from state after logged
40
   */
41
  setUser(){
42
    this.authService.getUserState().subscribe(res => {
43
      if(res){
44
        this.loggedUser = res;
45
      }
46
    });
47
  }
48

    
49
  /**
50
   * Show insert unit popup
51
   */
52
  insertUnitPopup() {
53
    this.sensorService.getPhenomenons().subscribe(
54
      response => this.phenomenons = response
55
    );
56
    this.showInsertUnitPopup = true;
57
  }
58

    
59
  logOut(): void {
60
    this.authService.doLogout();
61
  }
62

    
63
  /**
64
   * Unsubscribe after leaving
65
   */
66
  ngOnDestroy(): void {
67
    this.subscription.forEach(subs => subs.unsubscribe());
68
  }
69

    
70
  /**
71
   * Show add user popup
72
   */
73
  addUser() {
74
    this.showAddUserPopup = true;
75
  }
76

    
77
  /**
78
   * Emit inserted unit to add it to units
79
   * @param inserted inserted unit
80
   */
81
  addUnit(inserted: any) {
82
    this.emitNewUnit.emit(inserted);
83
  }
84
}
(3-3/3)