web app updated node context to use async

This commit is contained in:
Blake J. Harnden 2018-05-15 16:40:41 -07:00
parent e11798bae5
commit c989d809cb
2 changed files with 48 additions and 55 deletions

View file

@ -174,74 +174,64 @@ class NodeContext {
this.nodeEditModal = nodeEditModal; this.nodeEditModal = nodeEditModal;
this.servicesModal = servicesModal; this.servicesModal = servicesModal;
this.$nodeContext = $('#node-context'); this.$nodeContext = $('#node-context');
this.$nodeContext.click(this.onClick.bind(this));
this.$linkRfButton = $('#node-linkrf-button'); this.$linkRfButton = $('#node-linkrf-button');
this.$deleteButton = $('#node-delete-button'); this.$deleteButton = $('#node-delete-button');
this.onClick();
} }
show(nodeId, x, y) { async show(nodeId, x, y) {
const node = this.coreNetwork.getCoreNode(nodeId); const node = this.coreNetwork.getCoreNode(nodeId);
console.log('context node: ', node); console.log('context node: ', node);
this.coreRest.isRunning() if (await this.coreRest.isRunning()) {
.then(isRunning => { this.$deleteButton.attr('disabled', 'disabled');
if (isRunning) { } else {
this.$deleteButton.attr('disabled', 'disabled'); this.$deleteButton.removeAttr('disabled');
} else { }
this.$deleteButton.removeAttr('disabled');
}
console.log('node type: ', node.type); console.log('node type: ', node.type);
if (node.type === CoreNodeHelper.wlanNode) { if (node.type === CoreNodeHelper.wlanNode) {
this.$linkRfButton.removeClass('d-none'); this.$linkRfButton.removeClass('d-none');
} else { } else {
this.$linkRfButton.addClass('d-none'); this.$linkRfButton.addClass('d-none');
} }
this.$nodeContext.data('node', nodeId); this.$nodeContext.data('node', nodeId);
this.$nodeContext.css({ this.$nodeContext.css({
position: 'absolute', position: 'absolute',
left: x, left: x,
top: y top: y
}); });
this.$nodeContext.removeClass('d-none'); this.$nodeContext.removeClass('d-none');
})
.catch(function (err) {
console.log('error checking is session is running: ', err);
});
} }
hide() { hide() {
this.$nodeContext.addClass('d-none'); this.$nodeContext.addClass('d-none');
} }
onClick() { async onClick(event) {
const self = this; this.$nodeContext.addClass('d-none');
this.$nodeContext.click(function (event) { console.log('node context click: ', event);
self.$nodeContext.addClass('d-none'); const nodeId = this.$nodeContext.data('node');
console.log('node context click: ', event); const $target = $(event.target);
const nodeId = self.$nodeContext.data('node'); const option = $target.data('option');
const $target = $(event.target); console.log('node context: ', nodeId, option);
const option = $target.data('option'); switch (option) {
console.log('node context: ', nodeId, option); case 'edit':
switch (option) { this.nodeEditModal.show(nodeId);
case 'edit': break;
self.nodeEditModal.show(nodeId); case 'services':
break; await this.servicesModal.show(nodeId);
case 'services': break;
self.servicesModal.show(nodeId) case 'linkrf':
.catch(function (err) { console.log('linking all routers');
console.log('error showing services modal: ', err); this.coreNetwork.linkAllRouters(nodeId);
}); break;
break; case 'delete':
case 'linkrf': this.coreNetwork.deleteNode(nodeId);
console.log('linking all routers'); break;
self.coreNetwork.linkAllRouters(nodeId); }
break;
case 'delete': return false;
self.coreNetwork.deleteNode(nodeId);
break;
}
});
} }
} }

View file

@ -245,7 +245,10 @@
const nodeId = coreNetwork.network.getNodeAt(location); const nodeId = coreNetwork.network.getNodeAt(location);
if (nodeId) { if (nodeId) {
nodeContext.show(nodeId, x, y); nodeContext.show(nodeId, x, y)
.catch(function(err) {
console.log('error showing node context: ', err);
});
} else { } else {
const edgeId = coreNetwork.network.getEdgeAt(location); const edgeId = coreNetwork.network.getEdgeAt(location);
if (edgeId) { if (edgeId) {