diff --git a/src/api/websocket-api.js b/src/api/websocket-api.js
index 79da2f7..43d2e65 100644
--- a/src/api/websocket-api.js
+++ b/src/api/websocket-api.js
@@ -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;
diff --git a/src/containers/widget.js b/src/containers/widget.js
index 6006484..2879498 100644
--- a/src/containers/widget.js
+++ b/src/containers/widget.js
@@ -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 =
} else if (widget.type === 'NumberInput') {
- element =
+ element =
} else if (widget.type === 'Slider') {
- element = this.props.onWidgetStatusChange(w, this.props.index) } onInputChanged={(value) => this.inputDataChanged(widget, value)} />
+ element = this.props.onWidgetStatusChange(w, this.props.index) } onInputChanged={(value) => this.inputDataChanged(widget, value)} />
} else if (widget.type === 'Gauge') {
element =
} else if (widget.type === 'Box') {
diff --git a/src/data-managers/nodes-data-manager.js b/src/data-managers/nodes-data-manager.js
deleted file mode 100644
index 2374a1f..0000000
--- a/src/data-managers/nodes-data-manager.js
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * File: nodes-data-manager.js
- * Author: Markus Grigull
- * 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 .
- ******************************************************************************/
-
-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();
diff --git a/src/data-managers/simulation-models-data-manager.js b/src/data-managers/simulation-models-data-manager.js
index 79e6c4e..5496268 100644
--- a/src/data-managers/simulation-models-data-manager.js
+++ b/src/data-managers/simulation-models-data-manager.js
@@ -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();
diff --git a/src/data-managers/simulations-data-manager.js b/src/data-managers/simulations-data-manager.js
index 4ded924..d5fdfde 100644
--- a/src/data-managers/simulations-data-manager.js
+++ b/src/data-managers/simulations-data-manager.js
@@ -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' ]);
diff --git a/src/data-managers/simulator-data-data-manager.js b/src/data-managers/simulator-data-data-manager.js
index c697f36..728a6a0 100644
--- a/src/data-managers/simulator-data-data-manager.js
+++ b/src/data-managers/simulator-data-data-manager.js
@@ -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);
diff --git a/src/stores/node-store.js b/src/stores/node-store.js
deleted file mode 100644
index f871791..0000000
--- a/src/stores/node-store.js
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * File: node-store.js
- * Author: Markus Grigull
- * 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 .
- ******************************************************************************/
-
-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();
diff --git a/src/stores/simulator-data-store.js b/src/stores/simulator-data-store.js
index 8544e75..d5cdd8c 100644
--- a/src/stores/simulator-data-store.js
+++ b/src/stores/simulator-data-store.js
@@ -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)
}