From 790ca9c90a34f3245c0f23680f0b741dabfebe5d Mon Sep 17 00:00:00 2001 From: logaritmisk Date: Mon, 3 Oct 2016 22:27:21 +0200 Subject: [PATCH] Human file size for media info table. --- .../default/js/tables/media_info_table.js | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/data/interfaces/default/js/tables/media_info_table.js b/data/interfaces/default/js/tables/media_info_table.js index 46c34fa3..66004622 100644 --- a/data/interfaces/default/js/tables/media_info_table.js +++ b/data/interfaces/default/js/tables/media_info_table.js @@ -280,8 +280,8 @@ media_info_table_options = { } $("#media_info_table-SID-" + section_id + "_info").append(''); + humanFileSize(settings.json.filtered_file_size) + + ' (filtered from ' + humanFileSize(settings.json.total_file_size) + ')'); }, "preDrawCallback": function(settings) { var msg = " Fetching rows..."; @@ -484,4 +484,21 @@ function createChildTableMedia(row, rowData) { createChildTableMedia(row, rowData); } }); -} \ No newline at end of file +} + +// Taken from http://stackoverflow.com/questions/10420352/converting-file-size-in-bytes-to-human-readable#answer-14919494 +function humanFileSize(bytes, si) { + var thresh = si ? 1000 : 1024; + if(Math.abs(bytes) < thresh) { + return bytes + ' B'; + } + var units = si + ? ['kB','MB','GB','TB','PB','EB','ZB','YB'] + : ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB']; + var u = -1; + do { + bytes /= thresh; + ++u; + } while(Math.abs(bytes) >= thresh && u < units.length - 1); + return bytes.toFixed(1)+' '+units[u]; +}