From cf9ca25ec6d2d0990e32c3e8ced0d8a93ebed727 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Thu, 20 Feb 2025 19:23:12 +0100
Subject: [PATCH] To /files view add sorting by tags amount.

---
 src/templates/files.tmpl | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/templates/files.tmpl b/src/templates/files.tmpl
index 2338cf8..bb60fc2 100644
--- a/src/templates/files.tmpl
+++ b/src/templates/files.tmpl
@@ -54,7 +54,10 @@ function draw_files_table() {
             inverter = -1;
             _sort_key = sort_key.substring(1);
         }
-        return inverter * ((a[_sort_key] > b[_sort_key]) ? 1 : -1);
+        const cmp = "tags_count" == _sort_key
+                    ? (a.tags_showable.length > b.tags_showable.length)
+                    : (a[_sort_key] > b[_sort_key]);
+        return inverter * (cmp ? 1 : -1);
     });
     const table = document.getElementById("files_table");
     Array.from(document.getElementsByClassName("file_row")).forEach((row) => row.remove());
@@ -129,7 +132,7 @@ known files (shown: <span id="files_count">?</span>):
 <th><button class="sorter" onclick="sort_by(this, 'size'); ">size</button></th>
 <th><button class="sorter" onclick="sort_by(this, 'duration'); ">duration</button></th>
 <th>actions</th>
-<th>tags</th>
+<th>tags <button class="sorter" onclick="sort_by(this, 'tags_count'); ">count</button></th>
 <th><button class="sorter" onclick="sort_by(this, 'rel_path'); ">path</button></th>
 </tr>
 </table>
-- 
2.30.2