diff --git a/src/components/dialogs/edit-node.js b/src/components/dialogs/edit-node.js deleted file mode 100644 index beba460..0000000 --- a/src/components/dialogs/edit-node.js +++ /dev/null @@ -1,104 +0,0 @@ -/** - * File: edit-node.js - * Author: Markus Grigull - * Date: 06.07.2017 - * - * 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 { FormGroup, FormControl, ControlLabel } from 'react-bootstrap'; - -import Dialog from './dialog'; - -class NewNodeDialog extends React.Component { - valid: false; - - constructor(props) { - super(props); - - this.state = { - name: '', - endpoint: '', - config: {}, - simulators: [], - _id: '' - }; - } - - onClose(canceled) { - if (canceled === false) { - if (this.valid) { - this.props.onClose(this.state); - } - } else { - this.props.onClose(); - } - } - - handleChange(e) { - if (e.target.type === 'checkbox') { - this.setState({ [e.target.id]: e.target.checked }); - } else { - this.setState({ [e.target.id]: e.target.value }); - } - } - - resetState() { - this.setState({ name: this.props.node.name, endpoint: this.props.node.endpoint, config: this.props.node.config, simulators: this.props.node.simulators, _id: this.props.node._id }); - } - - validateForm(target) { - // check all controls - var endpoint = true; - var name = true; - - if (this.state.name === '' || this.props.nodes.find(node => node._id !== this.state._id && node.name === this.state.name) !== undefined) { - name = false; - } - - if (this.state.endpoint === '' || this.props.nodes.find(node => node._id !== this.state._id && node.endpoint === this.state.endpoint) !== undefined) { - endpoint = false; - } - - this.valid = endpoint && name; - - // return state to control - if (target === 'name') return name ? "success" : "error"; - else return endpoint ? "success" : "error"; - } - - render() { - return ( - this.onClose(c)} onReset={() => this.resetState()} valid={this.valid}> -
- - Name - this.handleChange(e)} /> - - - - Endpoint - this.handleChange(e)} /> - - -
-
- ); - } -} - -export default NewNodeDialog; diff --git a/src/components/dialogs/import-node.js b/src/components/dialogs/import-node.js deleted file mode 100644 index c91f772..0000000 --- a/src/components/dialogs/import-node.js +++ /dev/null @@ -1,129 +0,0 @@ -/** - * File: import-node.js - * Author: Markus Grigull - * Date: 03.09.2017 - * - * 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 { FormGroup, FormControl, ControlLabel } from 'react-bootstrap'; - -import Dialog from './dialog'; - -class ImportNodeDialog extends React.Component { - valid = false; - imported = false; - - constructor(props) { - super(props); - - this.state = { - name: '', - endpoint: '', - simulators: [] - }; - } - - onClose(canceled) { - if (canceled === false) { - this.props.onClose(this.state); - } else { - this.props.onClose(); - } - } - - handleChange(e) { - if (e.target.type === 'checkbox') { - this.setState({ [e.target.id]: e.target.checked }); - } else { - this.setState({ [e.target.id]: e.target.value }); - } - } - - resetState() { - this.setState({ name: '', endpoint: '' }); - - this.imported = false; - } - - loadFile(fileList) { - // get file - const file = fileList[0]; - if (!file.type.match('application/json')) { - return; - } - - // create file reader - const reader = new FileReader(); - const self = this; - - reader.onload = function(event) { - // read simulator - const node = JSON.parse(event.target.result); - self.imported = true; - self.setState({ name: node.name, endpoint: node.endpoint, simulators: node.simulators }); - }; - - reader.readAsText(file); - } - - validateForm(target) { - // check all controls - let endpoint = true; - let name = true; - - if (this.state.name === '' || this.props.nodes.find(node => node.name === this.state.name) !== undefined) { - name = false; - } - - if (this.state.endpoint === '' || this.props.nodes.find(node => node.endpoint === this.state.endpoint) !== undefined) { - endpoint = false; - } - - this.valid = endpoint && name; - - // return state to control - if (target === 'name') return name ? "success" : "error"; - else return endpoint ? "success" : "error"; - } - - render() { - return ( - this.onClose(c)} onReset={() => this.resetState()} valid={this.valid}> -
- - Simulator File - this.loadFile(e.target.files)} /> - - - - Name - this.handleChange(e)} /> - - - - Endpoint - this.handleChange(e)} /> - - -
-
- ); - } -} - -export default ImportNodeDialog; diff --git a/src/components/dialogs/new-node.js b/src/components/dialogs/new-node.js deleted file mode 100644 index aedd1ee..0000000 --- a/src/components/dialogs/new-node.js +++ /dev/null @@ -1,103 +0,0 @@ -/** - * File: new-node.js - * Author: Markus Grigull - * Date: 06.07.2017 - * - * 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 { FormGroup, FormControl, ControlLabel } from 'react-bootstrap'; - -import Dialog from './dialog'; - -class NewNodeDialog extends React.Component { - valid = false; - - constructor(props) { - super(props); - - this.state = { - name: '', - endpoint: '', - config: {}, - simulators: [] - }; - } - - onClose(canceled) { - if (canceled === false) { - if (this.valid) { - this.props.onClose(this.state); - } - } else { - this.props.onClose(); - } - } - - handleChange(e) { - if (e.target.type === 'checkbox') { - this.setState({ [e.target.id]: e.target.checked }); - } else { - this.setState({ [e.target.id]: e.target.value }); - } - } - - resetState() { - this.setState({ name: '', endpoint: '', config: {}, simulators: [] }); - } - - validateForm(target) { - // check all controls - var endpoint = true; - var name = true; - - if (this.state.name === '' || this.props.nodes.find(node => node.name === this.state.name) !== undefined) { - name = false; - } - - if (this.state.endpoint === '' || this.props.nodes.find(node => node.endpoint === this.state.endpoint) !== undefined) { - endpoint = false; - } - - this.valid = endpoint && name; - - // return state to control - if (target === 'name') return name ? "success" : "error"; - else return endpoint ? "success" : "error"; - } - - render() { - return ( - this.onClose(c)} onReset={() => this.resetState()} valid={this.valid}> -
- - Name - this.handleChange(e)} /> - - - - Endpoint - this.handleChange(e)} /> - - -
-
- ); - } -} - -export default NewNodeDialog;