Added context
This commit is contained in:
614
Birdmap.API/ClientApp/src/common/DeviceService.js
Normal file
614
Birdmap.API/ClientApp/src/common/DeviceService.js
Normal file
@ -0,0 +1,614 @@
|
||||
"use strict";
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
//----------------------
|
||||
// <auto-generated>
|
||||
// Generated using the NSwag toolchain v13.8.2.0 (NJsonSchema v10.2.1.0 (Newtonsoft.Json v12.0.0.0)) (http://NSwag.org)
|
||||
// </auto-generated>
|
||||
//----------------------
|
||||
// ReSharper disable InconsistentNaming
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ApiException = exports.SensorStatus = exports.Coordinates = exports.DeviceStatus = exports.Sensor = exports.Device = void 0;
|
||||
var DeviceService = /** @class */ (function () {
|
||||
function DeviceService(baseUrl, http) {
|
||||
this.jsonParseReviver = undefined;
|
||||
this.http = http ? http : window;
|
||||
this.baseUrl = baseUrl !== undefined && baseUrl !== null ? baseUrl : "api/devices";
|
||||
}
|
||||
/**
|
||||
* Get all device info
|
||||
* @return Array of devices
|
||||
*/
|
||||
DeviceService.prototype.getall = function () {
|
||||
var _this = this;
|
||||
var url_ = this.baseUrl;
|
||||
var options_ = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
return this.http.fetch(url_, options_).then(function (_response) {
|
||||
return _this.processGetall(_response);
|
||||
});
|
||||
};
|
||||
DeviceService.prototype.processGetall = function (response) {
|
||||
var _this = this;
|
||||
var status = response.status;
|
||||
var _headers = {};
|
||||
if (response.headers && response.headers.forEach) {
|
||||
response.headers.forEach(function (v, k) { return _headers[k] = v; });
|
||||
}
|
||||
;
|
||||
if (status === 200) {
|
||||
return response.text().then(function (_responseText) {
|
||||
var result200 = null;
|
||||
var resultData200 = _responseText === "" ? null : JSON.parse(_responseText, _this.jsonParseReviver);
|
||||
if (Array.isArray(resultData200)) {
|
||||
result200 = [];
|
||||
for (var _i = 0, resultData200_1 = resultData200; _i < resultData200_1.length; _i++) {
|
||||
var item = resultData200_1[_i];
|
||||
result200.push(Device.fromJS(item));
|
||||
}
|
||||
}
|
||||
return result200;
|
||||
});
|
||||
}
|
||||
else if (status === 404) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("No device found", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
else if (status !== 200 && status !== 204) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
};
|
||||
/**
|
||||
* Shut down all devices
|
||||
* @return Message sent
|
||||
*/
|
||||
DeviceService.prototype.offlineall = function () {
|
||||
var _this = this;
|
||||
var url_ = this.baseUrl + "/offline";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
var options_ = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
return this.http.fetch(url_, options_).then(function (_response) {
|
||||
return _this.processOfflineall(_response);
|
||||
});
|
||||
};
|
||||
DeviceService.prototype.processOfflineall = function (response) {
|
||||
var status = response.status;
|
||||
var _headers = {};
|
||||
if (response.headers && response.headers.forEach) {
|
||||
response.headers.forEach(function (v, k) { return _headers[k] = v; });
|
||||
}
|
||||
;
|
||||
if (status === 200) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return;
|
||||
});
|
||||
}
|
||||
else if (status === 500) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("Message sending unsuccessful", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
else if (status !== 200 && status !== 204) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
};
|
||||
/**
|
||||
* Bring all devices online
|
||||
* @return Message sent
|
||||
*/
|
||||
DeviceService.prototype.onlineall = function () {
|
||||
var _this = this;
|
||||
var url_ = this.baseUrl + "/online";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
var options_ = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
return this.http.fetch(url_, options_).then(function (_response) {
|
||||
return _this.processOnlineall(_response);
|
||||
});
|
||||
};
|
||||
DeviceService.prototype.processOnlineall = function (response) {
|
||||
var status = response.status;
|
||||
var _headers = {};
|
||||
if (response.headers && response.headers.forEach) {
|
||||
response.headers.forEach(function (v, k) { return _headers[k] = v; });
|
||||
}
|
||||
;
|
||||
if (status === 200) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return;
|
||||
});
|
||||
}
|
||||
else if (status === 500) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("Message sending unsuccessful", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
else if (status !== 200 && status !== 204) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
};
|
||||
/**
|
||||
* Get all device info
|
||||
* @param deviceID ID of device to query
|
||||
* @return Information about a particular device
|
||||
*/
|
||||
DeviceService.prototype.getdevice = function (deviceID) {
|
||||
var _this = this;
|
||||
var url_ = this.baseUrl + "/{deviceID}";
|
||||
if (deviceID === undefined || deviceID === null)
|
||||
throw new Error("The parameter 'deviceID' must be defined.");
|
||||
url_ = url_.replace("{deviceID}", encodeURIComponent("" + deviceID));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
var options_ = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
return this.http.fetch(url_, options_).then(function (_response) {
|
||||
return _this.processGetdevice(_response);
|
||||
});
|
||||
};
|
||||
DeviceService.prototype.processGetdevice = function (response) {
|
||||
var _this = this;
|
||||
var status = response.status;
|
||||
var _headers = {};
|
||||
if (response.headers && response.headers.forEach) {
|
||||
response.headers.forEach(function (v, k) { return _headers[k] = v; });
|
||||
}
|
||||
;
|
||||
if (status === 200) {
|
||||
return response.text().then(function (_responseText) {
|
||||
var result200 = null;
|
||||
var resultData200 = _responseText === "" ? null : JSON.parse(_responseText, _this.jsonParseReviver);
|
||||
result200 = Device.fromJS(resultData200);
|
||||
return result200;
|
||||
});
|
||||
}
|
||||
else if (status === 404) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("Device not found", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
else if (status !== 200 && status !== 204) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
};
|
||||
/**
|
||||
* Shut down device
|
||||
* @param deviceID ID of device to shut down
|
||||
* @return Message sent
|
||||
*/
|
||||
DeviceService.prototype.offlinedevice = function (deviceID) {
|
||||
var _this = this;
|
||||
var url_ = this.baseUrl + "/{deviceID}/offline";
|
||||
if (deviceID === undefined || deviceID === null)
|
||||
throw new Error("The parameter 'deviceID' must be defined.");
|
||||
url_ = url_.replace("{deviceID}", encodeURIComponent("" + deviceID));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
var options_ = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
return this.http.fetch(url_, options_).then(function (_response) {
|
||||
return _this.processOfflinedevice(_response);
|
||||
});
|
||||
};
|
||||
DeviceService.prototype.processOfflinedevice = function (response) {
|
||||
var status = response.status;
|
||||
var _headers = {};
|
||||
if (response.headers && response.headers.forEach) {
|
||||
response.headers.forEach(function (v, k) { return _headers[k] = v; });
|
||||
}
|
||||
;
|
||||
if (status === 200) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return;
|
||||
});
|
||||
}
|
||||
else if (status === 500) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("Message sending unsuccessful", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
else if (status !== 200 && status !== 204) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
};
|
||||
/**
|
||||
* Bring device online
|
||||
* @param deviceID ID of device to bring online
|
||||
* @return Message sent
|
||||
*/
|
||||
DeviceService.prototype.onlinedevice = function (deviceID) {
|
||||
var _this = this;
|
||||
var url_ = this.baseUrl + "/{deviceID}/online";
|
||||
if (deviceID === undefined || deviceID === null)
|
||||
throw new Error("The parameter 'deviceID' must be defined.");
|
||||
url_ = url_.replace("{deviceID}", encodeURIComponent("" + deviceID));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
var options_ = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
return this.http.fetch(url_, options_).then(function (_response) {
|
||||
return _this.processOnlinedevice(_response);
|
||||
});
|
||||
};
|
||||
DeviceService.prototype.processOnlinedevice = function (response) {
|
||||
var status = response.status;
|
||||
var _headers = {};
|
||||
if (response.headers && response.headers.forEach) {
|
||||
response.headers.forEach(function (v, k) { return _headers[k] = v; });
|
||||
}
|
||||
;
|
||||
if (status === 200) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return;
|
||||
});
|
||||
}
|
||||
else if (status === 500) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("Message sending unsuccessful", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
else if (status !== 200 && status !== 204) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
};
|
||||
/**
|
||||
* Get info about a particular device's sensor
|
||||
* @param deviceID ID of device to query
|
||||
* @param sensorID ID of sensor to query
|
||||
* @return Information about a sensor
|
||||
*/
|
||||
DeviceService.prototype.getsensor = function (deviceID, sensorID) {
|
||||
var _this = this;
|
||||
var url_ = this.baseUrl + "/{deviceID}/{sensorID}";
|
||||
if (deviceID === undefined || deviceID === null)
|
||||
throw new Error("The parameter 'deviceID' must be defined.");
|
||||
url_ = url_.replace("{deviceID}", encodeURIComponent("" + deviceID));
|
||||
if (sensorID === undefined || sensorID === null)
|
||||
throw new Error("The parameter 'sensorID' must be defined.");
|
||||
url_ = url_.replace("{sensorID}", encodeURIComponent("" + sensorID));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
var options_ = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
return this.http.fetch(url_, options_).then(function (_response) {
|
||||
return _this.processGetsensor(_response);
|
||||
});
|
||||
};
|
||||
DeviceService.prototype.processGetsensor = function (response) {
|
||||
var _this = this;
|
||||
var status = response.status;
|
||||
var _headers = {};
|
||||
if (response.headers && response.headers.forEach) {
|
||||
response.headers.forEach(function (v, k) { return _headers[k] = v; });
|
||||
}
|
||||
;
|
||||
if (status === 200) {
|
||||
return response.text().then(function (_responseText) {
|
||||
var result200 = null;
|
||||
var resultData200 = _responseText === "" ? null : JSON.parse(_responseText, _this.jsonParseReviver);
|
||||
result200 = Sensor.fromJS(resultData200);
|
||||
return result200;
|
||||
});
|
||||
}
|
||||
else if (status === 404) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("Device or sensor not found", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
else if (status !== 200 && status !== 204) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
};
|
||||
/**
|
||||
* Shut down sensor
|
||||
* @param deviceID ID of device to query
|
||||
* @param sensorID ID of sensor to query
|
||||
* @return Message sent
|
||||
*/
|
||||
DeviceService.prototype.offlinesensor = function (deviceID, sensorID) {
|
||||
var _this = this;
|
||||
var url_ = this.baseUrl + "/{deviceID}/{sensorID}/offline";
|
||||
if (deviceID === undefined || deviceID === null)
|
||||
throw new Error("The parameter 'deviceID' must be defined.");
|
||||
url_ = url_.replace("{deviceID}", encodeURIComponent("" + deviceID));
|
||||
if (sensorID === undefined || sensorID === null)
|
||||
throw new Error("The parameter 'sensorID' must be defined.");
|
||||
url_ = url_.replace("{sensorID}", encodeURIComponent("" + sensorID));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
var options_ = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
return this.http.fetch(url_, options_).then(function (_response) {
|
||||
return _this.processOfflinesensor(_response);
|
||||
});
|
||||
};
|
||||
DeviceService.prototype.processOfflinesensor = function (response) {
|
||||
var status = response.status;
|
||||
var _headers = {};
|
||||
if (response.headers && response.headers.forEach) {
|
||||
response.headers.forEach(function (v, k) { return _headers[k] = v; });
|
||||
}
|
||||
;
|
||||
if (status === 200) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return;
|
||||
});
|
||||
}
|
||||
else if (status === 500) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("Message sending unsuccessful", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
else if (status !== 200 && status !== 204) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
};
|
||||
/**
|
||||
* Bring sensor online
|
||||
* @param deviceID ID of device to query
|
||||
* @param sensorID ID of sensor to query
|
||||
* @return Message sent
|
||||
*/
|
||||
DeviceService.prototype.onlinesensor = function (deviceID, sensorID) {
|
||||
var _this = this;
|
||||
var url_ = this.baseUrl + "/{deviceID}/{sensorID}/online";
|
||||
if (deviceID === undefined || deviceID === null)
|
||||
throw new Error("The parameter 'deviceID' must be defined.");
|
||||
url_ = url_.replace("{deviceID}", encodeURIComponent("" + deviceID));
|
||||
if (sensorID === undefined || sensorID === null)
|
||||
throw new Error("The parameter 'sensorID' must be defined.");
|
||||
url_ = url_.replace("{sensorID}", encodeURIComponent("" + sensorID));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
var options_ = {
|
||||
method: "POST",
|
||||
headers: {}
|
||||
};
|
||||
return this.http.fetch(url_, options_).then(function (_response) {
|
||||
return _this.processOnlinesensor(_response);
|
||||
});
|
||||
};
|
||||
DeviceService.prototype.processOnlinesensor = function (response) {
|
||||
var status = response.status;
|
||||
var _headers = {};
|
||||
if (response.headers && response.headers.forEach) {
|
||||
response.headers.forEach(function (v, k) { return _headers[k] = v; });
|
||||
}
|
||||
;
|
||||
if (status === 200) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return;
|
||||
});
|
||||
}
|
||||
else if (status === 500) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("Message sending unsuccessful", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
else if (status !== 200 && status !== 204) {
|
||||
return response.text().then(function (_responseText) {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
};
|
||||
return DeviceService;
|
||||
}());
|
||||
exports.default = DeviceService;
|
||||
var Device = /** @class */ (function () {
|
||||
function Device(data) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
this[property] = data[property];
|
||||
}
|
||||
}
|
||||
if (!data) {
|
||||
this.coordinates = new Coordinates();
|
||||
this.sensors = [];
|
||||
}
|
||||
}
|
||||
Device.prototype.init = function (_data) {
|
||||
if (_data) {
|
||||
this.id = _data["id"];
|
||||
this.status = _data["status"];
|
||||
this.url = _data["url"];
|
||||
this.coordinates = _data["coordinates"] ? Coordinates.fromJS(_data["coordinates"]) : new Coordinates();
|
||||
if (Array.isArray(_data["sensors"])) {
|
||||
this.sensors = [];
|
||||
for (var _i = 0, _a = _data["sensors"]; _i < _a.length; _i++) {
|
||||
var item = _a[_i];
|
||||
this.sensors.push(Sensor.fromJS(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Device.fromJS = function (data) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
var result = new Device();
|
||||
result.init(data);
|
||||
return result;
|
||||
};
|
||||
Device.prototype.toJSON = function (data) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["id"] = this.id;
|
||||
data["status"] = this.status;
|
||||
data["url"] = this.url;
|
||||
data["coordinates"] = this.coordinates ? this.coordinates.toJSON() : undefined;
|
||||
if (Array.isArray(this.sensors)) {
|
||||
data["sensors"] = [];
|
||||
for (var _i = 0, _a = this.sensors; _i < _a.length; _i++) {
|
||||
var item = _a[_i];
|
||||
data["sensors"].push(item.toJSON());
|
||||
}
|
||||
}
|
||||
return data;
|
||||
};
|
||||
return Device;
|
||||
}());
|
||||
exports.Device = Device;
|
||||
var Sensor = /** @class */ (function () {
|
||||
function Sensor(data) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
this[property] = data[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
Sensor.prototype.init = function (_data) {
|
||||
if (_data) {
|
||||
this.id = _data["id"];
|
||||
this.status = _data["status"];
|
||||
}
|
||||
};
|
||||
Sensor.fromJS = function (data) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
var result = new Sensor();
|
||||
result.init(data);
|
||||
return result;
|
||||
};
|
||||
Sensor.prototype.toJSON = function (data) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["id"] = this.id;
|
||||
data["status"] = this.status;
|
||||
return data;
|
||||
};
|
||||
return Sensor;
|
||||
}());
|
||||
exports.Sensor = Sensor;
|
||||
var DeviceStatus;
|
||||
(function (DeviceStatus) {
|
||||
DeviceStatus["Online"] = "online";
|
||||
DeviceStatus["Error"] = "error";
|
||||
DeviceStatus["Offline"] = "offline";
|
||||
})(DeviceStatus = exports.DeviceStatus || (exports.DeviceStatus = {}));
|
||||
var Coordinates = /** @class */ (function () {
|
||||
function Coordinates(data) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
this[property] = data[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
Coordinates.prototype.init = function (_data) {
|
||||
if (_data) {
|
||||
this.latitude = _data["latitude"];
|
||||
this.longitude = _data["longitude"];
|
||||
}
|
||||
};
|
||||
Coordinates.fromJS = function (data) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
var result = new Coordinates();
|
||||
result.init(data);
|
||||
return result;
|
||||
};
|
||||
Coordinates.prototype.toJSON = function (data) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["latitude"] = this.latitude;
|
||||
data["longitude"] = this.longitude;
|
||||
return data;
|
||||
};
|
||||
return Coordinates;
|
||||
}());
|
||||
exports.Coordinates = Coordinates;
|
||||
var SensorStatus;
|
||||
(function (SensorStatus) {
|
||||
SensorStatus["Online"] = "online";
|
||||
SensorStatus["Unknown"] = "unknown";
|
||||
SensorStatus["Offline"] = "offline";
|
||||
})(SensorStatus = exports.SensorStatus || (exports.SensorStatus = {}));
|
||||
var ApiException = /** @class */ (function (_super) {
|
||||
__extends(ApiException, _super);
|
||||
function ApiException(message, status, response, headers, result) {
|
||||
var _this = _super.call(this) || this;
|
||||
_this.isApiException = true;
|
||||
_this.message = message;
|
||||
_this.status = status;
|
||||
_this.response = response;
|
||||
_this.headers = headers;
|
||||
_this.result = result;
|
||||
return _this;
|
||||
}
|
||||
ApiException.isApiException = function (obj) {
|
||||
return obj.isApiException === true;
|
||||
};
|
||||
return ApiException;
|
||||
}(Error));
|
||||
exports.ApiException = ApiException;
|
||||
function throwException(message, status, response, headers, result) {
|
||||
if (result !== null && result !== undefined)
|
||||
throw result;
|
||||
else
|
||||
throw new ApiException(message, status, response, headers, null);
|
||||
}
|
||||
//# sourceMappingURL=DeviceService.js.map
|
1
Birdmap.API/ClientApp/src/common/DeviceService.js.map
Normal file
1
Birdmap.API/ClientApp/src/common/DeviceService.js.map
Normal file
File diff suppressed because one or more lines are too long
607
Birdmap.API/ClientApp/src/common/DeviceService.ts
Normal file
607
Birdmap.API/ClientApp/src/common/DeviceService.ts
Normal file
@ -0,0 +1,607 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
//----------------------
|
||||
// <auto-generated>
|
||||
// Generated using the NSwag toolchain v13.8.2.0 (NJsonSchema v10.2.1.0 (Newtonsoft.Json v12.0.0.0)) (http://NSwag.org)
|
||||
// </auto-generated>
|
||||
//----------------------
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
export default class DeviceService {
|
||||
private http: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> };
|
||||
private baseUrl: string;
|
||||
protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined;
|
||||
|
||||
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise<Response> }) {
|
||||
this.http = http ? http : <any>window;
|
||||
this.baseUrl = baseUrl !== undefined && baseUrl !== null ? baseUrl : "api/devices";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all device info
|
||||
* @return Array of devices
|
||||
*/
|
||||
getall(): Promise<Device[]> {
|
||||
let url_ = this.baseUrl;
|
||||
|
||||
let options_ = <RequestInit>{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processGetall(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetall(response: Response): Promise<Device[]> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
if (Array.isArray(resultData200)) {
|
||||
result200 = [] as any;
|
||||
for (let item of resultData200)
|
||||
result200!.push(Device.fromJS(item));
|
||||
}
|
||||
return result200;
|
||||
});
|
||||
} else if (status === 404) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("No device found", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<Device[]>(<any>null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shut down all devices
|
||||
* @return Message sent
|
||||
*/
|
||||
offlineall(): Promise<void> {
|
||||
let url_ = this.baseUrl + "/offline";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_ = <RequestInit>{
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processOfflineall(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processOfflineall(response: Response): Promise<void> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
return;
|
||||
});
|
||||
} else if (status === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("Message sending unsuccessful", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<void>(<any>null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bring all devices online
|
||||
* @return Message sent
|
||||
*/
|
||||
onlineall(): Promise<void> {
|
||||
let url_ = this.baseUrl + "/online";
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_ = <RequestInit>{
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processOnlineall(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processOnlineall(response: Response): Promise<void> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
return;
|
||||
});
|
||||
} else if (status === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("Message sending unsuccessful", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<void>(<any>null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all device info
|
||||
* @param deviceID ID of device to query
|
||||
* @return Information about a particular device
|
||||
*/
|
||||
getdevice(deviceID: string): Promise<Device> {
|
||||
let url_ = this.baseUrl + "/{deviceID}";
|
||||
if (deviceID === undefined || deviceID === null)
|
||||
throw new Error("The parameter 'deviceID' must be defined.");
|
||||
url_ = url_.replace("{deviceID}", encodeURIComponent("" + deviceID));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_ = <RequestInit>{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processGetdevice(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetdevice(response: Response): Promise<Device> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result200 = Device.fromJS(resultData200);
|
||||
return result200;
|
||||
});
|
||||
} else if (status === 404) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("Device not found", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<Device>(<any>null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shut down device
|
||||
* @param deviceID ID of device to shut down
|
||||
* @return Message sent
|
||||
*/
|
||||
offlinedevice(deviceID: string): Promise<void> {
|
||||
let url_ = this.baseUrl + "/{deviceID}/offline";
|
||||
if (deviceID === undefined || deviceID === null)
|
||||
throw new Error("The parameter 'deviceID' must be defined.");
|
||||
url_ = url_.replace("{deviceID}", encodeURIComponent("" + deviceID));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_ = <RequestInit>{
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processOfflinedevice(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processOfflinedevice(response: Response): Promise<void> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
return;
|
||||
});
|
||||
} else if (status === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("Message sending unsuccessful", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<void>(<any>null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bring device online
|
||||
* @param deviceID ID of device to bring online
|
||||
* @return Message sent
|
||||
*/
|
||||
onlinedevice(deviceID: string): Promise<void> {
|
||||
let url_ = this.baseUrl + "/{deviceID}/online";
|
||||
if (deviceID === undefined || deviceID === null)
|
||||
throw new Error("The parameter 'deviceID' must be defined.");
|
||||
url_ = url_.replace("{deviceID}", encodeURIComponent("" + deviceID));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_ = <RequestInit>{
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processOnlinedevice(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processOnlinedevice(response: Response): Promise<void> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
return;
|
||||
});
|
||||
} else if (status === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("Message sending unsuccessful", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<void>(<any>null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get info about a particular device's sensor
|
||||
* @param deviceID ID of device to query
|
||||
* @param sensorID ID of sensor to query
|
||||
* @return Information about a sensor
|
||||
*/
|
||||
getsensor(deviceID: string, sensorID: string): Promise<Sensor> {
|
||||
let url_ = this.baseUrl + "/{deviceID}/{sensorID}";
|
||||
if (deviceID === undefined || deviceID === null)
|
||||
throw new Error("The parameter 'deviceID' must be defined.");
|
||||
url_ = url_.replace("{deviceID}", encodeURIComponent("" + deviceID));
|
||||
if (sensorID === undefined || sensorID === null)
|
||||
throw new Error("The parameter 'sensorID' must be defined.");
|
||||
url_ = url_.replace("{sensorID}", encodeURIComponent("" + sensorID));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_ = <RequestInit>{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "application/json",
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processGetsensor(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processGetsensor(response: Response): Promise<Sensor> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
let result200: any = null;
|
||||
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
|
||||
result200 = Sensor.fromJS(resultData200);
|
||||
return result200;
|
||||
});
|
||||
} else if (status === 404) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("Device or sensor not found", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<Sensor>(<any>null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shut down sensor
|
||||
* @param deviceID ID of device to query
|
||||
* @param sensorID ID of sensor to query
|
||||
* @return Message sent
|
||||
*/
|
||||
offlinesensor(deviceID: string, sensorID: string): Promise<void> {
|
||||
let url_ = this.baseUrl + "/{deviceID}/{sensorID}/offline";
|
||||
if (deviceID === undefined || deviceID === null)
|
||||
throw new Error("The parameter 'deviceID' must be defined.");
|
||||
url_ = url_.replace("{deviceID}", encodeURIComponent("" + deviceID));
|
||||
if (sensorID === undefined || sensorID === null)
|
||||
throw new Error("The parameter 'sensorID' must be defined.");
|
||||
url_ = url_.replace("{sensorID}", encodeURIComponent("" + sensorID));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_ = <RequestInit>{
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processOfflinesensor(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processOfflinesensor(response: Response): Promise<void> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
return;
|
||||
});
|
||||
} else if (status === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("Message sending unsuccessful", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<void>(<any>null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bring sensor online
|
||||
* @param deviceID ID of device to query
|
||||
* @param sensorID ID of sensor to query
|
||||
* @return Message sent
|
||||
*/
|
||||
onlinesensor(deviceID: string, sensorID: string): Promise<void> {
|
||||
let url_ = this.baseUrl + "/{deviceID}/{sensorID}/online";
|
||||
if (deviceID === undefined || deviceID === null)
|
||||
throw new Error("The parameter 'deviceID' must be defined.");
|
||||
url_ = url_.replace("{deviceID}", encodeURIComponent("" + deviceID));
|
||||
if (sensorID === undefined || sensorID === null)
|
||||
throw new Error("The parameter 'sensorID' must be defined.");
|
||||
url_ = url_.replace("{sensorID}", encodeURIComponent("" + sensorID));
|
||||
url_ = url_.replace(/[?&]$/, "");
|
||||
|
||||
let options_ = <RequestInit>{
|
||||
method: "POST",
|
||||
headers: {
|
||||
}
|
||||
};
|
||||
|
||||
return this.http.fetch(url_, options_).then((_response: Response) => {
|
||||
return this.processOnlinesensor(_response);
|
||||
});
|
||||
}
|
||||
|
||||
protected processOnlinesensor(response: Response): Promise<void> {
|
||||
const status = response.status;
|
||||
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
|
||||
if (status === 200) {
|
||||
return response.text().then((_responseText) => {
|
||||
return;
|
||||
});
|
||||
} else if (status === 500) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("Message sending unsuccessful", status, _responseText, _headers);
|
||||
});
|
||||
} else if (status !== 200 && status !== 204) {
|
||||
return response.text().then((_responseText) => {
|
||||
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
||||
});
|
||||
}
|
||||
return Promise.resolve<void>(<any>null);
|
||||
}
|
||||
}
|
||||
|
||||
export class Device implements IDevice {
|
||||
id!: string;
|
||||
status!: DeviceStatus;
|
||||
url!: string;
|
||||
coordinates!: Coordinates;
|
||||
sensors!: Sensor[];
|
||||
|
||||
constructor(data?: IDevice) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
(<any>this)[property] = (<any>data)[property];
|
||||
}
|
||||
}
|
||||
if (!data) {
|
||||
this.coordinates = new Coordinates();
|
||||
this.sensors = [];
|
||||
}
|
||||
}
|
||||
|
||||
init(_data?: any) {
|
||||
if (_data) {
|
||||
this.id = _data["id"];
|
||||
this.status = _data["status"];
|
||||
this.url = _data["url"];
|
||||
this.coordinates = _data["coordinates"] ? Coordinates.fromJS(_data["coordinates"]) : new Coordinates();
|
||||
if (Array.isArray(_data["sensors"])) {
|
||||
this.sensors = [] as any;
|
||||
for (let item of _data["sensors"])
|
||||
this.sensors!.push(Sensor.fromJS(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static fromJS(data: any): Device {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
let result = new Device();
|
||||
result.init(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
toJSON(data?: any) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["id"] = this.id;
|
||||
data["status"] = this.status;
|
||||
data["url"] = this.url;
|
||||
data["coordinates"] = this.coordinates ? this.coordinates.toJSON() : <any>undefined;
|
||||
if (Array.isArray(this.sensors)) {
|
||||
data["sensors"] = [];
|
||||
for (let item of this.sensors)
|
||||
data["sensors"].push(item.toJSON());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IDevice {
|
||||
id: string;
|
||||
status: DeviceStatus;
|
||||
url: string;
|
||||
coordinates: Coordinates;
|
||||
sensors: Sensor[];
|
||||
}
|
||||
|
||||
export class Sensor implements ISensor {
|
||||
id!: string;
|
||||
status!: SensorStatus;
|
||||
|
||||
constructor(data?: ISensor) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
(<any>this)[property] = (<any>data)[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(_data?: any) {
|
||||
if (_data) {
|
||||
this.id = _data["id"];
|
||||
this.status = _data["status"];
|
||||
}
|
||||
}
|
||||
|
||||
static fromJS(data: any): Sensor {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
let result = new Sensor();
|
||||
result.init(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
toJSON(data?: any) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["id"] = this.id;
|
||||
data["status"] = this.status;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ISensor {
|
||||
id: string;
|
||||
status: SensorStatus;
|
||||
}
|
||||
|
||||
export enum DeviceStatus {
|
||||
Online = "online",
|
||||
Error = "error",
|
||||
Offline = "offline",
|
||||
}
|
||||
|
||||
export class Coordinates implements ICoordinates {
|
||||
latitude!: number;
|
||||
longitude!: number;
|
||||
|
||||
constructor(data?: ICoordinates) {
|
||||
if (data) {
|
||||
for (var property in data) {
|
||||
if (data.hasOwnProperty(property))
|
||||
(<any>this)[property] = (<any>data)[property];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init(_data?: any) {
|
||||
if (_data) {
|
||||
this.latitude = _data["latitude"];
|
||||
this.longitude = _data["longitude"];
|
||||
}
|
||||
}
|
||||
|
||||
static fromJS(data: any): Coordinates {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
let result = new Coordinates();
|
||||
result.init(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
toJSON(data?: any) {
|
||||
data = typeof data === 'object' ? data : {};
|
||||
data["latitude"] = this.latitude;
|
||||
data["longitude"] = this.longitude;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ICoordinates {
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
}
|
||||
|
||||
export enum SensorStatus {
|
||||
Online = "online",
|
||||
Unknown = "unknown",
|
||||
Offline = "offline",
|
||||
}
|
||||
|
||||
export class ApiException extends Error {
|
||||
message: string;
|
||||
status: number;
|
||||
response: string;
|
||||
headers: { [key: string]: any; };
|
||||
result: any;
|
||||
|
||||
constructor(message: string, status: number, response: string, headers: { [key: string]: any; }, result: any) {
|
||||
super();
|
||||
|
||||
this.message = message;
|
||||
this.status = status;
|
||||
this.response = response;
|
||||
this.headers = headers;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
protected isApiException = true;
|
||||
|
||||
static isApiException(obj: any): obj is ApiException {
|
||||
return obj.isApiException === true;
|
||||
}
|
||||
}
|
||||
|
||||
function throwException(message: string, status: number, response: string, headers: { [key: string]: any; }, result?: any): any {
|
||||
if (result !== null && result !== undefined)
|
||||
throw result;
|
||||
else
|
||||
throw new ApiException(message, status, response, headers, null);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var ErrorDispatcher = {
|
||||
errorHandlers: [],
|
||||
registerErrorHandler: function (errorHandlerFn) {
|
||||
this.errorHandlers.push(errorHandlerFn);
|
||||
},
|
||||
raiseError: function (errorMessage) {
|
||||
for (var i = 0; i < this.errorHandlers.length; i++)
|
||||
this.errorHandlers[i](errorMessage);
|
||||
}
|
||||
};
|
||||
exports.default = ErrorDispatcher;
|
||||
//# sourceMappingURL=ErrorDispatcher.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"ErrorDispatcher.js","sourceRoot":"","sources":["ErrorDispatcher.ts"],"names":[],"mappings":";;AAAA,IAAM,eAAe,GAAG;IACtB,aAAa,EAAE,EAAE;IAEjB,oBAAoB,YAAC,cAAc;QACjC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC1C,CAAC;IAED,UAAU,YAAC,YAAY;QACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE;YAChD,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;IACxC,CAAC;CACF,CAAC;AAEF,kBAAe,eAAe,CAAC"}
|
@ -1,14 +0,0 @@
|
||||
const ErrorDispatcher = {
|
||||
errorHandlers: [],
|
||||
|
||||
registerErrorHandler(errorHandlerFn) {
|
||||
this.errorHandlers.push(errorHandlerFn);
|
||||
},
|
||||
|
||||
raiseError(errorMessage) {
|
||||
for (let i = 0; i < this.errorHandlers.length; i++)
|
||||
this.errorHandlers[i](errorMessage);
|
||||
}
|
||||
};
|
||||
|
||||
export default ErrorDispatcher;
|
@ -1,50 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var ErrorDispatcher_1 = require("./ErrorDispatcher");
|
||||
function get(url) {
|
||||
var options = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
return makeRequest(url, options);
|
||||
}
|
||||
function post(url, request) {
|
||||
var options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
},
|
||||
body: "",
|
||||
};
|
||||
if (request)
|
||||
options.body = JSON.stringify(request);
|
||||
return makeRequest(url, options);
|
||||
}
|
||||
function makeRequest(url, options) {
|
||||
return fetch(url, options)
|
||||
.then(ensureResponseSuccess)
|
||||
.catch(errorHandler);
|
||||
}
|
||||
function ensureResponseSuccess(response) {
|
||||
if (!response.ok)
|
||||
return response.json()
|
||||
.then(function (data) { return errorHandler(data); });
|
||||
return response.text()
|
||||
.then(function (text) { return text.length ? JSON.parse(text) : {}; });
|
||||
}
|
||||
function errorHandler(response) {
|
||||
console.log(response);
|
||||
if (response && response.Error)
|
||||
ErrorDispatcher_1.default.raiseError(response.Error);
|
||||
return Promise.reject();
|
||||
}
|
||||
exports.default = {
|
||||
get: get,
|
||||
post: post,
|
||||
makeRequest: makeRequest
|
||||
};
|
||||
//# sourceMappingURL=ServiceBase.js.map
|
@ -1 +0,0 @@
|
||||
{"version":3,"file":"ServiceBase.js","sourceRoot":"","sources":["ServiceBase.ts"],"names":[],"mappings":";;AAAA,qDAAgD;AAEhD,SAAS,GAAG,CAAC,GAAW;IACpB,IAAI,OAAO,GAAG;QACV,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACL,cAAc,EAAE,kBAAkB;YAClC,eAAe,EAAE,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC;SAClD;KACJ,CAAC;IAEF,OAAO,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,IAAI,CAAC,GAAW,EAAE,OAAY;IACnC,IAAI,OAAO,GAAG;QACV,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACL,cAAc,EAAE,kBAAkB;YAClC,eAAe,EAAE,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC;SAClD;QACD,IAAI,EAAE,EAAE;KACX,CAAC;IAEF,IAAI,OAAO;QACP,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAE3C,OAAO,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,WAAW,CAAC,GAAW,EAAE,OAAY;IAC1C,OAAO,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC;SACrB,IAAI,CAAC,qBAAqB,CAAC;SAC3B,KAAK,CAAC,YAAY,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,qBAAqB,CAAC,QAAa;IACxC,IAAI,CAAC,QAAQ,CAAC,EAAE;QACZ,OAAO,QAAQ,CAAC,IAAI,EAAE;aACjB,IAAI,CAAC,UAAC,IAAS,IAAK,OAAA,YAAY,CAAC,IAAI,CAAC,EAAlB,CAAkB,CAAC,CAAC;IAEjD,OAAO,QAAQ,CAAC,IAAI,EAAE;SACjB,IAAI,CAAC,UAAC,IAAS,IAAK,OAAA,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,EAAnC,CAAmC,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,YAAY,CAAC,QAAa;IAC/B,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEtB,IAAI,QAAQ,IAAI,QAAQ,CAAC,KAAK;QAC1B,yBAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE/C,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC;AAC5B,CAAC;AAED,kBAAe;IACX,GAAG,KAAA;IACH,IAAI,MAAA;IACJ,WAAW,aAAA;CACd,CAAC"}
|
@ -1,59 +0,0 @@
|
||||
import ErrorDispatcher from './ErrorDispatcher';
|
||||
|
||||
function get(url: string) {
|
||||
let options = {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
}
|
||||
};
|
||||
|
||||
return makeRequest(url, options);
|
||||
}
|
||||
|
||||
function post(url: string, request: any) {
|
||||
let options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': sessionStorage.getItem('user')
|
||||
},
|
||||
body: "",
|
||||
};
|
||||
|
||||
if (request)
|
||||
options.body = JSON.stringify(request);
|
||||
|
||||
return makeRequest(url, options);
|
||||
}
|
||||
|
||||
function makeRequest(url: string, options: any) {
|
||||
return fetch(url, options)
|
||||
.then(ensureResponseSuccess)
|
||||
.catch(errorHandler);
|
||||
}
|
||||
|
||||
function ensureResponseSuccess(response: any) {
|
||||
if (!response.ok)
|
||||
return response.json()
|
||||
.then((data: any) => errorHandler(data));
|
||||
|
||||
return response.text()
|
||||
.then((text: any) => text.length ? JSON.parse(text) : {});
|
||||
}
|
||||
|
||||
function errorHandler(response: any) {
|
||||
console.log(response);
|
||||
|
||||
if (response && response.Error)
|
||||
ErrorDispatcher.raiseError(response.Error);
|
||||
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
export default {
|
||||
get,
|
||||
post,
|
||||
makeRequest
|
||||
};
|
@ -1,59 +0,0 @@
|
||||
import { Box, Typography } from '@material-ui/core';
|
||||
import { BrowserRouter, NavLink, Redirect, Route, Switch } from 'react-router-dom';
|
||||
import { createStyles, makeStyles, Theme } from '@material-ui/core/styles';
|
||||
import React from 'react';
|
||||
|
||||
export default function BirdmapTitle(props: any) {
|
||||
const classes = useStyles();
|
||||
|
||||
return (
|
||||
<Box component="span" className={classes.root}>
|
||||
<Typography component="span" className={classes.bird}>
|
||||
<NavLink exact to="/" className={classes.nav_menu_item} activeClassName={classes.nav_menu_item_active}>
|
||||
Bird
|
||||
</NavLink>
|
||||
</Typography>
|
||||
<Typography component="span" className={classes.map}>
|
||||
<NavLink exact to="/heatmap" className={classes.nav_menu_item} activeClassName={classes.nav_menu_item_active}>
|
||||
map
|
||||
</NavLink>
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) =>
|
||||
createStyles({
|
||||
root: {
|
||||
display: 'inline',
|
||||
},
|
||||
bird: {
|
||||
textAlign: "left",
|
||||
fontWeight: 1000,
|
||||
fontSize: 30,
|
||||
textShadow: '3px 3px 0px rgba(0,0,0,0.2)',
|
||||
},
|
||||
map: {
|
||||
textAlign: "left",
|
||||
fontWeight: 100,
|
||||
fontSize: 26,
|
||||
textShadow: '2px 2px 0px rgba(0,0,0,0.2)',
|
||||
},
|
||||
nav_menu_item: {
|
||||
textDecoration: 'none',
|
||||
color: 'white',
|
||||
'&:hover': {
|
||||
textDecoration: 'underline',
|
||||
color: 'white',
|
||||
}
|
||||
},
|
||||
nav_menu_item_active: {
|
||||
textDecoration: 'none',
|
||||
color: 'white',
|
||||
'&:hover': {
|
||||
textDecoration: 'underline',
|
||||
color: 'white',
|
||||
}
|
||||
},
|
||||
}),
|
||||
);
|
Reference in New Issue
Block a user