Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2b0d2514

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

Re #8851 - Unit page - implementace

+ sensors checkboxes
+ checking sensor will reinitialize graph

Zobrazit rozdíly:

src/app/unit/components/unit.component.html
1 1
<app-nav-bar></app-nav-bar>
2 2

  
3
{{ unitId}}
4
<br>
5
------
6
<br><br>
7

  
8
<div class="col">
9
  <div class="input-group form-group">
10
    <div class="input-group-prepend">
11
      <span class="input-group-text">From</span>
12
    </div>
13
    <p-calendar [style]="{'width':'100%'}" [inputStyle]="{'width':'100%'}" [(ngModel)]="from" [showTime]="true" (onSelect)="showGraph()" [maxDate]="today" showButtonBar="true"></p-calendar>
3
<div class="container">
4
  <div class="row-2">
5
      <h5><span class="text-color-sensor-unit">Unit ID: {{unitId}}</span></h5>
14 6
  </div>
15
</div>
16
<div class="col">
17
  <div class="input-group form-group">
18
    <div class="input-group-prepend">
19
      <span class="input-group-text">To</span>
7
  <div class="row">
8
    <div class="col">
9
      <div class="input-group form-group">
10
        <div class="input-group-prepend">
11
          <span class="input-group-text">From</span>
12
        </div>
13
        <p-calendar [style]="{'width':'100%'}" [inputStyle]="{'width':'100%'}" [(ngModel)]="from" [showTime]="true" (onSelect)="showGraph()" [maxDate]="today" showButtonBar="true"></p-calendar>
14
      </div>
20 15
    </div>
21
    <p-calendar [style]="{'width':'100%'}" [inputStyle]="{'width':'100%'}" [(ngModel)]="to" [showTime]="true" (onSelect)="showGraph()" [maxDate]="today" showButtonBar="true"></p-calendar>
22
  </div>
23
</div>
24
<div *ngIf="showAggregation" class="col">
25
  <div class="input-group form-group">
26
    <div class="input-group-prepend">
27
      <span class="input-group-text">Aggregation</span>
16
    <div class="col">
17
      <div class="input-group form-group">
18
        <div class="input-group-prepend">
19
          <span class="input-group-text">To</span>
20
        </div>
21
        <p-calendar [style]="{'width':'100%'}" [inputStyle]="{'width':'100%'}" [(ngModel)]="to" [showTime]="true" (onSelect)="showGraph()" [maxDate]="today" showButtonBar="true"></p-calendar>
22
      </div>
23
    </div>
24
    <div *ngIf="showAggregation" class="col">
25
      <div class="input-group form-group">
26
        <div class="input-group-prepend">
27
          <span class="input-group-text">Aggregation</span>
28
        </div>
29
        <p-listbox [options]="aggregationFunction" [(ngModel)]="selectedAggregationFunction" optionLabel="name" optionValue="code" (onClick)="showGraph()" ></p-listbox>
30
      </div>
28 31
    </div>
29
    <p-listbox [options]="aggregationFunction" [(ngModel)]="selectedAggregationFunction" optionLabel="name" optionValue="code" (onClick)="showGraph()" ></p-listbox>
30 32
  </div>
31
</div>
32 33

  
33
<ng-container *ngFor="let group of sensorGroups">
34
  Group of sensors:
35
  <ng-container *ngFor="let sensor of sensors">
36
    <ng-container *ngIf="sensor.sensorId.toString().slice(0, 2) === group">
37
      {{ sensor.sensorId }}
38
    </ng-container>
34
  <ng-container *ngFor="let group of sensorGroups">
35
    <div class="row">
36
    Group of sensors:
37
      <ng-container *ngFor="let sensor of sensors">
38
        <ng-container *ngIf="sensor.sensorId.toString().slice(0, 5) === group">
39
          <div class="p-field-checkbox">
40
            <p-checkbox name="group1" value="{{sensor.sensorId}}" [value]="sensor.sensorId" inputId="{{sensor.sensorId}}" [(ngModel)]="selectedSensors" [inputId]="sensor.sensorId.toString()" (onChange)="addSensorToGraph(sensor.sensorId)"></p-checkbox>
41
            <label>{{sensor.sensorName}}</label>
42
          </div>
43
        </ng-container>
44
      </ng-container>
45
    </div>
46
    <div id="vega_container_{{group}}"></div>
39 47
  </ng-container>
