Files
gilze-angular/app/pages/flight/flight.component.js
T
2026-06-17 16:11:25 +02:00

84 lines
3.5 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 flight_class_1 = require("./../../classes/flight.class");
var FlightComponent = (function () {
function FlightComponent(data, router, route) {
this.data = data;
this.router = router;
this.route = route;
this.loading = true;
this.error = false;
this.id = 0;
this.flight = null;
this.name = "Loading";
}
FlightComponent.prototype.getFlight = function (id) {
var _this = this;
this.data.load().then(function () {
_this.data
.flight(id)
.subscribe(function (b) {
var status = b.status_code;
if (status != 200 && b.data.length != 1) {
_this.loading = false;
_this.error = true;
}
else {
_this.flight = flight_class_1.Flight.toFlight(b.data[0]);
_this.name = "Flight #" + _this.flight.id;
_this.loading = false;
}
});
});
};
FlightComponent.prototype.endFlight = function () {
var _this = this;
this.data.load().then(function () {
_this.data.endFlight(_this.flight.id).subscribe(function (b) {
console.log("flight ended");
_this.flight.endtime = Date.now().toString();
});
});
};
FlightComponent.prototype.ngOnInit = function () {
var _this = this;
this.id = this.route.snapshot.params['id'];
this.getFlight(this.id);
this.subscription = IntervalObservable_1.IntervalObservable.create(5000).subscribe(function () {
console.log("Reloading data...");
_this.getFlight(_this.id);
});
};
FlightComponent.prototype.ngOnDestroy = function () {
this.subscription.unsubscribe();
};
FlightComponent.prototype.onClick = function (user) {
this.router.navigate(['/user', user.id]);
};
FlightComponent.prototype.onClickPlane = function (plane) {
this.router.navigate(['/plane', plane.id]);
};
return FlightComponent;
}());
FlightComponent = __decorate([
core_1.Component({
selector: 'app-flight',
templateUrl: './flight.component.html',
styleUrls: ['./flight.component.css']
}),
__metadata("design:paramtypes", [data_service_1.DataService, router_1.Router, router_1.ActivatedRoute])
], FlightComponent);
exports.FlightComponent = FlightComponent;
//# sourceMappingURL=flight.component.js.map