From 6d7244eeea5a38c7215b8ef3cb87995b10dcb612 Mon Sep 17 00:00:00 2001 From: Tyron Madlener Date: Mon, 25 Jul 2011 22:10:52 +0300 Subject: [PATCH] - Live charting: Error message on invalid server response - Fixed bugged CPU chart not displaying anything --- js/jquery/jquery.sortableTable.js | 2 +- js/messages.php | 5 ++ js/server_status.js | 86 +++++++++++++++++++------------ server_status.php | 5 +- 4 files changed, 62 insertions(+), 36 deletions(-) diff --git a/js/jquery/jquery.sortableTable.js b/js/jquery/jquery.sortableTable.js index 2dd1ede1e2..1f4fc91db8 100644 --- a/js/jquery/jquery.sortableTable.js +++ b/js/jquery/jquery.sortableTable.js @@ -49,7 +49,7 @@ $('table').sortableTable('destroy') - removes all events from the table }, destroy : function( ) { $(this).data('sortableTable').destroy(); - }, + } }; if ( methods[method] ) { diff --git a/js/messages.php b/js/messages.php index 7632fcdcbf..92d849ff41 100644 --- a/js/messages.php +++ b/js/messages.php @@ -156,6 +156,11 @@ $js_messages['strIgnoreWhereAndGroup'] = __('Group queries, ignoring variable da $js_messages['strSumRows'] = __('Sum of grouped rows:'); $js_messages['strTotal'] = __('Total:'); +$js_messages['strLoadingLogs'] = __('Loading logs'); +$js_messages['strRefreshFailed'] = __('Monitor refresh failed'); +$js_messages['strInvalidResponseExplanation'] = __('While requesting new chart data the server returned an invalid response. This is most likely because your session expired. Reloading the page and reentering your credentials should help.'); +$js_messages['strReloadPage'] = __('Reload page'); + /* For inline query editing */ $js_messages['strGo'] = __('Go'); $js_messages['strCancel'] = __('Cancel'); diff --git a/js/server_status.js b/js/server_status.js index 42789ed4b0..d9d4d175ca 100644 --- a/js/server_status.js +++ b/js/server_status.js @@ -218,7 +218,8 @@ $(function() { true, numLoadedPoints >= chartObj.options.realtime.numMaxPoints ); - } + }, + error: function() { serverResponseError(); } } } @@ -260,7 +261,8 @@ $(function() { true, numLoadedPoints >= chartObj.options.realtime.numMaxPoints ); - } + }, + error: function() { serverResponseError(); } } }; @@ -295,7 +297,8 @@ $(function() { true, numLoadedPoints >= chartObj.options.realtime.numMaxPoints ); - } + }, + error: function() { serverResponseError(); } } }; } else { @@ -615,15 +618,12 @@ $(function() { { dataType: 'cpu', name: PMA_messages['strAverageLoad'], unit: '%', - transformFn: function(cur, prev) { - console.log('cpu-linux chart, transformFn()'); - console.log(cur); - console.log(prev); - if(prev == null) return undefined; - var diff_total = cur.busy + cur.idle - (prev.busy + prev.idle); - var diff_idle = cur.idle - prev.idle; - return 100*(diff_total - diff_idle) / diff_total; - } + // Needs to be string so it is not ignored by $.toJSON() + transformFn: + 'if(prev == null) return undefined;' + + 'var diff_total = cur.busy + cur.idle - (prev.busy + prev.idle);' + + 'var diff_idle = cur.idle - prev.idle;' + + 'return 100*(diff_total - diff_idle) / diff_total;' } ] }, @@ -922,14 +922,14 @@ $(function() { saveMonitor(); // Save settings $(this).dialog("close"); - } + }; dlgButtons[PMA_messages['strClose']] = function() { newChart = null; $('span#clearSeriesLink').hide(); $('#seriesPreview').html(''); $(this).dialog("close"); - } + }; $('div#addChartDialog').dialog({ width:'auto', @@ -1067,7 +1067,7 @@ $(function() { }); } ); - } + }; loadLogVars(); @@ -1284,7 +1284,7 @@ $(function() { $('#logAnalyseDialog').find('dateStart,dateEnd').datepicker('destroy'); $(this).dialog("close"); - } + }; dlgBtns[PMA_messages['strFromGeneralLog']] = function() { var dateStart = Date.parse($('#logAnalyseDialog input[name="dateStart"]').attr('value')) || min; @@ -1301,7 +1301,7 @@ $(function() { $('#logAnalyseDialog').find('dateStart,dateEnd').datepicker('destroy'); $(this).dialog("close"); - } + }; $('#logAnalyseDialog').dialog({ width: 'auto', @@ -1397,7 +1397,12 @@ $(function() { function refreshChartGrid() { /* Send to server */ runtime.refreshRequest = $.post('server_status.php?'+url_query, { ajax_request: true, chart_data: 1, type: 'chartgrid', requiredData: $.toJSON(runtime.dataList) },function(data) { - var chartData = $.parseJSON(data); + var chartData; + try { + chartData = $.parseJSON(data); + } catch(err) { + return serverResponseError(); + } var value, i=0; var diff; @@ -1429,10 +1434,9 @@ $(function() { value = value / elem.nodes[j].valueDivisor; if(elem.nodes[j].transformFn) { - value = elem.nodes[j].transformFn( - chartData[key][j], - (oldChartData == null) ? null : oldChartData[key][j] - ); + value = eval('(function(cur, prev) { ' + elem.nodes[j].transformFn + '})(' + + 'chartData[key][j],' + (oldChartData == null ? 'null' : 'oldChartData[key][j]') + ')'); + } if(value != undefined) @@ -1477,9 +1481,9 @@ $(function() { if(! opts.limitTypes) opts.limitTypes = false; - $('#loadingLogsDialog').html(PMA_messages['strAnalysingLogs'] + ' '); + $('#emptyDialog').html(PMA_messages['strAnalysingLogs'] + ' '); - $('#loadingLogsDialog').dialog({ + $('#emptyDialog').dialog({ width: 'auto', height: 'auto', buttons: { @@ -1503,17 +1507,23 @@ $(function() { limitTypes: opts.limitTypes }, function(data) { - var logData = $.parseJSON(data); + var logData; + try { + logData = $.parseJSON(data); + } catch(err) { + return serverResponseError(); + } if(logData.rows.length != 0) { runtime.logDataCols = buildLogTable(logData); /* Show some stats in the dialog */ - $('#loadingLogsDialog').html('

' + PMA_messages['strLogDataLoaded'] + '

'); + $('#emptyDialog').attr('title', PMA_messages['strLoadingLogs']); + $('#emptyDialog').html('

' + PMA_messages['strLogDataLoaded'] + '

'); $.each(logData.sum, function(key, value) { key = key.charAt(0).toUpperCase() + key.slice(1).toLowerCase(); if(key == 'Total') key = '' + key + ''; - $('#loadingLogsDialog').append(key + ': ' + value + '
'); + $('#emptyDialog').append(key + ': ' + value + '
'); }); /* Add filter options if more than a bunch of rows there to filter */ @@ -1551,19 +1561,19 @@ $(function() { dlgBtns[PMA_messages['strJumpToTable']] = function() { $(this).dialog("close"); $(document).scrollTop($('div#logTable').offset().top); - } + }; - $('#loadingLogsDialog').dialog( "option", "buttons", dlgBtns); + $('#emptyDialog').dialog( "option", "buttons", dlgBtns); } else { - $('#loadingLogsDialog').html('

' + PMA_messages['strNoDataFound'] + '

'); + $('#emptyDialog').html('

' + PMA_messages['strNoDataFound'] + '

'); var dlgBtns = {}; dlgBtns[PMA_messages['strClose']] = function() { $(this).dialog("close"); - } + }; - $('#loadingLogsDialog').dialog( "option", "buttons", dlgBtns ); + $('#emptyDialog').dialog( "option", "buttons", dlgBtns ); } } ); @@ -1682,7 +1692,7 @@ $(function() { return value.replace(/(\[.*?\])+/g,''); } return value; - } + }; for(var i=0; i < rows.length; i++) { if(i == 0) { @@ -1889,4 +1899,14 @@ $(function() { $(this).hide(); }); + function serverResponseError() { + var btns = {}; + btns[PMA_messages['strReloadPage']] = function() { + window.location.reload(); + }; + $('#emptyDialog').attr('title',PMA_messages['strRefreshFailed']); + $('#emptyDialog').html(' ' + PMA_messages['strInvalidResponseExplanation']) + $('#emptyDialog').dialog({ buttons: btns }); + } + }); \ No newline at end of file diff --git a/server_status.php b/server_status.php index 15dfb68882..e24cba8a93 100644 --- a/server_status.php +++ b/server_status.php @@ -1340,7 +1340,7 @@ function printMonitor() { |

-
+

@@ -1453,7 +1453,8 @@ function printMonitor() { -