diff --git a/octoprint/static/gcodeviewer/js/ui.js b/octoprint/static/gcodeviewer/js/ui.js index 4f9bc7b..f780c81 100644 --- a/octoprint/static/gcodeviewer/js/ui.js +++ b/octoprint/static/gcodeviewer/js/ui.js @@ -296,6 +296,9 @@ GCODE.ui = (function(){ } return -1; }, + updateLayerInfo: function(layerNum){ + printLayerInfo(layerNum); + }, processOptions: function(){ if(document.getElementById('sortLayersCheckbox').checked)GCODE.gCodeReader.setOption({sortLayers: true}); diff --git a/octoprint/static/js/ui.js b/octoprint/static/js/ui.js index 095ea4e..ae8872b 100644 --- a/octoprint/static/js/ui.js +++ b/octoprint/static/js/ui.js @@ -667,13 +667,6 @@ function GcodeFilesViewModel() { dataType: "json", data: {filename: filename} }) - $.ajax({ - url: "gcodefile/"+filename, - type: "GET", - success: function(response, rstatus) { - self.showGCodeViewer(response, rstatus); - } - }) } self.viewFile = function() { @@ -817,18 +810,53 @@ function WebcamViewModel() { function GcodeViewModel() { var self = this; + self.loadedFilename = undefined; + self.status = 'idle'; + + self.loadFile = function(filename){ + if(self.status == 'idle'){ + self.status = 'request'; + $.ajax({ + url: "gcodefile/"+filename, + type: "GET", + success: function(response, rstatus) { + if(rstatus === 'success'){ + self.showGCodeViewer(response, rstatus); + self.loadedFilename=filename; + self.status = 'idle'; + } + }, + error: function() { + self.status = 'idle'; + } + }) + } + } + + self.showGCodeViewer = function(response, rstatus){ + var par = {}; + par.target = {}; + par.target.result = response; + GCODE.gCodeReader.loadFile(par); + } + self.fromHistoryData = function(data) { - self._processProgressData(data.progress); + self._processData(data); } self.fromCurrentData = function(data) { - self._processProgressData(data.progress); + self._processData(data); } - self._processProgressData = function(data) { - var cmdIndex = GCODE.gCodeReader.getLinesCmdIndex(data.progress); - if(cmdIndex){ - GCODE.renderer.render(cmdIndex.layer, 0, cmdIndex.cmd); + self._processData = function(data) { + if(self.loadedFilename == data.job.filename){ + var cmdIndex = GCODE.gCodeReader.getLinesCmdIndex(data.progress.progress); + if(cmdIndex){ + GCODE.renderer.render(cmdIndex.layer, 0, cmdIndex.cmd); + GCODE.ui.updateLayerInfo(cmdIndex.layer); + } + }else{ + self.loadFile(data.job.filename); } }