Added context

This commit is contained in:
2020-11-18 09:56:30 +01:00
parent 41bf14a4e5
commit 490f0f3265
17 changed files with 69 additions and 235 deletions

View File

@ -0,0 +1,59 @@
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',
}
},
}),
);

View File

@ -1,614 +0,0 @@
"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

File diff suppressed because one or more lines are too long

View File

@ -1,607 +0,0 @@
/* 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);
}

View File

@ -1,11 +1,8 @@
import React, { Component } from 'react'
import DeviceService from './DeviceService'
import Accordion from '@material-ui/core/Accordion';
import DeviceComponent from './DeviceComponent'
import SensorComponent from './DeviceComponent'
import { Box } from '@material-ui/core';
import { withStyles } from '@material-ui/styles';
import { Box } from '@material-ui/core';
import { grey } from '@material-ui/core/colors';
import React from 'react';
import DevicesContext from '../../contexts/DevicesContext';
import DeviceComponent from './DeviceComponent';
const styles = theme => ({
root: {
@ -17,23 +14,16 @@ const styles = theme => ({
class Devices extends React.Component {
constructor(props) {
super(props);
this.state = {
devices: [],
};
}
static contextType = DevicesContext;
componentDidMount() {
new DeviceService().getall().then(result => {
this.setState({ devices: result });
}).catch(ex => {
console.log(ex);
});
}
render() {
const { classes } = this.props;
const Devices = this.state.devices.map((device, index) => (
const Devices = this.context.devices.map((device, index) => (
<DeviceComponent device={device} index={index} key={device.id}/>
));

View File

@ -1,15 +0,0 @@
import React, { Component } from 'react';
import AccordionDetails from '@material-ui/core/AccordionDetails';
export default class SensorComponent extends Component {
constructor(props) {
super(props);
}
render() {
return (
);
}
}

View File

@ -1,7 +1,7 @@
/*global google*/
import GoogleMapReact from 'google-map-react';
import React, { Component } from 'react';
import DeviceService from '../devices/DeviceService'
import DeviceService from '../../common/DeviceService'
import DeviceMarker from './DeviceMarker'
import { HubConnectionBuilder } from '@microsoft/signalr';
@ -75,7 +75,7 @@ export default class MapContainer extends Component {
newConnection.on(update_method_name, (id) => {
service.getdevice(id).then(result => {
var index = this.state.devices.findIndex((d => d.id == id));
var index = this.state.devices.findIndex((d => d.id === id));
const newDevices = [...this.state.devices];
newDevices[index] = result;
this.setState({ devices: newDevices });