diff --git a/src/common/api/rest-api.js b/src/common/api/rest-api.js index 084456c..50ff2de 100644 --- a/src/common/api/rest-api.js +++ b/src/common/api/rest-api.js @@ -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(); diff --git a/src/ic/ic-api-store.js b/src/ic/ic-api-store.js index d02d644..20d3816 100644 --- a/src/ic/ic-api-store.js +++ b/src/ic/ic-api-store.js @@ -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); } diff --git a/src/ic/ic-data-data-manager.js b/src/ic/ic-data-data-manager.js index 5e10007..d82497a 100644 --- a/src/ic/ic-data-data-manager.js +++ b/src/ic/ic-data-data-manager.js @@ -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) { diff --git a/src/ic/ics.js b/src/ic/ics.js index 2789b1e..a7024e8 100644 --- a/src/ic/ics.js +++ b/src/ic/ics.js @@ -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, + }); } }) }