88 lines
3.8 KiB
JavaScript
88 lines
3.8 KiB
JavaScript
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
};
|
|
var core_1 = require("@angular/core");
|
|
var data_service_1 = require("./../../services/data.service");
|
|
var router_1 = require("@angular/router");
|
|
var IntervalObservable_1 = require("rxjs/observable/IntervalObservable");
|
|
var plane_class_1 = require("./../../classes/plane.class");
|
|
var PlanesComponent = (function () {
|
|
function PlanesComponent(router, data) {
|
|
this.router = router;
|
|
this.data = data;
|
|
this.loading = true;
|
|
this.error = false;
|
|
this.planes = new Array();
|
|
}
|
|
PlanesComponent.prototype.getPlanesData = function () {
|
|
var _this = this;
|
|
this.data.load().then(function () {
|
|
_this.data
|
|
.planes()
|
|
.subscribe(function (response) {
|
|
var status = response.status_code;
|
|
if (status != 200) {
|
|
_this.loading = false;
|
|
_this.error = true;
|
|
}
|
|
else {
|
|
_this.error = false;
|
|
for (var i = 0; i < response.data.length; i++) {
|
|
var temp = plane_class_1.Plane.toPlane(response.data[i]);
|
|
var plane = _this.getPlaneByID(temp.id);
|
|
if (plane) {
|
|
if (!temp.equals(plane)) {
|
|
// push new one, delete old
|
|
var index = _this.planes.indexOf(plane);
|
|
_this.planes.splice(index, 1);
|
|
_this.planes.push(temp);
|
|
}
|
|
}
|
|
else {
|
|
_this.planes.push(temp);
|
|
}
|
|
}
|
|
_this.planes.sort(function (a, b) {
|
|
return a.name > b.name ? 1 : -1;
|
|
});
|
|
_this.loading = false;
|
|
}
|
|
});
|
|
});
|
|
};
|
|
PlanesComponent.prototype.ngOnInit = function () {
|
|
var _this = this;
|
|
this.getPlanesData();
|
|
this.subscription = IntervalObservable_1.IntervalObservable.create(5000).subscribe(function () {
|
|
console.log("Reloading data...");
|
|
_this.getPlanesData();
|
|
});
|
|
};
|
|
PlanesComponent.prototype.ngOnDestroy = function () {
|
|
this.subscription.unsubscribe();
|
|
};
|
|
PlanesComponent.prototype.onClick = function (plane) {
|
|
this.router.navigate(['/plane', plane.id]);
|
|
};
|
|
PlanesComponent.prototype.getPlaneByID = function (id) {
|
|
return this.planes.find(function (f) { return f.id === id; });
|
|
};
|
|
return PlanesComponent;
|
|
}());
|
|
PlanesComponent = __decorate([
|
|
core_1.Component({
|
|
selector: 'app-planes',
|
|
templateUrl: './planes.component.html',
|
|
styleUrls: ['./planes.component.css']
|
|
}),
|
|
__metadata("design:paramtypes", [router_1.Router, data_service_1.DataService])
|
|
], PlanesComponent);
|
|
exports.PlanesComponent = PlanesComponent;
|
|
//# sourceMappingURL=planes.component.js.map
|