diff --git a/webapp/app.py b/webapp/app.py index 888c0e79..839524c3 100644 --- a/webapp/app.py +++ b/webapp/app.py @@ -179,6 +179,7 @@ def get_session(session_id): "y": node.position.y, "z": node.position.z }, + "services": [x._name for x in node.services], "url": "/sessions/%s/nodes/%s" % (session_id, node.objid) }) @@ -278,6 +279,7 @@ def get_node(session_id, node_id): return jsonify( name=node.name, type=nodeutils.get_node_type(node.__class__).value, + services=[x._name for x in node.services], model=node.type, interfaces=interfaces, linksurl="/sessions/%s/nodes/%s/links" % (session_id, node.objid) diff --git a/webapp/static/corenetwork.js b/webapp/static/corenetwork.js index c153da74..25e21755 100644 --- a/webapp/static/corenetwork.js +++ b/webapp/static/corenetwork.js @@ -259,6 +259,7 @@ class CoreNetwork { const position = node.position; const coreNode = new CoreNode(node.id, node.type, node.name, position.x, position.y); coreNode.model = node.model; + coreNode.services = node.services; this.nodes.add(coreNode.getNetworkNode()); } diff --git a/webapp/static/coreui.js b/webapp/static/coreui.js index b17e685b..896ee97a 100644 --- a/webapp/static/coreui.js +++ b/webapp/static/coreui.js @@ -3,8 +3,8 @@ class ServiceModal { this.coreRest = coreRest; this.$modal = $('#service-modal'); this.$title = this.$modal.find('.modal-title'); - this.$button = $('#service-button'); - this.$button.click(this.onClick.bind(this)); + this.$saveButton = $('#service-button'); + this.$saveButton.click(this.onClick.bind(this)); } async show(service) { @@ -22,11 +22,14 @@ class ServicesModal { this.coreRest = coreRest; this.coreNetwork = coreNetwork; this.serviceModal = serviceModal; - this.$servicesModal = $('#services-modal'); - this.$servicesForm = this.$servicesModal.find('form'); + this.$modal = $('#services-modal'); + this.$modal.on('click', '.service-button', this.editService.bind(this)); + this.$form = this.$modal.find('form'); this.$serviceGroup = $('#service-group'); + this.$serviceGroup.on('change', this.groupChange.bind(this)); this.$servicesList = $('#services-list'); - this.$servicesButton = $('#services-button'); + this.$saveButton = $('#services-button'); + this.$saveButton.click(this.saveClicked.bind(this)); this.defaultServices = { mdr: new Set(["zebra", "OSPFv3MDR", "IPForward"]), PC: new Set(["DefaultRoute"]), @@ -39,9 +42,6 @@ class ServicesModal { this.serviceGroups = null; this.serviceOptions = new Map(); this.$currentGroup = null; - this.groupChange(); - this.saveClicked(); - this.$servicesModal.on('click', '.service-button', this.editService.bind(this)); } editService(event) { @@ -49,18 +49,21 @@ class ServicesModal { const $target = $(event.target); const service = $target.parent().parent().find('label').text(); console.log('edit service: ', service); - this.$servicesModal.modal('hide'); + this.$modal.modal('hide'); this.serviceModal.show(service); return false; } async show(nodeId) { + // get node and set default services for node type this.node = this.coreNetwork.getCoreNode(nodeId); if (this.node.services.length) { this.nodeDefaults = new Set(this.node.services); } else { this.nodeDefaults = this.defaultServices[this.node.model] || new Set(); } + + // retrieve service groups this.serviceGroups = await coreRest.getServices(nodeId); // clear data @@ -68,8 +71,10 @@ class ServicesModal { this.$servicesList.html(''); this.serviceOptions.clear(); - this.$servicesModal.find('.modal-title').text(`Services: ${this.node.name}`); + // set title + this.$modal.find('.modal-title').text(`Services: ${this.node.name}`); + // generate service form options for (let group in this.serviceGroups) { const $option = $('