webui: enable sorting on version column#1365
Merged
joergsteffens merged 2 commits intobareos:masterfrom Feb 3, 2023
frb121:dev/fbergkemper/master/s5350
Merged
webui: enable sorting on version column#1365joergsteffens merged 2 commits intobareos:masterfrom frb121:dev/fbergkemper/master/s5350
joergsteffens merged 2 commits intobareos:masterfrom
frb121:dev/fbergkemper/master/s5350
Conversation
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; | ||
| } |
Member
There was a problem hiding this comment.
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.
Member
There was a problem hiding this comment.
Unfortunately, formatting gets corrupted while copy&paste.
joergsteffens
requested changes
Feb 3, 2023
Member
joergsteffens
left a comment
There was a problem hiding this comment.
Looks good. As discussed, I extended the version sorting function. Feel free to squash the commits. After this, the PR can gets merged.
Contributor
Author
Commit squashed. Thanks for the improvement. |
10 tasks
joergsteffens
approved these changes
Feb 3, 2023
- client table: enable sorting on version column - client table: remove broken update notification logic - client table: remove broken update package download logic
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thank you for contributing to the Bareos Project!
Please check
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-toolto have some simple automated checks run and a proper changelog record added.General
Source code quality