mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
Start simulator ID fetching
This commit is contained in:
parent
984d40134f
commit
e7bc53b374
3 changed files with 62 additions and 5 deletions
|
@ -28,6 +28,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 NodeStore from '../stores/node-store';
|
||||
import UserStore from '../stores/user-store';
|
||||
import NotificationsDataManager from '../data-managers/notifications-data-manager';
|
||||
|
||||
|
@ -40,7 +41,7 @@ import '../styles/app.css';
|
|||
|
||||
class App extends Component {
|
||||
static getStores() {
|
||||
return [ SimulationStore, SimulatorStore, UserStore ];
|
||||
return [ SimulationStore, NodeStore, UserStore ];
|
||||
}
|
||||
|
||||
static calculateState(prevState) {
|
||||
|
@ -164,12 +165,12 @@ class App extends Component {
|
|||
});
|
||||
|
||||
if (simulator != null) {
|
||||
AppDispatcher.dispatch({
|
||||
/*AppDispatcher.dispatch({
|
||||
type: 'simulatorData/open',
|
||||
identifier: simulator._id,
|
||||
endpoint: simulator.endpoint,
|
||||
signals: data.signals
|
||||
});
|
||||
});*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,5 +20,37 @@
|
|||
******************************************************************************/
|
||||
|
||||
import RestDataManager from './rest-data-manager';
|
||||
import RestAPI from '../api/rest-api';
|
||||
|
||||
export default new RestDataManager('node', '/nodes');
|
||||
class NodesDataManager extends RestDataManager {
|
||||
constructor() {
|
||||
super('node', '/nodes');
|
||||
}
|
||||
|
||||
getSimulators(node) {
|
||||
RestAPI.post('http://' + node.endpoint + '/api/v1', {
|
||||
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;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
console.log(node);
|
||||
}).catch(error => {
|
||||
console.warn(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new NodesDataManager();
|
||||
|
|
|
@ -22,4 +22,28 @@
|
|||
import ArrayStore from './array-store';
|
||||
import NodesDataManager from '../data-managers/nodes-data-manager';
|
||||
|
||||
export default new ArrayStore('nodes', NodesDataManager);
|
||||
class NodeStore extends ArrayStore {
|
||||
constructor() {
|
||||
super('nodes', NodesDataManager);
|
||||
}
|
||||
|
||||
reduce(state, action) {
|
||||
switch(action.type) {
|
||||
case 'nodes/loaded':
|
||||
if (Array.isArray(action.data)) {
|
||||
action.data.forEach(node => {
|
||||
NodesDataManager.getSimulators(node);
|
||||
});
|
||||
} else {
|
||||
NodesDataManager.getSimulators(action.data);
|
||||
}
|
||||
|
||||
return super.reduce(state, action);
|
||||
|
||||
default:
|
||||
return super.reduce(state, action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new NodeStore();
|
||||
|
|
Loading…
Add table
Reference in a new issue