Skip to content

webui: enable sorting on version column#1365

Merged
joergsteffens merged 2 commits intobareos:masterfrom
frb121:dev/fbergkemper/master/s5350
Feb 3, 2023
Merged

webui: enable sorting on version column#1365
joergsteffens merged 2 commits intobareos:masterfrom
frb121:dev/fbergkemper/master/s5350

Conversation

@frb121
Copy link
Contributor

@frb121 frb121 commented Jan 30, 2023

  • client table: enable sorting on version column
  • client table: remove broken update notification logic from version column
  • client table: remove broken update package download logic from actions column

Thank you for contributing to the Bareos Project!

Please check

  • Short description and the purpose of this PR is present above this paragraph
  • Your name is present in the AUTHORS file (optional)

If you have any questions or problems, please give a comment in the PR.

Helpful documentation and best practices

Checklist for the reviewer of the PR (will be processed by the Bareos team)

Make sure you check/merge the PR using devtools/pr-tool to have some simple automated checks run and a proper changelog record added.

General
  • Is the PR title usable as CHANGELOG entry?
  • Purpose of the PR is understood
  • Commit descriptions are understandable and well formatted
  • Check backport line
Source code quality
  • Source code changes are understandable
  • Variable and function names are meaningful
  • Code comments are correct (logically and spelling)
  • Required documentation changes are present and part of the PR

@frb121 frb121 self-assigned this Jan 30, 2023
Comment on lines +24 to +84
function sortSemanticVersion (a, b) {
var i, diff;
var regExStrip0 = /(\.0+)+$/;
var segmentsA = a.replace(regExStrip0, '').split('.');
var segmentsB = b.replace(regExStrip0, '').split('.');
var l = Math.min(segmentsA.length, segmentsB.length);

for (i = 0; i < l; i++) {
diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10);
if (diff) {
return diff;
}
}
return segmentsA.length - segmentsB.length;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function sortSemanticVersion (a, b) {
var i, diff;
var regExStrip0 = /(\.0+)+$/;
var segmentsA = a.replace(regExStrip0, '').split('.');
var segmentsB = b.replace(regExStrip0, '').split('.');
var l = Math.min(segmentsA.length, segmentsB.length);
for (i = 0; i < l; i++) {
diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10);
if (diff) {
return diff;
}
}
return segmentsA.length - segmentsB.length;
}
function compareSegments(a, b)
{
// 1a < 1 < 1.0
// 1abc < 1xyz < 1 < 2abc < 2
// 1~pre1.abc < 1~pre2.abc < 1~pre10.abc
if (a == b) {
return 0;
}
if (isNaN(a) && isNaN(b)) {
// a: str, b: str
if (a <= b) {
return -1;
} else {
return 1;
}
} else if (isNaN(a)) {
// a: str, b: number
return -1;
} else if (isNaN(b)) {
// a: number, b: str
return 1;
} else {
// a: number, b: number
return parseInt(a) - parseInt(b);
}
}
function getSegments(str)
{
return str.match(/[\d]+|[^\d]+|\./g).filter(seg => seg != '.');
}
function sortSemanticVersion(a, b) {
var segmentsA = getSegments(a);
var segmentsB = getSegments(b);
var len = Math.min(segmentsA.length, segmentsB.length);
for (var i = 0; i < len; i++) {
var result = compareSegments(segmentsA[i], segmentsB[i]);
if (result != 0) {
return result;
}
}
return segmentsA.length - segmentsB.length;
}

I tested your sort function and found a few glitches, especially with ~pre versions. Writing this function took me more time than expected, but I thing it covers all our version strings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, formatting gets corrupted while copy&paste.

@joergsteffens joergsteffens self-requested a review February 1, 2023 09:26
Copy link
Member

@joergsteffens joergsteffens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. As discussed, I extended the version sorting function. Feel free to squash the commits. After this, the PR can gets merged.

@frb121
Copy link
Contributor Author

frb121 commented Feb 3, 2023

Looks good. As discussed, I extended the version sorting function. Feel free to squash the commits. After this, the PR can gets merged.

Commit squashed. Thanks for the improvement.

frb121 and others added 2 commits February 3, 2023 14:47
- client table: enable sorting on version column
- client table: remove broken update notification logic
- client table: remove broken update package download logic
@joergsteffens joergsteffens merged commit 8608e0f into bareos:master Feb 3, 2023
@frb121 frb121 deleted the dev/fbergkemper/master/s5350 branch April 21, 2023 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants