1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

Merge branch '169-invalid-simualtor-id' into develop

This commit is contained in:
Steffen Vogel 2018-05-31 22:23:39 +02:00
commit 6f1ce46b45
8 changed files with 42 additions and 202 deletions

View file

@ -35,7 +35,7 @@ class WebsocketAPI {
}
getURL(endpoint) {
// create an anchor element (note: no need to append this element to the document)
// create an anchor element (note: no need to append this element to the document)
var link = document.createElement('a');
link.href = endpoint;

View file

@ -164,9 +164,19 @@ class Widget extends React.Component {
}
inputDataChanged(widget, data) {
let simulationModel = null;
for (let model of this.state.simulationModels) {
if (model._id !== widget.simulationModel) {
continue;
}
simulationModel = model;
}
AppDispatcher.dispatch({
type: 'simulatorData/inputChanged',
simulator: widget.simulator,
simulator: simulationModel.simulator,
signal: widget.signal,
data
});
@ -209,9 +219,9 @@ class Widget extends React.Component {
} else if (widget.type === 'Button') {
element = <WidgetButton widget={widget} editing={this.props.editing} />
} else if (widget.type === 'NumberInput') {
element = <WidgetNumberInput widget={widget} editing={this.props.editing} />
element = <WidgetNumberInput widget={widget} editing={this.props.editing} simulationModel={simulationModel} />
} else if (widget.type === 'Slider') {
element = <WidgetSlider widget={widget} editing={this.props.editing} onWidgetChange={(w) => this.props.onWidgetStatusChange(w, this.props.index) } onInputChanged={(value) => this.inputDataChanged(widget, value)} />
element = <WidgetSlider widget={widget} editing={this.props.editing} simulationModel={simulationModel} onWidgetChange={(w) => this.props.onWidgetStatusChange(w, this.props.index) } onInputChanged={(value) => this.inputDataChanged(widget, value)} />
} else if (widget.type === 'Gauge') {
element = <WidgetGauge widget={widget} data={this.state.simulatorData} editing={this.props.editing} simulationModel={simulationModel} />
} else if (widget.type === 'Box') {

View file

@ -1,101 +0,0 @@
/**
* File: nodes-data-manager.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 26.06.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 <http://www.gnu.org/licenses/>.
******************************************************************************/
import RestDataManager from './rest-data-manager';
import RestAPI from '../api/rest-api';
import AppDispatcher from '../app-dispatcher';
class NodesDataManager extends RestDataManager {
constructor() {
super('node', '/nodes');
}
getURL(node) {
// create an anchor element (note: no need to append this element to the document)
var link = document.createElement('a');
link.href = node.endpoint;
link.pathname = link.pathname + 'api/v1';
return link.href;
}
getSimulators(node) {
RestAPI.post(this.getURL(node), {
action: 'nodes',
id: node._id
}).then(response => {
// assign IDs to simulators
response.response.forEach(element => {
if (element.type === "websocket") {
// add the (villas-node) node ID to the simulator
node.simulators = node.simulators.map(simulator => {
if (simulator.name === element.name) {
simulator.id = element.id;
}
return simulator;
});
}
});
AppDispatcher.dispatch({
type: 'nodes/simulatorsFetched',
data: node
});
AppDispatcher.dispatch({
type: 'simulatorData/open',
node: node,
endpoint: node.endpoint,
});
}).catch(error => {
AppDispatcher.dispatch({
type: 'nodes/simulatorsFetch-error',
error: error
});
});
}
update(object, token = null) {
var obj = {};
obj[this.type] = this.filterKeys(object);
// filter simulator IDs
obj[this.type].simulators = obj[this.type].simulators.map(simulator => {
delete simulator.id;
return simulator;
});
RestAPI.put(this.makeURL(this.url + '/' + object._id), obj, token).then(response => {
AppDispatcher.dispatch({
type: this.type + 's/edited',
data: Object.assign({}, object, response[this.type])
});
}).catch(error => {
AppDispatcher.dispatch({
type: this.type + 's/edit-error',
error: error
});
});
}
}
export default new NodesDataManager();

View file

@ -20,5 +20,31 @@
******************************************************************************/
import RestDataManager from './rest-data-manager';
import AppDispatcher from '../app-dispatcher';
export default new RestDataManager('simulationModel', '/models');
class SimulationModelDataManager extends RestDataManager {
constructor() {
super('simulationModel', '/models');
this.onLoad = this.onModelsLoad;
}
onModelsLoad(data) {
if (!Array.isArray(data))
data = [ data ];
for (let model of data)
this.loadModelData(model);
}
loadModelData(model) {
AppDispatcher.dispatch({
type: 'simulatorData/prepare',
inputLength: parseInt(model.inputLength, 10),
outputLength: parseInt(model.outputLength, 10),
id: model.simulator
});
}
}
export default new SimulationModelDataManager();

View file

@ -20,35 +20,5 @@
******************************************************************************/
import RestDataManager from './rest-data-manager';
import AppDispatcher from '../app-dispatcher';
class SimulationsDataManager extends RestDataManager {
constructor() {
super('simulation', '/simulations', [ '_id', 'name', 'projects', 'models' ]);
this.onLoad = this.onSimulationsLoad;
}
onSimulationsLoad(data) {
if (Array.isArray(data)) {
for (let simulation of data) {
this.loadSimulationData(simulation);
}
} else {
this.loadSimulationData(data);
}
}
loadSimulationData(simulation) {
for (let model of simulation.models) {
AppDispatcher.dispatch({
type: 'simulatorData/prepare',
inputLength: parseInt(model.inputLength, 10),
outputLength: parseInt(model.outputLength, 10),
id: model.simulator
});
}
}
}
export default new SimulationsDataManager();
export default new RestDataManager('simulation', '/simulations', [ '_id', 'name', 'projects', 'models' ]);

View file

@ -63,8 +63,6 @@ class SimulatorDataDataManager {
const data = this.messageToBuffer(message);
socket.send(data);
console.log(data);
return true;
}
@ -156,7 +154,6 @@ class SimulatorDataDataManager {
const nsec = (message.timestamp - sec * 1e3) * 1e6;
view.setUint8(0x00, bits, true);
view.setUint8(0x01, message.id, true);
view.setUint16(0x02, message.length, true);
view.setUint32(0x04, message.sequence, true);
view.setUint32(0x08, sec, true);

View file

@ -1,61 +0,0 @@
/**
* File: node-store.js
* Author: Markus Grigull <mgrigull@eonerc.rwth-aachen.de>
* Date: 26.06.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 <http://www.gnu.org/licenses/>.
******************************************************************************/
import ArrayStore from './array-store';
import NodesDataManager from '../data-managers/nodes-data-manager';
class NodeStore extends ArrayStore {
constructor() {
super('nodes', NodesDataManager);
}
reduce(state, action) {
switch(action.type) {
case 'nodes/loaded':
// get simulator IDs
if (Array.isArray(action.data)) {
action.data.forEach(node => {
NodesDataManager.getSimulators(node);
});
} else {
NodesDataManager.getSimulators(action.data);
}
return super.reduce(state, action);
case 'nodes/edited':
NodesDataManager.getSimulators(action.data);
return super.reduce(state, action);
case 'nodes/simulatorsFetched':
return this.updateElements(state, [action.data]);
case 'nodes/simulatorsFetch-error':
return state;
default:
return super.reduce(state, action);
}
}
}
export default new NodeStore();

View file

@ -54,7 +54,6 @@ class SimulationDataStore extends ReduceStore {
length: action.inputLength,
version: 2,
type: 0,
id: 0,
timestamp: Date.now(),
values: new Array(action.inputLength).fill(0)
}