deduplicate 'getPrettySize' and similar variants

pull/1/head
ansuz 4 years ago
parent 792c05874e
commit 3b9bf65709

@ -1,13 +1,13 @@
define([ define([
'jquery', 'jquery',
'/common/hyperscript.js', '/common/hyperscript.js',
'/common/common-util.js',
'/customize/messages.js', '/customize/messages.js',
'/customize/application_config.js', '/customize/application_config.js',
'/common/outer/local-store.js', '/common/outer/local-store.js',
'/customize/pages.js', '/customize/pages.js',
'/api/config', '/api/config',
], function ($, h, Util, Msg, AppConfig, LocalStore, Pages, Config) { '/common/common-ui-elements.js',
], function ($, h, Msg, AppConfig, LocalStore, Pages, Config, UIElements) {
var accounts = { var accounts = {
donateURL: AppConfig.donateURL || "https://opencollective.com/cryptpad/", donateURL: AppConfig.donateURL || "https://opencollective.com/cryptpad/",
upgradeURL: AppConfig.upgradeURL upgradeURL: AppConfig.upgradeURL
@ -56,7 +56,7 @@ define([
}; };
SPECIAL_GROUP_ITEMS.storage1 = function (f) { SPECIAL_GROUP_ITEMS.storage1 = function (f) {
return groupItemTemplate( return groupItemTemplate(
Msg._getKey('features_f_' + f, [Util.getPrettySize(Config.defaultStorageLimit, Msg)]), // .features_f_storage1 Msg._getKey('features_f_' + f, [UIElements.prettySize(Config.defaultStorageLimit)]), // .features_f_storage1
Msg['features_f_' + f + '_note'] // .features_f_storage1_note Msg['features_f_' + f + '_note'] // .features_f_storage1_note
); );
}; };

@ -8,6 +8,7 @@ define([
'/common/hyperscript.js', '/common/hyperscript.js',
'/customize/messages.js', '/customize/messages.js',
'/common/common-interface.js', '/common/common-interface.js',
'/common/common-ui-elements.js',
'/common/common-util.js', '/common/common-util.js',
'/common/common-hash.js', '/common/common-hash.js',
'/common/common-signing-keys.js', '/common/common-signing-keys.js',
@ -26,6 +27,7 @@ define([
h, h,
Messages, Messages,
UI, UI,
UIElements,
Util, Util,
Hash, Hash,
Keys, Keys,
@ -273,12 +275,7 @@ define([
return $div; return $div;
}; };
var getPrettySize = function (bytes) { // XXX duplicate of UIElements.prettySize ? var getPrettySize = UIElements.prettySize;
var unit = Util.magnitudeOfBytes(bytes);
var value = unit === 'GB' ? Util.bytesToGigabytes(bytes) : Util.bytesToMegabytes(bytes);
return unit === 'GB' ? Messages._getKey('formattedGB', [value])
: Messages._getKey('formattedMB', [value]);
};
create['defaultlimit'] = function () { create['defaultlimit'] = function () {
var key = 'defaultlimit'; var key = 'defaultlimit';

@ -34,10 +34,14 @@ define([
}; };
UIElements.prettySize = function (bytes) { UIElements.prettySize = function (bytes) {
var kB = Util.bytesToKilobytes(bytes); var unit = Util.magnitudeOfBytes(bytes);
if (kB < 1024) { return kB + Messages.KB; } // XXX replace with Msg.formattedKB ? if (unit === 'GB') {
var mB = Util.bytesToMegabytes(bytes); return Messages._getKey('formattedGB', [ Util.bytesToGigabytes(bytes)]);
return mB + Messages.MB; // XXX replace with Msg.formattedMB } else if (unit === 'MB') {
return Messages._getKey('formattedMB', [ Util.bytesToMegabytes(bytes)]);
} else {
return Messages._getKey('formattedKB', [ Util.bytesToKilobytes(bytes)]);
}
}; };
UIElements.updateTags = function (common, hrefs) { UIElements.updateTags = function (common, hrefs) {

@ -269,18 +269,11 @@
Util.magnitudeOfBytes = function (bytes) { Util.magnitudeOfBytes = function (bytes) {
if (bytes >= oneGigabyte) { return 'GB'; } if (bytes >= oneGigabyte) { return 'GB'; }
else if (bytes >= oneMegabyte) { return 'MB'; } // smallest supported format is MB to preserve existing behaviour
else /* if (bytes >= oneMegabyte) */ { return 'MB'; }
//else { return 'KB'; }
}; };
Util.getPrettySize = function (bytes, Messages) { // XXX not used anywhere?
var unit = Util.magnitudeOfBytes(bytes);
if (unit === 'GB') {
return Messages._getKey('formattedGB', [Util.bytesToGigabytes(bytes)]);
}
return Messages._getKey('formattedMB', [Util.bytesToMegabytes(bytes)]);
};
// given a path, asynchronously return an arraybuffer // given a path, asynchronously return an arraybuffer
var getCacheKey = function (src) { var getCacheKey = function (src) {
var _src = src.replace(/(\/)*$/, ''); // Remove trailing slashes var _src = src.replace(/(\/)*$/, ''); // Remove trailing slashes

Loading…
Cancel
Save