Checking for new version on GitHub

This commit is contained in:
Gunnar Skjold
2020-05-14 21:13:13 +02:00
parent 778daf8645
commit 85a70016fa
4 changed files with 88 additions and 16 deletions

View File

@@ -1,3 +1,4 @@
var nextVersion;
var im, em;
$(function() {
im = $("#importMeter");
@@ -18,7 +19,9 @@ $(function() {
});
}
if($('.SimpleMeter').length > 0) {
var meters = $('.SimpleMeter');
if(meters.length > 0) {
fetch();
}
@@ -98,6 +101,65 @@ $(function() {
$('#config-system-link').addClass('active');
break;
}
var swv = $('#swVersion')
if(meters.length > 0 && swv.length == 1 && swv.text() != "SNAPSHOT") {
var v = swv.text().substring(1).split('.');
var v_major = parseInt(v[0]);
var v_minor = parseInt(v[1]);
var v_patch = parseInt(v[2]);
$.ajax({
url: swv.data('url'),
dataType: 'json'
}).done(function(releases) {
releases.reverse();
var me;
var next_patch;
var next_minor;
var next_major;
$.each(releases, function(i, release) {
var ver2 = release.tag_name;
var v2 = ver2.substring(1).split('.');
var v2_major = parseInt(v2[0]);
var v2_minor = parseInt(v2[1]);
var v2_patch = parseInt(v2[2]);
if(v2_major == v_major) {
if(v2_minor == v_minor) {
if(v2_patch > v_patch) {
next_patch = release;
}
} else if(v2_minor == v_minor+1) {
next_minor = release;
}
} else if(v2_major == v_major+1) {
if(next_major) {
var mv = next_major.tag_name.substring(1).split('.');
var mv_major = parseInt(mv[0]);
var mv_minor = parseInt(mv[1]);
var mv_patch = parseInt(mv[2]);
if(v2_minor == mv_minor) {
next_major = release;
}
} else {
next_major = release;
}
}
});
if(next_minor) {
nextVersion = next_minor;
} else if(next_major) {
nextVersion = next_major;
} else if(next_patch) {
nextVersion = next_patch;
}
if(nextVersion) {
$('#newVersionTag').text(nextVersion.tag_name);
$('#newVersionUrl').prop('href', nextVersion.html_url);
$('#newVersion').removeClass('d-none');
}
});
}
});
var setStatus = function(id, status) {
@@ -254,3 +316,11 @@ var fetch = function() {
setStatus("esp", "danger");
});
}
var upgrade = function() {
if(nextVersion) {
if(confirm("Are you sure you want to perform upgrade to " + nextVersion.tag_name + "?")) {
window.location.href="/upgrade?version=" + nextVersion.id;
}
}
}