74 lines
1.8 KiB
TypeScript
74 lines
1.8 KiB
TypeScript
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
import { DataService } from './../../services/data.service';
|
|
import { IntervalObservable } from 'rxjs/observable/IntervalObservable';
|
|
import { Subscription } from 'rxjs/Subscription';
|
|
|
|
import { Reader } from "./../../classes/reader.class";
|
|
import { Plane } from "./../../classes/plane.class";
|
|
import { Params, ActivatedRoute, Router } from '@angular/router';
|
|
|
|
|
|
@Component({
|
|
selector: 'app-reader',
|
|
templateUrl: './reader.component.html',
|
|
styleUrls: ['./reader.component.css']
|
|
})
|
|
|
|
export class ReaderComponent implements OnInit, OnDestroy {
|
|
|
|
loading:boolean = true;
|
|
error:boolean = false;
|
|
name:string = "Loading";
|
|
id:number = 0;
|
|
|
|
public reader:Reader = new Reader(0, "", null);
|
|
|
|
public subscription:Subscription;
|
|
|
|
constructor(private route: ActivatedRoute, private router: Router, private data:DataService){}
|
|
|
|
|
|
getReader(id:number): void {
|
|
this.data.load().then(()=> {
|
|
this.data
|
|
.reader(id)
|
|
.subscribe(b => {
|
|
|
|
var status = b.status_code;
|
|
|
|
if(status != 200 && b.data.length != 1)
|
|
{
|
|
this.loading = false;
|
|
this.error = true;
|
|
}
|
|
else{
|
|
|
|
this.reader = Reader.toReader(b.data[0]);
|
|
this.name = this.reader.reader_id;
|
|
this.loading = false;
|
|
}
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.id = this.route.snapshot.params['id'];
|
|
|
|
this.getReader(this.id);
|
|
|
|
this.subscription = IntervalObservable.create(5000).subscribe(() => {
|
|
console.log("Reloading data...");
|
|
this.getReader(this.id);
|
|
});
|
|
}
|
|
|
|
ngOnDestroy(): void {
|
|
this.subscription.unsubscribe();
|
|
}
|
|
|
|
onClick(plane: Plane): void {
|
|
this.router.navigate(['/plane', plane.id]);
|
|
}
|
|
|
|
} |