Merge pull request #1259 from ostephens/version_check

Alert user if more recent version available from github. Closes #1258
This commit is contained in:
Antonin Delpeuch 2017-09-27 16:06:43 +02:00 committed by GitHub
commit 6cae3bc3be

View File

@ -68,28 +68,29 @@ Refine.selectActionArea = function(id) {
};
$(function() {
var isThereNewRelease = function() {
// TODO: This eeds to be modified to do checking based solely on version, not revision
var thisRevision = OpenRefineVersion.revision;
var thisVersion = OpenRefineVersion.version;
var revision_pattern = /r([0-9]+)/;
if (!revision_pattern.test(thisRevision)) { // probably "trunk"
var isThereNewRelease = function(thisVer,latestVer) {
// Assumes Semantic Version numbering format of form X.Y.Z where X, Y, and Z are non-negative integer
// Ignores any trailing letters e.g. 2.7.1-rc.1 will be interpreted as equivalent to 2.7.1
if(thisVer == latestVer) {
return false;
}
var thisVerParts = thisVer.split(".");
var latestVerParts = latestVer.split(".");
while(thisVerParts.length < 3)
thisVerParts.push(0);
while(latestVerParts.length < 3)
latestVerParts.push(0);
var latestRevision = OpenRefineReleases.releases[0].revision;
var latestVersion = OpenRefineReleases.releases[0].version;
var thisRev = parseInt(revision_pattern.exec(thisRevision)[1],10);
var latestRev = parseInt(revision_pattern.exec(OpenRefineReleases.releases[0].revision)[1],10);
// Parser version into main version and suffix which follows dash
// Parse version from dot separated string into array of integers
// compare left to right, including suffix
return latestRev > thisRev;
for(var i=0; i<3; i++) {
var thisVerPartInt = parseInt(thisVerParts[i],10);
var latestVerPartInt = parseInt(latestVerParts[i],10);
if(thisVerPartInt == latestVerPartInt) {
continue;
} else {
return !(thisVerPartInt > latestVerPartInt);
}
}
return false;
};
var showVersion = function() {
@ -101,30 +102,19 @@ $(function() {
$("#openrefine-version").text($.i18n._('core-index')["version"]+" " + OpenRefineVersion.full_version);
// Format of releases.js fetched from server
// var releases = {
// "homepage" : "http://code.google.com/p/google-refine/wiki/Downloads",
// "releases" : [
// {
// "description": "OpenRefine 2.6",
// "version": "2.6-alpha1",
// },
// {
// "description": "Google Refine 2.5",
// "version": "2.5",
// "revision": "r2407"
// },
// ]
// }
var script = $('<script></script>')
.attr("src", "http://google-refine.googlecode.com/svn/support/releases.js")
.attr("type", "text/javascript");
document.body.appendChild(script[0]);
$.getJSON("https://api.github.com/repos/openrefine/openrefine/releases/latest",
function( data ) {
var latestVersion = data.tag_name;
var latestVersionName = data.name;
var latestVersionUrl = data.html_url;
var thisVersion = OpenRefineVersion.version;
var poll = function() {
if ("releases" in window) {
if (isThereNewRelease()) {
if(latestVersion.startsWith("v")) {
latestVersion = latestVersion.substr(1);
}
if (isThereNewRelease(thisVersion,latestVersion)) {
var container = $('<div id="notification-container">')
.appendTo(document.body);
var notification = $('<div id="notification">')
@ -132,15 +122,12 @@ $(function() {
.appendTo(container);
$('<a>')
.addClass('notification-action')
.attr("href", releases.homepage)
.text($.i18n._('core-index')["download"]+' ' + releases.releases[0].description + ' '+$.i18n._('core-index')["now"]+'.')
.attr("href", latestVersionUrl)
.attr("target", "_blank")
.text($.i18n._('core-index')["download"]+' ' + latestVersionName + ' '+$.i18n._('core-index')["now"]+'.')
.appendTo(notification);
}
} else {
window.setTimeout(poll, 1000);
}
};
window.setTimeout(poll, 1000);
});
}
);
};