Merge pull request #1259 from ostephens/version_check
Alert user if more recent version available from github. Closes #1258
This commit is contained in:
commit
6cae3bc3be
@ -68,28 +68,29 @@ Refine.selectActionArea = function(id) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
var isThereNewRelease = function() {
|
var isThereNewRelease = function(thisVer,latestVer) {
|
||||||
// TODO: This eeds to be modified to do checking based solely on version, not revision
|
// Assumes Semantic Version numbering format of form X.Y.Z where X, Y, and Z are non-negative integer
|
||||||
var thisRevision = OpenRefineVersion.revision;
|
// Ignores any trailing letters e.g. 2.7.1-rc.1 will be interpreted as equivalent to 2.7.1
|
||||||
var thisVersion = OpenRefineVersion.version;
|
if(thisVer == latestVer) {
|
||||||
|
|
||||||
var revision_pattern = /r([0-9]+)/;
|
|
||||||
|
|
||||||
if (!revision_pattern.test(thisRevision)) { // probably "trunk"
|
|
||||||
return false;
|
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;
|
for(var i=0; i<3; i++) {
|
||||||
var latestVersion = OpenRefineReleases.releases[0].version;
|
var thisVerPartInt = parseInt(thisVerParts[i],10);
|
||||||
|
var latestVerPartInt = parseInt(latestVerParts[i],10);
|
||||||
var thisRev = parseInt(revision_pattern.exec(thisRevision)[1],10);
|
if(thisVerPartInt == latestVerPartInt) {
|
||||||
var latestRev = parseInt(revision_pattern.exec(OpenRefineReleases.releases[0].revision)[1],10);
|
continue;
|
||||||
|
} else {
|
||||||
// Parser version into main version and suffix which follows dash
|
return !(thisVerPartInt > latestVerPartInt);
|
||||||
// Parse version from dot separated string into array of integers
|
}
|
||||||
|
}
|
||||||
// compare left to right, including suffix
|
return false;
|
||||||
return latestRev > thisRev;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var showVersion = function() {
|
var showVersion = function() {
|
||||||
@ -100,31 +101,20 @@ $(function() {
|
|||||||
OpenRefineVersion = data;
|
OpenRefineVersion = data;
|
||||||
|
|
||||||
$("#openrefine-version").text($.i18n._('core-index')["version"]+" " + OpenRefineVersion.full_version);
|
$("#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]);
|
|
||||||
|
|
||||||
var poll = function() {
|
$.getJSON("https://api.github.com/repos/openrefine/openrefine/releases/latest",
|
||||||
if ("releases" in window) {
|
function( data ) {
|
||||||
if (isThereNewRelease()) {
|
var latestVersion = data.tag_name;
|
||||||
|
var latestVersionName = data.name;
|
||||||
|
var latestVersionUrl = data.html_url;
|
||||||
|
var thisVersion = OpenRefineVersion.version;
|
||||||
|
|
||||||
|
if(latestVersion.startsWith("v")) {
|
||||||
|
latestVersion = latestVersion.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isThereNewRelease(thisVersion,latestVersion)) {
|
||||||
var container = $('<div id="notification-container">')
|
var container = $('<div id="notification-container">')
|
||||||
.appendTo(document.body);
|
.appendTo(document.body);
|
||||||
var notification = $('<div id="notification">')
|
var notification = $('<div id="notification">')
|
||||||
@ -132,15 +122,12 @@ $(function() {
|
|||||||
.appendTo(container);
|
.appendTo(container);
|
||||||
$('<a>')
|
$('<a>')
|
||||||
.addClass('notification-action')
|
.addClass('notification-action')
|
||||||
.attr("href", releases.homepage)
|
.attr("href", latestVersionUrl)
|
||||||
.text($.i18n._('core-index')["download"]+' ' + releases.releases[0].description + ' '+$.i18n._('core-index')["now"]+'.')
|
.attr("target", "_blank")
|
||||||
|
.text($.i18n._('core-index')["download"]+' ' + latestVersionName + ' '+$.i18n._('core-index')["now"]+'.')
|
||||||
.appendTo(notification);
|
.appendTo(notification);
|
||||||
}
|
}
|
||||||
} else {
|
});
|
||||||
window.setTimeout(poll, 1000);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
window.setTimeout(poll, 1000);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user