Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 236e408d

Přidáno uživatelem Jakub Hlaváč před téměř 4 roky(ů)

Re #8789 - Přidat sensor - formulář, endpoint

+ adding error catchup on requests
+ toast message upon request

Zobrazit rozdíly:

src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.html
45 45
  <p-footer>
46 46
    <div class="row justify-content-end align-items-center">
47 47
      <div>
48
        <p-button icon="pi pi-check" (click)="processInsertion()" type="submit" label="Uložit" class="pr-2"></p-button>
48
        <p-button icon="pi pi-check" (click)="processSensorInsertion()" type="submit" label="Uložit" class="pr-2"></p-button>
49 49
        <p-button icon="pi pi-times" (click)="close()" label="Zavřít" class="pr-2"></p-button>
50 50
      </div>
51 51
    </div>
src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.ts
1 1
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
2 2
import {FormArray, FormBuilder, FormGroup, Validators} from '@angular/forms';
3 3
import {ManagementService} from '../../../shared/api/endpoints/services/management.service';
4
import {InsertUnit} from '../../../shared/api/endpoints/models/insert-unit';
5
import {InsertSensor} from '../../../shared/api/endpoints/models/insert-sensor';
6
import {map} from 'rxjs/operators';
7
import {HttpResponse} from '@angular/common/http';
8
import {ToastService} from '../../../shared/services/toast.service';
4 9

  
5 10
@Component({
6 11
  selector: 'app-sensor-insert-popup',
......
19 24

  
20 25
  constructor(
21 26
    private formBuilder: FormBuilder,
22
    private managementService: ManagementService
27
    private managementService: ManagementService,
28
    private toastService: ToastService
23 29
  ) {
24 30
    this.initForm();
25 31
  }
......
27 33
  ngOnInit(): void {
28 34
  }
29 35

  
30
  processInsertion() {
31
  // TODO endpoint
32
  }
33

  
34 36
  close() {
35 37
    this.isVisibleChange.emit(false);
36 38
  }
......
63 65
    this.addSensor();
64 66
    this.insertForm.reset();
65 67
  }
68

  
69
  processSensorInsertion() {
70
    if (this.insertForm.valid) {
71
      const unit: InsertUnit = {
72
        unit_id: this.unit.unitId
73
      }
74
      const sensors: InsertSensor[] = [];
75
      const frmArray = this.insertForm?.get('sensors') as FormArray;
76

  
77
      frmArray.controls.forEach(control => {
78
        const sensor: InsertSensor = {
79
          sensor_id: control.get('sensorId').value,
80
          sensor_name: control.get('sensorName').value,
81
          sensor_type: control.get('sensorType').value,
82
          phenomenon: {
83
            phenomenon_id: control.get('phenomenons').value
84
          },
85
        }
86
        sensors.push(sensor);
87
      });
88

  
89
      /* TODO this.managementService.insertSensor$Response({body: {unit, sensors}}).pipe(
90
        map((response: HttpResponse<any>) => {
91
          if (response.status === 200) {
92
            this.toastService.showSuccessMessage('Sensors inserted to unit!');
93
            this.close()
94
          } else {
95
          }
96
        })
97
      ).toPromise().then().catch(err => this.toastService.showError(err.error.message));*/
98
    }
99
  }
66 100
}

Také k dispozici: Unified diff