]> arthur.barton.de Git - netdata.git/commitdiff
properly show version and check version using the internal version string too
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 12 Feb 2017 11:54:28 +0000 (13:54 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 12 Feb 2017 11:54:28 +0000 (13:54 +0200)
web/index.html

index e2a2e07d3c34c60dcdb243d8dc016a628ff26e49..13aa53c6e4d44ae4222f7518133f942a0fb92d53 100644 (file)
                         // update the dashboard hostname
                         document.getElementById('hostname').innerHTML = options.hostname;
                         document.getElementById('hostname').href = NETDATA.serverDefault;
+                        document.getElementById('netdataVersion').innerHTML = options.version;
 
                         // update the dashboard title
                         document.title = options.hostname + ' netdata dashboard';
             document.getElementById('versionCheckLog').innerHTML = msg;
         }
 
-        function getNetdataVersion(callback) {
-            versionLog('Downloading installed version info from netdata...');
+        function getNetdataCommitIdFromVersion() {
+            var s = options.version.split('-');
+
+            if(s.length !== 3) return null;
+            if(s[2][0] == 'g') {
+                var v = s[2].split('_')[0].substring(1, 8);
+                if(v.length === 7) {
+                    versionLog('Installed git commit id of netdata is ' + v);
+                    document.getElementById('netdataCommitId').innerHTML = v;
+                    return v;
+                }
+            }
+            return null;
+        }
+
+        function getNetdataCommitId(force, callback) {
+            versionLog('Downloading installed git commit id from netdata...');
 
             $.ajax({
                 url: 'version.txt',
             .done(function(data) {
                 data = data.replace(/(\r\n|\n|\r| |\t)/gm,"");
                 if(data.length !== 40) {
-                    versionLog('Received version string is invalid.');
-                    callback(null);
+                    var c = getNetdataCommitIdFromVersion();
+                    if(c === null) versionLog('Cannot find the git commit id of netdata.');
+                    callback(c);
                 }
                 else {
-                    versionLog('Installed version of netdata is ' + data);
-                    document.getElementById('netdataVersion').innerHTML = data;
+                    versionLog('Installed git commit id of netdata is ' + data);
+                    document.getElementById('netdataCommitId').innerHTML = data.substring(0, 7);
                     callback(data);
                 }
             })
             .fail(function() {
-                versionLog('Failed to download installed version info from netdata!');
-                callback(null);
+                versionLog('Failed to download installed git commit id from netdata!');
+
+                if(force === true) {
+                    var c = getNetdataCommitIdFromVersion();
+                    if(c === null) versionLog('Cannot find the git commit id of netdata.');
+                    callback(c);
+                }
+                else
+                    callback(null);
             });
         }
 
         function getGithubLatestCommit(callback) {
-            versionLog('Downloading latest version info from github...');
+            versionLog('Downloading latest git commit id info from github...');
 
             $.ajax({
                 url: 'https://api.github.com/repos/firehol/netdata/commits',
                 cache: false
             })
             .done(function(data) {
-                versionLog('Latest version info from github is ' + data[0].sha);
+                versionLog('Latest git commit id from github is ' + data[0].sha);
                 callback(data[0].sha);
             })
             .fail(function() {
-                versionLog('Failed to download installed version info from github!');
+                versionLog('Failed to download installed git commit id from github!');
                 callback(null);
             });
         }
 
-        function checkForUpdate(callback) {
-            getNetdataVersion(function(sha1) {
+        function checkForUpdate(force, callback) {
+            getNetdataCommitId(force, function(sha1) {
                 if(sha1 === null) callback(null, null);
 
                 getGithubLatestCommit(function(sha2) {
                 }
             }
 
-            checkForUpdate(function(sha1, sha2) {
+            checkForUpdate(force, function(sha1, sha2) {
                 var save = false;
 
                 if(sha1 === null) {
                     save = false;
-                    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>');
+                    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>');
                 }
                 else if(sha2 === null) {
                     save = false;
-                    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>');
+                    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>');
                 }
                 else if(sha1 === sha2) {
                     save = true;
-                    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>');
+                    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>');
                 }
                 else {
                     save = true;
                     var compare = 'https://github.com/firehol/netdata/compare/' + sha1.toString() + '...' + sha2.toString();
 
-                    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>');
+                    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>');
 
                     document.getElementById('update_badge').innerHTML = '!';
                 }
                     <h4 class="modal-title" id="updateModalLabel">Update Check</h4>
                 </div>
                 <div class="modal-body">
-                    Your netdata version: <b><code><span id="netdataVersion">Unknown</span></code></b>
+                    Your netdata version: <b><code><span id="netdataVersion">Unknown</span></code></b><br/>
+                    Your netdata commit: <b><code><span id="netdataCommitId">Unknown</span></code></b>
                     <br/>
                     <div style="padding: 10px;"></div>
                     <div id="versionCheckLog">Not checked yet. Please press the Check Now button.</div>