Browse Source

Human friendly file sizes in files manager

Vova Tkach 5 years ago
parent
commit
e89cb7d73e

+ 1 - 1
engine/assets/cp.styles.css

@@ -1153,7 +1153,7 @@ ul.pagination {
 }
 }
 
 
 .data-table.table_fm_files .col_type {
 .data-table.table_fm_files .col_type {
-	width: 6rem;
+	width: 8rem;
 }
 }
 
 
 .data-table.table_fm_files .col_action {
 .data-table.table_fm_files .col_action {

File diff suppressed because it is too large
+ 0 - 0
engine/assets/cp.styles.css.go


+ 20 - 1
engine/modules/module_files_act_list.go

@@ -1,6 +1,7 @@
 package modules
 package modules
 
 
 import (
 import (
+	"fmt"
 	"html"
 	"html"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
@@ -67,7 +68,25 @@ func (this *Modules) RegisterAction_FilesList() *Action {
 							Classes: "delete",
 							Classes: "delete",
 						},
 						},
 					})
 					})
-					str_files += `<tr class="file"><td class="col_name"><span class="text-dotted">` + html.EscapeString(file_name) + `</span></td><td class="col_type">` + utils.Int64ToStr(utils.GetFileSize(file)) + `</td><td class="col_action">` + actions + `</td></tr>`
+
+					size_value := float64(utils.GetFileSize(file))
+					size_text := "Bytes"
+
+					if size_value > 1024 {
+						size_value = size_value / 1024
+						size_text = "Kb"
+					}
+					if size_value > 1024 {
+						size_value = size_value / 1024
+						size_text = "Mb"
+					}
+					if size_value > 1024 {
+						size_value = size_value / 1024
+						size_text = "Gb"
+					}
+
+					str_size := fmt.Sprintf("%5.2f %s", size_value, size_text)
+					str_files += `<tr class="file"><td class="col_name"><span class="text-dotted">` + html.EscapeString(file_name) + `</span></td><td class="col_type">` + str_size + `</td><td class="col_action">` + actions + `</td></tr>`
 				}
 				}
 			}
 			}
 		}
 		}

Some files were not shown because too many files changed in this diff