Projekt

Obecné

Profil

Stáhnout (1.91 KB) Statistiky
| Větev: | Tag: | Revize:
1
import { Component, OnInit } from '@angular/core';
2
import {Group} from '../../shared/api/endpoints/models/group';
3
import {Drivers} from '../../shared/api/endpoints/models/drivers';
4
import {GeneralInfo} from '../../shared/api/endpoints/models/general-info';
5
import {Lastpos} from '../../shared/api/endpoints/models/lastpos';
6
import {Sensor} from '../../shared/api/endpoints/models/sensor';
7
import {Unit} from '../../shared/api/endpoints/models/unit';
8
import {DataService} from '../../shared/api/endpoints/services/data.service';
9
import {tap} from 'rxjs/operators';
10
import {Observable} from 'rxjs';
11
import {Phenomenon} from '../../shared/api/endpoints/models/phenomenon';
12
import {SensorsService} from '../../shared/api/endpoints/services/sensors.service';
13

    
14
@Component({
15
  selector: 'app-dashboard',
16
  templateUrl: './dashboard.component.html',
17
  styleUrls: ['./dashboard.component.scss']
18
})
19
export class DashboardComponent implements OnInit {
20

    
21
  groups: Group[];
22
  units: Array<{ drivers?: Drivers; generalInfo?: GeneralInfo; holder?: any; lastpos?: Lastpos; sensors?: Array<Sensor>; unit?: Unit }>;
23
  showInsertUnitPopup = false;
24
  editedUnit: Unit;
25
  showEditUnitPopup = false;
26
  phenomenons: Phenomenon[];
27

    
28
  constructor(
29
    private dataService: DataService,
30
    private sensorService: SensorsService
31
  ) {
32
    this.sensorService.getPhenomenons().subscribe(
33
      response => this.phenomenons = response
34
    );
35
  }
36

    
37
  ngOnInit(): void {
38
    this.getUnits();
39
  }
40

    
41
  getUnits() {
42
    this.dataService.getData().pipe(
43
      tap(data => {
44
        this.units = data;
45
        this.units.forEach(unit => unit.sensors.sort((a, b)  => a.sensorId - b.sensorId));
46
      })
47
    ).subscribe();
48
  }
49

    
50
  editUnit($event: MouseEvent, unit: Unit) {
51
    $event.stopPropagation();
52
    this.editedUnit = unit;
53
    this.showEditUnitPopup = true;
54
  }
55

    
56
  insertUnitPopup() {
57
    this.showInsertUnitPopup = true;
58
  }
59

    
60
  getEditedUnit(): Unit {
61
    return this.editedUnit;
62
  }
63
}
(3-3/3)