From: Christian Heller <c.heller@plomlompom.de>
Date: Thu, 20 Feb 2025 18:23:12 +0000 (+0100)
Subject: To /files view add sorting by tags amount.
X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/todos?a=commitdiff_plain;h=cf9ca25ec6d2d0990e32c3e8ced0d8a93ebed727;p=ytplom

To /files view add sorting by tags amount.
---

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>