Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b5525aef

Přidáno uživatelem Jakub Hlaváč před více než 3 roky(ů)

Re #8850 - Ověření funkčnosti - implementované enpointy

+ new use case add position to unit
  • tweaking all calls to operations with units and sensors
    + adding sensor type enum from backend endpoint
    + some form validation :)
    - removing all endpoints from /senslog1

Zobrazit rozdíly:

nginx.conf
24 24
      root   /usr/share/nginx/html;
25 25
    }
26 26

  
27
    location /senslog1 {
28
              proxy_set_header X-Forwarded-Host $host;
29
              proxy_set_header X-Forwarded-Server $host;
30
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
31
              #proxy_pass http://<ContainerName>:<PortNumber>;
32
              # In our case Container name is as we setup in docker-compose `beservice` and port 8080
33
              proxy_pass http://51.15.45.95:8080;
34
              proxy_max_temp_file_size "1024m";
35
              proxy_read_timeout       "60s";
36

  
37
              add_header X-Frame-Options SAMEORIGIN always;
38

  
39
    }
40

  
41
    location /senslog-lite2/rest {
42
              proxy_set_header X-Forwarded-Host $host;
43
              proxy_set_header X-Forwarded-Server $host;
44
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
45
              #proxy_pass http://<ContainerName>:<PortNumber>;
46
              # In our case Container name is as we setup in docker-compose `beservice` and port 8080
47
              proxy_pass http://51.15.45.95:8080;
48
              proxy_max_temp_file_size "1024m";
49
              proxy_read_timeout       "60s";
50

  
51
              add_header X-Frame-Options SAMEORIGIN always;
52

  
53
    }
54

  
55
    location /api/SensLogV1/OGCSensorThings {
56
              proxy_set_header X-Forwarded-Host $host;
57
              proxy_set_header X-Forwarded-Server $host;
58
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
59
              #proxy_pass http://<ContainerName>:<PortNumber>;
60
              # In our case Container name is as we setup in docker-compose `beservice` and port 8080
61
              proxy_pass http://51.15.45.95:9080;
62
              proxy_max_temp_file_size "1024m";
63
              proxy_read_timeout       "60s";
64

  
65
              add_header X-Frame-Options SAMEORIGIN always;
66

  
67
    }
