Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 370c3423

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

Re #8677 - Nová obrazovka Unit

+ new view for all unit sensors

Zobrazit rozdíly:

src/app/app-routing.module.ts
6 6
import {RoleGuard} from './auth/guards/role.guard';
7 7
import {AdministrationComponent} from './administration/components/administration.component';
8 8
import {SensorComponent} from './sensor/components/sensor.component';
9
import {UnitComponent} from './unit/components/unit.component';
9 10

  
10 11
const routes: Routes = [
11 12
  {
......
25 26
    data: {
26 27
      expectedRole: ['1', '0']
27 28
    }
29
  }, {
30
    canActivate: [AuthGuard, RoleGuard],
31
    path: 'dashboard/unit/:unitId',
32
    component: UnitComponent,
33
    pathMatch: 'full',
34
    data: {
35
      expectedRole: ['1', '0']
36
    }
28 37
  }, {
29 38
    canActivate: [AuthGuard, RoleGuard],
30 39
    path: 'administration',
src/app/app.module.ts
12 12
import {AdministrationModule} from './administration/administration.module';
13 13
import {SensorModule} from './sensor/sensor.module';
14 14
import {FontAwesomeModule} from '@fortawesome/angular-fontawesome';
15
import {UnitModule} from './unit/unit.module';
15 16

  
16 17
@NgModule({
17 18
  declarations: [
......
28 29
    DashboardModule,
29 30
    AdministrationModule,
30 31
    SensorModule,
31
    FontAwesomeModule
32
    FontAwesomeModule,
33
    UnitModule
32 34
  ],
33 35
  providers: [],
34 36
  bootstrap: [AppComponent]
src/app/unit/components/unit.component.html
1
<app-nav-bar></app-nav-bar>
2

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

  
8
<div class="row">
9
  <div class="col">
10
    <p-calendar [style]="{'width':'100%'}" [inputStyle]="{'width':'100%'}" [(ngModel)]="rangeDates" selectionMode="range" [showTime]="true" [numberOfMonths]="3" (onSelect)="showGraph()"></p-calendar>
11
  </div>
12
  <div class="col">
13
    <p-listbox [options]="aggregationFunction" [(ngModel)]="selectedAggregationFunction" optionLabel="name" optionValue="code" (onClick)="showGraph()"></p-listbox>
14
  </div>
15
</div>
16

  
17

  
18
<!--  {{ data | json}}-->
src/app/unit/components/unit.component.ts
1
import {Component, OnInit} from '@angular/core';
2
import {ActivatedRoute} from '@angular/router';
3
import {AnalyticsService} from '../../shared/api/endpoints/services/analytics.service';
4
import {tap} from 'rxjs/operators';
5
import {Sensors} from '../../shared/api/endpoints/models/sensors';
6
import {AggreationModel} from '../../shared/models/aggreation.model';
7
import * as moment from 'moment-timezone';
8

  
9
@Component({
10
  selector: 'app-unit',
11
  templateUrl: './unit.component.html',
12
  styleUrls: ['./unit.component.scss']
13
})
14
export class UnitComponent implements OnInit {
15

  
16
  preselectedSensors: string;
17
  unitId: number;
18
  data;
19
  rangeDates: Date[];
20
  aggregationFunction: AggreationModel[];
21
  selectedAggregationFunction: string;
22

  
23
  constructor(
24
    private activatedRoute: ActivatedRoute,
25
    private analyticsService: AnalyticsService
26
  ) {
27
    this.aggregationFunction = [
28
      {name: 'Hour', code: 'HOUR'},
29
      {name: 'Day', code: 'DAY'},
30
      {name: 'Month', code: 'MONTH'},
31
      {name: 'Year', code: 'YEAR'}
32
    ];
33
  }
34

  
35
  ngOnInit(): void {
36
/*    this.route.queryParams.subscribe(params => {
37
      if(params.sensors)  {
38
        this.preselectedSensors = params.sensors;
39
      }
40
    });*/
41

  
42
    this.unitId = parseInt(this.activatedRoute.snapshot.paramMap.get('unitId'), 10);
43

  
44
    this.showGraph()
45
  }
46

  
47
  showGraph() {
48
    let agg = 'HOUR';
49
    let range: Date[] = [moment().subtract(12, 'months').toDate(), moment().toDate()];
50
    if (this.selectedAggregationFunction) {
51
      agg = this.selectedAggregationFunction;
52
    }
53

  
54
    if (this.rangeDates) {
55
      range = this.rangeDates;
56
    }
57

  
58
    this.analyticsService.getAnalytics({unit_id: this.unitId, sensor_id: null,
59
      from: moment(range[0]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3),
60
      to: moment(range[1]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3), interval: agg}).pipe(
61
      tap(data => {
62
        this.data = Object.entries(data);
63
        console.log(this.data);
64
      })
65
    ).subscribe();
66
  }
67
}
src/app/unit/unit.module.ts
1
import { NgModule } from '@angular/core';
2
import { CommonModule } from '@angular/common';
3
import { UnitComponent } from './components/unit.component';
4
import {NavBarModule} from '../shared/nav-bar/nav-bar.module';
5
import {CalendarModule} from 'primeng/calendar';
6
import {FormsModule} from '@angular/forms';
7
import {ListboxModule} from 'primeng/listbox';
8

  
9

  
10

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

Také k dispozici: Unified diff