diff options
author | Marc Delisle <marc@infomarc.info> | 2015-06-18 18:49:36 +0300 |
---|---|---|
committer | Marc Delisle <marc@infomarc.info> | 2015-06-18 18:49:36 +0300 |
commit | 72833685b7291bc178ffec5397ae627dbabcd2dd (patch) | |
tree | cd5e8885bb4847bfb9039492faec4160cc7abadc /js | |
parent | 8636f7ef29be60bd0149db30a769041d5f68f6fe (diff) | |
parent | d608832a9dd539f7c78d28e5f7c6dd8f55510c91 (diff) |
Merge pull request #1741 from nisargjhaveri/debug_console
Group/Ungroup queries in console SQL debug
Diffstat (limited to 'js')
-rw-r--r-- | js/console.js | 151 | ||||
-rw-r--r-- | js/messages.php | 1 |
2 files changed, 126 insertions, 26 deletions
diff --git a/js/console.js b/js/console.js index 3ca4f6431d..d32e7c1039 100644 --- a/js/console.js +++ b/js/console.js @@ -1100,6 +1100,13 @@ var PMA_consoleBookmarks = { }; var PMA_consoleDebug = { + _config: { + groupQueries: false + }, + _lastDebugInfo: { + debugInfo: null, + url: null + }, initialize: function() { // Try to get debug info after every AJAX request $( document ).ajaxSuccess(function(event, xhr, settings, data) { @@ -1108,6 +1115,29 @@ var PMA_consoleDebug = { } }); + // Initialize config + this._initConfig(); + + if (this.configParam('groupQueries')) { + $('#debug_console').addClass('grouped'); + } else { + $('#debug_console').addClass('ungrouped'); + } + + // Initialize actions in toolbar + $('#debug_console .button.group_queries').click(function() { + $('#debug_console').addClass('grouped'); + $('#debug_console').removeClass('ungrouped'); + PMA_consoleDebug.configParam('groupQueries', true); + PMA_consoleDebug.refresh(); + }); + $('#debug_console .button.ungroup_queries').click(function() { + $('#debug_console').addClass('ungrouped'); + $('#debug_console').removeClass('grouped'); + PMA_consoleDebug.configParam('groupQueries', false); + PMA_consoleDebug.refresh(); + }); + // Show SQL debug info for first page load if (typeof debugSQLInfo !== 'undefined' && debugSQLInfo !== 'null') { $('#pma_console .button.debug').removeClass('hide'); @@ -1117,6 +1147,19 @@ var PMA_consoleDebug = { } PMA_consoleDebug.showLog(debugSQLInfo); }, + _initConfig: function() { + var config = JSON.parse($.cookie('pma_console_dbg_config')); + if (config) { + this._config = config; + } + }, + configParam: function(name, value) { + if (typeof value === 'undefined') { + return this._config[name]; + } + this._config[name] = value; + $.cookie('pma_console_dbg_config', JSON.stringify(this._config)); + }, _formatFunctionCall: function(dbgStep) { var functionName = ''; if ('class' in dbgStep) { @@ -1126,8 +1169,7 @@ var PMA_consoleDebug = { functionName += dbgStep.function; if (dbgStep.args.length) { functionName += '(...)'; - } - else { + } else { functionName += '()'; } return functionName; @@ -1181,8 +1223,7 @@ var PMA_consoleDebug = { .append( $('<span>').text(step) ); - } - else { + } else { if (typeof step.args === 'string' && step.args) { step.args = [step.args]; } @@ -1219,14 +1260,80 @@ var PMA_consoleDebug = { } return $traceElem; }, + _formatQueryOrGroup: function(queryInfo) { + var grouped, queryText, totalTime, count, i; + if (Array.isArray(queryInfo)) { + // It is grouped + grouped = true; + + queryText = queryInfo[0].query; + + totalTime = 0; + for (i in queryInfo) { + totalTime += queryInfo[i].time; + } + + count = queryInfo.length; + } else { + queryText = queryInfo.query; + totalTime = queryInfo.time; + } + + var $query = $('<div class="message collapsed hide_trace">') + .append( + $('#debug_console .templates .debug_query').clone() + ) + .append( + $('<div class="query">') + .text(queryText) + ); + if (grouped) { + $query.find('.text.count').removeClass('hide'); + $query.find('.text.count span').text(count); + } + $query.find('.text.time span').text(totalTime); + + if (grouped) { + var $singleQuery; + for (i in queryInfo) { + $singleQuery = $('<div class="message welcome trace">') + .text( (parseInt(i) + 1) + '.' ) + .append( + $('<span class="time">').text( + PMA_messages.strConsoleDebugTimeTaken + + ' ' + queryInfo[i].time + 's' + ) + ); + this._appendQueryExtraInfo(queryInfo[i], $singleQuery); + $query + .append('<div class="message welcome trace">') + .append($singleQuery); + } + } else { + this._appendQueryExtraInfo(queryInfo, $query); + } + + return $query; + }, + _appendQueryExtraInfo: function(query, $elem) { + if ('error' in query) { + $elem.append( + $('<div>').html(query.error) + ); + } + $elem.append(this._formatBackTrace(query.trace)); + }, showLog: function(debugInfo, url) { + this._lastDebugInfo.debugInfo = debugInfo; + this._lastDebugInfo.url = url; + $('#debug_console .debugLog').empty(); $("#debug_console .debug>.welcome").empty(); + var debugJson = false; if (typeof debugInfo === "object" && 'queries' in debugInfo) { debugJson = debugInfo; - } - else if (typeof debugInfo === "string") { + } else if (typeof debugInfo === "string") { try { debugJson = JSON.parse(debugInfo); } catch (e) { @@ -1249,7 +1356,7 @@ var PMA_consoleDebug = { // Calculate total time and make unique query array var totalTime = 0; - var i, query; + var i; for (i = 0; i < totalExec; ++i) { totalTime += allQueries[i].time; if (!(allQueries[i].hash in uniqueQueries)) { @@ -1281,29 +1388,21 @@ var PMA_consoleDebug = { ); } - for (i = 0; i < totalExec; ++i) { - query = $('<div class="message collapsed hide_trace">') - .append( - $('<div class="action_content">') - .append( - $('#debug_console .templates .debug_query').clone() - ) - ) - .append( - $('<div class="query">') - .text(allQueries[i].query) - ); - query.find('.text.time span').text(allQueries[i].time); - if ('error' in allQueries[i]) { - query.append( - $('<div>').html(allQueries[i].error) - ); + if (this.configParam('groupQueries')) { + for (i in uniqueQueries) { + $('#debug_console .debugLog').append(this._formatQueryOrGroup(uniqueQueries[i])); + } + } else { + for (i = 0; i < totalExec; ++i) { + $('#debug_console .debugLog').append(this._formatQueryOrGroup(allQueries[i])); } - query.append(this._formatBackTrace(allQueries[i].trace)); - $('#debug_console .debugLog').append(query); } PMA_consoleMessages._msgEventBinds($('#debug_console .message:not(.binded)')); + }, + refresh: function() { + var last = this._lastDebugInfo; + PMA_consoleDebug.showLog(last.debugInfo, last.url); } }; diff --git a/js/messages.php b/js/messages.php index a8617d75c9..dea5190b6a 100644 --- a/js/messages.php +++ b/js/messages.php @@ -593,6 +593,7 @@ $js_messages['strConsoleDebugSummary'] = __('%s queries executed %s times in %s $js_messages['strConsoleDebugArgsSummary'] = __('%s argument(s) passed'); $js_messages['strConsoleDebugShowArgs'] = __('Show arguments'); $js_messages['strConsoleDebugHideArgs'] = __('Hide arguments'); +$js_messages['strConsoleDebugTimeTaken'] = __('Time taken:'); $js_messages['strNoLocalStorage'] = __('Your web browser does not support local storage of settings or the quota limit has been reached, some features may not work properly for you. In Safari, such problem is commonly caused by "Private Mode Browsing".'); echo "var PMA_messages = new Array();\n"; |