From 3b58073285cc096d40c69120bd8ac9e8c983643d Mon Sep 17 00:00:00 2001 From: Markus Grigull Date: Sun, 9 Jul 2017 18:14:53 +0200 Subject: [PATCH] Change simulator selection in simulator model Disable simulator detection for testing --- .../dialog/edit-simulation-model.js | 22 +++++++++----- src/components/dialog/new-simulation-model.js | 21 ++++++++----- src/containers/app.js | 30 ++++++++++--------- src/containers/simulation.js | 24 ++++++--------- src/containers/simulators.js | 5 +++- src/data-managers/nodes-data-manager.js | 15 +++++++--- 6 files changed, 69 insertions(+), 48 deletions(-) diff --git a/src/components/dialog/edit-simulation-model.js b/src/components/dialog/edit-simulation-model.js index 3de81dd..de5855d 100644 --- a/src/components/dialog/edit-simulation-model.js +++ b/src/components/dialog/edit-simulation-model.js @@ -31,7 +31,7 @@ class EditSimulationModelDialog extends Component { show: PropTypes.bool.isRequired, onClose: PropTypes.func.isRequired, data: PropTypes.object.isRequired, - simulators: PropTypes.array.isRequired + nodes: PropTypes.array.isRequired }; valid: false; @@ -41,8 +41,9 @@ class EditSimulationModelDialog extends Component { this.state = { name: '', - simulator: '', - length: 1 + simulator: { node: '', simulator: '' }, + length: 1, + mapping: [{ name: 'Signal', type: 'Type' }] } } @@ -68,7 +69,12 @@ class EditSimulationModelDialog extends Component { } } - this.setState({ [e.target.id]: e.target.value }); + if (e.target.id === 'simulator') { + var value = e.target.value.split("/"); + this.setState({ simulator: { node: value[0], simulator: value[1] } }); + } else { + this.setState({ [e.target.id]: e.target.value }); + } } handleMappingChange(event, row, column) { @@ -124,9 +130,11 @@ class EditSimulationModelDialog extends Component { Simulator - this.handleChange(e)}> - {this.props.simulators.map(simulator => ( - + this.handleChange(e)}> + {this.props.nodes.map(node => ( + node.simulators.map((simulator, index) => ( + + )) ))} diff --git a/src/components/dialog/new-simulation-model.js b/src/components/dialog/new-simulation-model.js index 5789e51..0acc38d 100644 --- a/src/components/dialog/new-simulation-model.js +++ b/src/components/dialog/new-simulation-model.js @@ -30,7 +30,7 @@ class NewSimulationModelDialog extends Component { static propTypes = { show: PropTypes.bool.isRequired, onClose: PropTypes.func.isRequired, - simulators: PropTypes.array.isRequired + nodes: PropTypes.array.isRequired }; valid: false; @@ -40,7 +40,7 @@ class NewSimulationModelDialog extends Component { this.state = { name: '', - simulator: '', + simulator: { node: '', simulator: '' }, length: '1', mapping: [ { name: 'Signal', type: 'Type' } ] }; @@ -68,7 +68,12 @@ class NewSimulationModelDialog extends Component { } } - this.setState({ [e.target.id]: e.target.value }); + if (e.target.id === 'simulator') { + var value = e.target.value.split("/"); + this.setState({ simulator: { node: value[0], simulator: value[1] } }); + } else { + this.setState({ [e.target.id]: e.target.value }); + } } handleMappingChange(event, row, column) { @@ -86,7 +91,7 @@ class NewSimulationModelDialog extends Component { resetState() { this.setState({ name: '', - simulator: this.props.simulators[0] != null ? this.props.simulators[0]._id : '', + simulator: { node: this.props.nodes[0] ? this.props.nodes[0].name : '', simulator: this.props.nodes[0].simulators[0] ? this.props.nodes[0].simulators[0].name : '' }, length: '1', mapping: [ { name: 'Signal', type: 'Type' } ] }); @@ -130,9 +135,11 @@ class NewSimulationModelDialog extends Component { Simulator - this.handleChange(e)}> - {this.props.simulators.map(simulator => ( - + this.handleChange(e)}> + {this.props.nodes.map(node => ( + node.simulators.map((simulator, index) => ( + + )) ))} diff --git a/src/containers/app.js b/src/containers/app.js index 14d02cc..adc5f05 100644 --- a/src/containers/app.js +++ b/src/containers/app.js @@ -27,7 +27,7 @@ import NotificationSystem from 'react-notification-system'; import AppDispatcher from '../app-dispatcher'; import SimulationStore from '../stores/simulation-store'; -import SimulatorStore from '../stores/simulator-store'; +//import SimulatorStore from '../stores/simulator-store'; import NodeStore from '../stores/node-store'; import UserStore from '../stores/user-store'; import NotificationsDataManager from '../data-managers/notifications-data-manager'; @@ -41,12 +41,12 @@ import '../styles/app.css'; class App extends Component { static getStores() { - return [ SimulationStore, NodeStore, UserStore ]; + return [ NodeStore, UserStore, SimulationStore ]; } static calculateState(prevState) { // get list of running simulators - var simulators = SimulatorStore.getState().filter(simulator => { + /*var simulators = SimulatorStore.getState().filter(simulator => { return simulator.running === true; }); @@ -75,16 +75,16 @@ class App extends Component { if (equal) { simulators = prevState.runningSimulators; } - } + }*/ let currentUser = UserStore.getState().currentUser; return { - simulations: SimulationStore.getState(), + nodes: NodeStore.getState(), currentRole: currentUser? currentUser.role : '', - token: UserStore.getState().token, + token: UserStore.getState().token/*, - runningSimulators: simulators + runningSimulators: simulators*/ }; } @@ -104,7 +104,7 @@ class App extends Component { // load all simulators and simulations to fetch simulation data AppDispatcher.dispatch({ - type: 'simulators/start-load' + type: 'nodes/start-load' }); AppDispatcher.dispatch({ @@ -136,7 +136,9 @@ class App extends Component { } requiredSimulatorsBySimulations() { - var simulators = []; + return []; + + /*var simulators = []; this.state.simulations.forEach((simulation) => { simulation.models.forEach((simulationModel) => { @@ -155,24 +157,24 @@ class App extends Component { }); }); - return simulators; + return simulators;*/ } - connectSimulator(state, data) { + /*connectSimulator(state, data) { // get simulator object const simulator = state.runningSimulators.find(element => { return element._id === data.simulator; }); if (simulator != null) { - /*AppDispatcher.dispatch({ + AppDispatcher.dispatch({ type: 'simulatorData/open', identifier: simulator._id, endpoint: simulator.endpoint, signals: data.signals - });*/ + }); } - } + }*/ render() { // get children diff --git a/src/containers/simulation.js b/src/containers/simulation.js index 59e37c5..52f5649 100644 --- a/src/containers/simulation.js +++ b/src/containers/simulation.js @@ -24,7 +24,7 @@ import { Container } from 'flux/utils'; import { Button, Modal, Glyphicon } from 'react-bootstrap'; import SimulationStore from '../stores/simulation-store'; -import SimulatorStore from '../stores/simulator-store'; +import NodeStore from '../stores/node-store'; import AppDispatcher from '../app-dispatcher'; import Table from '../components/table'; @@ -34,13 +34,13 @@ import EditSimulationModelDialog from '../components/dialog/edit-simulation-mode class Simulation extends Component { static getStores() { - return [ SimulationStore, SimulatorStore ]; + return [ SimulationStore, NodeStore ]; } static calculateState() { return { simulations: SimulationStore.getState(), - simulators: SimulatorStore.getState(), + nodes: NodeStore.getState(), newModal: false, deleteModal: false, @@ -58,7 +58,7 @@ class Simulation extends Component { }); AppDispatcher.dispatch({ - type: 'simulators/start-load' + type: 'nodes/start-load' }); } @@ -119,14 +119,8 @@ class Simulation extends Component { } } - getSimulatorName(id) { - for (var i = 0; i < this.state.simulators.length; i++) { - if (this.state.simulators[i]._id === id) { - return this.state.simulators[i].name; - } - } - - return id; + getSimulatorName(simulator) { + return simulator.node + '/' + simulator.simulator; } render() { @@ -136,16 +130,16 @@ class Simulation extends Component { - this.getSimulatorName(id)} /> + this.getSimulatorName(simulator)} /> this.setState({ editModal: true, modalData: this.state.simulation.models[index], modalIndex: index })} onDelete={(index) => this.setState({ deleteModal: true, modalData: this.state.simulation.models[index], modalIndex: index })} />
- this.closeNewModal(data)} simulators={this.state.simulators} /> + this.closeNewModal(data)} nodes={this.state.nodes} /> - this.closeEditModal(data)} data={this.state.modalData} simulators={this.state.simulators} /> + this.closeEditModal(data)} data={this.state.modalData} nodes={this.state.nodes} /> diff --git a/src/containers/simulators.js b/src/containers/simulators.js index fd6c450..acaf5ad 100644 --- a/src/containers/simulators.js +++ b/src/containers/simulators.js @@ -193,7 +193,10 @@ class Simulators extends Component {

Simulators

- + + +
+ Hint: Node names must be unique. Simulator names must be unique on a node. this.onTreeDataChange(treeData)} onNodeDelete={(node) => this.showDeleteNodeModal(node)} onNodeEdit={(node) => this.showEditNodeModal(node)} onNodeAdd={(node) => this.showAddSimulatorModal(node)} onSimulatorEdit={(node, index) => this.showEditSimulatorModal(node, index)} onSimulatorDelete={(node, index) => this.showDeleteSimulatorModal(node, index)} /> diff --git a/src/data-managers/nodes-data-manager.js b/src/data-managers/nodes-data-manager.js index ab04da9..af68fc1 100644 --- a/src/data-managers/nodes-data-manager.js +++ b/src/data-managers/nodes-data-manager.js @@ -21,6 +21,7 @@ import RestDataManager from './rest-data-manager'; import RestAPI from '../api/rest-api'; +import AppDispatcher from '../app-dispatcher'; class NodesDataManager extends RestDataManager { constructor() { @@ -28,7 +29,7 @@ class NodesDataManager extends RestDataManager { } getSimulators(node) { - RestAPI.post('http://' + node.endpoint + '/api/v1', { + /*RestAPI.post('http://' + node.endpoint + '/api/v1', { action: 'nodes', id: node._id }).then(response => { @@ -46,10 +47,16 @@ class NodesDataManager extends RestDataManager { } }); - console.log(node); + AppDispatcher.dispatch({ + type: 'nodes/edited', + data: node + }); }).catch(error => { - console.warn(error); - }); + AppDispatcher.dispatch({ + type: 'nodes/edit-error', + error: error + }); + });*/ } }