Skip to content

Commit

Permalink
Fix volumetry chart: incorrect units handling
Browse files Browse the repository at this point in the history
Change-Id: I56d00eacc8ef7c72a44a2d2ab9ee82b87b293453
  • Loading branch information
bforest committed Jul 9, 2018
1 parent 810cba6 commit 2d807aa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Supported DBMS:

## [Unreleased]
### Fixed
- Bug fix: fixed volumetry line chart display issue
- Bug fix: fix volumetry chart: incorrect units handling (KB / MB / GB / TB)
- Bug fix: fix volumetry line chart display issue
- Bug fix: fixed invalid JSON response ("select-audits" webscript)


Expand Down
1 change: 1 addition & 0 deletions CHANGELOG_FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ SGBD support

## [Unreleased]
### Fixed
- Correction de l'affichage des graphiques de volumétrie avec des données qui ont un format différent (Ko / Mo / Go / To)
- Correction de l'affichage du graphique de volumétrie en mode "courbe"
- Correction du retour JSON du webscript "select-audits"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,55 +41,72 @@ AtolStatistics.dateFormatMasks = {
};

AtolStatistics.util.fileSizes = {
'BYTES_B' : 1,
'BYTES_KB': 1024,
'BYTES_MB': 1048576,
'BYTES_GB': 1073741824,
'BYTES_TB': 1099511627776
};

AtolStatistics.util.fileSizeMessages = {
'BYTES_B' : Alfresco.util.message("size.bytes"),
'BYTES_KB': Alfresco.util.message("size.kilobytes"),
'BYTES_MB': Alfresco.util.message("size.megabytes"),
'BYTES_GB': Alfresco.util.message("size.gigabytes"),
'BYTES_TB': Alfresco.util.message("size.terabytes")
};

AtolStatistics.util.roundNumber = function (number, digits) {
var multiple = Math.pow(10, digits);
return Math.round(number * multiple) / multiple;
}

AtolStatistics.util.formatFileSize = function (fileSize) {
AtolStatistics.util.formatFileSize = function (fileSize, unit) {
if (typeof fileSize == "string") {
fileSize = parseInt(fileSize, 10);
}

if (unit) {
return {
unit: unit,
value: AtolStatistics.util.roundNumber(fileSize / AtolStatistics.util.fileSizes[unit], 2),
message: AtolStatistics.util.fileSizeMessages[unit]
};
}

if (fileSize < AtolStatistics.util.fileSizes.BYTES_KB) {
return {
unitValue: 1,
unit: "BYTES_B",
value: fileSize,
message: Alfresco.util.message("size.bytes")
message: AtolStatistics.util.fileSizeMessages["BYTES_B"]
};
}
else if (fileSize < AtolStatistics.util.fileSizes.BYTES_MB) {
return {
unitValue: AtolStatistics.util.fileSizes.BYTES_KB,
unit: "BYTES_KB",
value: AtolStatistics.util.roundNumber(fileSize / AtolStatistics.util.fileSizes.BYTES_KB, 2),
message: Alfresco.util.message("size.kilobytes")
message: AtolStatistics.util.fileSizeMessages["BYTES_KB"]
};
}
else if (fileSize < AtolStatistics.util.fileSizes.BYTES_GB) {
return {
unitValue: AtolStatistics.util.fileSizes.BYTES_MB,
unit: "BYTES_MB",
value: AtolStatistics.util.roundNumber(fileSize / AtolStatistics.util.fileSizes.BYTES_MB, 2),
message: Alfresco.util.message("size.megabytes")
message: AtolStatistics.util.fileSizeMessages["BYTES_MB"]
};
}
else if (fileSize < AtolStatistics.util.fileSizes.BYTES_TB) {
return {
unitValue: AtolStatistics.util.fileSizes.BYTES_GB,
unit: "BYTES_GB",
value: AtolStatistics.util.roundNumber(fileSize / AtolStatistics.util.fileSizes.BYTES_GB, 2),
message: Alfresco.util.message("size.gigabytes")
message: AtolStatistics.util.fileSizeMessages["BYTES_GB"]
};
}

return {
unitValue: AtolStatistics.util.fileSizes.BYTES_TB,
unit: "BYTES_TB",
value: AtolStatistics.util.roundNumber(fileSize / AtolStatistics.util.fileSizes.BYTES_TB, 2),
message: Alfresco.util.message("size.terabytes")
message: AtolStatistics.util.fileSizeMessages["BYTES_TB"]
};
};

Expand Down
24 changes: 11 additions & 13 deletions module_share/src/main/web/components/atolcd/statistics/volumetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ if (typeof AtolStatistics == "undefined" || !AtolStatistics) {

if (!Dom.hasClass(this.id + "-bar-stack-criteria-container", "hidden") && Dom.get(this.id + "-bar_stack-criteria").checked) {
// Volumetry conversion by sites
var value_obj = {};
labelVolumetry = (this.msg("tool.volumetry.label") +" ("+ AtolStatistics.util.formatFileSize(response.json.maxLocal).message +")");
var value_obj = {},
maxLocalValue = AtolStatistics.util.formatFileSize(response.json.maxLocal);
labelVolumetry = (this.msg("tool.volumetry.label") + " (" + maxLocalValue.message + ")");

chartArguments.axis.y.label.text = [labelVolumetry];
for (i=0, ii=response.json.stackedValues.length ; i<ii ; i++) {
Expand All @@ -277,14 +278,8 @@ if (typeof AtolStatistics == "undefined" || !AtolStatistics) {
if (value == null) {
value_obj[siteId].push(value);
} else {
var valueConvert = AtolStatistics.util.formatFileSize(value),
stackedConvert = AtolStatistics.util.formatFileSize(response.json.maxLocal),
jsonConvertStackedValue = valueConvert.value;

if (valueConvert.message != stackedConvert.message) {
jsonConvertStackedValue = AtolStatistics.util.roundNumber(value / stackedConvert.unitValue, 2); // Convert format of a value when it's different from the max format
}
value_obj[siteId].push(jsonConvertStackedValue);
// convert format of a value when it's different from the max format
value_obj[siteId].push(AtolStatistics.util.formatFileSize(value, maxLocalValue.unit).value);
}

// Complete Columns of matrices and build groups array when we are on the last iteration of the first loop
Expand All @@ -297,16 +292,19 @@ if (typeof AtolStatistics == "undefined" || !AtolStatistics) {

} else {
// Conversion of total volumetries
var jsonConvertValues = [];
labelVolumetry = (this.msg("tool.volumetry.label") +" ("+ AtolStatistics.util.formatFileSize(response.json.maxCount).message +")");
var jsonConvertValues = [],
maxValue = AtolStatistics.util.formatFileSize(response.json.maxCount);
labelVolumetry = (this.msg("tool.volumetry.label") + " (" + maxValue.message + ")");

chartArguments.axis.y.label.text = [labelVolumetry];
for (i=0, ii=response.json.values.length ; i<ii ; i++) {
value = response.json.values[i];
if (value == null) {
jsonConvertValues[i] = value;
} else {
jsonConvertValues[i] = AtolStatistics.util.formatFileSize(value).value; // json responses converted in the right format (Bytes, Kb, Mb, Gb or Tb)
// convert format of a value when it's different from the max format
// json response converted in the right format (Bytes, Kb, Mb, Gb or Tb)
jsonConvertValues[i] = AtolStatistics.util.formatFileSize(value, maxValue.unit).value;
}
}
chartArguments.data.columns.push([labelVolumetry].concat(jsonConvertValues));
Expand Down

0 comments on commit 2d807aa

Please sign in to comment.