@cryptotaxi247 / netdata-1 / commits / 51b6f39da

properly show version and check version using the internal version string too

Costa Tsaousis (ktsaou) committed Feb 12, 2017 at 13:54 UTC 51b6f39da5a5ded1042b627909a87e5b7681a54e
1 file changed +44 -19
web/index.html
+44 -19
@@ -2259,6 +2259,7 @@
2259 // update the dashboard hostname
2260 document.getElementById('hostname').innerHTML = options.hostname;
2261 document.getElementById('hostname').href = NETDATA.serverDefault;
2262 + document.getElementById('netdataVersion').innerHTML = options.version;
2263
2264 // update the dashboard title
2265 document.title = options.hostname + ' netdata dashboard';
@@ -2290,8 +2291,23 @@
2291 document.getElementById('versionCheckLog').innerHTML = msg;
2292 }
2293
2293 - function getNetdataVersion(callback) {
2294 - versionLog('Downloading installed version info from netdata...');
2294 + function getNetdataCommitIdFromVersion() {
2295 + var s = options.version.split('-');
2296 +
2297 + if(s.length !== 3) return null;
2298 + if(s[2][0] == 'g') {
2299 + var v = s[2].split('_')[0].substring(1, 8);
2300 + if(v.length === 7) {
2301 + versionLog('Installed git commit id of netdata is ' + v);
2302 + document.getElementById('netdataCommitId').innerHTML = v;
2303 + return v;
2304 + }
2305 + }
2306 + return null;
2307 + }
2308 +
2309 + function getNetdataCommitId(force, callback) {
2310 + versionLog('Downloading installed git commit id from netdata...');
2311
2312 $.ajax({
2313 url: 'version.txt',
@@ -2302,23 +2318,31 @@
2318 .done(function(data) {
2319 data = data.replace(/(\r\n|\n|\r| |\t)/gm,"");
2320 if(data.length !== 40) {
2305 - versionLog('Received version string is invalid.');
2306 - callback(null);
2321 + var c = getNetdataCommitIdFromVersion();
2322 + if(c === null) versionLog('Cannot find the git commit id of netdata.');
2323 + callback(c);
2324 }
2325 else {
2309 - versionLog('Installed version of netdata is ' + data);
2310 - document.getElementById('netdataVersion').innerHTML = data;
2326 + versionLog('Installed git commit id of netdata is ' + data);
2327 + document.getElementById('netdataCommitId').innerHTML = data.substring(0, 7);
2328 callback(data);
2329 }
2330 })
2331 .fail(function() {
2315 - versionLog('Failed to download installed version info from netdata!');
2316 - callback(null);
2332 + versionLog('Failed to download installed git commit id from netdata!');
2333 +
2334 + if(force === true) {
2335 + var c = getNetdataCommitIdFromVersion();
2336 + if(c === null) versionLog('Cannot find the git commit id of netdata.');
2337 + callback(c);
2338 + }
2339 + else
2340 + callback(null);
2341 });
2342 }
2343
2344 function getGithubLatestCommit(callback) {
2321 - versionLog('Downloading latest version info from github...');
2345 + versionLog('Downloading latest git commit id info from github...');
2346
2347 $.ajax({
2348 url: 'https://api.github.com/repos/firehol/netdata/commits',
@@ -2326,17 +2350,17 @@
2350 cache: false
2351 })
2352 .done(function(data) {
2329 - versionLog('Latest version info from github is ' + data[0].sha);
2353 + versionLog('Latest git commit id from github is ' + data[0].sha);
2354 callback(data[0].sha);
2355 })
2356 .fail(function() {
2333 - versionLog('Failed to download installed version info from github!');
2357 + versionLog('Failed to download installed git commit id from github!');
2358 callback(null);
2359 });
2360 }
2361
2338 - function checkForUpdate(callback) {
2339 - getNetdataVersion(function(sha1) {
2362 + function checkForUpdate(force, callback) {
2363 + getNetdataCommitId(force, function(sha1) {
2364 if(sha1 === null) callback(null, null);
2365
2366 getGithubLatestCommit(function(sha2) {
@@ -2366,26 +2390,26 @@
2390 }
2391 }
2392
2369 - checkForUpdate(function(sha1, sha2) {
2393 + checkForUpdate(force, function(sha1, sha2) {
2394 var save = false;
2395
2396 if(sha1 === null) {
2397 save = false;
2374 - versionLog('<p><big>Failed to get your netdata version!</big></p><p>You can always get the latest version of netdata from <a href="https://github.com/firehol/netdata" target="_blank">its github page</a>.</p>');
2398 + versionLog('<p><big>Failed to get your netdata git commit id!</big></p><p>You can always get the latest netdata from <a href="https://github.com/firehol/netdata" target="_blank">its github page</a>.</p>');
2399 }
2400 else if(sha2 === null) {
2401 save = false;
2378 - versionLog('<p><big>Failed to get the latest version from github.</big></p><p>You can always get the latest version of netdata from <a href="https://github.com/firehol/netdata" target="_blank">its github page</a>.</p>');
2402 + versionLog('<p><big>Failed to get the latest git commit id from github.</big></p><p>You can always get the latest netdata from <a href="https://github.com/firehol/netdata" target="_blank">its github page</a>.</p>');
2403 }
2404 else if(sha1 === sha2) {
2405 save = true;
2382 - versionLog('<p><big>You already have the latest version of netdata!</big></p><p>No update yet?<br/>Probably, we need some motivation to keep going on!</p><p>If you haven\'t already, <a href="https://github.com/firehol/netdata" target="_blank">give netdata a <b>Star</b> at its github page</a>.</p>');
2406 + versionLog('<p><big>You already have the latest netdata!</big></p><p>No update yet?<br/>Probably, we need some motivation to keep going on!</p><p>If you haven\'t already, <a href="https://github.com/firehol/netdata" target="_blank">give netdata a <b>Star</b> at its github page</a>.</p>');
2407 }
2408 else {
2409 save = true;
2410 var compare = 'https://github.com/firehol/netdata/compare/' + sha1.toString() + '...' + sha2.toString();
2411
2388 - versionLog('<p><big><strong>New version of netdata available!</strong></big></p><p>Latest version: ' + sha2.toString() + '</p><p><a href="' + compare + '" target="_blank">Click here for the changes log</a> since your installed version, and<br/><a href="https://github.com/firehol/netdata/wiki/Updating-Netdata" target="_blank">click here for directions on updating</a> your netdata installation.</p><p>We suggest to review the changes log for new features you may be interested, or important bug fixes you may need.<br/>Keeping your netdata updated, is generally a good idea.</p>');
2412 + versionLog('<p><big><strong>New version of netdata available!</strong></big></p><p>Latest commit: <b><code>' + sha2.substring(0, 7).toString() + '</code></b></p><p><a href="' + compare + '" target="_blank">Click here for the changes log</a> since your installed version, and<br/><a href="https://github.com/firehol/netdata/wiki/Updating-Netdata" target="_blank">click here for directions on updating</a> your netdata installation.</p><p>We suggest to review the changes log for new features you may be interested, or important bug fixes you may need.<br/>Keeping your netdata updated, is generally a good idea.</p>');
2413
2414 document.getElementById('update_badge').innerHTML = '!';
2415 }
@@ -3314,7 +3338,8 @@
3338 <h4 class="modal-title" id="updateModalLabel">Update Check</h4>
3339 </div>
3340 <div class="modal-body">
3317 - Your netdata version: <b><code><span id="netdataVersion">Unknown</span></code></b>
3341 + Your netdata version: <b><code><span id="netdataVersion">Unknown</span></code></b><br/>
3342 + Your netdata commit: <b><code><span id="netdataCommitId">Unknown</span></code></b>
3343 <br/>
3344 <div style="padding: 10px;"></div>
3345 <div id="versionCheckLog">Not checked yet. Please press the Check Now button.</div>