show pretty representations of storage usage

This commit is contained in:
ansuz 2017-05-19 18:37:31 +02:00
parent 1378a0c1f6
commit ba5ef5157e
5 changed files with 49 additions and 11 deletions

View File

@ -410,6 +410,10 @@ define(function () {
out.upgrade = "Mejorar";
out.upgradeTitle = "Mejora tu cuenta para obtener más espacio";
out.MB = "MB";
out.GB = "GB";
out.formattedMB = "{0} MB";
out.formattedGB = "{0} GB";
out.pinLimitReached = "Has llegado al limite de espacio";
out.pinLimitReachedAlert = "Has llegado al limite de espacio. Nuevos pads no serán movidos a tu CryptDrive.<br>Para resolver este problema, puedes quitar pads de tu CryptDrive (incluso en la papelera) o mejorar tu cuenta para obtener más espacio.";
out.pinLimitNotPinned = "Has llegado al limite de espacio.<br>Este pad no estará presente en tu CryptDrive.";

View File

@ -61,6 +61,9 @@ define(function () {
out.upgrade = "Améliorer";
out.upgradeTitle = "Améliorer votre compte pour augmenter la limite de stockage";
out.MB = "Mo";
out.GB = "Go";
out.formattedMB = "{0} Mo";
out.formattedGB = "{0} Go";
out.greenLight = "Tout fonctionne bien";
out.orangeLight = "Votre connexion est lente, ce qui réduit la qualité de l'éditeur";

View File

@ -63,6 +63,10 @@ define(function () {
out.upgrade = "Upgrade";
out.upgradeTitle = "Upgrade your account to increase the storage limit";
out.MB = "MB";
out.GB = "GB";
out.formattedMB = "{0} MB";
out.formattedGB = "{0} GB";
out.greenLight = "Everything is working fine";
out.orangeLight = "Your slow connection may impact your experience";

View File

@ -81,12 +81,25 @@ define([], function () {
.replace(/_+/g, '_');
};
var oneKilobyte = 1024;
var oneMegabyte = 1024 * oneKilobyte;
var oneGigabyte = 1024 * oneMegabyte;
Util.bytesToGigabytes = function (bytes) {
return Math.ceil(bytes / oneGigabyte * 100) / 100;
};
Util.bytesToMegabytes = function (bytes) {
return Math.floor((bytes / (1024 * 1024) * 100)) / 100;
return Math.ceil(bytes / oneMegabyte * 100) / 100;
};
Util.bytesToKilobytes = function (bytes) {
return Math.floor(bytes / 1024 * 100) / 100;
return Math.ceil(bytes / oneKilobyte * 100) / 100;
};
Util.magnitudeOfBytes = function (bytes) {
if (bytes >= oneGigabyte) { return 'GB'; }
else if (bytes >= oneMegabyte) { return 'MB'; }
};
Util.fetch = function (src, cb) {

View File

@ -745,8 +745,7 @@ define([
if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); }
rpc.updatePinLimits(function (e, limit, plan) {
if (e) { return cb(e); }
var MB = common.bytesToMegabytes(limit);
cb(e, MB, plan);
cb(e, limit, plan);
});
};
@ -754,8 +753,7 @@ define([
if (!pinsReady()) { return void cb('[RPC_NOT_READY]'); }
rpc.getLimit(function (e, limit, plan) {
if (e) { return cb(e); }
var MB = common.bytesToMegabytes(limit);
cb(void 0, MB, plan);
cb(void 0, limit, plan);
});
};
@ -771,7 +769,7 @@ define([
return void cb (null, false, data);
};
var todo = function (e, used) {
usage = common.bytesToMegabytes(used);
usage = used; //common.bytesToMegabytes(used);
if (e) { return void cb(e); }
common.getPinLimit(andThen);
};
@ -802,9 +800,14 @@ define([
common.isOverPinLimit(todo);
}, LIMIT_REFRESH_RATE);
}
var usage = data.usage;
var limit = data.limit;
var unit = Messages.MB;
var unit = Util.magnitudeOfBytes(data.limit);
var usage = unit === 'GB'? Util.bytesToGigabytes(data.usage):
Util.bytesToMegabytes(data.usage);
var limit = unit === 'GB'? Util.bytesToGigabytes(data.limit):
Util.bytesToMegabytes(data.limit);
var $limit = $('<span>', {'class': 'cryptpad-limit-bar'}).appendTo($container);
var quota = usage/limit;
var width = Math.floor(Math.min(quota, 1)*200); // the bar is 200px width
@ -823,11 +826,22 @@ define([
}).text(Messages.upgrade).appendTo($upgradeLink);
}
var prettyUsage;
var prettyLimit;
if (unit === 'GB') {
prettyUsage = usage; //Messages._getKey('formattedGB', [usage]);
prettyLimit = Messages._getKey('formattedGB', [limit]);
} else {
prettyUsage = usage; //Messages._getKey('formattedMB', [usage]);
prettyLimit = Messages._getKey('formattedMB', [limit]);
}
if (quota < 0.8) { $usage.addClass('normal'); }
else if (quota < 1) { $usage.addClass('warning'); }
else { $usage.addClass('above'); }
var $text = $('<span>', {'class': 'usageText'});
$text.text(usage + ' / ' + limit + ' ' + unit);
$text.text(prettyUsage + ' / ' + prettyLimit);
$limit.append($usage).append($text);
window.setTimeout(function () {
common.isOverPinLimit(todo);