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

WIP: Show graph representing the current config #265

This commit is contained in:
Laura Fuentes Grau 2020-11-27 13:38:51 +01:00
parent b79de99e9a
commit 0bc737349f
4 changed files with 55 additions and 0 deletions

View file

@ -170,6 +170,28 @@ class RestAPI {
});
}
apiDownload(url, token) {
return new Promise(function (resolve, reject) {
var req = request.get(url).buffer(true).responseType("blob");
if (token != null) {
req.set('Authorization', "Bearer " + token);
}
req.end(function (error, res) {
if (res == null || res.status !== 200) {
if (req.url !== prevURL) error.handled = isNetworkError(error);
prevURL = req.url;
reject(error);
} else {
let parts = url.split("/");
resolve({data: res.body, type: res.type, id: parts[parts.length-1]})
}
});
});
}
}
export default new RestAPI();

View file

@ -40,6 +40,16 @@ class ICAPIStore extends ArrayStore {
console.log("status error");
return super.reduce(state, action);
case 'ic-api/get-graph':
ICDataDataManager.getGraph(action.url, action.socketname, action.token);
return super.reduce(state, action);
case 'ic-api/graph-received':
return super.reduce(state, action);
case 'ic-api/graph-error':
return super.reduce(state, action);
default:
return super.reduce(state, action);
}

View file

@ -61,6 +61,22 @@ class IcDataDataManager {
})
}
getGraph(url,socketname,token){
RestAPI.apiDownload(url, null).then(response => {
AppDispatcher.dispatch({
type: 'ic-api/status-received',
data: response,
token: token,
socketname: socketname,
});
}).catch(error => {
AppDispatcher.dispatch({
type: 'ic-api/status-error',
error: error
})
})
}
closeAll() {
// close every open socket
for (var identifier in this._sockets) {

View file

@ -125,6 +125,13 @@ class InfrastructureComponents extends Component {
token: this.state.sessionToken,
icid: ic.id,
});
AppDispatcher.dispatch({
type: 'ic-api/get-graph',
url: ic.apiurl + "/graph.svg",
socketname: splitWebsocketURL[splitWebsocketURL.length - 1],
token: this.state.sessionToken,
});
}
})
}