Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detecting and sorting version numbers #395

Closed
corbosman opened this issue Oct 24, 2013 · 24 comments
Closed

detecting and sorting version numbers #395

corbosman opened this issue Oct 24, 2013 · 24 comments

Comments

@corbosman
Copy link

I cant seem to figure out a way to sort a column with version numbers. They're not sorting properly. Screenshot: http://grab.by/rr04

Cor

@Mottie
Copy link
Owner

Mottie commented Oct 24, 2013

Hi @corbosman!

Try using the ipAddress parser. It detects the ip address format of four blocks of numbers ###.###.###.### but will work with less.

$('table').tablesorter({
    theme: 'blue',
    headers: {
        3: { sorter: "ipAddress" }
    }
});

The biggest problem is when you write the version number that doesn't match the others. As seen in the screenshot you shared, 6.0 only has two blocks of numbers while the rest of the column has three 6.0.3. Here is a demo showing the parser working and the problem it runs into. In order to fix that issue, you'll need to copy and modify that parser.

@Mottie
Copy link
Owner

Mottie commented Nov 9, 2013

I'm guessing this issue has been resolved, so I'm going to close it. If you continue to have problems, please feel free to continue this discussion.

@Mottie Mottie closed this as completed Nov 9, 2013
@akshayrawat
Copy link

The ipAddress parser is not enough to deal with quirky version numbering schemes. This is one way to deal with version numbers with 1,2 or max 3 parts.

$.tablesorter.addParser({
    id: 'versionNumber',

    is: function() {
        // Do not auto detect 
        return false;
    },

    format: function(text) {
        var parts = text.split('.');
        if(parts.length == 1) {
            return parts[0] + '000' + '000';
        } else if(parts.length == 2) {
            return parts[0] + ('000' + parts[1]).slice(-3) + '000';
        } else if(parts.length == 3) {
            return parts[0] + ('000' + parts[1]).slice(-3) + ('000' + parts[2]).slice(-3);
        }
        return text;
    },

    type: 'numeric'
});

@TheSin-
Copy link
Collaborator

TheSin- commented Nov 12, 2013

this is very very limited to be a version number parser, what about alpha, beta, etc

I'll try and put something a little more robust together and post it here.

@Mottie Mottie reopened this Nov 12, 2013
@thezoggy
Copy link
Collaborator

id recommend basing the sorter off semver.. http://semver.org/
for some filter ideas:
https://github.com/isaacs/node-semver

@TheSin-
Copy link
Collaborator

TheSin- commented Nov 12, 2013

that is a very good example and this seems to be very complete, I agree with you zoggy

Examples: 1.9.0 -> 1.10.0 -> 1.11.0.
Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92.
Examples: 1.0.0-alpha+001, 1.0.0+20130313144700, 1.0.0-beta+exp.sha.5114f85.
Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0.

@Mottie
Copy link
Owner

Mottie commented Nov 12, 2013

Thanks for the input guys!

Honestly, instead of writing a widget that we have to maintain... we should just include that plugin and have the widget interact with it.

@TheSin-
Copy link
Collaborator

TheSin- commented Nov 12, 2013

sounds good to me, you on it or shall I look into it?

@Mottie
Copy link
Owner

Mottie commented Nov 12, 2013

@TheSin- Oh, I thought you were doing it... I've got a bunch of other stuff I'm trying to work on. And I haven't even gotten to the pull requests yet!

@TheSin-
Copy link
Collaborator

TheSin- commented Nov 12, 2013

no problem at all I just haven't linked to an external lib yet and I wasn't sure if you wanted to make the external lib a git module etc etc. I'll try and get a version of this to approval ;)

@Mottie
Copy link
Owner

Mottie commented Nov 13, 2013

Hmm, maybe the code from this StackOverflow question would work... I haven't tested it, but the demo includes some testing: http://jsfiddle.net/ripper234/Xv9WL/28/

Edit: Ugh, nevermind... I think it would be easier to just include the file. I know about git modules, but never got around to learning how to add and maintain them. What do you think?

@thezoggy
Copy link
Collaborator

git modules are a bit funky. you basically include it and reference which commit you want to include at.. it doesnt really include anything.. just think of it like a shortcut. when people clone your repo they actually dont get the submodule.. unless they do a specific command to get them.. which most people dont know/takes extra effort. in the end we gave up on using them for one of the projects we worked on since it was causing more headaches than it was worth.

@Mottie
Copy link
Owner

Mottie commented Nov 13, 2013

I've also looked at git-subtree before; but in this case I think you need admin privileges in both repos.

@Mottie
Copy link
Owner

Mottie commented Nov 20, 2013

