Projekt

Obecné

Profil

Stáhnout (3.11 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 {Phenomenon} from '../../shared/api/endpoints/models/phenomenon';
11
import {SensorsService} from '../../shared/api/endpoints/services/sensors.service';
12
import {ConfirmationService, ConfirmEventType, MessageService} from 'primeng/api';
13
import {ManagementService} from '../../shared/api/endpoints/services/management.service';
14
import {InsertUnit} from '../../shared/api/endpoints/models/insert-unit';
15

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

    
23
  position: 'bottom';
24
  groups: Group[];
25
  units: Array<{ drivers?: Drivers; generalInfo?: GeneralInfo; holder?: any; lastpos?: Lastpos; sensors?: Array<Sensor>; unit?: Unit }>;
26
  showInsertUnitPopup = false;
27
  editedUnit: Unit;
28
  showEditUnitPopup = false;
29
  showInsertSensorPopup = false;
30
  phenomenons: Phenomenon[];
31

    
32
  constructor(
33
    private dataService: DataService,
34
    private sensorService: SensorsService,
35
    private confirmationService: ConfirmationService,
36
    private messageService: MessageService,
37
    private managementService: ManagementService
38
  ) {
39
    this.sensorService.getPhenomenons().subscribe(
40
      response => this.phenomenons = response
41
    );
42
  }
43

    
44
  ngOnInit(): void {
45
    this.getUnits();
46
  }
47

    
48
  getUnits() {
49
    this.dataService.getData().pipe(
50
      tap(data => {
51
        this.units = data;
52
        this.units.forEach(unit => unit.sensors.sort((a, b)  => a.sensorId - b.sensorId));
53
      })
54
    ).subscribe();
55
  }
56

    
57
  editUnit($event: MouseEvent, unit: Unit) {
58
    $event.stopPropagation();
59
    this.editedUnit = unit;
60
    this.showEditUnitPopup = true;
61
  }
62

    
63
  insertUnitPopup() {
64
    this.showInsertUnitPopup = true;
65
  }
66

    
67
  getEditedUnit(): Unit {
68
    return this.editedUnit;
69
  }
70

    
71
  addSensor($event: any, unit: Unit) {
72
    $event.stopPropagation();
73
    this.showInsertSensorPopup = true;
74
    this.editedUnit = unit;
75
  }
76

    
77
  deleteUnit($event: any, unit: Unit) {
78
    $event.stopPropagation();
79
    this.confirmationService.confirm({
80
      message: 'Do you want to delete this unit?',
81
      header: 'Delete Unit Confirmation',
82
      icon: 'pi pi-info-circle',
83
      accept: () => {
84
        console.log('ACCEPTED');
85
        // TODO this.processUnitDeletion(unit);
86
        // this.messageService.add({severity:'info', summary:'Confirmed', detail:'Record deleted'});
87
      },
88
      reject: () => {
89
        console.log('REJECTED');
90
      },
91
      key: 'positionDialog'
92
    });
93
  }
94

    
95
  processUnitDeletion(insertUnit: InsertUnit) {
96
    this.managementService.deleteUnit({body: {unit: insertUnit}});
97
  }
98
}
(3-3/3)