Fixed send.js table sorting. Looks like it stopped working a long time ago.

This commit is contained in:
Benjamin Erhart 2021-10-22 12:21:22 +02:00
parent 357e3efead
commit f3f25166d4
2 changed files with 21 additions and 17 deletions

View File

@ -11,7 +11,7 @@ function unhumanize(text) {
} }
} }
function sortTable(n) { function sortTable(n) {
var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0; var table, rows, switching, i, x, y, valX, valY, shouldSwitch, dir, switchcount = 0;
table = document.getElementById("file-list"); table = document.getElementById("file-list");
switching = true; switching = true;
// Set the sorting direction to ascending: // Set the sorting direction to ascending:
@ -21,7 +21,7 @@ function sortTable(n) {
while (switching) { while (switching) {
// Start by saying: no switching is done: // Start by saying: no switching is done:
switching = false; switching = false;
rows = table.getElementsByTagName("TR"); rows = table.getElementsByClassName("row");
/* Loop through all table rows (except the /* Loop through all table rows (except the
first, which contains table headers): */ first, which contains table headers): */
for (i = 1; i < (rows.length - 1); i++) { for (i = 1; i < (rows.length - 1); i++) {
@ -29,18 +29,22 @@ function sortTable(n) {
shouldSwitch = false; shouldSwitch = false;
/* Get the two elements you want to compare, /* Get the two elements you want to compare,
one from current row and one from the next: */ one from current row and one from the next: */
x = rows[i].getElementsByTagName("TD")[n]; x = rows[i].getElementsByClassName("cell-data")[n];
y = rows[i + 1].getElementsByTagName("TD")[n]; y = rows[i + 1].getElementsByClassName("cell-data")[n];
valX = x.classList.contains("size") ? unhumanize(x.innerHTML.toLowerCase()) : x.innerHTML;
valY = y.classList.contains("size") ? unhumanize(y.innerHTML.toLowerCase()) : y.innerHTML;
/* Check if the two rows should switch place, /* Check if the two rows should switch place,
based on the direction, asc or desc: */ based on the direction, asc or desc: */
if (dir == "asc") { if (dir == "asc") {
if (unhumanize(x.innerHTML.toLowerCase()) > unhumanize(y.innerHTML.toLowerCase())) { if (valX > valY) {
// If so, mark as a switch and break the loop: // If so, mark as a switch and break the loop:
shouldSwitch= true; shouldSwitch= true;
break; break;
} }
} else if (dir == "desc") { } else if (dir == "desc") {
if (unhumanize(x.innerHTML.toLowerCase()) < unhumanize(y.innerHTML.toLowerCase())) { if (valX < valY) {
// If so, mark as a switch and break the loop: // If so, mark as a switch and break the loop:
shouldSwitch= true; shouldSwitch= true;
break; break;

View File

@ -32,7 +32,7 @@
{% endif %} {% endif %}
<div class="file-list" id="file-list"> <div class="file-list" id="file-list">
<div class="d-flex"> <div class="d-flex row">
<div id="filename-header" class="heading">Filename</div> <div id="filename-header" class="heading">Filename</div>
<div id="size-header" class="heading">Size</div> <div id="size-header" class="heading">Size</div>
</div> </div>
@ -41,26 +41,26 @@
<div> <div>
<img width="30" height="30" title="" alt="" src="{{ static_url_path }}/img/web_folder.png" /> <img width="30" height="30" title="" alt="" src="{{ static_url_path }}/img/web_folder.png" />
<a href="{{ info.link }}"> <a href="{{ info.link }}">
<span>{{ info.basename }}</span> <span class="cell-data">{{ info.basename }}</span>
</a> </a>
</div> </div>
<div>&mdash;</div> <div class="cell-data">&mdash;</div>
</div> </div>
{% endfor %} {% endfor %}
{% for info in files %} {% for info in files %}
<div class="d-flex"> <div class="d-flex row">
<div> <div>
<img width="30" height="30" title="" alt="" src="{{ static_url_path }}/img/web_file.png" /> <img width="30" height="30" title="" alt="" src="{{ static_url_path }}/img/web_file.png" />
{% if download_individual_files %} {% if download_individual_files %}
<a href="{{ info.link }}"> <a href="{{ info.link }}">
<span>{{ info.basename }}</span> <span class="cell-data">{{ info.basename }}</span>
</a> </a>
{% else %} {% else %}
<span>{{ info.basename }}</span> <span class="cell-data">{{ info.basename }}</span>
{% endif %} {% endif %}
</div> </div>
<div>{{ info.size_human }}</div> <div class="cell-data size">{{ info.size_human }}</div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>