diff --git a/src/ic/ic-pages/default-page.js b/src/ic/ic-pages/default-page.js new file mode 100644 index 0000000..dbff7db --- /dev/null +++ b/src/ic/ic-pages/default-page.js @@ -0,0 +1,42 @@ +/** + * This file is part of VILLASweb. + * + * VILLASweb is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VILLASweb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VILLASweb. If not, see . + ******************************************************************************/ + +import React from 'react'; +import {Col, Container, Row} from "react-bootstrap"; + +class DefaultICPage extends React.Component { + + constructor() { + super(); + } + + render() { + return (
+

{this.props.ic.name}

+ + + + {this.props.ICParamsTable(this.props.ic)} + + + +
+ ) + } +} + +export default DefaultICPage; diff --git a/src/ic/ic-pages/gateway-villas-node.js b/src/ic/ic-pages/gateway-villas-node.js new file mode 100644 index 0000000..3e09d0f --- /dev/null +++ b/src/ic/ic-pages/gateway-villas-node.js @@ -0,0 +1,169 @@ +/** + * This file is part of VILLASweb. + * + * VILLASweb is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VILLASweb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VILLASweb. If not, see . + ******************************************************************************/ + +import React from 'react'; +import {Button, Col, Container, Row} from "react-bootstrap"; +import IconButton from "../../common/icon-button"; +import ConfirmCommand from "../confirm-command"; +import FileSaver from 'file-saver'; +import AppDispatcher from "../../common/app-dispatcher"; + +class GatewayVillasNode extends React.Component { + + constructor() { + super(); + + this.state = { + confirmCommand: false, + command: '', + } + } + + async downloadGraph(url) { + let blob = await fetch(url).then(r => r.blob()) + FileSaver.saveAs(blob, this.props.ic.name + ".svg"); + } + + sendControlCommand() { + if (this.state.command === "restart") { + AppDispatcher.dispatch({ + type: 'ics/restart', + url: this.props.ic.apiurl + "/restart", + token: this.props.sessionToken, + }); + } else if (this.state.command === "shutdown") { + AppDispatcher.dispatch({ + type: 'ics/shutdown', + url: this.props.ic.apiurl + "/shutdown", + token: this.props.sessionToken, + }); + } + } + + confirmCommand(canceled){ + if(!canceled){ + this.sendControlCommand(); + } + + this.setState({confirmCommand: false, command: ''}); + } + + render() { + + let graphURL = "" + if (this.props.ic.apiurl !== "") { + graphURL = this.props.ic.apiurl + "/graph.svg" + } + + console.log("Villasnode Gateway: ", this.props.ic) + + return (
+ + +

{this.props.ic.name} + + + this.props.refresh(this.props.ic, this.props.sessionToken)} + icon='sync-alt' + buttonStyle={this.props.buttonStyle} + iconStyle={this.props.iconStyle} + /> + +

+ + + + + {this.props.ICParamsTable(this.props.ic)} + + +
+ this.downloadGraph(graphURL)} + icon='download' + buttonStyle={this.props.buttonStyle} + iconStyle={this.props.iconStyle} + /> +
+
+ Graph: +
+ {"Graph +
+ + {this.props.currentUser.role === "Admin" ? +
+
+ Controls: +
+ + +
+
+ :
+ } + this.confirmCommand(c)} + /> + + + + + Raw Status + {this.props.rawDataTable(this.props.ic.statusupdateraw)} + + + Raw Config + {this.props.rawDataTable(this.props.ic.statusupdateraw != null ? this.props.ic.statusupdateraw.config : null )} + + + Raw Statistics + {this.props.rawDataTable(this.props.ic.statusupdateraw != null ? this.props.ic.statusupdateraw.statistics : null)} + + + + + + +
+ ) + + } + +} + +export default GatewayVillasNode; diff --git a/src/ic/ic-pages/manager-villas-relay.js b/src/ic/ic-pages/manager-villas-relay.js new file mode 100644 index 0000000..04987ee --- /dev/null +++ b/src/ic/ic-pages/manager-villas-relay.js @@ -0,0 +1,62 @@ +/** + * This file is part of VILLASweb. + * + * VILLASweb is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * VILLASweb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with VILLASweb. If not, see . + ******************************************************************************/ + +import React from 'react'; +import IconButton from "../../common/icon-button"; +import {Col, Container, Row} from "react-bootstrap"; + +class ManagerVillasRelay extends React.Component { + + constructor() { + super(); + } + + render() { + return (
+ +

{this.props.ic.name} + + + this.props.refresh(this.props.ic, this.props.sessionToken)} + icon='sync-alt' + buttonStyle={this.props.buttonStyle} + iconStyle={this.props.iconStyle} + /> + +

+ + + + + {this.props.ICParamsTable(this.props.ic)} + + + Raw Status + {this.props.rawDataTable(this.props.ic.statusupdateraw)} + + + +
+ ) + } + +} + +export default ManagerVillasRelay; diff --git a/src/ic/ic.js b/src/ic/ic.js index 40e300b..444d825 100644 --- a/src/ic/ic.js +++ b/src/ic/ic.js @@ -20,22 +20,18 @@ import ICstore from './ic-store'; import ICdataStore from './ic-data-store' import { Container as FluxContainer } from 'flux/utils'; import AppDispatcher from '../common/app-dispatcher'; -import { Container, Col, Row, Table, Button } from 'react-bootstrap'; +import { Table, } from 'react-bootstrap'; import moment from 'moment'; import ReactJson from 'react-json-view'; -import ConfirmCommand from './confirm-command'; -import IconButton from '../common/icon-button'; -import FileSaver from 'file-saver'; - - +import GatewayVillasNode from './ic-pages/gateway-villas-node' +import ManagerVillasRelay from './ic-pages/manager-villas-relay' +import DefaultICPage from './ic-pages/default-page' class InfrastructureComponent extends React.Component { constructor(props) { super(props); this.state = { - confirmCommand: false, - command: '', sessionToken: localStorage.getItem("token"), currentUser: JSON.parse(localStorage.getItem("currentUser")), }; @@ -61,21 +57,19 @@ class InfrastructureComponent extends React.Component { }); } - - refresh() { + static refresh(ic, token) { // get status of VILLASnode and VILLASrelay ICs - if (this.state.ic.category === "gateway" && (this.state.ic.type === "villas-node" || this.state.ic.type === "villas-relay") - && this.state.ic.apiurl !== '' && this.state.ic.apiurl !== undefined && this.state.ic.apiurl !== null && !this.state.ic.managedexternally) { + if (ic.apiurl !== '' && ic.apiurl !== undefined && ic.apiurl !== null && !ic.managedexternally) { AppDispatcher.dispatch({ type: 'ics/get-status', - url: this.state.ic.apiurl, - token: this.state.sessionToken, - ic: this.state.ic + url: ic.apiurl, + token: token, + ic: ic }); } } - isJSON(data) { + static isJSON(data) { if (data === undefined || data === null) { return false; } @@ -89,46 +83,61 @@ class InfrastructureComponent extends React.Component { return true } - async downloadGraph(url) { - let blob = await fetch(url).then(r => r.blob()) - FileSaver.saveAs(blob, this.state.ic.name + ".svg"); - } - - sendControlCommand() { - if (this.state.command === "restart") { - AppDispatcher.dispatch({ - type: 'ics/restart', - url: this.state.ic.apiurl + "/restart", - token: this.state.sessionToken, - }); - } else if (this.state.command === "shutdown") { - AppDispatcher.dispatch({ - type: 'ics/shutdown', - url: this.state.ic.apiurl + "/shutdown", - token: this.state.sessionToken, - }); + static rawDataTable(rawData){ + if(rawData !== null && InfrastructureComponent.isJSON(rawData)){ + return ( + + ) + } else { + return ( +
No valid JSON raw data available.
+ ) } } - confirmCommand(canceled){ - if(!canceled){ - this.sendControlCommand(); - } - - this.setState({confirmCommand: false, command: ''}); + static ICParamsTable(ic) { + return ( + + + + + + + + + + + + + + + +
Name{ic.name}
Description{ic.description}
UUID{ic.uuid}
State{ic.state}
Category{ic.category}
Type{ic.type}
Uptime{moment.duration(ic.uptime, "seconds").humanize()}
Location{ic.location}
Websocket URL{ic.websocketurl}
API URL{ic.apiurl}
Start parameter schema + {InfrastructureComponent.isJSON(ic.startparameterschema) ? + :
No Start parameter schema JSON available.
} +
+ ) } - render() { if (this.state.ic === undefined) { return

Loading Infrastructure Component...

; } - let graphURL = "" - if (this.state.ic.apiurl !== "") { - graphURL = this.state.ic.apiurl + "/graph.svg" - } - const buttonStyle = { marginLeft: '5px', } @@ -138,196 +147,36 @@ class InfrastructureComponent extends React.Component { width: '25px' } - return
-

{this.state.ic.name}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Name{this.state.ic.name}
Description{this.state.ic.description}
UUID{this.state.ic.uuid}
State{this.state.ic.state}
Category{this.state.ic.category}
Type{this.state.ic.type}
Uptime{moment.duration(this.state.ic.uptime, "seconds").humanize()}
Location{this.state.ic.location}
Websocket URL{this.state.ic.websocketurl}
API URL{this.state.ic.apiurl}
Start parameter schema - {this.isJSON(this.state.ic.startparameterschema) ? - :
No Start parameter schema JSON available.
} -
- - - {this.state.category ==="gateway" && this.state.ic.type === "villas-node" ? - <> -
- this.downloadGraph(graphURL)} - icon='download' - buttonStyle={buttonStyle} - iconStyle={iconStyle} - /> -
-
- Graph: -
- {"Graph -
- - {this.state.currentUser.role === "Admin" ? -
-
- Controls: -
- - -
-
- :
- } - this.confirmCommand(c)} - /> - - :
} - - {this.state.category ==="gateway" && this.state.ic.type === "villas-relay" ? - <> -
- this.refresh()} - icon='sync-alt' - buttonStyle={buttonStyle} - iconStyle={iconStyle} - /> -
-
- Raw Status - {this.state.ic.statusupdateraw !== null && this.isJSON(this.state.ic.statusupdateraw) ? - :
No valid JSON raw data available.
} - - : -
} - - - {this.state.category ==="gateway" && this.state.ic.type === "villas-node" ? - <> -
- this.refresh()} - icon='sync-alt' - buttonStyle={buttonStyle} - iconStyle={iconStyle} - /> -
- - - - Raw Status - {this.state.ic.statusupdateraw !== null && this.isJSON(this.state.ic.statusupdateraw) ? - :
No valid JSON raw data available.
} - - - Raw Config - {this.state.ic.statusupdateraw && this.isJSON(this.state.ic.statusupdateraw["config"]) ? - :
No valid config JSON raw data available.
} - - - Raw Statistics - {this.state.ic.statusupdateraw && this.isJSON(this.state.ic.statusupdateraw["statistics"]) ? - :
No valid statistics JSON raw data available.
} - - -
- :
} - -
; + let page = <>IC page not defined + if (this.state.ic.category ==="gateway" && this.state.ic.type === "villas-node") { + page = InfrastructureComponent.ICParamsTable(ic)} + rawDataTable = {(rawData) => InfrastructureComponent.rawDataTable(rawData)} + refresh = {(ic, token) => InfrastructureComponent.refresh(ic, token)} + buttonStyle = {buttonStyle} + iconStyle = {iconStyle} + /> + } else if (this.state.ic.category ==="manager" && this.state.ic.type === "villas-relay") { + page = InfrastructureComponent.ICParamsTable(ic)} + rawDataTable = {(rawData) => InfrastructureComponent.rawDataTable(rawData)} + refresh = {(ic, token) => InfrastructureComponent.refresh(ic, token)} + buttonStyle = {buttonStyle} + iconStyle = {iconStyle} + /> + } else { + page = InfrastructureComponent.ICParamsTable(ic)} + /> + } + return page } }