Skip to content

Commit

Permalink
SAK-46803 Sorting by grade is not working correctly when user locale …
Browse files Browse the repository at this point in the history
…use a comma as decimal separator (sakaiproject#10164)
  • Loading branch information
josecebe authored Jan 20, 2022
1 parent b7f165c commit cb8041f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions gradebookng/tool/src/webapp/scripts/gradebook-gbgrade-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,11 @@ GbGradeTable.cellRenderer = function (instance, td, row, col, prop, value, cellP
}
var isExtraCredit = false;

const numberValue = GbGradeTable.localizedStringToNumber(value);
if (GbGradeTable.settings.isPointsGradeEntry) {
isExtraCredit = parseFloat(value) > parseFloat(column.points);
isExtraCredit = numberValue > parseFloat(column.points);
} else if (GbGradeTable.settings.isPercentageGradeEntry) {
isExtraCredit = parseFloat(value) > 100;
isExtraCredit = numberValue > 100;
}

if (isExtraCredit && !hasExcuse) {
Expand Down Expand Up @@ -2245,8 +2246,8 @@ GbGradeTable.sort = function(colIndex, direction) {
}

clone.sort(function(row_a, row_b) {
var a = row_a[colIndex];
var b = row_b[colIndex];
var a = GbGradeTable.localizedStringToNumber(row_a[colIndex]);
var b = GbGradeTable.localizedStringToNumber(row_b[colIndex]);

return sortCompareFunction(a, b);
});
Expand Down Expand Up @@ -3132,6 +3133,17 @@ GbGradeTable.localizeNumber = function(number) {
return '' + number;
};

GbGradeTable.localizedStringToNumber = function(localizedString) {
// Get the thousands and decimals separator for a random localized number and remove duplicated values converting it into a set
const parts = [...new Set(GbGradeTable.localizeNumber(11111111.1).replace(/\d+/g,'').split(''))];
if (localizedString === null) return null;
if (parts.length == 1) parts.unshift('');

// Remove thousands separator and change decimal separator to "." (to convert the localized String into a Number object)
return Number(String(localizedString)
.replaceAll(parts[0],'')
.replace(parts[1],'.'));
};

// Commit values to the grade data and the table meta data where applicable
GbGradeTable.syncScore = function(studentId, assignmentId, value) {
Expand Down

0 comments on commit cb8041f

Please sign in to comment.