40
  <div id="vega_container_{{group}}"></div>
41
</ng-container>
48
</div>
src/app/unit/components/unit.component.ts
1 1
import {Component, OnInit} from '@angular/core';
2 2
import {ActivatedRoute} from '@angular/router';
3 3
import {AnalyticsService} from '../../shared/api/endpoints/services/analytics.service';
4
import {map, tap} from 'rxjs/operators';
4
import {map} from 'rxjs/operators';
5 5
import {AggregationModel} from '../../shared/models/aggregationModel';
6 6
import * as moment from 'moment-timezone';
7 7
import {GraphLoader} from '../../shared/graph-loading/graphloader';
......
10 10
import {ToastService} from '../../shared/services/toast.service';
11 11
import {Sensor} from '../../shared/api/endpoints/models/sensor';
12 12

  
13
declare var require: any
14 13

  
15 14
@Component({
16 15
  selector: 'app-unit',
......
27 26
  from: Date;
28 27
  to: Date;
29 28
  today: Date;
29
  analyticsData: any[] = [];
30
  observationsData: any[] = [];
30 31
  sensorGroups = [];
31
  selectedSensors = [];
32
  selectedSensors: any[] = [];
32 33
  sensors: Sensor[];
33 34
  showAggregation = false;
34 35
  aggregationFunction: AggregationModel[];
......
56 57
            const sensorType = sensor.sensorId.toString().slice(0, 5);
57 58
            if (!this.sensorGroups.some(group => group === sensorType)) {
58 59
              this.sensorGroups.push(sensorType);
60
              setTimeout(() => {
61
                  GraphLoader.getGraph(null, null, null, '#vega_container_' + sensor.sensorId.toString().slice(0, 5));
62
              }, 0);
59 63
            }
60 64
            if (!this.selectedSensors.some(sens => sens.toString().slice(0, 5) === sensorType)) {
61 65
              this.selectedSensors.push(sensor.sensorId);
......
63 67
          })
64 68
        }
65 69
      }
66
    )
70
    );
67 71
  }
68 72

  
69 73
  ngOnInit(): void {
......
108 112
        }
109 113
      })
110 114
    ).subscribe(data => {
115
      if (data) {
116
        this.analyticsData = data;
111 117
        const objectKeys = Object.keys(data);
112
        for(const key of objectKeys ) {
113
          if (data[key].data) {
114
            const view = '#vega_container_' + key.slice(0, 5);
115
            if (this.selectedSensors.some(sens => sens.toString() === key)) {
116
              GraphLoader.getGraph(key, data[key].data, data[key].interval, view);
118
          for(const key of objectKeys ) {
119
            if (data[key].data) {
120
              const view = '#vega_container_' + key.slice(0, 5);
121
              if (this.selectedSensors.some(sens => sens.toString() === key)) {
122
                GraphLoader.getGraph(key, data[key].data, data[key].interval, view);
123
              }
117 124
            }
118 125
          }
119 126
        }
120
      });
127
      }, err => this.toastService.showError(err.error.message));
128
  }
129

  
130
  addSensorToGraph(sensorId: number) {
131
    const objectKeys = Object.keys(this.analyticsData);
132
    for(const key of objectKeys ) {
133
      if (this.analyticsData[key].data) {
134
        const view = '#vega_container_' + key.slice(0, 5);
135
        if (sensorId.toString() === key) {
136
          GraphLoader.getGraph(key, this.analyticsData[key].data, this.analyticsData[key].interval, view);
137
        }
138
      }
139
    }
121 140
  }
122 141
}
src/app/unit/unit.module.ts
5 5
import {CalendarModule} from 'primeng/calendar';
6 6
import {FormsModule} from '@angular/forms';
7 7
import {ListboxModule} from 'primeng/listbox';
8
import {CheckboxModule} from 'primeng/checkbox';
8 9

  
9 10

  
10 11

  
11 12
@NgModule({
12 13
  declarations: [UnitComponent],
13
  imports: [
14
    CommonModule,
15
    NavBarModule,
16
    CalendarModule,
17
    FormsModule,
18
    ListboxModule
19
  ]
14
    imports: [
15
        CommonModule,
16
        NavBarModule,
17
        CalendarModule,
18
        FormsModule,
19
        ListboxModule,
20
        CheckboxModule
21
    ]
20 22
})
21 23
export class UnitModule { }

Také k dispozici: Unified diff