Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | 57x 5x 5x 5x 5x 5x 4x 4x 4x 4x 3x 3x 1x 4x 4x | import { Component, inject, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { TwinpadApiService } from '../../services/twinpad-api.service';
import { Signal } from '../../models/signals';
import { TableModule } from 'primeng/table';
import { ToastModule } from 'primeng/toast';
import { MessageService } from 'primeng/api';
import { NgIf } from '@angular/common';
import { Subscription } from 'rxjs';
import { SignalsTableComponent } from '../signals-table/signals-table.component';
import { ModesTableComponent } from '../modes-table/modes-table.component';
import { Device } from '../../models/devices';
import { DeviceCardComponent } from '../device-card/device-card.component';
import { HttpErrorResponse } from '@angular/common/http';
import { ErrorComponent } from '../error/error.component';
@Component({
selector: 'app-device',
imports: [TableModule, ToastModule, NgIf, SignalsTableComponent, DeviceCardComponent, ErrorComponent, ModesTableComponent],
providers: [],
templateUrl: './device.component.html',
styleUrl: './device.component.scss'
})
export class DeviceComponent implements OnInit, OnDestroy {
private messageService = inject(MessageService);
deviceId: string;
device: Device;
private deviceSubscription: Subscription = new Subscription;
private routeSub: Subscription;
isLoading: boolean = false;
signals: Signal[];
error: HttpErrorResponse;
constructor(private twinpadApiService: TwinpadApiService,
private route: ActivatedRoute
) {}
ngOnInit() {
this.routeSub = this.route.params.subscribe(params => {
this.deviceId = params['device_id'];
this.deviceSubscription?.unsubscribe();
this.deviceSubscription = this.twinpadApiService.callPeriodically(() => this.twinpadApiService.getDevice(this.deviceId), 3000).subscribe(
{
'next': data => {
this.device = data;
this.isLoading = false;
},
'error': error => {
this.error = error;
}
});
});
}
refreshDeviceStatus(){
this.deviceSubscription = this.twinpadApiService.getDevice(this.deviceId).subscribe({
next: data => {
this.device = data;
},
error: error => {
this.error = error;
}
});
}
ngOnDestroy(): void {
this.deviceSubscription?.unsubscribe();
this.routeSub?.unsubscribe();
}
}
|