From da5a2ca0052f0f4a4a50501e7d9239ed44e11112 Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Thu, 22 Oct 2015 23:57:09 -0400 Subject: [PATCH] fix for rendering issue --- js/SerialMonitor/appState.js | 8 ++++++++ js/SerialMonitor/lattice.js | 8 ++++++++ js/models/SerialComm.js | 19 +++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 js/SerialMonitor/appState.js create mode 100644 js/SerialMonitor/lattice.js diff --git a/js/SerialMonitor/appState.js b/js/SerialMonitor/appState.js new file mode 100644 index 00000000..052883c5 --- /dev/null +++ b/js/SerialMonitor/appState.js @@ -0,0 +1,8 @@ +/** + * Created by aghassaei on 10/22/15. + */ + + +define([], function(){ + return {}; +}); \ No newline at end of file diff --git a/js/SerialMonitor/lattice.js b/js/SerialMonitor/lattice.js new file mode 100644 index 00000000..052883c5 --- /dev/null +++ b/js/SerialMonitor/lattice.js @@ -0,0 +1,8 @@ +/** + * Created by aghassaei on 10/22/15. + */ + + +define([], function(){ + return {}; +}); \ No newline at end of file diff --git a/js/models/SerialComm.js b/js/models/SerialComm.js index a1ed3c9f..32e4384a 100644 --- a/js/models/SerialComm.js +++ b/js/models/SerialComm.js @@ -2,8 +2,10 @@ * Created by aghassaei on 6/17/15. */ -define(['underscore', 'backbone', 'socketio', 'machineState', 'cam'], - function(_, Backbone, io, machineState, cam){ +//todo get cam, lattice, appstate out of here + +define(['underscore', 'backbone', 'socketio', 'machineState', 'cam', 'lattice', 'appState'], + function(_, Backbone, io, machineState, cam, lattice, appState){ var SerialComm = Backbone.Model.extend({ @@ -23,9 +25,14 @@ define(['underscore', 'backbone', 'socketio', 'machineState', 'cam'], initialize: function(){ this.machineState = machineState; this.listenTo(machineState, "change", this._updateVirtualMachine); + if (appState.get) this.listenTo(appState, "change:currentNav", this._navChanged); this.attemptToConnectToNode(); }, + _navChanged: function(){ + if (appState.previous("currentNav") == "navComm") lattice.showCells("cells"); + }, + attemptToConnectToNode: function(){ if (!this.get("connected")) { this.socket = io.connect('http://localhost:8080', {'forceNew':true}); @@ -75,8 +82,16 @@ define(['underscore', 'backbone', 'socketio', 'machineState', 'cam'], if (machineState && machineState.isReadyStatus()){ var lineNum = cam.get("simLineNumber"); var allLines = cam.get("dataOut").split("\n"); + if (lineNum == 0) lattice.hideCells("cells"); if (lineNum >= 0 && lineNum < allLines.length) { var line = allLines[lineNum]; + + if (line.substr(0,2) == "({"){ + var index = line.substr(1,line.length-2); + index = JSON.parse(index); + lattice.showCellAtIndex(index); + } + self.listenToOnce(machineState, "readyForNextCommand", function(){ lineNum ++; cam.set("simLineNumber", lineNum); -- GitLab