diff --git a/.gitignore b/.gitignore index 432376e..0f64ee6 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ upgopher # Output of the go coverage tool, specifically when used with LiteIDE *.out +.DS_Store # Dependency directories (remove the comment below to include it) diff --git a/internal/statics/statics.go b/internal/statics/statics.go index 04638c0..9518bdd 100644 --- a/internal/statics/statics.go +++ b/internal/statics/statics.go @@ -190,49 +190,49 @@ func getHTML() string { - - - - - - - - - %s - -
NameSizeActions
-
-
-
1curl -X POST -F "file=@[/path/to/file]" http://[SERVER]:[PORT]/
-
-
-
-

Upload a File

-
-
- -
- -
-
- %s -
-
- %s -
-
- %s - - - ` - return html + + + Name + Size + Actions + + + + %s + + +
+
+
1curl -X POST -F "file=@[/path/to/file]" http://[SERVER]:[PORT]/
+
+
+
+

Upload a File

+
+
+ +
+
+
+ %s +
+
+ %s +
+
+ + + +` + return html } // Javascript Code func getJS() string { - javascript := ` + + // Sorting functionality + function sortTable(n, type = 'string') { + const table = document.querySelector(".styled-table tbody"); + const rows = Array.from(table.rows); + const isAsc = table.dataset.sortOrder === 'asc'; + const sortOrder = isAsc ? 'desc' : 'asc'; + table.dataset.sortOrder = sortOrder; + + rows.sort((rowA, rowB) => { + const cellA = rowA.cells[n].innerText.trim(); + const cellB = rowB.cells[n].innerText.trim(); + + if (type === 'number') { + const numA = parseFloat(cellA) || 0; + const numB = parseFloat(cellB) || 0; + return sortOrder === 'asc' ? numA - numB : numB - numA; + } else { + if (cellA < cellB) return sortOrder === 'asc' ? -1 : 1; + if (cellA > cellB) return sortOrder === 'asc' ? 1 : -1; + return 0; + } + }); + + // Remove existing rows and append sorted rows + table.innerHTML = ""; + rows.forEach(row => table.appendChild(row)); + + // Update sort icons + document.querySelectorAll("th i").forEach(icon => icon.className = 'fa'); // Reset all icons + const icon = document.getElementById(n === 0 ? 'name-icon' : 'size-icon'); + icon.className = "fa fa-sort-" + (sortOrder === 'asc' ? 'asc' : 'desc'); + } ` return javascript }