From 5f55ebd90aaf0b62638be668b2969b83e70ac3f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 4 Feb 2013 22:24:32 +0100 Subject: [PATCH] GCode file list now automatically switches to page with newly uploaded file as soon as upload request comes back from backend as finished. Progress bar also gets emptied again then. Careful: might take a bit after the upload progress reaches 100% since the file still has to be written to disk in the backend (have to look into how to get this done in a streaming way), metadata analysis gets triggered after returning a response. Different sorting options are still on my mental todo list ;) Closes #34. --- octoprint/gcodefiles.py | 2 +- octoprint/server.py | 5 +++-- octoprint/static/js/ui.js | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/octoprint/gcodefiles.py b/octoprint/gcodefiles.py index 87cd26a..cc88bcb 100644 --- a/octoprint/gcodefiles.py +++ b/octoprint/gcodefiles.py @@ -119,7 +119,7 @@ class GcodeManager: if absolutePath is not None: file.save(absolutePath) self._metadataAnalyzer.addFileToQueue(os.path.basename(absolutePath)) - return absolutePath + return self._getBasicFilename(absolutePath) return None def removeFile(self, filename): diff --git a/octoprint/server.py b/octoprint/server.py index fde0a4b..5fde4a9 100644 --- a/octoprint/server.py +++ b/octoprint/server.py @@ -238,10 +238,11 @@ def readGcodeFile(filename): @app.route(BASEURL + "gcodefiles/upload", methods=["POST"]) def uploadGcodeFile(): + filename = None if "gcode_file" in request.files.keys(): file = request.files["gcode_file"] - gcodeManager.addFile(file) - return readGcodeFiles() + filename = gcodeManager.addFile(file) + return jsonify(files=gcodeManager.getAllFileData(), filename=filename) @app.route(BASEURL + "gcodefiles/load", methods=["POST"]) def loadGcodeFile(): diff --git a/octoprint/static/js/ui.js b/octoprint/static/js/ui.js index 36e44cf..2c88413 100644 --- a/octoprint/static/js/ui.js +++ b/octoprint/static/js/ui.js @@ -658,6 +658,11 @@ function GcodeFilesViewModel() { }); self.files(sortedFiles); + + if (response.filename) { + // got a file to scroll to + self.switchToFile(response.filename); + } } self.loadFile = function(filename) { @@ -679,6 +684,22 @@ function GcodeFilesViewModel() { }) } + self.switchToFile = function(filename) { + var pos = -1; + var filelist = self.files(); + for (var i = 0; i < filelist.length; i++) { + if (filelist[i].name == filename) { + pos = i; + break; + } + } + + if (pos > -1) { + var page = Math.floor(pos / self.pageSize()); + self.changePage(page); + } + } + self.changePage = function(newPage) { if (newPage < 0 || newPage > self.lastPage()) return; @@ -1057,6 +1078,7 @@ $(function() { dataType: "json", done: function (e, data) { gcodeFilesViewModel.fromResponse(data.result); + $("#gcode_upload_progress .bar").css("width", "0%"); }, progressall: function (e, data) { var progress = parseInt(data.loaded / data.total * 100, 10);