mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-29 06:25:18 -04:00
Adds optional binary prefixes.
This commit is contained in:
parent
3cd11139a2
commit
27c598d96e
3 changed files with 40 additions and 10 deletions
|
@ -38,10 +38,13 @@ var H5AI_CONFIG = {
|
||||||
so that it will be persistent.
|
so that it will be persistent.
|
||||||
|
|
||||||
Set parent folder labels to real folder names.
|
Set parent folder labels to real folder names.
|
||||||
|
Binary prefix set to true uses 1024B=1KiB when formatting
|
||||||
|
file sizes (see http://en.wikipedia.org/wiki/Binary_prefix).
|
||||||
*/
|
*/
|
||||||
"view": {
|
"view": {
|
||||||
"modes": ["details", "icons"],
|
"modes": ["details", "icons"],
|
||||||
"setParentFolderLabels": true
|
"setParentFolderLabels": true,
|
||||||
|
"binaryPrefix": false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,21 @@
|
||||||
modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
|
modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
|
||||||
|
|
||||||
var reParseSize = /^\s*([\.\d]+)\s*([kmgt]?)b?\s*$/i,
|
var reParseSize = /^\s*([\.\d]+)\s*([kmgt]?)b?\s*$/i,
|
||||||
treshhold = 1000.0,
|
decimalMetric = {
|
||||||
kilo = 1000.0,
|
t: 1000.0,
|
||||||
sizeUnits = ['B', 'KB', 'MB', 'GB', 'TB'],
|
k: 1000.0,
|
||||||
|
u: ['B', 'KB', 'MB', 'GB', 'TB']
|
||||||
|
},
|
||||||
|
binaryMetric = {
|
||||||
|
t: 1024.0,
|
||||||
|
k: 1024.0,
|
||||||
|
u: ['B', 'KiB', 'MiB', 'GiB', 'TiB']
|
||||||
|
},
|
||||||
|
|
||||||
parseSize = function (str) {
|
parseSize = function (str) {
|
||||||
|
|
||||||
var match = reParseSize.exec(str),
|
var match = reParseSize.exec(str),
|
||||||
|
kilo = decimalMetric.k,
|
||||||
val, unit;
|
val, unit;
|
||||||
|
|
||||||
if (!match) {
|
if (!match) {
|
||||||
|
@ -29,20 +37,35 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
|
||||||
return val;
|
return val;
|
||||||
},
|
},
|
||||||
|
|
||||||
formatSize = function (size) {
|
defaultMetric = decimalMetric,
|
||||||
|
|
||||||
|
setDefaultMetric = function (metric) {
|
||||||
|
|
||||||
|
if (!metric) {
|
||||||
|
defaultMetric = decimalMetric;
|
||||||
|
} else if (metric === true) {
|
||||||
|
defaultMetric = binaryMetric;
|
||||||
|
} else {
|
||||||
|
defaultMetric = metric;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
formatSize = function (size, metric) {
|
||||||
|
|
||||||
|
metric = metric || defaultMetric;
|
||||||
|
|
||||||
if (!_.isNumber(size) || size < 0) {
|
if (!_.isNumber(size) || size < 0) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
var i = 0,
|
var i = 0,
|
||||||
maxI = sizeUnits.length - 1;
|
maxI = metric.u.length - 1;
|
||||||
|
|
||||||
while (size >= treshhold && i < maxI) {
|
while (size >= metric.t && i < maxI) {
|
||||||
size /= kilo;
|
size /= metric.k;
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
return (i <= 1 ? Math.round(size) : size.toFixed(1)).toString() + ' ' + sizeUnits[i];
|
return (i <= 1 ? Math.round(size) : size.toFixed(1)).toString() + ' ' + metric.u[i];
|
||||||
},
|
},
|
||||||
|
|
||||||
defaultDateFormat = 'YYYY-MM-DD HH:mm',
|
defaultDateFormat = 'YYYY-MM-DD HH:mm',
|
||||||
|
@ -72,6 +95,7 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
parseSize: parseSize,
|
parseSize: parseSize,
|
||||||
|
setDefaultMetric: setDefaultMetric,
|
||||||
formatSize: formatSize,
|
formatSize: formatSize,
|
||||||
setDefaultDateFormat: setDefaultDateFormat,
|
setDefaultDateFormat: setDefaultDateFormat,
|
||||||
parseDate: parseDate,
|
parseDate: parseDate,
|
||||||
|
|
|
@ -3,7 +3,8 @@ modulejs.define('view/extended', ['_', '$', 'core/settings', 'core/resource', 'c
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
modes: ['details', 'icons'],
|
modes: ['details', 'icons'],
|
||||||
setParentFolderLabels: false
|
setParentFolderLabels: false,
|
||||||
|
binaryPrefix: false
|
||||||
},
|
},
|
||||||
|
|
||||||
settings = _.extend({}, defaults, allsettings.view),
|
settings = _.extend({}, defaults, allsettings.view),
|
||||||
|
@ -103,6 +104,8 @@ modulejs.define('view/extended', ['_', '$', 'core/settings', 'core/resource', 'c
|
||||||
$ul = $(listTemplate),
|
$ul = $(listTemplate),
|
||||||
$emtpy = $(emptyTemplate);
|
$emtpy = $(emptyTemplate);
|
||||||
|
|
||||||
|
format.setDefaultMetric(settings.binaryUnits);
|
||||||
|
|
||||||
if (entry.parent) {
|
if (entry.parent) {
|
||||||
$ul.append(update(entry.parent));
|
$ul.append(update(entry.parent));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue