add display sizes to files (#5455)
Signed-off-by: Simon Smith <simonsmith5521@gmail.com>
Simon Smith committed
Oct 21, 2023 at 01:28 UTC
1002bbb952ba88363dbb23e86fdd2f13fb8d91c1
1 file changed
+24
-2
views/default.handlebars
+24
-2
@@ -862,6 +862,13 @@
862
<tr>
863
<td class="areaHead3">
864
<div class="toright2">
865
+ <select id=p13sizedropdown onchange=p13updateFiles()>
866
+ <option value=0 selected="selected">Human Readble</option>
867
+ <option value=1 title=Bytes>Bytes</option>
868
+ <option value=10 title=KB>Kilobytes</option>
869
+ <option value=20 title=MB>Megabytes</option>
870
+ <option value=30 title=GB>Gigabyte</option>
871
+ </select>
872
<select id=p13sortdropdown onchange=p13updateFiles()>
873
<option value=1 selected="selected">Sort by name</option>
874
<option value=2>Sort by size</option>
@@ -10784,7 +10791,7 @@
10791
10792
function p13updateFiles(checkedNames) {
10793
var html1 = '', html2 = '', displayPath = '<a href=# style=cursor:pointer onclick="return p13folderup(0)">' + "Root" + '</a>', fullPath = 'Root';
10787
-
10794
+ if(p13filetree==null) return;
10795
// Work on parsing the file path
10796
var x = p13filetree.path.split('\\');
10797
p13filetreelocation = [];
@@ -10811,7 +10818,22 @@
10818
10819
// Figure out the size
10820
var fsize = '';
10814
- if (f.s != null) { fsize = getFileSizeStr(f.s); }
10821
+ if (f.s != null) {
10822
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
10823
+ const i = parseInt(Math.floor(Math.log(Math.abs(f.s)) / Math.log(1024)), 10);
10824
+ const option = Q('p13sizedropdown').options[Q('p13sizedropdown').selectedIndex];
10825
+ if(Q('p13sizedropdown').value==0){
10826
+ if (f.s === 0){
10827
+ fsize = 'n/a';
10828
+ }else{
10829
+ fsize = (i === 0 ? `${f.s} ${sizes[i]}` : `${(f.s / (1024 ** i)).toFixed(2)} ${sizes[i]}`);
10830
+ }
10831
+ }else if(Q('p13sizedropdown').value==1){
10832
+ fsize = getFileSizeStr(f.s);
10833
+ }else{
10834
+ fsize = `${(f.s / (2 ** option.value)).toFixed(2)} ${option.title}`;
10835
+ }
10836
+ }
10837
10838
var h = '';
10839
if (f.t < 3) {