From 3db21f1a707b6b6108198bd5b833f0d609b9a336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 18 Nov 2015 17:44:11 +0100 Subject: [PATCH] Fixed highlighting for files in folders While at it also adjusted highlighting so that the folder containing the currently selected file will be highlighted if the selected file is not within the current folder but in one of its sub folders. --- src/octoprint/static/js/app/viewmodels/files.js | 15 +++++++++++++-- src/octoprint/templates/sidebar/files.jinja2 | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/octoprint/static/js/app/viewmodels/files.js b/src/octoprint/static/js/app/viewmodels/files.js index 72d36695..0743725f 100644 --- a/src/octoprint/static/js/app/viewmodels/files.js +++ b/src/octoprint/static/js/app/viewmodels/files.js @@ -146,12 +146,20 @@ $(function() { self.highlightFilename(newValue); }); + self.highlightCurrentFilename = function() { + self.highlightFilename(self.printerState.filename()); + }; + self.highlightFilename = function(filename) { if (filename == undefined) { self.listHelper.selectNone(); } else { self.listHelper.selectItem(function(item) { - return item.name == filename; + if (item.type == "folder") { + return _.startsWith(filename, OctoPrint.files.pathForElement(item) + "/"); + } else { + return OctoPrint.files.pathForElement(item) == filename; + } }); } }; @@ -195,6 +203,7 @@ $(function() { self.allItems(files); self.currentPath(""); self.listHelper.addFilter("emptyFolder"); + if (!switchToPath) { self.listHelper.updateItems(files); } else { @@ -221,12 +230,13 @@ $(function() { self.totalSpace(response.total); } - self.highlightFilename(self.printerState.filename()); + self.highlightCurrentFilename(); }; self.changeFolder = function(data) { self.currentPath(OctoPrint.files.pathForElement(data)); self.listHelper.updateItems(data.children); + self.highlightCurrentFilename(); }; self.navigateUp = function() { @@ -244,6 +254,7 @@ $(function() { self.currentPath(""); self.listHelper.updateItems(self.allItems()); } + self.highlightCurrentFilename(); }; self.loadFile = function(file, printAfterLoad) { diff --git a/src/octoprint/templates/sidebar/files.jinja2 b/src/octoprint/templates/sidebar/files.jinja2 index 31be4107..994d7a0a 100644 --- a/src/octoprint/templates/sidebar/files.jinja2 +++ b/src/octoprint/templates/sidebar/files.jinja2 @@ -35,7 +35,7 @@