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,17 +174,15 @@ 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 => {
if (isRunning) {
this.$deleteButton.attr('disabled', 'disabled'); this.$deleteButton.attr('disabled', 'disabled');
} else { } else {
this.$deleteButton.removeAttr('disabled'); this.$deleteButton.removeAttr('disabled');
@ -204,44 +202,36 @@ class NodeContext {
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) {
self.$nodeContext.addClass('d-none');
console.log('node context click: ', event); console.log('node context click: ', event);
const nodeId = self.$nodeContext.data('node'); const nodeId = this.$nodeContext.data('node');
const $target = $(event.target); const $target = $(event.target);
const option = $target.data('option'); const option = $target.data('option');
console.log('node context: ', nodeId, option); console.log('node context: ', nodeId, option);
switch (option) { switch (option) {
case 'edit': case 'edit':
self.nodeEditModal.show(nodeId); this.nodeEditModal.show(nodeId);
break; break;
case 'services': case 'services':
self.servicesModal.show(nodeId) await this.servicesModal.show(nodeId);
.catch(function (err) {
console.log('error showing services modal: ', err);
});
break; break;
case 'linkrf': case 'linkrf':
console.log('linking all routers'); console.log('linking all routers');
self.coreNetwork.linkAllRouters(nodeId); this.coreNetwork.linkAllRouters(nodeId);
break; break;
case 'delete': case 'delete':
self.coreNetwork.deleteNode(nodeId); this.coreNetwork.deleteNode(nodeId);
break; break;
} }
});
return false;
} }
} }

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) {