mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
Change simulator selection in simulator model
Disable simulator detection for testing
This commit is contained in:
parent
46bcb2fc21
commit
89f70f027a
6 changed files with 69 additions and 48 deletions
|
@ -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 {
|
|||
</FormGroup>
|
||||
<FormGroup controlId="simulator" validationState={this.validateForm('simulator')}>
|
||||
<ControlLabel>Simulator</ControlLabel>
|
||||
<FormControl componentClass="select" placeholder="Select simulator" value={this.state.simulator} onChange={(e) => this.handleChange(e)}>
|
||||
{this.props.simulators.map(simulator => (
|
||||
<option key={simulator._id} value={simulator._id}>{simulator.name}</option>
|
||||
<FormControl componentClass="select" placeholder="Select simulator" value={this.state.simulator.node + '/' + this.state.simulator.simulator} onChange={(e) => this.handleChange(e)}>
|
||||
{this.props.nodes.map(node => (
|
||||
node.simulators.map((simulator, index) => (
|
||||
<option key={node._id + index} value={node.name + '/' + simulator.name}>{node.name}/{simulator.name}</option>
|
||||
))
|
||||
))}
|
||||
</FormControl>
|
||||
</FormGroup>
|
||||
|
|
|
@ -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 {
|
|||
</FormGroup>
|
||||
<FormGroup controlId="simulator" validationState={this.validateForm('simulator')}>
|
||||
<ControlLabel>Simulator</ControlLabel>
|
||||
<FormControl componentClass="select" placeholder="Select simulator" value={this.state.simulator} onChange={(e) => this.handleChange(e)}>
|
||||
{this.props.simulators.map(simulator => (
|
||||
<option key={simulator._id} value={simulator._id}>{simulator.name}</option>
|
||||
<FormControl componentClass="select" placeholder="Select simulator" value={this.state.simulator.node + '/' + this.state.simulator.simulator} onChange={(e) => this.handleChange(e)}>
|
||||
{this.props.nodes.map(node => (
|
||||
node.simulators.map((simulator, index) => (
|
||||
<option key={node._id + index} value={node.name + '/' + simulator.name}>{node.name}/{simulator.name}</option>
|
||||
))
|
||||
))}
|
||||
</FormControl>
|
||||
</FormGroup>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
|||
|
||||
<Table data={this.state.simulation.models}>
|
||||
<TableColumn title='Name' dataKey='name' />
|
||||
<TableColumn title='Simulator' dataKey='simulator' width='180' modifier={(id) => this.getSimulatorName(id)} />
|
||||
<TableColumn title='Simulator' dataKey='simulator' width='180' modifier={(simulator) => this.getSimulatorName(simulator)} />
|
||||
<TableColumn title='Length' dataKey='length' width='100' />
|
||||
<TableColumn title='' width='70' editButton deleteButton onEdit={(index) => 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 })} />
|
||||
</Table>
|
||||
|
||||
<Button onClick={() => this.setState({ newModal: true })}><Glyphicon glyph="plus" /> Simulation Model</Button>
|
||||
|
||||
<NewSimulationModelDialog show={this.state.newModal} onClose={(data) => this.closeNewModal(data)} simulators={this.state.simulators} />
|
||||
<NewSimulationModelDialog show={this.state.newModal} onClose={(data) => this.closeNewModal(data)} nodes={this.state.nodes} />
|
||||
|
||||
<EditSimulationModelDialog show={this.state.editModal} onClose={(data) => this.closeEditModal(data)} data={this.state.modalData} simulators={this.state.simulators} />
|
||||
<EditSimulationModelDialog show={this.state.editModal} onClose={(data) => this.closeEditModal(data)} data={this.state.modalData} nodes={this.state.nodes} />
|
||||
|
||||
<Modal show={this.state.deleteModal}>
|
||||
<Modal.Header>
|
||||
|
|
|
@ -193,7 +193,10 @@ class Simulators extends Component {
|
|||
<div className='section'>
|
||||
<h1>Simulators</h1>
|
||||
|
||||
<Button onClick={() => this.setState({ newNodeModal: true })}><Glyphicon glyph="plus" /> Add Node</Button>
|
||||
<Button onClick={() => this.setState({ newNodeModal: true })}><Glyphicon glyph="plus" /> Node</Button>
|
||||
|
||||
<br />
|
||||
<small><i>Hint: Node names must be unique. Simulator names must be unique on a node.</i></small>
|
||||
|
||||
<NodeTree data={this.state.nodes} onDataChange={(treeData) => 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)} />
|
||||
|
||||
|
|
|
@ -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
|
||||
});
|
||||
});*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue