1
0
Fork 0

added version check for admin interface

This commit is contained in:
Jan Steemann 2014-01-31 23:58:36 +01:00
parent ad3c835b19
commit 74c0457b4b
2 changed files with 129 additions and 2 deletions

View File

@ -3,6 +3,40 @@
(function() {
"use strict";
window.versionHelper = {
fromString: function (s) {
var parts = s.replace(/-.*$/g, '').split('.');
return {
major: parseInt(parts[0]) || 0,
minor: parseInt(parts[1]) || 0,
patch: parseInt(parts[2]) || 0
};
},
toString: function (v) {
return v.major + '.' + v.minor + '.' + v.patch;
},
toStringMainLine: function (v) {
return v.major + '.' + v.minor;
},
compareVersions: function (l, r) {
if (l.major === r.major) {
if (l.minor === r.minor) {
if (l.patch === r.patch) {
return 0;
}
return l.patch - r.patch;
}
return l.minor - r.minor;
}
return l.major - r.major;
},
compareVersionStrings: function (l, r) {
l = window.versionHelper.fromString(l);
r = window.versionHelper.fromString(r);
return window.versionHelper.compareVersions(l, r);
}
};
window.arangoHelper = {
lastNotificationMessage: null,
@ -71,12 +105,12 @@
$.gritter.removeAll();
this.lastNotificationMessage = null;
},
arangoNotification: function (message) {
arangoNotification: function (message, time) {
var returnVal = false;
$.gritter.add({
title: "Notice:",
text: message,
time: 3000,
time: time || 3000,
before_open: function(){
returnVal = true;
}

View File

@ -76,6 +76,8 @@
collection: window.arangoCollectionsStore
});
// this.initVersionCheck();
var self = this;
$(window).resize(function() {
self.handleResize();
@ -83,6 +85,97 @@
this.handleResize();
},
/*
initVersionCheck: function () {
// this checks for version updates
var self = this;
var versionCheck = function () {
$.ajax({
async: true,
crossDomain: true,
dataType: "jsonp",
url: "https://www.arangodb.org/repositories/versions.php?callback=parseVersions",
success: function (json) {
if (typeof json !== 'object') {
return;
}
// turn our own version string into a version object
var currentVersion = window.versionHelper.fromString(self.footerView.system.version);
// get our mainline version
var mainLine = window.versionHelper.toStringMainLine(currentVersion);
var mainLines = Object.keys(json).sort(window.versionHelper.compareVersionStrings);
var latestMainLine;
mainLines.forEach(function (l) {
if (json[l].stable) {
if (window.versionHelper.compareVersionStrings(l, mainLine) > 0) {
latestMainLine = json[l];
}
}
});
var update;
if (latestMainLine !== undefined &&
Object.keys(latestMainLine.versions.length > 0) {
var mainLineVersions = Object.keys(latestMainLine.versions);
mainLineVersions = mainLineVersions.sort(window.versionHelper.compareVersionStrings);
var latest = mainLineVersions[mainLineVersions.length - 1];
update = {
type: "major",
version: latest,
changes: latestMainLine.versions[latest].changes
};
}
// check which stable mainline versions are available remotely
if (update === undefined &&
json.hasOwnProperty(mainLine) &&
json[mainLine].stable &&
json[mainLine].hasOwnProperty("versions") &&
Object.keys(json[mainLine].versions).length > 0) {
// sort by version numbers
var mainLineVersions = Object.keys(json[mainLine].versions);
mainLineVersions = mainLineVersions.sort(window.versionHelper.compareVersionStrings);
var latest = mainLineVersions[mainLineVersions.length - 1];
var result = window.versionHelper.compareVersions(
currentVersion,
window.versionHelper.fromString(latest)
);
if (result < 0) {
update = {
type: "minor",
version: latest,
changes: json[mainLine].versions[latest].changes
};
}
}
if (update !== undefined) {
var msg = "A newer version of ArangoDB (" + update.version +
") has become available. You may want to check the " +
"changelog at <a href=\"" + update.changes + "\">" +
update.changes + "</a>";
arangoHelper.arangoNotification(msg, 15000);
}
},
error: function () {
// re-schedule the version check
window.setTimeout(versionCheck, 60000);
}
});
};
window.setTimeout(versionCheck, 5000);
},
*/
logsAllowed: function () {
return (window.databaseName === '_system');
},