From 8e13e4fcc0207a5fc5ef4befa26440a111c2592a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 19 Jun 2020 15:07:18 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Allow=20sorting=20of=20file=20list?= =?UTF-8?q?=20by=20last=20print=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit part 1/2 of #3433 --- src/octoprint/static/js/app/viewmodels/files.js | 13 +++++++++++++ src/octoprint/templates/sidebar/files_header.jinja2 | 1 + 2 files changed, 14 insertions(+) diff --git a/src/octoprint/static/js/app/viewmodels/files.js b/src/octoprint/static/js/app/viewmodels/files.js index d1f75560e..cecfd25ba 100644 --- a/src/octoprint/static/js/app/viewmodels/files.js +++ b/src/octoprint/static/js/app/viewmodels/files.js @@ -152,6 +152,19 @@ $(function() { if (a["date"] === undefined || a["date"] < b["date"]) return 1; return 0; }, + "last_printed": function(a, b) { + // sorts descending + var valA = (a.prints && a.prints.last && a.prints.last.date) ? a.prints.last.date : ""; + var valB = (b.prints && b.prints.last && b.prints.last.date) ? b.prints.last.date : ""; + + if (valA > valB) { + return -1; + } else if (valA < valB) { + return 1; + } else { + return 0; + } + }, "size": function(a, b) { // sorts descending if (b["size"] === undefined || a["size"] > b["size"]) return -1; diff --git a/src/octoprint/templates/sidebar/files_header.jinja2 b/src/octoprint/templates/sidebar/files_header.jinja2 index b120cd9a1..9f996e74d 100644 --- a/src/octoprint/templates/sidebar/files_header.jinja2 +++ b/src/octoprint/templates/sidebar/files_header.jinja2 @@ -7,6 +7,7 @@
  • {{ _('Sort by name') }} ({{ _('ascending') }})
  • {{ _('Sort by upload date') }} ({{ _('descending') }})
  • +
  • {{ _('Sort by date of last print') }} ({{ _('descending') }})
  • {{ _('Sort by file size') }} ({{ _('descending') }})