"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 FlightsComponent = (function () { function FlightsComponent(router, data) { this.router = router; this.data = data; this.loading = true; this.error = false; this.flights = new Array(); } FlightsComponent.prototype.getFlightsData = function () { var _this = this; this.data.load().then(function () { _this.data .flights() .subscribe(function (response) { var status = response.status_code; if (status != 200) { _this.loading = false; _this.error = true; } else { for (var i = 0; i < response.data.length; i++) { var temp = flight_class_1.Flight.toFlight(response.data[i]); var flight = _this.getFlightByID(temp.id); if (flight) { if (!flight.equals(temp)) { // push new one, delete old var index = _this.flights.indexOf(flight); _this.flights.splice(index, 1); _this.flights.push(temp); } } else { _this.flights.push(temp); } } _this.flights.sort(function (a, b) { return a.id < b.id ? 1 : -1; }); _this.loading = false; } }); }); }; FlightsComponent.prototype.getFlightByID = function (id) { return this.flights.find(function (f) { return f.id === id; }); }; FlightsComponent.prototype.ngOnInit = function () { var _this = this; this.getFlightsData(); this.subscription = IntervalObservable_1.IntervalObservable.create(5000).subscribe(function () { console.log("Reloading data..."); _this.getFlightsData(); }); }; FlightsComponent.prototype.ngOnDestroy = function () { this.subscription.unsubscribe(); }; FlightsComponent.prototype.onClick = function (flight) { this.router.navigate(['/flight', flight.id]); }; return FlightsComponent; }()); FlightsComponent = __decorate([ core_1.Component({ selector: 'app-flights', templateUrl: './flights.component.html', styleUrls: ['./flights.component.css'] }), __metadata("design:paramtypes", [router_1.Router, data_service_1.DataService]) ], FlightsComponent); exports.FlightsComponent = FlightsComponent; //# sourceMappingURL=flights.component.js.map