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

Add running simulator detection

This commit is contained in:
Markus Grigull 2017-03-17 20:14:34 +01:00
parent b7d2d57e0d
commit 05b74fc090
3 changed files with 45 additions and 21 deletions

View file

@ -13,7 +13,7 @@ import Promise from 'es6-promise';
class RestAPI {
get(url, token) {
return new Promise(function (resolve, reject) {
var req = request.get(url).set('Access-Control-Allow-Origin', '*');
var req = request.get(url);
if (token != null) {
req.set('x-access-token', token);

View file

@ -9,7 +9,7 @@
import RestDataManager from './rest-data-manager';
import RestAPI from '../api/rest-api';
//import AppDispatcher from '../app-dispatcher';
import AppDispatcher from '../app-dispatcher';
class SimulatorsDataManager extends RestDataManager {
constructor() {
@ -17,10 +17,32 @@ class SimulatorsDataManager extends RestDataManager {
}
isRunning(simulator) {
RestAPI.get('http://localhost/nodes.json').then(response => {
console.log(response);
// get path and name
var path = simulator.endpoint.substring(0, simulator.endpoint.lastIndexOf('/'));
path += '/nodes.json';
var name = simulator.endpoint.substring(simulator.endpoint.lastIndexOf('/') + 1);
// send request
RestAPI.get('http://' + path).then(response => {
// check if simulator is running
var running = false;
response.forEach(sim => {
if (sim.name === name) {
running = true;
}
});
simulator.running = running;
AppDispatcher.dispatch({
type: 'simulators/running',
simulator: simulator,
running: running
});
}).catch(error => {
console.log(error);
//console.log(error);
});
}
}

View file

@ -16,24 +16,26 @@ class SimulatorStore extends ArrayStore {
}
reduce(state, action) {
// handle action
state = super.reduce(state, action);
switch (action.type) {
case 'simulators/loaded':
// get simulator running state
if (Array.isArray(action.data)) {
action.data.forEach((simulator) => {
SimulatorsDataManager.isRunning(simulator);
});
} else {
SimulatorsDataManager.isRunning(action.data);
}
if (action.type === 'simulators/loaded') {
// get simulator running state
if (Array.isArray(action.data)) {
action.data.forEach((simulator) => {
//SimulatorsDataManager.isRunning(simulator);
});
} else {
//SimulatorsDataManager.isRunning(action.data);
}
} else if (action.type === 'simulators/running') {
// set running state
console.log(action);
return super.reduce(state, action);
case 'simulators/running':
// update simulator
return this.updateElements(state, [ action.simulator ]);
default:
return super.reduce(state, action);
}
return state;
}
}