Merge pull request 'df-browse-sizesort-patch' (#9) from df/webif:df-browse-sizesort-patch into master

This commit is contained in:
af123 2020-06-17 23:58:33 +00:00
commit f40a82df57
2 changed files with 32 additions and 14 deletions

View File

@ -292,7 +292,7 @@ if {$parent ne ""} {
" "
} }
proc s_time {a b} { proc s_file_stat {a b attr} {
global dir global dir
set a "$dir/$a" set a "$dir/$a"
@ -310,19 +310,29 @@ proc s_time {a b} {
} }
if {[catch {file stat $a l}]} { return 0} if {[catch {file stat $a l}]} { return 0}
set at $l(mtime) set at $l($attr)
if {[catch {file stat $b l}]} { return 0} if {[catch {file stat $b l}]} { return 0}
set bt $l(mtime) set bt $l($attr)
if {$at < $bt} { return -1 } if {$at < $bt} { return -1 }
if {$at > $bt} { return 1 } if {$at > $bt} { return 1 }
return 0 return 0
} }
proc s_time {a b} {
tailcall s_file_stat $a $b mtime
}
proc s_size {a b} {
tailcall s_file_stat $a $b size
}
set files [readdir -nocomplain $dir] set files [readdir -nocomplain $dir]
switch $order { switch $order {
1 { set files [lsort -command s_time $files] } 1 { set files [lsort -command s_time $files] }
2 { set files [lreverse [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] } default { set files [lsort -nocase $files] }
} }
@ -337,22 +347,30 @@ Directories: $dircount, Files: $filecount
# Sort icons # Sort icons
puts "<div id=sortdiv>" 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 {Alphabetical order A->Z}}
{1 sort_date date {Oldest first}}
{2 sort_date reverse-date {Newest first}}
{3 sort_size size {Smallest first}}
{4 sort_size reverse-size {Largest first}}}
puts "
Sort by: "
foreach sl $sortlist { foreach sl $sortlist {
lassign $sl index img descr lassign $sl index img descr tt
if {$index} { puts " | " } if {$index} { puts " | " }
set tag "Currently sorting" set tag " (current)"
if {$order != $index} { if {$order != $index} {
puts " set qs [regsub -all {&order=[[[:digit:]]+} $env(QUERY_STRING) ""]
<a href=\"$env(SCRIPT_NAME)?$env(QUERY_STRING)&order=$index\">" puts "<a href=\"$env(SCRIPT_NAME)?$qs&order=$index\" title=\"$tt\">"
set tag "Sort" set tag ""
} set ket "a"
puts "<img class=va border=0 src=/img/$img.gif> $tag by $descr" } else {
if {$order != $index} { puts "<span title=\"$tt\">"
puts "</a>" set ket "span"
} }
puts "<img class=va border=0 src=/img/$img.gif> $descr$tag</$ket>"
} }
puts "</div>" puts "</div>"

Binary file not shown.

After

Width:  |  Height:  |  Size: 618 B