From b824882eb25d5a55906dd6a4f89c4bf8cb953bd0 Mon Sep 17 00:00:00 2001 From: df Date: Sun, 14 Jun 2020 23:49:13 +0000 Subject: [PATCH 1/5] 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. --- webif/html/browse/index.jim | 46 +++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/webif/html/browse/index.jim b/webif/html/browse/index.jim index 762a1c7..669831e 100755 --- a/webif/html/browse/index.jim +++ b/webif/html/browse/index.jim @@ -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 "
" -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 " - " - set tag "Sort" + puts "" + set tag "" } - puts " $tag by $descr" + puts " $descr$tag" if {$order != $index} { puts "" } @@ -443,4 +476,3 @@ if {[llength $plugins(buttons)]} { puts "
" footer - From 478d9db2e2ff33d1e7a46ebef3807fdc183167cb Mon Sep 17 00:00:00 2001 From: df Date: Mon, 15 Jun 2020 02:47:06 +0000 Subject: [PATCH 2/5] Add sort by size (icon) --- webif/html/img/sort-size.png/sort_size.gif | Bin 0 -> 618 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 webif/html/img/sort-size.png/sort_size.gif diff --git a/webif/html/img/sort-size.png/sort_size.gif b/webif/html/img/sort-size.png/sort_size.gif new file mode 100644 index 0000000000000000000000000000000000000000..d5fbda59995752ee7daa7811b307b4c035a9a362 GIT binary patch literal 618 zcmZ?wbhEHb6krfwIF`(yYG|isWT$Ryr)lb7VC`mN?`iJjo19yomS2@xP?b?!mtESJ zSJ7Nh)m~iJRod8F(L6D-^FUSGq^h>bRqc~&I;M7XbaZ!jH}%fy>FMe1?d|XHPnmu? zZThK+6DOw6I6Z07q^VPCcG{=({T}ym|BSYC-C4{E+g!}sh%}WyEPl`=SbhUNXl(CFok;KoJ6qDp) Date: Mon, 15 Jun 2020 03:31:28 +0000 Subject: [PATCH 3/5] Avoid sort order build-up in sort URL parameter string Fixes behaviour where each new sort added &order=n to the query string. --- webif/html/browse/index.jim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webif/html/browse/index.jim b/webif/html/browse/index.jim index 669831e..a1b60be 100755 --- a/webif/html/browse/index.jim +++ b/webif/html/browse/index.jim @@ -379,7 +379,8 @@ foreach sl $sortlist { set tag " (current)" if {$order != $index} { - puts "" + set qs [regsub -all {&order=[[[:digit:]]+} $env(QUERY_STRING) ""] + puts "" set tag "" } puts " $descr$tag" From 42cf8bf238f5408e82a07652f78ff29e661eb387 Mon Sep 17 00:00:00 2001 From: df Date: Tue, 16 Jun 2020 04:12:08 +0000 Subject: [PATCH 4/5] Add tooltips for sort orders Also generalise the file sort function to allow sorting by any quantity returned by `[file stat]` --- webif/html/browse/index.jim | 54 +++++++++++++------------------------ 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/webif/html/browse/index.jim b/webif/html/browse/index.jim index a1b60be..d10aa01 100755 --- a/webif/html/browse/index.jim +++ b/webif/html/browse/index.jim @@ -292,7 +292,7 @@ if {$parent ne ""} { " } -proc s_time {a b} { +proc s_file_stat {a b attr} { global dir set a "$dir/$a" @@ -310,40 +310,21 @@ proc s_time {a b} { } if {[catch {file stat $a l}]} { return 0} - set at $l(mtime) + set at $l($attr) 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 } return 0 } +proc s_time {a b} { + tailcall s_file_stat $a $b mtime +} + 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 + tailcall s_file_stat $a $b size } set files [readdir -nocomplain $dir] @@ -367,26 +348,27 @@ Directories: $dircount, Files: $filecount # Sort icons puts "" From 0ef47da7b6e20728f8e3ac429366c40c380addf2 Mon Sep 17 00:00:00 2001 From: HummyPkg Date: Thu, 18 Jun 2020 00:57:22 +0100 Subject: [PATCH 5/5] Remove trailing whitespace, restore last blank line --- webif/html/browse/index.jim | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/webif/html/browse/index.jim b/webif/html/browse/index.jim index d10aa01..9c27973 100755 --- a/webif/html/browse/index.jim +++ b/webif/html/browse/index.jim @@ -104,7 +104,7 @@ set filecount 0 proc entry {file} {{i 0}} { global dircount filecount dinuse - + set bfile [file tail $file] regsub -all " +" $bfile "" tbfile if {[string index $bfile 0] == "\025"} { @@ -320,7 +320,7 @@ proc s_file_stat {a b attr} { } proc s_time {a b} { - tailcall s_file_stat $a $b mtime + tailcall s_file_stat $a $b mtime } proc s_size {a b} { @@ -348,9 +348,11 @@ Directories: $dircount, Files: $filecount # Sort icons puts "
" 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}}} + {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 { @@ -368,7 +370,7 @@ foreach sl $sortlist { puts "" set ket "span" } - puts " $descr$tag" + puts " $descr$tag" } puts "
" @@ -459,3 +461,4 @@ if {[llength $plugins(buttons)]} { puts "" footer +