Add sort by size

Implementing https://hummy.tv/forum/threads/webif-web-interface-1-4-x.7712/post-142116.

The sort line is reorganised to allow for two more sort orders.
This commit is contained in:
df 2020-06-14 23:49:13 +00:00 committed by HummyPkg
parent 4b3efc2e72
commit b824882eb2
1 changed files with 39 additions and 7 deletions

View File

@ -319,10 +319,39 @@ proc s_time {a b} {
return 0
}
proc s_size {a b} {
global dir
set a "$dir/$a"
set b "$dir/$b"
set ad [file isdirectory $a]
set bd [file isdirectory $b]
if {$ad && !$bd} { return -1 }
if {$bd && !$ad} { return 1 }
if {$ad && $bd} {
if {$a < $b} { return -1 }
if {$a > $b} { return 1 }
return 0
}
if {[catch {file stat $a l}]} { return 0}
set as $l(size)
if {[catch {file stat $b l}]} { return 0}
set bs $l(size)
if {$as < $bs} { return -1 }
if {$as > $bs} { return 1 }
return 0
}
set files [readdir -nocomplain $dir]
switch $order {
1 { set files [lsort -command s_time $files] }
2 { set files [lreverse [lsort -command s_time $files]] }
3 { set files [lsort -command s_size $files] }
4 { set files [lreverse [lsort -command s_size $files]] }
default { set files [lsort -nocase $files] }
}
@ -337,19 +366,23 @@ Directories: $dircount, Files: $filecount
# Sort icons
puts "<div id=sortdiv>"
set sortlist {{0 sort_name name} {1 sort_date date} {2 sort_date reverse-date}}
set sortlist {
{0 sort_name name}
{1 sort_date date} {2 sort_date reverse-date}
{3 sort_size size} {4 sort_size reverse-size}}
puts "
Sort by: "
foreach sl $sortlist {
lassign $sl index img descr
if {$index} { puts " | " }
set tag "Currently sorting"
set tag " (current)"
if {$order != $index} {
puts "
<a href=\"$env(SCRIPT_NAME)?$env(QUERY_STRING)&order=$index\">"
set tag "Sort"
puts "<a href=\"$env(SCRIPT_NAME)?$env(QUERY_STRING)&order=$index\">"
set tag ""
}
puts "<img class=va border=0 src=/img/$img.gif> $tag by $descr"
puts "<img class=va border=0 src=/img/$img.gif> $descr$tag"
if {$order != $index} {
puts "</a>"
}
@ -443,4 +476,3 @@ if {[llength $plugins(buttons)]} {
puts "</div>"
footer