From 0c966efe7306cc508ccf934e430d1e0b9010ac45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 15 May 2023 12:05:57 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20folder=20sorting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was completely non deterministic due to no info about last print and upload date having been collected in the backend. This is fixed now, making storing by last upload date, last print etc also apply to folders. The corresponding data has also been made available in the frontend. Closes #4800 --- src/octoprint/filemanager/storage.py | 2 ++ src/octoprint/server/api/files.py | 29 ++++++++++++++++++- .../static/js/app/viewmodels/files.js | 11 +++---- src/octoprint/templates/sidebar/files.jinja2 | 7 +++-- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/octoprint/filemanager/storage.py b/src/octoprint/filemanager/storage.py index e4ae04bdf..0d84c8b4d 100644 --- a/src/octoprint/filemanager/storage.py +++ b/src/octoprint/filemanager/storage.py @@ -1653,6 +1653,8 @@ class LocalFileStorage(StorageInterface): "type": "folder", "typePath": ["folder"], } + if entry_stat: + entry_data["date"] = int(entry_stat.st_mtime) result[entry_name] = entry_data except Exception: diff --git a/src/octoprint/server/api/files.py b/src/octoprint/server/api/files.py index 416d68ca4..2a236a76f 100644 --- a/src/octoprint/server/api/files.py +++ b/src/octoprint/server/api/files.py @@ -387,10 +387,37 @@ def _getFileList( if file_or_folder["type"] == "folder": if "children" in file_or_folder: - file_or_folder["children"] = analyse_recursively( + children = analyse_recursively( file_or_folder["children"].values(), path + file_or_folder["name"] + "/", ) + latest_print = None + success = 0 + failure = 0 + for child in children: + if ( + "prints" not in child + or "last" not in child["prints"] + or "date" not in child["prints"]["last"] + ): + continue + + success += child["prints"].get("success", 0) + failure += child["prints"].get("failure", 0) + + if ( + latest_print is None + or child["prints"]["last"]["date"] > latest_print["date"] + ): + latest_print = child["prints"]["last"] + + file_or_folder["children"] = children + file_or_folder["prints"] = { + "success": success, + "failure": failure, + } + if latest_print: + file_or_folder["prints"]["last"] = latest_print file_or_folder["refs"] = { "resource": url_for( diff --git a/src/octoprint/static/js/app/viewmodels/files.js b/src/octoprint/static/js/app/viewmodels/files.js index dd025833c..b738c9d4e 100644 --- a/src/octoprint/static/js/app/viewmodels/files.js +++ b/src/octoprint/static/js/app/viewmodels/files.js @@ -180,13 +180,10 @@ $(function () { // initialize list helper var listHelperFilters = { printed: function (data) { - return ( - !( - data["prints"] && - data["prints"]["success"] && - data["prints"]["success"] > 0 - ) || - (data["type"] && data["type"] === "folder") + return !( + data["prints"] && + data["prints"]["success"] && + data["prints"]["success"] > 0 ); }, sd: function (data) { diff --git a/src/octoprint/templates/sidebar/files.jinja2 b/src/octoprint/templates/sidebar/files.jinja2 index 8ce10c8db..e96350f9e 100644 --- a/src/octoprint/templates/sidebar/files.jinja2 +++ b/src/octoprint/templates/sidebar/files.jinja2 @@ -19,7 +19,7 @@
{{ _('Internal') }}:
-
{{ _('Uploaded') }}:
+
{{ _('Updated') }}:
{{ _('Size') }}:
@@ -34,7 +34,7 @@