diff --git a/webapp/app.py b/webapp/app.py index 04b2bd58..30d933b9 100644 --- a/webapp/app.py +++ b/webapp/app.py @@ -147,10 +147,9 @@ def get_session(session_id): }, "url": "/sessions/%s/nodes/%s" % (session_id, node.objid) }) - state = EventTypes(session.state) return jsonify( - state=state.name, + state=session.state, nodes=nodes ) diff --git a/webapp/static/core.css b/webapp/static/core.css index 82cd3552..564c1c1d 100644 --- a/webapp/static/core.css +++ b/webapp/static/core.css @@ -4,6 +4,7 @@ #info-card-table td { font-size: 12px; + padding: .5rem; } #node-select { @@ -11,6 +12,10 @@ height: 40px; } +#sessions-modal td { + cursor: pointer; +} + .navbar-text { color: #fff !important; font-weight: bold; diff --git a/webapp/static/corenetwork.js b/webapp/static/corenetwork.js index 9cb4ef25..5216be9c 100644 --- a/webapp/static/corenetwork.js +++ b/webapp/static/corenetwork.js @@ -163,12 +163,24 @@ class CoreNetwork { async initialSession() { const session = await this.coreRest.retrieveSession(); console.log('retrieved session: ', session); - const response = await coreRest.getSession(); - console.log('session info: ', response); - this.joinedSessionNodes(response.nodes); + await this.joinSession(session.id); return session; } + async newSession() { + const session = await this.coreRest.createSession(); + this.coreRest.currentSession = session.id; + this.reset(); + return session; + } + + reset() { + this.nodeId = 0; + this.nodes.clear(); + this.edges.clear(); + this.links = {}; + } + enableNodeCreation(enabled) { console.log('node created enabled: ', enabled); this.nodesEnabled = enabled; @@ -194,7 +206,13 @@ class CoreNetwork { return this.nodeId; } - joinedSessionNodes(nodes) { + async joinSession(sessionId) { + this.reset(); + this.coreRest.currentSession = sessionId; + const session = await coreRest.getSession(); + console.log('session info: ', session); + const nodes = session.nodes; + const self = this; const nodeIds = [0]; @@ -229,6 +247,11 @@ class CoreNetwork { } else { this.nodeId = 0; } + + return { + id: sessionId, + state: session.state + }; } createEdgeFromLink(linkData) { diff --git a/webapp/static/corerest.js b/webapp/static/corerest.js index 4a30b4ff..b13ebf83 100644 --- a/webapp/static/corerest.js +++ b/webapp/static/corerest.js @@ -92,15 +92,14 @@ class CoreRest { const session = {id: 0, state: 0}; if (sessions.length) { - this.currentSession = sessions[0].id; + session.id = sessions[0].id; session.state = sessions[0].state; } else { response = await this.createSession(); - this.currentSession = response.id; + session.id = response.id; session.state = response.state; } - session.id = this.currentSession; return session; } } diff --git a/webapp/templates/index.html b/webapp/templates/index.html index 693729c7..f5ca4467 100644 --- a/webapp/templates/index.html +++ b/webapp/templates/index.html @@ -38,6 +38,7 @@ Sessions
@@ -131,15 +132,14 @@ const $infoCardTable = $('#info-card-table'); const $infoCardHeader = $('#info-card-header'); const $nodeSelect = $('#node-select'); + const $newSessionButton = $('#new-session-button'); // initial core setup const coreRest = new CoreRest(); const coreNetwork = new CoreNetwork('core-network', coreRest); coreNetwork.initialSession() .then(function(session) { - $sessionId.text(`Session: ${session.id}`); - const isStartEnabled = session.state !== SessionStates.runtime; - setRunButton(isStartEnabled); + joinSession(session); }) .catch(function (err) { console.log('initial session error: ', err); @@ -165,12 +165,16 @@ } function addInfoTable(name, value) { - if (value) { - let $nameCell = $('