From aee2c7d569d3f9270a46a2aba160f073e260c1be Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 24 May 2018 08:42:17 +0200 Subject: [PATCH 1/7] remove obsolete node store and data manager --- src/data-managers/nodes-data-manager.js | 101 ------------------------ src/stores/node-store.js | 61 -------------- 2 files changed, 162 deletions(-) delete mode 100644 src/data-managers/nodes-data-manager.js delete mode 100644 src/stores/node-store.js 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/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(); From 67c4bbc791d9856b9f2cf1da490ad1c6efab9b94 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 24 May 2018 08:43:07 +0200 Subject: [PATCH 2/7] remove node id from websocket payload --- src/data-managers/simulator-data-data-manager.js | 1 - src/stores/simulator-data-store.js | 1 - 2 files changed, 2 deletions(-) diff --git a/src/data-managers/simulator-data-data-manager.js b/src/data-managers/simulator-data-data-manager.js index c697f36..69becc4 100644 --- a/src/data-managers/simulator-data-data-manager.js +++ b/src/data-managers/simulator-data-data-manager.js @@ -156,7 +156,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/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) } From 1c76184ccd81a1588cc07c6a39e8ba5068c64c54 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 24 May 2018 08:44:11 +0200 Subject: [PATCH 3/7] use new simulation model data manager for initialising simulator data store (closes #169) --- .../simulation-models-data-manager.js | 28 +++++++++++++++- src/data-managers/simulations-data-manager.js | 32 +------------------ 2 files changed, 28 insertions(+), 32 deletions(-) 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' ]); From 6b06798c76edd9554a5a7f3c181bfba5ee8b6376 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 24 May 2018 08:44:40 +0200 Subject: [PATCH 4/7] do not log all outgoing websocket data --- src/data-managers/simulator-data-data-manager.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/data-managers/simulator-data-data-manager.js b/src/data-managers/simulator-data-data-manager.js index 69becc4..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; } From d56fc4c5d55162d7d65506a9d4df9e65463c5cf8 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 24 May 2018 08:44:51 +0200 Subject: [PATCH 5/7] whitespace cleanup --- src/api/websocket-api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 0b1420bce0354c37efd89a832ded2a996f5f4917 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 31 May 2018 22:21:53 +0200 Subject: [PATCH 6/7] use simulation model in inputDataChanged() --- src/containers/widget.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/containers/widget.js b/src/containers/widget.js index 6006484..039ae21 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 }); From 6f7d0f29bbc95954cf617c09dd6850aa5035381c Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 31 May 2018 22:22:22 +0200 Subject: [PATCH 7/7] pass simulationModel to widget --- src/containers/widget.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/containers/widget.js b/src/containers/widget.js index 039ae21..2879498 100644 --- a/src/containers/widget.js +++ b/src/containers/widget.js @@ -219,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') {