Any news on this @TheSin-?

No rush, I was just looking at issues to see what I need to do next.

@TheSin-
Copy link
Collaborator

TheSin- commented Nov 20, 2013

sadly I haven't had any time at all been working on an other project and I have a major dealer seminar that I need to present at in 2 week in the UK, 10 presentations in 2 days, so been pretty busy, it's still on my list though.

@Mottie
Copy link
Owner

Mottie commented Nov 20, 2013

No, worries, I can do it. Good luck!

@Mottie
Copy link
Owner

Mottie commented Nov 21, 2013

Wow, this semver parser project is WAY more complicated than I anticipated.

What I started doing is modifying the semver.js code which I know think should be used as the sorter instead a parser (using semver.gt() and/or semver.lt())

Then it gets complicated LOL

As @TheSin- shared before, the next statement is how SemVer 2.0.0 does comparisons

1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0

But then I read comments like this (from isaacs, the guy who wrote semver.js)

Right now, 1.0.0-3 is a "build release". Ie, it's higher precedence than 1.0.0, because when git describe --tags reports 1.0.0-3-deadbeef, you're actually talking about a prerelease for the 1.0.1 tag, which comes 3 commits AFTER the 1.0.0 tag.

So, should we only support SemVer 2.0.0, or allow the parser/sorter to also work with older formatting? Or write two parsers/sorters that allow the user to choose which one they want to support? bangs head into desk

@Mottie
Copy link
Owner

Mottie commented Nov 22, 2013

Here's a demo of what I have so far: http://jsfiddle.net/Mottie/abkNM/1626/

@thezoggy
Copy link
Collaborator

Only semver 2.

-----Original Message-----
From: "Rob G" [email protected]
Sent: ‎11/‎21/‎2013 5:59 PM
To: "Mottie/tablesorter" [email protected]
Cc: "thezoggy" [email protected]
Subject: Re: [tablesorter] detecting and sorting version numbers (#395)

Wow, this semver parser project is WAY more complicated than I anticipated.

What I started doing is modifying the semver.js code which I know think should be used as the sorter instead a parser (using semver.gt() and/or semver.lt())

Then it gets complicated LOL

As @TheSin- shared before, the next statement is how SemVer 2.0.0 does comparisons

1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0

But then I read comments like this (from isaacs, the guy who wrote semver.js)

Right now, 1.0.0-3 is a "build release". Ie, it's higher precedence than 1.0.0, because when git describe --tags reports 1.0.0-3-deadbeef, you're actually talking about a prerelease for the 1.0.1 tag, which comes 3 commits AFTER the 1.0.0 tag.

So, should we only support SemVer 2.0.0, or allow the parser/sorter to also work with older formatting? Or write two parsers/sorters that allow the user to choose which one they want to support? bangs head into desk


Reply to this email directly or view it on GitHub:
#395 (comment)

@TheSin-
Copy link
Collaborator

TheSin- commented Nov 22, 2013

Right now, 1.0.0-3 is a "build release". Ie, it's higher precedence than 1.0.0, because when git describe --tags reports 1.0.0-3-deadbeef, you're actually talking about a prerelease for the 1.0.1 tag, which comes 3 commits AFTER the 1.0.0 tag.

this is correct, version-[0-9]+ = revision of a version and in it's self is higher then the base version.

@Mottie Mottie closed this as completed in 66ec824 Dec 2, 2013
@Mottie
Copy link
Owner

Mottie commented Dec 2, 2013

New demo here

@corbosman
Copy link
Author

awesome. thanks.

@TheSin-
Copy link
Collaborator

TheSin- commented Dec 2, 2013

very nice Rob, and great work!

@Mottie
Copy link
Owner

Mottie commented Jun 21, 2014

Just a quick update... this is code for a generic version, or number block, parser (demo):

$(function () {

    /************************
    Generic version parser
    ************************/
    // set the number of blocks
    // e.g. 2 = 000.000
    // and 3 = 000.000.000
    var blocks = 3,
        // length of each block
        // 3 = 000
        // 4 = 0000
        digits = 3;

    $.tablesorter.addParser({
        id: "versions",
        is: function (s) {
            return false;
        },
        format: function (s, table) {
            var i,
            a = s ? s.split(".") : [],
            r = "",
            d = new Array(digits + 1).join('0');
            for (i = 0; i < blocks; i++) {
                r += (d + (a[i] || 0)).slice(-digits);
            }
            return s ? $.tablesorter.formatFloat(r, table) : s;
        },
        type: "numeric"
    });

    $('table').tablesorter({
        theme: 'blue',
        headers: {
            3: { sorter: "versions" }
        }
    });

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants