Last active
November 14, 2016 10:54
-
-
Save jpellizzari/8e4c8f1d9f44e87cb055841a43992cfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Change to getNodeDetails to make this work. Returns a promise to allow for chaining | |
export function getNodeDetails(topologyUrlsById, currentTopologyId, options, nodeMap, dispatch) { | |
// get details for all opened nodes | |
const obj = nodeMap.last(); | |
if (obj && topologyUrlsById.has(obj.topologyId)) { | |
const topologyUrl = topologyUrlsById.get(obj.topologyId); | |
let urlComponents = [topologyUrl, '/', encodeURIComponent(obj.id)]; | |
if (currentTopologyId === obj.topologyId) { | |
// Only forward filters for nodes in the current topology | |
const optionsQuery = buildOptionsQuery(options); | |
urlComponents = urlComponents.concat(['?', optionsQuery]); | |
} | |
const url = urlComponents.join('').substr(1); | |
return reqwest({ | |
url | |
}) | |
.then(res => { | |
console.log('node details recvd'); | |
// make sure node is still selected | |
if (nodeMap.has(res.node.id)) { | |
console.log(res.node.controls); | |
dispatch(receiveNodeDetails(res.node)); | |
} | |
}) | |
.catch(err => { | |
log(`Error in node details request: ${err.responseText}`); | |
// dont treat missing node as error | |
if (err.status === 404) { | |
dispatch(receiveNotFound(obj.id)); | |
} else { | |
dispatch(receiveError(topologyUrl)); | |
} | |
}); | |
} else if (obj) { | |
log('No details or url found for ', obj); | |
} | |
return null; | |
} | |
// Special action created to test immediately calling getNodeDetails | |
export function doControlAndUpdate(nodeId, control) { | |
return (dispatch, getState) => { | |
const url = `api/control/${encodeURIComponent(control.probeId)}/` | |
+ `${encodeURIComponent(control.nodeId)}/${control.id}`; | |
dispatch({ | |
type: ActionTypes.DO_CONTROL, | |
nodeId | |
}); | |
reqwest({ | |
method: 'POST', | |
url | |
}) | |
.then(res => { | |
if (res) { | |
if (res.pipe) { | |
dispatch(blurSearch()); | |
const resizeTtyControl = res.resize_tty_control && | |
{id: res.resize_tty_control, probeId: control.probeId, nodeId: control.nodeId}; | |
dispatch(receiveControlPipe( | |
res.pipe, | |
nodeId, | |
res.raw_tty, | |
resizeTtyControl)); | |
} | |
if (res.removedNode) { | |
dispatch(receiveControlNodeRemoved(nodeId)); | |
} | |
} | |
const state = getState(); | |
return getNodeDetails( | |
state.get('topologyUrlsById'), | |
state.get('currentTopologyId'), | |
getActiveTopologyOptions(state), | |
state.get('nodeDetails'), | |
dispatch | |
); | |
}) | |
.then(() => { | |
console.log('control success'); | |
dispatch(receiveControlSuccess(nodeId)); | |
}) | |
.catch(e => { | |
throw e; | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment