From e60934b6234ab1ea291fc020934a8bbd40851c3f Mon Sep 17 00:00:00 2001 From: Ihsan Ullah Date: Fri, 26 May 2023 14:40:18 +0500 Subject: [PATCH 1/4] Resources -> Datasets : fiel sizes added in readable format --- src/static/riot/datasets/management.tag | 39 +++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/static/riot/datasets/management.tag b/src/static/riot/datasets/management.tag index d437771e3..ac09406b3 100644 --- a/src/static/riot/datasets/management.tag +++ b/src/static/riot/datasets/management.tag @@ -1,7 +1,8 @@ + --------------------------------------> +
@@ -26,13 +27,14 @@ + --------------------------------------> - + + @@ -45,6 +47,7 @@ onclick="{show_info_modal.bind(this, dataset)}"> +
Name TypeUploaded...SizeUploaded In Use Public Delete?{ dataset.name } { dataset.type }{ format_file_size(dataset.file_size) } { timeSince(Date.parse(dataset.created_when)) } ago @@ -284,6 +287,7 @@ } CODALAB.api.get_datasets(filters) .done(function (data) { + console.log(data.results) self.datasets = data.results self.pagination = { "count": data.count, @@ -443,6 +447,35 @@ } } + // Function to format file size + self.format_file_size = function(file_size) { + + // parse file size from string to float + try { + n = parseFloat(file_size) + } + catch(err) { + // return empty string if parsing fails + return "" + } + + // constant units to show with files size + // file size is in KB, converting it to MB and GB + const units = ['KB', 'MB', 'GB'] + + // loop incrementer for selecting desired unit + let i = 0 + + // loop over n until it is greater than 1000 + while(n >= 1000 && ++i){ + n = n/1000; + } + + // restrict file size to 1 decimal number concatinated with unit + return(n.toFixed(1) + ' ' + units[i]); + + } +