Skip to content

Commit

Permalink
Merge pull request #2561 from CartoDB/2547-fix-quota-progress-bar
Browse files Browse the repository at this point in the history
Round down the quota usage
  • Loading branch information
viddo committed Mar 2, 2015
2 parents 5ccc1f1 + f90e0a7 commit 2db3c90
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Bugfixes:
* Fixes for new dashboard texts [#2499](https://github.com/CartoDB/cartodb/pull/2499)
* Fixes a problem generating images from private visualizations of private org users.
* Remove lighter font weights [#2513](https://github.com/CartoDB/cartodb/pull/2513)
* Fix quota usage rounding [#2561](https://github.com/CartoDB/cartodb/pull/2561)

3.8.0 (2015-01-30)
------------------
Expand Down
2 changes: 1 addition & 1 deletion config/frontend.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#This file defines the version of the frontend code that is going to be loaded.
3.7.15
3.7.17
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ fn.prototype.suffix = function() {
return this.UNIT_SUFFIXES[this.unit];
};

fn.prototype.toString = function() {
return this.size().toFixed(0) + this.suffix();
fn.prototype.toString = function(decimals) {
var size = this.size();
if (decimals) {
// 1 decimal: 9.995 => 9.9
var round = Math.pow(10, decimals);
size = Math.floor(size * round) / round;
} else {
size = Math.floor(size);
}
return size + this.suffix();
};

module.exports = fn;
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ module.exports = cdb.admin.DropdownMenu.extend({
render: function() {
var user = this.model;
var usedDataBytes = user.get('db_size_in_bytes');
var availableDataSize = user.get('quota_in_bytes');
var usedDataPct = Math.round(usedDataBytes / availableDataSize * 100);
var quotaInBytes = user.get('quota_in_bytes');
var usedDataPct = Math.round(usedDataBytes / quotaInBytes * 100);
var progressBarClass = '';

if (usedDataPct > 70 && usedDataPct < 91) {
Expand All @@ -55,10 +55,10 @@ module.exports = cdb.admin.DropdownMenu.extend({
email: user.get('email'),
accountType: accountType,
isOrgAdmin: user.isOrgAdmin(),
usedDataStr: bytesToSize(usedDataBytes).toString(),
usedDataStr: bytesToSize(usedDataBytes).toString(2),
usedDataPct: usedDataPct,
progressBarClass: progressBarClass,
availableDataStr: bytesToSize(availableDataSize).toString(),
availableDataStr: bytesToSize(quotaInBytes).toString(),
showUpgradeLink: upgradeAccountUrl && (user.isOrgAdmin() || !user.isInsideOrg()),
upgradeUrl: upgradeAccountUrl,
publicProfileUrl: currentUserUrl.toPublicProfile(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,23 @@ describe('new_common/view_helpers/bytes_to_size', function() {
});

describe('.toString', function() {
it('should return a string of the size rounded up to closest decimal, suffixed by appropriate unit', function() {
it('should return a string of the size rounded down to closest full number, suffixed by appropriate unit', function() {
expect(bytesToSize(0).toString()).toEqual('0B');
expect(bytesToSize(311296).toString()).toEqual('304kB');
expect(bytesToSize(1048576000000).toString()).toEqual('977GB');
expect(bytesToSize(1048576000000).toString()).toEqual('976GB');
expect(bytesToSize(10485759).toString()).toEqual('9MB');
});

describe('when given 1', function() {
it('should return a string with 1 decimal rounded down', function() {
expect(bytesToSize(10485759).toString(1)).toEqual('9.9MB');
});
});

describe('when given 2', function() {
it('should return a string with 2 decimals rounded down', function() {
expect(bytesToSize(10485759).toString(2)).toEqual('9.99MB');
});
});
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cartodb-ui",
"version": "3.7.15",
"version": "3.7.17",
"description": "CartoDB UI frontend",
"repository": {
"type": "git",
Expand Down

0 comments on commit 2db3c90

Please sign in to comment.