Skip to content

Commit

Permalink
Merge pull request #455 from weaveworks/454-option-api
Browse files Browse the repository at this point in the history
Apply topology options to detail API
  • Loading branch information
davkal committed Sep 7, 2015
2 parents e81efe6 + b698006 commit 453f1bc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
38 changes: 31 additions & 7 deletions client/app/scripts/actions/app-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ module.exports = {
value: value
});
RouterUtils.updateRoute();
WebapiUtils.getNodesDelta(AppStore.getCurrentTopologyUrl(), AppStore.getActiveTopologyOptions());
WebapiUtils.getNodesDelta(
AppStore.getCurrentTopologyUrl(),
AppStore.getActiveTopologyOptions()
);
},

clickCloseDetails: function() {
Expand All @@ -28,7 +31,11 @@ module.exports = {
nodeId: nodeId
});
RouterUtils.updateRoute();
WebapiUtils.getNodeDetails(AppStore.getCurrentTopologyUrl(), AppStore.getSelectedNodeId());
WebapiUtils.getNodeDetails(
AppStore.getCurrentTopologyUrl(),
AppStore.getSelectedNodeId(),
AppStore.getActiveTopologyOptions()
);
},

clickTopology: function(topologyId) {
Expand All @@ -37,7 +44,10 @@ module.exports = {
topologyId: topologyId
});
RouterUtils.updateRoute();
WebapiUtils.getNodesDelta(AppStore.getCurrentTopologyUrl(), AppStore.getActiveTopologyOptions());
WebapiUtils.getNodesDelta(
AppStore.getCurrentTopologyUrl(),
AppStore.getActiveTopologyOptions()
);
},

openWebsocket: function() {
Expand Down Expand Up @@ -106,8 +116,15 @@ module.exports = {
type: ActionTypes.RECEIVE_TOPOLOGIES,
topologies: topologies
});
WebapiUtils.getNodesDelta(AppStore.getCurrentTopologyUrl(), AppStore.getActiveTopologyOptions());
WebapiUtils.getNodeDetails(AppStore.getCurrentTopologyUrl(), AppStore.getSelectedNodeId());
WebapiUtils.getNodesDelta(
AppStore.getCurrentTopologyUrl(),
AppStore.getActiveTopologyOptions()
);
WebapiUtils.getNodeDetails(
AppStore.getCurrentTopologyUrl(),
AppStore.getSelectedNodeId(),
AppStore.getActiveTopologyOptions()
);
},

receiveApiDetails: function(apiDetails) {
Expand All @@ -129,8 +146,15 @@ module.exports = {
state: state,
type: ActionTypes.ROUTE_TOPOLOGY
});
WebapiUtils.getNodesDelta(AppStore.getCurrentTopologyUrl(), AppStore.getActiveTopologyOptions());
WebapiUtils.getNodeDetails(AppStore.getCurrentTopologyUrl(), AppStore.getSelectedNodeId());
WebapiUtils.getNodesDelta(
AppStore.getCurrentTopologyUrl(),
AppStore.getActiveTopologyOptions()
);
WebapiUtils.getNodeDetails(
AppStore.getCurrentTopologyUrl(),
AppStore.getSelectedNodeId(),
AppStore.getActiveTopologyOptions()
);
}
};

Expand Down
18 changes: 13 additions & 5 deletions client/app/scripts/utils/web-api-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ let currentOptions = null;
let topologyTimer = 0;
let apiDetailsTimer = 0;


function buildOptionsQuery(options) {
return _.map(options, function(value, param) {
return param + '=' + value;
}).join('&');
}

function createWebsocket(topologyUrl, optionsQuery) {
if (socket) {
socket.onclose = null;
Expand Down Expand Up @@ -77,9 +84,7 @@ function getTopologies() {
}

function getTopology(topologyUrl, options) {
const optionsQuery = _.map(options, function(value, param) {
return param + '=' + value;
}).join('&');
const optionsQuery = buildOptionsQuery(options);

// only recreate websocket if url changed
if (topologyUrl && (topologyUrl !== currentUrl || currentOptions !== optionsQuery)) {
Expand All @@ -89,9 +94,12 @@ function getTopology(topologyUrl, options) {
}
}

function getNodeDetails(topologyUrl, nodeId) {
function getNodeDetails(topologyUrl, nodeId, options) {
const optionsQuery = buildOptionsQuery(options);

if (topologyUrl && nodeId) {
const url = [topologyUrl, encodeURIComponent(nodeId)].join('/').substr(1);
const url = [topologyUrl, '/', encodeURIComponent(nodeId), '?', optionsQuery]
.join('').substr(1);
reqwest({
url: url,
success: function(res) {
Expand Down

0 comments on commit 453f1bc

Please sign in to comment.