68

  
69 27
    location /analytics {
70 28
              proxy_set_header X-Forwarded-Host $host;
71 29
              proxy_set_header X-Forwarded-Server $host;
proxy-config.json
1 1
{
2
  "/senslog1": {
3
    "target": "http://51.15.45.95:8080",
4
    "secure": false
5
  },
6
  "/senslog-lite2/rest": {
7
    "target": "http://51.15.45.95:8080",
8
    "secure": false
9
  },
10
  "/api/SensLogV1/OGCSensorThings": {
11
    "target": "http://51.15.45.95:9080",
12
    "secure": false
13
  },
14 2
  "/analytics": {
15 3
    "target": "http://51.15.45.95:9090",
16 4
    "secure": false
src/app/auth/interceptors/auth.interceptor.ts
32 32
      return of(null);
33 33
    }
34 34

  
35
    if (request.url.includes('DataService') || request.url.includes('GroupService') || request.url.includes('SensorService')){
36
      request = request.clone({
37
        setParams: {
38
          user: localStorage.getItem(GlobalVariable.USER_NAME)
39
        }
40
      });
41
    }
42

  
43 35
    console.log('Sending request!', request);
44 36
    return next.handle(request)
45 37
      .pipe(
46 38
        catchError(err => {
47
          if ((err instanceof HttpErrorResponse && err.status === 504 || err.status === 502 || err.status === 401 ||
48
            err.status === 0 || err.status === 500)) {
39
          if ((err instanceof HttpErrorResponse && err.status === 502 || err.status === 401 ||
40
            err.status === 0)) {
49 41
            console.log(err);
50 42
            this.toastService.showError(err.error);
51 43
            return this.handleError(request, next);
44
          } else if ((err instanceof HttpErrorResponse && err.status === 500 || err.status === 504 || err.status === 500)) {
45
            this.toastService.showError(err.error);
46
            this.handle500Error(err);
52 47
          } else {
53 48
            return throwError(err);
54 49
          }
......
60 55
    this.authService.doLogout();
61 56
    return of(null);
62 57
  }
58

  
59
  handle500Error(err: any) {
60
    this.authService.redirectToDashboard();
61
    return of(null);
62
  }
63 63
}
src/app/auth/services/auth.service.ts
84 84
    localStorage.setItem(GlobalVariable.RIGHTS, userCookie.rightsID.toString());
85 85
    this.cookieService.set('user', username);
86 86
  }
87

  
88
  redirectToDashboard() {
89
    this.router.navigate(['/dashboard']);
90
  }
87 91
}
src/app/auth/states/user.state.ts
3 3
import {User} from '../models/user';
4 4
import {AuthService} from '../services/auth.service';
5 5
import {LoginService} from '../../shared/api/endpoints/services/login.service';
6
import {ToastService} from '../../shared/services/toast.service';
6 7

  
7 8
@Injectable({
8 9
  providedIn: 'root'
......
11 12
  private userState$: BehaviorSubject<User> = new BehaviorSubject<User>(null);
12 13

  
13 14
  constructor(
14
    private loginService: LoginService
15
    private loginService: LoginService,
16
    private toastService: ToastService
15 17
  ) {}
16 18

  
17 19
  setUser(user: User): void {
......
28 30

  
29 31
  getUser$(refresh: boolean = false): Observable<User> {
30 32
   if (this.userState$.getValue()){
31
      this.loginService.getUserInfo().subscribe(res => this.userState$.next({...this.userState$.getValue(), userInfo: res}));
32
    }
33
      this.loginService.getUserInfo$Response().subscribe(res => {
34
        this.userState$.next({...this.userState$.getValue(), userInfo: res.body});
35
      }, err => this.toastService.showError(err.error.message));
36
   }
33 37
    return this.userState$.asObservable();
34 38
  }
35 39

  
src/app/dashboard/components/dashboard.component.html
1
<app-nav-bar></app-nav-bar>
1
<app-nav-bar (emitNewUnit)="addUnit($event)"></app-nav-bar>
2 2

  
3 3
<div class="container dashboard">
4
<!--  <div class="row">-->
5
<!--    <div class="col-md-6"></div>-->
6
<!--    <div class="col-md-6 text-right">-->
7
<!--      <p-button label="Add unit" icon="pi pi-cog" (onClick)="insertUnitPopup()"></p-button>-->
8
<!--    </div>-->
9
<!--  </div>-->
10
<p-accordion>
11
    <p-accordionTab *ngFor="let unit of units">
12
      <p-header [className]="'dashboard-unit-wrapper'">
13
        <div [className]="'row dashboard-unit'">
14
          <div class="col-md-8"><h3>{{ unit.unit.description}}</h3></div>
15
          <div class="col-md-4 text-right">
16
            <p-button label="Sensors graph" icon="pi pi-chart-line" [routerLink]="['/dashboard/unit', unit.unit.unitId]"></p-button>
17
            <p-splitButton *ngIf="loggedUser?.userInfo?.rightsId == 0 || loggedUser?.userInfo?.rightsId == 1" label="Add sensor" (onClick)="insertSensorPopup($event, unit.unit)" icon="pi pi-plus-circle" (onDropdownClick)="showItems($event, unit.unit)" [model]="items" styleClass="p-button-success"></p-splitButton>
4
  <p-accordion>
5
      <p-accordionTab *ngFor="let unit of units">
6
        <p-header [className]="'dashboard-unit-wrapper'">
7
          <div [className]="'row dashboard-unit'">
8
            <div class="col-md-8"><h3>{{ unit.unit.description}}</h3></div>
9
            <div class="col-md-4 text-right">
10
              <p-button label="Sensors graph" icon="pi pi-chart-line" [routerLink]="['/dashboard/unit', unit.unit.unitId]"></p-button>
11
              <p-splitButton *ngIf="loggedUser?.userInfo?.rightsId == 0 || loggedUser?.userInfo?.rightsId == 1" label="Add sensor" (onClick)="insertSensorPopup($event, unit.unit)"
12
                             icon="pi pi-plus-circle" (onDropdownClick)="showItems($event, unit.unit)" [model]="items" styleClass="p-button-success"></p-splitButton>
13
            </div>
18 14
          </div>
15
        </p-header>
16
        <div>
17
          <ng-container *ngFor="let sensor of unit.sensors">
18
            <app-sensors *ngIf="sensor" [sensor]="sensor" [unitId]="unit.unit.unitId" [phenomenons]="phenomenons" [loggedUser]="loggedUser" (emitSensorDeletion)="deleteSensor(unit.unit.unitId, $event)"></app-sensors>
19
          </ng-container>
19 20
        </div>
20
      </p-header>
21
      <div>
22
        <app-sensors *ngFor="let sensor of unit.sensors" [sensor]="sensor" [unitId]="unit.unit.unitId" [phenomenons]="phenomenons" [loggedUser]="loggedUser"></app-sensors>
23
      </div>
24
    </p-accordionTab>
25
</p-accordion>
21
      </p-accordionTab>
22
  </p-accordion>
26 23
</div>
27 24

  
28
<app-unit-popup *ngIf="editedUnit" [(isVisible)]="showEditUnitPopup" [unit]="editedUnit"></app-unit-popup>
29
<app-sensor-insert-popup *ngIf="editedUnit" [unit]="editedUnit" [(isVisible)]="showInsertSensorPopup" [phenomenons]="phenomenons"></app-sensor-insert-popup>
30

  
25
<app-unit-popup *ngIf="showEditUnitPopup" [(isVisible)]="showEditUnitPopup" [unit]="editedUnit"></app-unit-popup>
26
<app-sensor-insert-popup *ngIf="showInsertSensorPopup" [unit]="editedUnit" [(isVisible)]="showInsertSensorPopup" [phenomenons]="phenomenons" [sensorTypes]="sensorTypes" (emitNewSensor)="addSensors($event)"></app-sensor-insert-popup>
27
<app-position-insert-popup *ngIf="showInsertPositionPopup" [unitId]="editedUnit.unitId" [(isVisible)]="showInsertPositionPopup"></app-position-insert-popup>
31 28

  
32 29

  
33 30
<p-confirmDialog [style]="{width: '50vw'}" key="positionDialog" [position]="position" [baseZIndex]="10000" rejectButtonStyleClass="p-button-outlined"></p-confirmDialog>
src/app/dashboard/components/dashboard.component.ts
10 10
import {SensorsService} from '../../shared/api/endpoints/services/sensors.service';
11 11
import {ConfirmationService, MenuItem, MessageService} from 'primeng/api';
12 12
import {ManagementService} from '../../shared/api/endpoints/services/management.service';
13
import {InsertUnit} from '../../shared/api/endpoints/models/insert-unit';
14 13
import {ToastService} from '../../shared/services/toast.service';
15 14
import {map} from 'rxjs/operators';
16 15
import {HttpResponse} from '@angular/common/http';
17 16
import {AuthService} from '../../auth/services/auth.service';
18 17
import {User} from '../../auth/models/user';
18
import {SensorType} from '../../shared/api/endpoints/models/sensor-type';
19 19

  
20 20
@Component({
21 21
  selector: 'app-dashboard',
......
32 32
  editedUnit: Unit;
33 33
  showEditUnitPopup = false;
34 34
  showInsertSensorPopup = false;
35
  showInsertPositionPopup = false;
35 36
  phenomenons: Phenomenon[];
37
  sensorTypes: SensorType[];
36 38

  
37 39
  constructor(
38 40
    private dataService: DataService,
......
76 78

  
77 79
  insertSensorPopup($event: any, unit: Unit) {
78 80
    $event.stopPropagation();
81
    this.sensorService.getSensorTypes().subscribe(
82
      response => this.sensorTypes = response
83
    )
79 84
    this.showInsertSensorPopup = true;
80 85
    this.editedUnit = unit;
81 86
  }
......
87 92
      header: 'Delete Unit Confirmation',
88 93
      icon: 'pi pi-info-circle',
89 94
      accept: () => {
90
        // TODO this.processUnitDeletion(unit);
95
        this.processUnitDeletion(unit);
91 96
      },
92 97
      reject: () => {
93 98
        this.toastService.operationRejected();
......
96 101
    });
97 102
  }
98 103

  
99
  processUnitDeletion(insertUnit: InsertUnit) {
100
    this.managementService.deleteUnit$Response({body: {unit: insertUnit}}).pipe(
104
  processUnitDeletion(unit: Unit) {
105
    this.managementService.deleteUnit$Response({body: {
106
      unit: {
107
        unit_id: unit.unitId
108
      }}
109
    }).pipe(
101 110
      map((response: HttpResponse<any>) => {
102 111
        if (response.status === 200) {
103 112
          this.toastService.showSuccessMessage(response.body.message);
113
          this.units = this.units.filter(testedUnit => testedUnit.unit.unitId !== unit.unitId);
104 114
        } else {
105 115
        }
106 116
      })
......
114 124
          event.stopPropagation();
115 125
          this.editUnitPopup($event, unit);
116 126
        }},
127
      {label: 'Insert position', icon: 'pi pi-cog', command: () => {
128
          event.stopPropagation();
129
          this.insertPosition($event, unit);
130
        }},
117 131
      {label: 'Delete unit', icon: 'pi pi-times', command: () => {
118 132
          event.stopPropagation();
119 133
          this.deleteUnit($event, unit);
120 134
        }}
121 135
    ]
122 136
  }
137

  
138
  addUnit(inserted: any) {
139
    const sensors: Sensor[] = [];
140
    inserted.sensors.forEach(sens => {
141
      sensors.push({
142
        sensorId: sens.sensor_id,
143
        sensorType: sens.sensor_type,
144
        sensorName: sens.sensor_name,
145
        phenomenon: {
146
          phenomenonId: sens.phenomenon.phenomenon_id.toString()
147
        }
148
      })
149
    });
150
    this.units.push({
151
      unit: {
152
        unitId: inserted.unit.unit_id,
153
        description: inserted.unit.description
154
      },
155
      sensors
156
    })
157
  }
158

  
159
  addSensors(inserted: any) {
160
    inserted.sensors.forEach(sens => {
161
      this.units.find(un => un.unit.unitId === inserted.unit.unit_id).sensors.push({
162
        sensorId: sens.sensor_id,
163
        sensorType: sens.sensor_type,
164
        sensorName: sens.sensor_name,
165
        phenomenon: {
166
          phenomenonId: sens.phenomenon.phenomenon_id.toString()
167
        }
168
      })
169
    });
170
  }
171

  
172
  deleteSensor(unitId: number, sensor: Sensor) {
173
    this.units.find(unit => unit.unit.unitId === unitId).sensors =
174
      this.units.find(unit => unit.unit.unitId === unitId).sensors.filter(testedSensor => testedSensor.sensorId !== sensor.sensorId);
175
  }
176

  
177
  private insertPosition($event: any, unit: Unit) {
178
    $event.stopPropagation();
179
    this.showInsertPositionPopup = true;
180
    this.editedUnit = unit;
181
  }
123 182
}
src/app/dashboard/components/position-insert-popup/position-insert-popup.component.html
1
<p-dialog [visible]="isVisible" [modal]="true" [closable]="false" [draggable]="false" header="Add position to unit!" [style]="{width: '70vw'}"
2
          [baseZIndex]="10000" (onShow)="clearFormArray()">
3

  
4
  <form [formGroup]="insertForm">
5
    <div class="input-group form-group">
6
      <div class="input-group-prepend">
7
        <span class="input-group-text">Latitude</span>
8
      </div>
9
      <input type="number" formControlName="lat" class="form-control" id="lat"
10
             placeholder="Latitude WGS-84 coordinates" step="0.0001" min="-90" max="90"/>
11
      <div *ngIf="insertForm.get('lat').invalid &&
12
        insertForm.get('lat').errors &&
13
        (insertForm.get('lat').dirty || insertForm.get('lat').touched)">
14
        <small class="text-danger"
15
               *ngIf="insertForm.get('lat').hasError('required')">
16
          This field is required.
17
        </small>
18
        <small class="text-danger"
19
               *ngIf="insertForm.get('lat').hasError('min')">
20
          The minimum value for this field is -90.
21
        </small>
22
        <small class="text-danger"
23
               *ngIf="insertForm.get('lat').hasError('max')">
24
          The minimum value for this field is 90.
25
        </small>
26
      </div>
27
    </div>
28
    <div class="input-group form-group">
29
      <div class="input-group-prepend">
30
        <span class="input-group-text">Longitude</span>
31
      </div>
32
      <input type="number" formControlName="lon" class="form-control" id="lon"
33
             placeholder="Longitude WGS-84 coordinates" step="0.0001" min="-180" max="180"/>
34
      <div *ngIf="insertForm.get('lon').invalid &&
35
        insertForm.get('lon').errors &&
36
        (insertForm.get('lon').dirty || insertForm.get('lon').touched)">
37
        <small class="text-danger"
38
               *ngIf="insertForm.get('lon').hasError('required')">
39
          This field is required.
40
        </small>
41
        <small class="text-danger"
42
               *ngIf="insertForm.get('lon').hasError('min')">
43
          The minimum value for this field is -180.
44
        </small>
45
        <small class="text-danger"
46
               *ngIf="insertForm.get('lon').hasError('max')">
47
          The minimum value for this field is 180.
48
        </small>
49
      </div>
50
    </div>
51
    <hr>
52
    <div class="input-group form-group">
53
      <div class="input-group-prepend">
54
        <span class="input-group-text">Altitude</span>
55
      </div>
56
      <input type="number" formControlName="alt" class="form-control" id="alt"
57
             placeholder="Altitude in meters"/>
58
    </div>
59
    <div class="input-group form-group">
60
      <div class="input-group-prepend">
61
        <span class="input-group-text">Speed</span>
62
      </div>
63
      <input type="number" formControlName="speed" class="form-control" id="speed"
64
             placeholder="Speed of the unit"/>
65
    </div>
66
    <div class="input-group form-group">
67
      <div class="input-group-prepend">
68
        <span class="input-group-text">Dilution</span>
69
      </div>
70
      <input type="number" formControlName="dop" class="form-control" id="dop"
71
             placeholder="Dilution of precision"/>
72
    </div>
73
  </form>
74

  
75
  <p-footer>
76
    <div class="row justify-content-end align-items-center">
77
      <div>
78
        <p-button icon="pi pi-times" (click)="close()" label="Close" class="pr-2"></p-button>
79
        <p-button icon="pi pi-check" (click)="processInsertion()" type="submit" label="Save" class="pr-2"></p-button>
80
      </div>
81
    </div>
82
  </p-footer>
83
</p-dialog>
src/app/dashboard/components/position-insert-popup/position-insert-popup.component.ts
1
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
2
import {FormArray, FormBuilder, FormGroup, Validators} from '@angular/forms';
3
import {ManagementService} from '../../../shared/api/endpoints/services/management.service';
4
import * as moment from 'moment-timezone';
5
import {map} from 'rxjs/operators';
6
import {HttpResponse} from '@angular/common/http';
7
import {ToastService} from '../../../shared/services/toast.service';
8
import {SensorsService} from '../../../shared/api/endpoints/services/sensors.service';
9

  
10
@Component({
11
  selector: 'app-position-insert-popup',
12
  templateUrl: './position-insert-popup.component.html',
13
  styleUrls: ['./position-insert-popup.component.scss']
14
})
15
export class PositionInsertPopupComponent implements OnInit {
16

  
17
  insertForm: FormGroup;
18

  
19
  @Input() isVisible;
20
  @Input() unitId;
21
  @Output() isVisibleChange: EventEmitter<boolean> = new EventEmitter<boolean>();
22

  
23
  constructor(
24
    private formBuilder: FormBuilder,
25
    private sensorService: SensorsService,
26
    private toastService: ToastService,
27
  ) {
28
    this.initForm();
29
  }
30

  
31
  ngOnInit(): void {
32
  }
33
  initForm() {
34
    this.insertForm = this.formBuilder.group({
35
      lat: ['', [Validators.required, Validators.min(-90), Validators.max(90)]],
36
      lon: ['', [Validators.required, Validators.min(-180), Validators.max(180)]],
37
      alt: '',
38
      speed: '',
39
      dop: ''
40
    });
41
  }
42

  
43
  clearFormArray() {
44
    this.insertForm.reset();
45
  }
46

  
47
  processInsertion() {
48
    if (this.insertForm.valid) {
49
      const lat = this.insertForm.controls.lat.value;
50
      const lon = this.insertForm.controls.lon.value;
51
      const alt = this.insertForm.controls.alt.value;
52
      const speed = this.insertForm.controls.speed.value;
53
      const dop = this.insertForm.controls.dop.value;
54

  
55
      this.sensorService.insertPosition$Response( {
56
        lat, lon, alt, speed, dop, unit_id: this.unitId, date: moment().format('yyyy-MM-DD HH:mm:ssZZ')
57
      }).pipe(
58
        map((response: HttpResponse<any>) => {
59
          if (response.status === 200) {
60
            this.toastService.showSuccessMessage('Position to unit ' + this.unitId + ' inserted!');
61
            this.close();
62
          } else {
63
            this.toastService.showError('Position insertion caused error!');
64
          }
65
        })
66
      ).toPromise().then().catch(err => this.toastService.showError(err.error.message));
67
    }
68
  }
69

  
70
  close() {
71
    this.isVisibleChange.emit(false);
72
  }
73
}
src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.html
22 22
          <div class="input-group-prepend">
23 23
            <span class="input-group-text">Sensor type</span>
24 24
          </div>
25
          <input type="text" formControlName="sensorType" class="form-control" id="sensorType"
26
                 placeholder="sensorType"/>
25
          <select formControlName="sensorType" id="sensorType">
26
            <option *ngFor="let sensorType of sensorTypes; let i = index" [value]="sensorTypes[i].sensorType">
27
              {{sensorTypes[i].sensorType}}
28
            </option>
29
          </select>
27 30
        </div>
28 31
        <div class="input-group form-group">
29 32
          <div class="input-group-prepend">
......
45 48
  <p-footer>
46 49
    <div class="row justify-content-end align-items-center">
47 50
      <div>
48
        <p-button icon="pi pi-check" (click)="processSensorInsertion()" type="submit" label="Uložit" class="pr-2"></p-button>
49
        <p-button icon="pi pi-times" (click)="close()" label="Zavřít" class="pr-2"></p-button>
51
        <p-button icon="pi pi-times" (click)="close()" label="Close" class="pr-2"></p-button>
52
        <p-button icon="pi pi-check" (click)="processSensorInsertion()" type="submit" label="Save" class="pr-2"></p-button>
50 53
      </div>
51 54
    </div>
52 55
  </p-footer>
src/app/dashboard/components/sensor-insert-popup/sensor-insert-popup.component.ts
6 6
import {map} from 'rxjs/operators';
7 7
import {HttpResponse} from '@angular/common/http';
8 8
import {ToastService} from '../../../shared/services/toast.service';
9
import {SensorType} from '../../../shared/api/endpoints/models/sensor-type';
10
import {Phenomenon} from '../../../shared/api/endpoints/models/phenomenon';
9 11

  
10 12
@Component({
11 13
  selector: 'app-sensor-insert-popup',
......
17 19
  insertForm: FormGroup;
18 20
  items: FormArray;
19 21

  
20
  @Input() phenomenons;
22
  @Input() phenomenons: Phenomenon[];
21 23
  @Input() isVisible;
22 24
  @Input() unit;
25
  @Input() sensorTypes: SensorType[];
23 26
  @Output() isVisibleChange: EventEmitter<boolean> = new EventEmitter<boolean>();
27
  @Output() emitNewSensor: EventEmitter<{unit: InsertUnit, sensors: InsertSensor[]}> =
28
    new EventEmitter<{unit: InsertUnit, sensors: InsertSensor[]}>()
24 29

  
25 30
  constructor(
26 31
    private formBuilder: FormBuilder,
......
86 91
        sensors.push(sensor);
87 92
      });
88 93

  
89
      /* TODO this.managementService.insertSensor$Response({body: {unit, sensors}}).pipe(
94
      this.managementService.insertSensor$Response({body: {unit, sensors}}).pipe(
90 95
        map((response: HttpResponse<any>) => {
91 96
          if (response.status === 200) {
92 97
            this.toastService.showSuccessMessage('Sensors inserted to unit!');
93
            this.close()
98
            this.emitNewSensor.emit({unit, sensors});
99
            this.close();
94 100
          } else {
95 101
          }
96 102
        })
97
      ).toPromise().then().catch(err => this.toastService.showError(err.error.message));*/
103
      ).toPromise().then().catch(err => this.toastService.showError(err.error.message));
98 104
    }
99 105
  }
100 106
}
src/app/dashboard/components/sensor-popup/sensor-popup.component.html
28 28
      </div>
29 29
  </form>
30 30
  <p-footer>
31
    <div class="row justify-content-end align-items-center">
32 31
      <div>
33
        <p-button icon="pi pi-check" (click)="processSensorEdition()" type="submit" label="Uložit" class="pr-2"></p-button>
34
        <p-button icon="pi pi-times" (click)="close()" label="Zavřít" class="pr-2"></p-button>
32
        <p-button icon="pi pi-times" (click)="close()" label="Close" class="pr-2"></p-button>
33
        <p-button icon="pi pi-check" (click)="processSensorEdition()" type="submit" label="Save" class="pr-2"></p-button>
35 34
      </div>
36
    </div>
37 35
  </p-footer>
38 36
</p-dialog>
src/app/dashboard/components/sensor-popup/sensor-popup.component.ts
4 4
import {map} from 'rxjs/operators';
5 5
import {HttpResponse} from '@angular/common/http';
6 6
import {ToastService} from '../../../shared/services/toast.service';
7
import {Sensor} from '../../../shared/api/endpoints/models/sensor';
7 8

  
8 9
@Component({
9 10
  selector: 'app-sensor-popup',
......
15 16
  insertForm: FormGroup;
16 17

  
17 18
  @Input() isVisible;
18
  @Input() sensor;
19
  @Input() sensor: Sensor;
19 20
  @Input() phenomenons;
20 21
  @Input() unitId;
21 22
  @Output() isVisibleChange: EventEmitter<boolean> = new EventEmitter<boolean>();
......
50 51

  
51 52
  processSensorEdition() {
52 53
    if (this.insertForm.valid) {
53
      /* TODO this.managementService.updateSensor$Response({body: {
54
      this.managementService.updateSensor$Response({body: {
54 55
        unit: {
55 56
          unit_id: this.unitId
56 57
        },
......
60 61
              sensor_type: this.insertForm.controls.sensorType.value,
61 62
              sensor_name: this.insertForm.controls.sensorName.value,
62 63
              phenomenon: {
63
                phenomenon_id: this.insertForm.controls.phenomenon.value.phenomenonId
64
                phenomenon_id: this.insertForm.controls.phenomenon.value
64 65
              }
65 66
            }
66 67
          ]
......
68 69
       map((response: HttpResponse<any>) => {
69 70
         if (response.status === 200) {
70 71
           this.toastService.showSuccessMessage('Sensor ' + response.body.sensors[0].sensorName + ' updated!');
72
           this.changeSensor();
71 73
           this.close()
72 74
         } else {
73 75
         }
74 76
       })
75
     ).toPromise().then().catch(err => this.toastService.showError(err.error.message));*/
77
     ).toPromise().then().catch(err => this.toastService.showError(err.error.message));
76 78
    }
77 79
  }
80

  
81
  private changeSensor() {
82
    this.sensor.sensorType = this.insertForm.controls.sensorType.value;
83
    this.sensor.sensorName = this.insertForm.controls.sensorName.value;
84
    this.sensor.phenomenon.phenomenonId = this.insertForm.controls.phenomenon.value;
85
  }
78 86
}
src/app/dashboard/components/sensors/sensors.component.ts
1
import {Component, Input, OnInit} from '@angular/core';
1
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
2 2
import {Sensor} from '../../../shared/api/endpoints/models/sensor';
3 3
import {ConfirmationService} from 'primeng/api';
4 4
import {ManagementService} from '../../../shared/api/endpoints/services/management.service';
......
18 18
  @Input() unitId: number;
19 19
  @Input() phenomenons;
20 20
  @Input() loggedUser: User;
21
  @Output() emitSensorDeletion: EventEmitter<Sensor> = new EventEmitter<Sensor>()
21 22
  showSensorPopup = false;
22 23
  editedSensor: Sensor;
23 24
  constructor(
......
41 42
      header: 'Delete Sensor Confirmation',
42 43
      icon: 'pi pi-info-circle',
43 44
      accept: () => {
44
        console.log('ACCEPTED');
45
        // TODO this.processSensorDeletion(sensor);
45
        this.processSensorDeletion(sensor);
46 46
      },
47 47
      reject: () => {
48 48
        this.toastService.operationRejected();
......
65 65
      map((response: HttpResponse<any>) => {
66 66
        if (response.status === 200) {
67 67
          this.toastService.showSuccessMessage(response.body.message);
68
          this.emitSensorDeletion.emit(sensor);
68 69
        } else {
69 70
        }
70 71
      })
src/app/dashboard/components/unit-popup/unit-popup.component.html
12 12
  <p-footer>
13 13
    <div class="row justify-content-end align-items-center">
14 14
      <div>
15
        <p-button icon="pi pi-check" (click)="saveUnit()" type="submit" label="Save" class="pr-2"></p-button>
16 15
        <p-button icon="pi pi-times" (click)="close()" label="Close" class="pr-2"></p-button>
16
        <p-button icon="pi pi-check" (click)="saveUnit()" type="submit" label="Save" class="pr-2"></p-button>
17 17
      </div>
18 18
    </div>
19 19
  </p-footer>
src/app/dashboard/components/unit-popup/unit-popup.component.ts
40 40
  saveUnit() {
41 41
    if (this.insertForm.controls.unitDescription.value && this.insertForm.controls.unitDescription.value !== this.unit.description) {
42 42
      this.unit.description = this.insertForm.controls.unitDescription.value;
43
      /*TODO this.managementService.updateUnit$Response({ body: { unit: this.unit}}).toPromise().then( res => {
44
        if (res) {
43
      this.managementService.updateUnit$Response({ body: {
44
        unit: {
45
            unit_id: this.unit.unitId,
46
            description: this.unit.description
47
          }}
48
      }).toPromise().then( response => {
49
        if (response.status === 200) {
45 50
          this.toastService.showSuccess();
51
          this.close();
52
        } else {
53
          this.toastService.showError(response.body);
46 54
        }
47
      }).catch(err => this.toastService.showError(err.body.message));*/
55
      }).catch(err => this.toastService.showError(err.body.message));
48 56
    }
49 57
  }
50 58

  
src/app/dashboard/dashboard.module.ts
13 13
import { SensorInsertPopupComponent } from './components/sensor-insert-popup/sensor-insert-popup.component';
14 14
import {ConfirmDialogModule} from 'primeng/confirmdialog';
15 15
import {SplitButtonModule} from 'primeng/splitbutton';
16
import { PositionInsertPopupComponent } from './components/position-insert-popup/position-insert-popup.component';
16 17

  
17 18

  
18 19

  
19 20
@NgModule({
20
  declarations: [DashboardComponent, SensorsComponent, UnitPopupComponent, SensorPopupComponent, SensorInsertPopupComponent],
21
  declarations: [DashboardComponent, SensorsComponent, UnitPopupComponent, SensorPopupComponent, SensorInsertPopupComponent, PositionInsertPopupComponent],
21 22
  imports: [
22 23
    CommonModule,
23 24
    NavBarModule,
src/app/sensor/components/sensor.component.ts
2 2
import {ActivatedRoute} from '@angular/router';
3 3
import * as moment from 'moment-timezone';
4 4
import {AnalyticsService} from '../../shared/api/endpoints/services/analytics.service';
5
import {AggreationModel} from '../../shared/models/aggreation.model';
5
import {AggregationModel} from '../../shared/models/aggregationModel';
6 6
import {GraphLoader} from '../../shared/graph-loading/graphloader';
7 7
import {ObservationService} from '../../shared/api/endpoints/services/observation.service';
8 8
import {HttpResponse} from '@angular/common/http';
......
24 24
  to: Date;
25 25
  today: Date;
26 26
  showAggregation = false;
27
  aggregationFunction: AggreationModel[];
27
  aggregationFunction: AggregationModel[];
28 28
  selectedAggregationFunction = 'HOUR';
29 29

  
30 30
  constructor(
src/app/shared/api/endpoints/models.ts
20 20
export { Observation } from './models/observation';
21 21
export { Statistics } from './models/statistics';
22 22
export { OldObservation } from './models/old-observation';
23
export { SensorType } from './models/sensor-type';
src/app/shared/api/endpoints/services/data.service.ts
33 33
  /**
34 34
   * Path part for operation getData
35 35
   */
36
  static readonly GetDataPath = '/senslog1/DataService?Operation=GetUnits';
36
  static readonly GetDataPath = '/senslog15/DataService?Operation=GetUnits';
37 37

  
38 38
  /**
39 39
   * Get data.
src/app/shared/api/endpoints/services/group.service.ts
29 29
  /**
30 30
   * Path part for operation getGroups
31 31
   */
32
  static readonly GetGroupsPath = '/senslog1/GroupService';
32
  static readonly GetGroupsPath = '/senslog15/GroupService';
33 33

  
34 34
  /**
35 35
   * Get groups.
src/app/shared/api/endpoints/services/observation.service.ts
29 29
  /**
30 30
   * Path part for operation getObservation
31 31
   */
32
  static readonly GetObservationPath = '/senslog1/SensorService?Operation=GetObservations';
32
  static readonly GetObservationPath = '/senslog15/SensorService?Operation=GetObservations';
33 33

  
34 34
  /**
35 35
   * Get observation.
src/app/shared/api/endpoints/services/sensors.service.ts
11 11

  
12 12
import { Phenomenon } from '../models/phenomenon';
13 13
import { Sensor } from '../models/sensor';
14
import { SensorType } from '../models/sensor-type';
14 15

  
15 16

  
16 17
/**
......
30 31
  /**
31 32
   * Path part for operation getUnitSensors
32 33
   */
33
  static readonly GetUnitSensorsPath = '/senslog1/SensorService?Operation=GetSensors';
34
  static readonly GetUnitSensorsPath = '/senslog15/SensorService?Operation=GetSensors';
34 35

  
35 36
  /**
36 37
   * Get unit sensors.
......
132 133
    );
133 134
  }
134 135

  
136
  /**
137
   * Path part for operation getSensorTypes
138
   */
139
  static readonly GetSensorTypesPath = '/senslog15/SensorService?Operation=GetAllSensorTypes';
140

  
141
  /**
142
   * Get sensor types.
143
   *
144
   *
145
   *
146
   * This method provides access to the full `HttpResponse`, allowing access to response headers.
147
   * To access only the response body, use `getSensorTypes()` instead.
148
   *
149
   * This method doesn't expect any request body.
150
   */
151
  getSensorTypes$Response(params?: {
152
  }): Observable<StrictHttpResponse<Array<SensorType>>> {
153

  
154
    const rb = new RequestBuilder(this.rootUrl, SensorsService.GetSensorTypesPath, 'get');
155
    if (params) {
156
    }
157

  
158
    return this.http.request(rb.build({
159
      responseType: 'json',
160
      accept: 'application/json'
161
    })).pipe(
162
      filter((r: any) => r instanceof HttpResponse),
163
      map((r: HttpResponse<any>) => {
164
        return r as StrictHttpResponse<Array<SensorType>>;
165
      })
166
    );
167
  }
168

  
169
  /**
170
   * Get sensor types.
171
   *
172
   *
173
   *
174
   * This method provides access to only to the response body.
175
   * To access the full response (for headers, for example), `getSensorTypes$Response()` instead.
176
   *
177
   * This method doesn't expect any request body.
178
   */
179
  getSensorTypes(params?: {
180
  }): Observable<Array<SensorType>> {
181

  
182
    return this.getSensorTypes$Response(params).pipe(
183
      map((r: StrictHttpResponse<Array<SensorType>>) => r.body as Array<SensorType>)
184
    );
185
  }
186

  
187
  /**
188
   * Path part for operation insertPosition
189
   */
190
  static readonly InsertPositionPath = '/senslog15/FeederServlet?Operation=InsertPosition';
191

  
192
  /**
193
   * Insert position to unit.
194
   *
195
   *
196
   *
197
   * This method provides access to the full `HttpResponse`, allowing access to response headers.
198
   * To access only the response body, use `insertPosition()` instead.
199
   *
200
   * This method doesn't expect any request body.
201
   */
202
  insertPosition$Response(params: {
203
    lat: number;
204
    lon: number;
205
    unit_id: number;
206
    date: string;
207
    alt?: string;
208
    speed?: number;
209
    dop?: number;
210
  }): Observable<StrictHttpResponse<void>> {
211

  
212
    const rb = new RequestBuilder(this.rootUrl, SensorsService.InsertPositionPath, 'get');
213
    if (params) {
214
      rb.query('lat', params.lat, {});
215
      rb.query('lon', params.lon, {});
216
      rb.query('unit_id', params.unit_id, {});
217
      rb.query('date', params.date, {});
218
      rb.query('alt', params.alt, {});
219
      rb.query('speed', params.speed, {});
220
      rb.query('dop', params.dop, {});
221
    }
222

  
223
    return this.http.request(rb.build({
224
      responseType: 'text',
225
      accept: '*/*'
226
    })).pipe(
227
      filter((r: any) => r instanceof HttpResponse),
228
      map((r: HttpResponse<any>) => {
229
        return (r as HttpResponse<any>).clone({ body: undefined }) as StrictHttpResponse<void>;
230
      })
231
    );
232
  }
233

  
234
  /**
235
   * Insert position to unit.
236
   *
237
   *
238
   *
239
   * This method provides access to only to the response body.
240
   * To access the full response (for headers, for example), `insertPosition$Response()` instead.
241
   *
242
   * This method doesn't expect any request body.
243
   */
244
  insertPosition(params: {
245
    lat: number;
246
    lon: number;
247
    unit_id: number;
248
    date: string;
249
    alt?: string;
250
    speed?: number;
251
    dop?: number;
252
  }): Observable<void> {
253

  
254
    return this.insertPosition$Response(params).pipe(
255
      map((r: StrictHttpResponse<void>) => r.body as void)
256
    );
257
  }
258

  
135 259
}
src/app/shared/api/openapi.yaml
88 88
            schema:
89 89
              $ref: '#/components/schemas/UserInfo'
90 90

  
91
  /senslog1/SensorService?Operation=GetSensors:
91
  /senslog15/SensorService?Operation=GetSensors:
92 92
    get:
93 93
      tags:
94 94
        - sensors
......
111 111
                  $ref: '#/components/schemas/Sensor'
112 112

  
113 113

  
114
  /senslog1/SensorService?Operation=GetObservations:
114
  /senslog15/SensorService?Operation=GetObservations:
115 115
    get:
116 116
      tags:
117 117
        - observation
......
148 148
        500:
149 149
          description: Internal server error
150 150

  
151
  /senslog1/GroupService:
151
  /senslog15/GroupService:
152 152
    get:
153 153
      tags:
154 154
      - group
......
180 180
                items:
181 181
                  $ref: '#/components/schemas/Group'
182 182

  
183
  /senslog1/DataService?Operation=GetUnits:
183
  /senslog15/DataService?Operation=GetUnits:
184 184
    get:
185 185
      tags:
186 186
        - data
......
367 367
                items:
368 368
                  $ref: '#/components/schemas/Phenomenon'
369 369

  
370
  /senslog15/SensorService?Operation=GetAllSensorTypes:
371
    get:
372
      tags:
373
        - sensors
374
      summary: Get sensor types
375
      operationId: getSensorTypes
376
      responses:
377
        200:
378
          description: Getting all Sensor types
379
          content:
380
            application/json:
381
              schema:
382
                type: array
383
                items:
384
                  $ref: '#/components/schemas/SensorType'
385

  
370 386
  /senslog15/ManagementService?Operation=UpdateUnit:
371 387
    put:
372 388
      tags:
......
523 539
                items:
524 540
                  $ref: '#/components/schemas/Right'
525 541

  
542
  /senslog15/FeederServlet?Operation=InsertPosition:
543
    get:
544
      tags:
545
        - sensors
546
      parameters:
547
        - in: query
548
          name: lat
549
          required: true
550
          schema:
551
            type: number
552
        - in: query
553
          name: lon
554
          required: true
555
          schema:
556
            type: number
557
        - in: query
558
          name: unit_id
559
          required: true
560
          schema:
561
            type: integer
562
        - in: query
563
          name: date
564
          required: true
565
          schema:
566
            type: string
567
        - in: query
568
          name: alt
569
          required: false
570
          schema:
571
            type: string
572
        - in: query
573
          name: speed
574
          required: false
575
          schema:
576
            type: number
577
        - in: query
578
          name: dop
579
          required: false
580
          schema:
581
            type: number
582
      summary: Insert position to unit
583
      operationId: insertPosition
584
      responses:
585
        200:
586
          description: success
526 587

  
527 588
components:
528 589
  schemas:
......
672 733
          type: boolean
673 734
        is_moving:
674 735
          type: boolean
675
    #TODO
736

  
676 737
    AlertEvents:
677 738
      type: array
678 739

  
......
685 746
          $ref: '#/components/schemas/Attributes'
686 747
        position:
687 748
          $ref: '#/components/schemas/Position'
688
    #TODO
749

  
689 750
    GeneralInfo:
690 751
      type: array
691
    #TODO
752

  
692 753
    Drivers:
693 754
      type: array
694 755

  
......
752 813
        value:
753 814
          type: number
754 815

  
816
    SensorType:
817
      type: object
818
      properties:
819
        phenomenon:
820
          $ref: '#/components/schemas/Phenomenon'
821
        sensorId:
822
          type: integer
823
        sensorName:
824
          type: string
825
        sensorType:
826
          type: string
827

  
755 828

  
756 829

  
757 830

  
src/app/shared/models/aggreation.model.ts
1
/* tslint:disable */
2
/* eslint-disable */
3
export interface AggreationModel {
4
  name?: string,
5
  code?: string
6
}
src/app/shared/models/aggregationModel.ts
1
/* tslint:disable */
2
/* eslint-disable */
3
export interface AggregationModel {
4
  name?: string,
5
  code?: string
6
}
src/app/shared/models/vegaModel.ts
1
/* tslint:disable */
2
/* eslint-disable */
3
export interface VegaModel {
4
  sensordId?: string,
5
  data?: []
6
}
src/app/shared/nav-bar/components/nav-bar.component.html
36 36
</div>
37 37

  
38 38
<app-user-insert-popup *ngIf="showAddUserPopup" [(isVisible)]="showAddUserPopup"></app-user-insert-popup>
39
<app-unit-insert-popup [(isVisible)]="showInsertUnitPopup" [phenomenons]="phenomenons"></app-unit-insert-popup>
39
<app-unit-insert-popup [(isVisible)]="showInsertUnitPopup" [phenomenons]="phenomenons" (emitNewUnit)="addUnit($event)"></app-unit-insert-popup>
src/app/shared/nav-bar/components/nav-bar.component.ts
1
import {Component, OnDestroy, OnInit} from '@angular/core';
1
import {Component, EventEmitter, OnDestroy, OnInit, Output} from '@angular/core';
2 2
import {AuthService} from '../../../auth/services/auth.service';
3 3
import {User} from '../../../auth/models/user';
4 4
import {Subscription} from 'rxjs';
5 5
import {Right} from '../../api/endpoints/models/right';
6 6
import {Phenomenon} from '../../api/endpoints/models/phenomenon';
7 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';
8 10

  
9 11
@Component({
10 12
  selector: 'app-nav-bar',
......
19 21
  rights: Right[];
20 22
  showInsertUnitPopup = false;
21 23
  phenomenons: Phenomenon[];
24
  @Output() emitNewUnit: EventEmitter<{unit: InsertUnit, sensors: InsertSensor[]}> =
25
    new EventEmitter<{unit: InsertUnit, sensors: InsertSensor[]}>()
22 26
  constructor(
23 27
    private authService: AuthService,
24 28
    private sensorService: SensorsService
......
55 59
  addUser() {
56 60
    this.showAddUserPopup = true;
57 61
  }
62

  
63
  addUnit(inserted: any) {
64
    this.emitNewUnit.emit(inserted);
65
  }
58 66
}
src/app/shared/nav-bar/components/unit-insert-popup/unit-insert-popup.component.html
7 7
        <span class="input-group-text">Unit ID</span>
8 8
      </div>
9 9
      <input type="text" formControlName="unitId" class="form-control" id="unitId" placeholder="unitId"/>
10
      <div *ngIf="insertForm.get('unitId').invalid &&
11
        insertForm.get('unitId').errors &&
12
        (insertForm.get('unitId').dirty || insertForm.get('unitId').touched)">
13
        <small class="text-danger"
14
               *ngIf="insertForm.get('unitId').hasError('required')">
15
          This field is required.
16
        </small>
17
      </div>
10 18
    </div>
11 19
    <div class="input-group form-group">
12 20
      <div class="input-group-prepend">
......
14 22
      </div>
15 23
      <input type="text" formControlName="unitDescription" class="form-control" id="unitDescription"
16 24
             placeholder="unitDescription"/>
25
      <div *ngIf="insertForm.get('unitDescription').invalid &&
26
        insertForm.get('unitDescription').errors &&
27
        (insertForm.get('unitDescription').dirty || insertForm.get('unitDescription').touched)">
28
        <small class="text-danger"
29
               *ngIf="insertForm.get('unitDescription').hasError('required')">
30
          This field is required.
31
        </small>
32
      </div>
33
    </div>
34
    <div class="input-group form-group">
35
      <div class="input-group-prepend">
36
        <span class="input-group-text">Latitude</span>
37
      </div>
38
      <input type="number" formControlName="lat" class="form-control" id="lat"
39
             placeholder="Latitude WGS-84 coordinates" step="0.0001" min="-90" max="90"/>
40
      <div *ngIf="insertForm.get('lat').invalid &&
41
        insertForm.get('lat').errors &&
42
        (insertForm.get('lat').dirty || insertForm.get('lat').touched)">
43
        <small class="text-danger"
44
               *ngIf="insertForm.get('lat').hasError('required')">
45
          This field is required.
46
        </small>
47
        <small class="text-danger"
48
               *ngIf="insertForm.get('lat').hasError('min')">
49
          The minimum value for this field is -90.
50
        </small>
51
        <small class="text-danger"
52
               *ngIf="insertForm.get('lat').hasError('max')">
53
          The minimum value for this field is 90.
54
        </small>
55
      </div>
56
    </div>
57
    <div class="input-group form-group">
58
      <div class="input-group-prepend">
59
        <span class="input-group-text">Longitude</span>
60
      </div>
61
      <input type="number" formControlName="lon" class="form-control" id="lon"
62
             placeholder="Longitude WGS-84 coordinates" step="0.0001" min="-180" max="180"/>
63
      <div *ngIf="insertForm.get('lon').invalid &&
64
        insertForm.get('lon').errors &&
65
        (insertForm.get('lon').dirty || insertForm.get('lon').touched)">
66
        <small class="text-danger"
67
               *ngIf="insertForm.get('lon').hasError('required')">
68
          This field is required.
69
        </small>
70
        <small class="text-danger"
71
               *ngIf="insertForm.get('lon').hasError('min')">
72
          The minimum value for this field is -180.
73
        </small>
74
        <small class="text-danger"
75
               *ngIf="insertForm.get('lon').hasError('max')">
76
          The minimum value for this field is 180.
77
        </small>
78
      </div>
17 79
    </div>
18 80
    <hr>
19 81
    <div class="input-group form-group">
......
62 124
  <p-footer>
63 125
    <div class="row justify-content-end align-items-center">
64 126
      <div>
65
        <p-button icon="pi pi-check" (click)="processInsertion()" type="submit" label="Uložit" class="pr-2"></p-button>
66
        <p-button icon="pi pi-times" (click)="close()" label="Zavřít" class="pr-2"></p-button>
127
        <p-button icon="pi pi-times" (click)="close()" label="Close" class="pr-2"></p-button>
128
        <p-button icon="pi pi-check" (click)="processInsertion()" type="submit" label="Save" class="pr-2"></p-button>
67 129
      </div>
68 130
    </div>
69 131
  </p-footer>
src/app/shared/nav-bar/components/unit-insert-popup/unit-insert-popup.component.ts
8 8
import {InsertSensor} from '../../../api/endpoints/models/insert-sensor';
9 9
import {Phenomenon} from '../../../api/endpoints/models/phenomenon';
10 10
import {SensorsService} from '../../../api/endpoints/services/sensors.service';
11
import * as moment from 'moment-timezone';
11 12

  
12 13
@Component({
13 14
  selector: 'app-unit-insert-popup',
......
22 23
  @Input()phenomenons: Phenomenon[];
23 24
  @Input() isVisible;
24 25
  @Output() isVisibleChange: EventEmitter<boolean> = new EventEmitter<boolean>();
26
  @Output() emitNewUnit: EventEmitter<{unit: InsertUnit, sensors: InsertSensor[]}> =
27
    new EventEmitter<{unit: InsertUnit, sensors: InsertSensor[]}>()
25 28

  
26 29
  constructor(
27 30
    private formBuilder: FormBuilder,
......
43 46
    this.insertForm = this.formBuilder.group({
44 47
      unitId: ['', [Validators.required]],
45 48
      unitDescription: ['', Validators.required],
49
      lat: ['', [Validators.required, Validators.min(-90), Validators.max(90)]],
50
      lon: ['', [Validators.required, Validators.min(-180), Validators.max(180)]],
46 51
      sensors: this.formBuilder.array([this.createSensor()])
47 52
    });
48 53
  }
......
72 77

  
73 78
  processInsertion() {
74 79
    if (this.insertForm.valid) {
80
      const lat = this.insertForm.controls.lat.value;
81
      const lon = this.insertForm.controls.lon.value;
75 82
      const unit: InsertUnit = {
76 83
        unit_id: this.insertForm.controls.unitId.value,
77 84
        description: this.insertForm.controls.unitDescription.value
......
94 101
      this.managementService.insertUnit$Response({ body: { unit, sensors}}).pipe(
95 102
        map((response: HttpResponse<any>) => {
96 103
          if (response.status === 200) {
97
            this.toastService.showSuccessMessage('Unit ' + response.body.unitId + ' inserted!');
98
            this.close()
104
            this.sensorService.insertPosition$Response( {lat, lon, unit_id: this.insertForm.controls.unitId.value, date: moment().format('yyyy-MM-DD HH:mm:ssZZ')}).pipe(
105
              map((response2: HttpResponse<any>) => {
106
                if (response2.status === 200) {
107
                  this.toastService.showSuccessMessage('Unit ' + response.body.unitId + ' inserted!');
108
                  this.toastService.showSuccessMessage('Position to unit ' + response2.body.unitId + ' inserted!');
109
                  this.emitNewUnit.emit({unit, sensors});
110
                  this.close();
111
                } else {
112
                  this.toastService.showError('Unit insertion ' + response2.body.unitId + ' caused error! Wrong position!');
113
                  this.managementService.deleteUnit({body: {unit}}).toPromise().then().catch(
114
                    err => this.toastService.showError(err.error.message));
115
                }
116
              })
117
            ).toPromise().then().catch(err => this.toastService.showError(err.error.message));
99 118
          } else {
100 119
          }
101 120
        })
src/app/shared/nav-bar/components/user-insert-popup/user-insert-popup.component.html
23 23
        <input type="text" formControlName="userRealName" class="form-control" id="userRealName"
24 24
               placeholder="User real name"/>
25 25
      </div>
26
<!--      <div class="input-group form-group">
26
      <div class="input-group form-group">
27 27
        <div class="input-group-prepend">
28 28
          <span class="input-group-text">Group</span>
29 29
        </div>
30 30
        <select formControlName="groups" id="groups">
31 31
          <option *ngFor="let group of groups; let i = index" [value]="groups[i].id">
32
            {{group[i]?.group_name}}
32
            {{groups[i].group_name}}
33 33
          </option>
34 34
        </select>
35
      </div>-->
35
      </div>
36 36
      <div class="input-group form-group">
37 37
        <div class="input-group-prepend">
38 38
          <span class="input-group-text">Role</span>
......
49 49
  <p-footer>
50 50
    <div class="row justify-content-end align-items-center">
51 51
      <div>
52
        <p-button icon="pi pi-check" (click)="saveUser()" type="submit" label="Save" class="pr-2"></p-button>
53 52
        <p-button icon="pi pi-times" (click)="close()" label="Close" class="pr-2"></p-button>
53
        <p-button icon="pi pi-check" (click)="saveUser()" type="submit" label="Save" class="pr-2"></p-button>
54 54
      </div>
55 55
    </div>
56 56
  </p-footer>
src/app/shared/nav-bar/components/user-insert-popup/user-insert-popup.component.ts
28 28
    private toastService: ToastService
29 29
  ) {
30 30
    this.initForm();
31
    // TODO this.getGroups();
31
    this.getGroups();
32 32
  }
33 33

  
34 34
  ngOnInit(): void {
......
38 38
    this.groupService.getGroups({Operation: 'GetGroups'}).pipe(
39 39
      tap(data => this.groups = data)
40 40
    ).subscribe();
41
    console.log(this.groups);
42 41
  }
43 42

  
44 43
  getRights() {
......
58 57
        userName: this.insertForm.controls.userName.value,
59 58
        rightsId: this.insertForm.controls.rights.value,
60 59
        userRealName: this.insertForm.controls.userRealName.value,
61
        groupId: 2 // TODO
60
        groupId: this.insertForm.controls.groups.value
62 61
        }
63 62
      }).pipe(
64 63
        map((response: HttpResponse<any>) => {
......
78 77
      userName: ['', Validators.required],
79 78
      userPass: ['', Validators.required],
80 79
      userRealName: ['', Validators.required],
81
      // TODO groups: ['', Validators.required],
80
      groups: ['', Validators.required],
82 81
      rights: ['', Validators.required]
83 82
    });
84 83
  }
src/app/unit/components/unit.component.ts
2 2
import {ActivatedRoute} from '@angular/router';
3 3
import {AnalyticsService} from '../../shared/api/endpoints/services/analytics.service';
4 4
import {map, tap} from 'rxjs/operators';
5
import {AggreationModel} from '../../shared/models/aggreation.model';
5
import {AggregationModel} from '../../shared/models/aggregationModel';
6 6
import * as moment from 'moment-timezone';
7 7
import {GraphLoader} from '../../shared/graph-loading/graphloader';
8 8
import {SensorsService} from '../../shared/api/endpoints/services/sensors.service';
......
31 31
  selectedSensors = [];
32 32
  sensors: Sensor[];
33 33
  showAggregation = false;
34
  aggregationFunction: AggreationModel[];
34
  aggregationFunction: AggregationModel[];
35 35
  selectedAggregationFunction = 'HOUR';
36 36

  
37 37
  constructor(
......
53 53
        this.sensors = sensors;
54 54
        if (sensors) {
55 55
          sensors.forEach(sensor => {
56
            const sensorType = sensor.sensorId.toString().slice(0, 2);
56
            const sensorType = sensor.sensorId.toString().slice(0, 5);
57 57
            if (!this.sensorGroups.some(group => group === sensorType)) {
58 58
              this.sensorGroups.push(sensorType);
59 59
            }
60
            if (!this.selectedSensors.some(sens => sens.toString().slice(0, 2) === sensorType)) {
60
            if (!this.selectedSensors.some(sens => sens.toString().slice(0, 5) === sensorType)) {
61 61
              this.selectedSensors.push(sensor.sensorId);
62 62
            }
63 63
          })
... Rozdílový soubor je zkrácen, protože jeho délka přesahuje max. limit.

Také k dispozici: Unified diff