From e662a877b805d1e2294e166f229b02a066b9736e Mon Sep 17 00:00:00 2001 From: Amanda Ghassaei <amandaghassaei@gmail.com> Date: Fri, 11 Sep 2015 19:43:50 -0400 Subject: [PATCH] next line in send menu --- js/menus/SendMenuView.js | 28 +++++++++++++++++++++++----- js/menus/templates/SendMenuView.html | 2 +- js/models/SerialComm.js | 1 - 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/js/menus/SendMenuView.js b/js/menus/SendMenuView.js index feea3546..74a9de89 100644 --- a/js/menus/SendMenuView.js +++ b/js/menus/SendMenuView.js @@ -19,9 +19,12 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s _initialize: function(){ + this.listenTo(this.model, "change:stockSimulationPlaying", this.render); this.listenTo(serialComm, "change:isStreaming", this.render); - this.listenTo(cam, "change:simLineNumber", this._drawGcodeHighlighter); + this.listenTo(cam, "change:simLineNumber", this._lineNumChanged); + + this.nextLine = cam.get("simLineNumber"); }, _startStream: function(e){ @@ -44,12 +47,23 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s _decrementLineNum: function(e){ e.preventDefault(); - console.log("prev"); + var nextLine = this.nextLine - 1; + if (nextLine < 0) nextLine = 0; + this._setNextLine(nextLine); }, _incrementLineNum: function(e){ e.preventDefault(); - console.log("next"); + var nextLine = this.nextLine + 1; + var length = cam.get("dataOut").split("\n").length; + if (nextLine > length-1) nextLine = length-1; + this._setNextLine(nextLine); + }, + + _setNextLine: function(val){ + this.nextLine = val; + $("#nextLine").val(this.nextLine); + this._drawGcodeHighlighter(val); }, _openSerialMonitor: function(e){ @@ -57,8 +71,12 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s serialComm.openSerialMonitor(); }, - _drawGcodeHighlighter: function(){ + _lineNumChanged: function(){ var lineNum = cam.get("simLineNumber"); + this._setNextLine(lineNum); + }, + + _drawGcodeHighlighter: function(lineNum){ if (lineNum == 0) return; var code = cam.get("dataOut").split("\n"); code[lineNum] = "<span id='gcodeHighlighter'>" + code[lineNum] + " </span>"; @@ -73,7 +91,7 @@ define(['jquery', 'underscore', 'menuParent', 'serialComm', 'commPlist', 'text!s }, _makeTemplateJSON: function(){ - return _.extend(serialComm.toJSON(), commPlist, cam.toJSON(), camPlist); + return _.extend(serialComm.toJSON(), commPlist, cam.toJSON(), camPlist, {nextLine:this.nextLine}); }, _render: function(){ diff --git a/js/menus/templates/SendMenuView.html b/js/menus/templates/SendMenuView.html index c7f271af..1d14b9f2 100644 --- a/js/menus/templates/SendMenuView.html +++ b/js/menus/templates/SendMenuView.html @@ -10,7 +10,7 @@ <% } %> <br/> <a href="#" id="openSerialMonitor" class="btn btn-block btn-lg btn-default">Open Serial Monitor</a><br/> - Next Line: <input id="nextLine" value="" placeholder="##" class="intInput form-control unresponsiveInput" type="text"> + Next Line: <input id="nextLine" value=<%= nextLine %> placeholder="##" class="intInput form-control unresponsiveInput" type="text"> <a href="#" id="previousLineButton" class="btn btn-lg btn-default">Prev</a> <a href="#" id="nextLineButton" class="btn btn-lg btn-default">Next</a><br/><br/> <div id="gcodeEditor"><%= dataOut %></div><br/> diff --git a/js/models/SerialComm.js b/js/models/SerialComm.js index 03ae3ba4..f341e3c7 100644 --- a/js/models/SerialComm.js +++ b/js/models/SerialComm.js @@ -92,7 +92,6 @@ define(['underscore', 'backbone', 'socketio', 'machineState'], function(_, Backb socket.on('connected', function(data){ serialComm.set("connected", true, {silent:true}); - console.log(data); _.each(_.keys(data), function(key){ if (data[key] !== null) serialComm.set(key, data[key]); }); -- GitLab