Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 760650ec

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

Re #8520 - Obrazovka 'Sensor' - implementace

+ new view Sensor with url /dashboard/unit/:unitId/sensor/:sensorId

Zobrazit rozdíly:

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

  
9 10
const routes: Routes = [
10 11
  {
......
16 17
    path: 'dashboard',
17 18
    component: DashboardComponent,
18 19
    pathMatch: 'full'
19
  },
20
  {
20
  }, {
21
    canActivate: [AuthGuard, RoleGuard],
22
    path: 'dashboard/unit/:unitId/sensor/:sensorId',
23
    component: SensorComponent,
24
    pathMatch: 'full',
25
    data: {
26
      expectedRole: ['1', '0']
27
    }
28
  }, {
21 29
    canActivate: [AuthGuard, RoleGuard],
22 30
    path: 'administration',
23 31
    component: AdministrationComponent,
src/app/app.module.ts
10 10
import {LoginModule} from './login/login.module';
11 11
import {DashboardModule} from './dashboard/dashboard.module';
12 12
import {AdministrationModule} from './administration/administration.module';
13
import {SensorModule} from './sensor/sensor.module';
13 14

  
14 15
@NgModule({
15 16
  declarations: [
......
24 25
    AuthModule,
25 26
    LoginModule,
26 27
    DashboardModule,
27
    AdministrationModule
28
    AdministrationModule,
29
    SensorModule
28 30
  ],
29 31
  providers: [],
30 32
  bootstrap: [AppComponent]
src/app/sensor/components/sensor.component.html
1
<app-nav-bar></app-nav-bar>
2

  
3
Sensor ID {{sensorId}}
4
<br>
5
Unit ID {{unitId}}
6
<br>
7
<br>
8

  
9

  
10

  
11
<div *ngFor="let observation of observations">
12
  {{ observation | json}}
13
  <br>
14
</div>
src/app/sensor/components/sensor.component.ts
1
import { Component, OnInit } from '@angular/core';
2
import {ActivatedRoute} from '@angular/router';
3
import {ObservationService} from '../../shared/api/endpoints/services/observation.service';
4
import {tap} from 'rxjs/operators';
5
import {Observation} from '../../shared/api/endpoints/models/observation';
6

  
7
@Component({
8
  selector: 'app-sensor',
9
  templateUrl: './sensor.component.html',
10
  styleUrls: ['./sensor.component.scss']
11
})
12
export class SensorComponent implements OnInit {
13

  
14
  sensorId: number;
15
  unitId: number;
16
  observations: Observation[]
17
  constructor(
18
    private activatedRoute: ActivatedRoute,
19
    private observationService: ObservationService
20
  ) {
21
    this.sensorId = parseInt(this.activatedRoute.snapshot.paramMap.get('sensorId'), 10);
22
    this.unitId = parseInt(this.activatedRoute.snapshot.paramMap.get('unitId'), 10);
23
  }
24

  
25
  ngOnInit(): void {
26
    this.getObservations();
27
  }
28

  
29
  getObservations(){
30
    this.observationService.getObservation({unit_id: this.unitId, sensor_id: this.sensorId}).pipe(
31
      tap(data => this.observations = data)
32
    ).toPromise();
33
  }
34
}
src/app/sensor/sensor.module.ts
1
import { NgModule } from '@angular/core';
2
import { CommonModule } from '@angular/common';
3
import { SensorComponent } from './components/sensor.component';
4
import {NavBarModule} from '../shared/nav-bar/nav-bar.module';
5

  
6

  
7

  
8
@NgModule({
9
  declarations: [SensorComponent],
10
  imports: [
11
    CommonModule,
12
    NavBarModule
13
  ]
14
})
15
export class SensorModule { }

Také k dispozici: Unified diff