mirror of
https://github.com/maximebf/php-debugbar.git
synced 2025-07-25 18:51:42 +02:00
Use table, render once
This commit is contained in:
@@ -544,7 +544,8 @@ if (typeof(PhpDebugBar) == 'undefined') {
|
||||
});
|
||||
});
|
||||
|
||||
this.datasetTab = new PhpDebugBar.DebugBar.Tab({"icon":"history", "title":"History", "widget": new PhpDebugBar.Widgets.DatasetWidget()});
|
||||
this.datasetTab = new PhpDebugBar.DebugBar.Tab({"icon":"history", "title":"Request history", "widget": new PhpDebugBar.Widgets.DatasetWidget()});
|
||||
this.datasetTab.initialize();
|
||||
this.datasetTab.$tab.appendTo( this.$headerRight).hide();
|
||||
this.datasetTab.$tab.click(function() {
|
||||
if (!self.isMinimized() && self.activePanelName == '__datasets') {
|
||||
@@ -948,7 +949,7 @@ if (typeof(PhpDebugBar) == 'undefined') {
|
||||
this.datasets[id] = data;
|
||||
|
||||
this.datasetTab.$tab.show();
|
||||
this.datasetTab.set('data', this.datasets);
|
||||
this.datasetTab.set('data', data);
|
||||
this.datasetTab.set('badge', getObjectSize(this.datasets));
|
||||
|
||||
if (typeof(show) == 'undefined' || show) {
|
||||
|
@@ -270,26 +270,6 @@ if (typeof(PhpDebugBar) == 'undefined') {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* An extension of KVListWidget where the data represents incoming requsts
|
||||
*
|
||||
* Options:
|
||||
* - data
|
||||
*/
|
||||
var DatasetWidget = PhpDebugBar.Widgets.DatasetWidget = KVListWidget.extend({
|
||||
|
||||
className: csscls('kvlist datasetlist'),
|
||||
|
||||
itemRenderer: function(dt, dd, key, value) {
|
||||
dt.text(key);
|
||||
dd.html(value.__meta.uri );
|
||||
dd.on('click', function() {
|
||||
window.phpdebugbar.showDataSet(key);
|
||||
})
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -664,5 +644,61 @@ if (typeof(PhpDebugBar) == 'undefined') {
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Displays datasets in a table
|
||||
*
|
||||
*/
|
||||
var DatasetWidget = PhpDebugBar.Widgets.DatasetWidget = PhpDebugBar.Widget.extend({
|
||||
|
||||
initialize: function(options) {
|
||||
if (!options['itemRenderer']) {
|
||||
options['itemRenderer'] = this.itemRenderer;
|
||||
}
|
||||
this.set(options);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
this.bindAttr(['itemRenderer', 'data'], function() {
|
||||
if (!this.$table) {
|
||||
this.$el.empty();
|
||||
this.$table = $('<tbody />');
|
||||
$('<table><thead><tr><th style="width: 175px;">Date</th><th style="width: 80px;">Method</th><th>URL</th></tr></thead></table>').append(this.$table).appendTo(this.$el);
|
||||
}
|
||||
|
||||
if (!this.has('data')) {
|
||||
return;
|
||||
}
|
||||
|
||||
var data = this.get('data');
|
||||
if (!data.__meta) {
|
||||
return;
|
||||
}
|
||||
|
||||
var tr = $('<tr />').addClass(csscls('table-row')).appendTo(this.$table);
|
||||
this.get('itemRenderer')(tr, data);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Renders the content of a <li> element
|
||||
*
|
||||
* @param {jQuery} tr The <tr> element as a jQuery Object
|
||||
* @param {Object} value An item from the data array
|
||||
*/
|
||||
itemRenderer: function(tr, value) {
|
||||
var meta = value.__meta;
|
||||
tr
|
||||
.append('<td>' + meta['datetime'] + '</td>')
|
||||
.append('<td>' + meta['method'] + '</td>')
|
||||
.append($('<td />').append(meta['uri']))
|
||||
.css('cursor', 'pointer')
|
||||
.on('click', function() {
|
||||
window.phpdebugbar.showDataSet(meta['id']);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
})(PhpDebugBar.$);
|
||||
|
Reference in New Issue
Block a user