108 lines
5.5 KiB
JavaScript
108 lines
5.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");
|
|
require("rxjs/add/operator/map");
|
|
var http_1 = require("@angular/http");
|
|
var DataService = (function () {
|
|
function DataService(http) {
|
|
this.http = http;
|
|
this.url = "";
|
|
}
|
|
DataService.prototype.load = function () {
|
|
var _this = this;
|
|
return new Promise(function (resolve, reject) {
|
|
if (_this.url != "") {
|
|
resolve();
|
|
}
|
|
else {
|
|
_this.http.get('/app/config/api.json').subscribe(function (res) {
|
|
var data = res.json();
|
|
_this.url = data.protocol + data.hostname + ":" + data.port + "/" + data.api;
|
|
console.log(_this.url);
|
|
resolve();
|
|
});
|
|
}
|
|
});
|
|
};
|
|
//FLIGHTS
|
|
DataService.prototype.flight = function (id) {
|
|
var flightdata = this.http.get(this.url + "/flights/" + id, { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return flightdata;
|
|
};
|
|
DataService.prototype.flights = function () {
|
|
var flightdata = this.http.get(this.url + "/flights", { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return flightdata;
|
|
};
|
|
DataService.prototype.endFlight = function (id) {
|
|
var flight = this.http.put(this.url + "/flights/" + id + "/stop", { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return flight;
|
|
};
|
|
//USERS
|
|
DataService.prototype.user = function (id) {
|
|
var usersdata = this.http.get(this.url + "/users/" + id, { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return usersdata;
|
|
};
|
|
DataService.prototype.users = function () {
|
|
var usersdata = this.http.get(this.url + "/users", { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return usersdata;
|
|
};
|
|
DataService.prototype.postUser = function (user) {
|
|
var userData = this.http.post(this.url + "/users", { name: user.name, cardId: user.card, role: user.role }, { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return userData;
|
|
};
|
|
DataService.prototype.editUser = function (user) {
|
|
var userData = this.http.put(this.url + "/users/" + user.id, { name: user.name, cardId: user.card, role: user.role }, { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return userData;
|
|
};
|
|
//READERS
|
|
DataService.prototype.reader = function (id) {
|
|
var readerData = this.http.get(this.url + "/readers/" + id, { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return readerData;
|
|
};
|
|
DataService.prototype.readers = function () {
|
|
var readersData = this.http.get(this.url + "/readers", { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return readersData;
|
|
};
|
|
DataService.prototype.editReader = function (reader) {
|
|
var readerData = this.http.put(this.url + "/readers/" + reader.id, { readerId: reader.reader_id, planeId: reader.plane.id }, { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return readerData;
|
|
};
|
|
//PLANES
|
|
DataService.prototype.plane = function (id) {
|
|
var planeData = this.http.get(this.url + "/planes/" + id, { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return planeData;
|
|
};
|
|
DataService.prototype.planes = function () {
|
|
var planesData = this.http.get(this.url + "/planes", { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return planesData;
|
|
};
|
|
DataService.prototype.postPlane = function (plane) {
|
|
var userData = this.http.post(this.url + "/planes", { name: plane.name, registration: plane.registration, model: plane.model, comment: plane.comment }, { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return userData;
|
|
};
|
|
DataService.prototype.editPlane = function (plane) {
|
|
var planeData = this.http.put(this.url + "/planes/" + plane.id, { name: plane.name, registration: plane.registration, model: plane.model, comment: plane.comment }, { headers: this.getHeaders() }).map(function (r) { return r.json(); });
|
|
return planeData;
|
|
};
|
|
//OTHER
|
|
DataService.prototype.getHeaders = function () {
|
|
var headers = new http_1.Headers();
|
|
headers.append('Accept', 'application/json');
|
|
return headers;
|
|
};
|
|
return DataService;
|
|
}());
|
|
DataService = __decorate([
|
|
core_1.Injectable(),
|
|
__metadata("design:paramtypes", [http_1.Http])
|
|
], DataService);
|
|
exports.DataService = DataService;
|
|
//# sourceMappingURL=data.service.js.map
|