(function($) { var csscls = PhpDebugBar.utils.makecsscls('phpdebugbar-widgets-'); /** * Widget for the displaying sql queries * * Options: * - data */ var SQLQueriesWidget = PhpDebugBar.Widgets.SQLQueriesWidget = PhpDebugBar.Widget.extend({ className: csscls('sqlqueries'), onFilterClick: function(el) { $(el).toggleClass(csscls('excluded')); var excludedLabels = []; this.$toolbar.find(csscls('.filter') + csscls('.excluded')).each(function() { excludedLabels.push(this.rel); }); this.$list.$el.find("li[connection=" + $(el).attr("rel") + "]").toggle(); this.set('exclude', excludedLabels); }, onCopyToClipboard: function (el) { var code = $(el).parent('li').find('code').get(0); var copy = function () { try { document.execCommand('copy'); alert('Query copied to the clipboard'); } catch (err) { console.log('Oops, unable to copy'); } }; var select = function (node) { if (document.selection) { var range = document.body.createTextRange(); range.moveToElementText(node); range.select(); } else if (window.getSelection) { var range = document.createRange(); range.selectNodeContents(node); window.getSelection().removeAllRanges(); window.getSelection().addRange(range); } copy(); window.getSelection().removeAllRanges(); }; select(code); }, render: function() { this.$status = $('
').addClass(csscls('status')).appendTo(this.$el); this.$toolbar = $('').addClass(csscls('toolbar')).appendTo(this.$el); var filters = [], self = this; this.$list = new PhpDebugBar.Widgets.ListWidget({ itemRenderer: function(li, stmt) { $('
').addClass(csscls('sql')).html(PhpDebugBar.Widgets.highlight(stmt.sql, 'sql')).appendTo(li);
if (stmt.duration_str) {
$('').addClass(csscls('duration')).text(stmt.duration_str).appendTo(li);
}
if (stmt.memory_str) {
$('').addClass(csscls('memory')).text(stmt.memory_str).appendTo(li);
}
if (typeof(stmt.row_count) != 'undefined') {
$('').addClass(csscls('row-count')).text(stmt.row_count).appendTo(li);
}
if (typeof(stmt.stmt_id) != 'undefined' && stmt.stmt_id) {
$('').addClass(csscls('stmt-id')).text(stmt.stmt_id).appendTo(li);
}
if (stmt.connection) {
$('').addClass(csscls('database')).text(stmt.connection).appendTo(li);
li.attr("connection",stmt.connection);
if ( $.inArray(stmt.connection, filters) == -1 ) {
filters.push(stmt.connection);
$('')
.addClass(csscls('filter'))
.text(stmt.connection)
.attr('rel', stmt.connection)
.on('click', function() { self.onFilterClick(this); })
.appendTo(self.$toolbar);
if (filters.length>1) {
self.$toolbar.show();
self.$list.$el.css("margin-bottom","20px");
}
}
}
if (typeof(stmt.is_success) != 'undefined' && !stmt.is_success) {
li.addClass(csscls('error'));
li.append($('').addClass(csscls('error')).text("[" + stmt.error_code + "] " + stmt.error_message));
}
$('')
.addClass(csscls('copy-clipboard'))
.css('cursor', 'pointer')
.on('click', function (event) {
self.onCopyToClipboard(this);
event.stopPropagation();
})
.appendTo(li);
if (stmt.params && !$.isEmptyObject(stmt.params)) {
var table = $('Params |
---|