diff --git a/src/DebugBar/DataCollector/DatasetCollector.php b/src/DebugBar/DataCollector/DatasetCollector.php
new file mode 100644
index 0000000..3bbfcda
--- /dev/null
+++ b/src/DebugBar/DataCollector/DatasetCollector.php
@@ -0,0 +1,56 @@
+ array(
+ "icon" => "history",
+ "title" => "Requests",
+ "widget" => 'PhpDebugBar.Widgets.DatasetListWidget',
+ "default" => "{}",
+ "position" => "right"
+ )
+ );
+ }
+
+ function getAssets()
+ {
+ return [];
+ }
+}
diff --git a/src/DebugBar/JavascriptRenderer.php b/src/DebugBar/JavascriptRenderer.php
index 9539630..0777f70 100644
--- a/src/DebugBar/JavascriptRenderer.php
+++ b/src/DebugBar/JavascriptRenderer.php
@@ -11,6 +11,7 @@
namespace DebugBar;
use DebugBar\DataCollector\AssetProvider;
+use DebugBar\DataCollector\DatasetCollector;
use DebugBar\DataCollector\Renderable;
/**
@@ -1124,7 +1125,8 @@ class JavascriptRenderer
}
}
}
- $controls = array_merge($widgets, $this->controls);
+
+ $controls = array_merge($widgets, $this->controls, (new DatasetCollector())->getWidgets());
foreach (array_filter($controls) as $name => $options) {
$opts = array_diff_key($options, array_flip($excludedOptions));
@@ -1133,12 +1135,13 @@ class JavascriptRenderer
if (!isset($opts['title'])) {
$opts['title'] = ucfirst(str_replace('_', ' ', $name));
}
- $js .= sprintf("%s.addTab(\"%s\", new %s({%s%s}));\n",
+ $js .= sprintf("%s.addTab(\"%s\", new %s({%s%s}), \"%s\");\n",
$varname,
$name,
isset($options['tab']) ? $options['tab'] : 'PhpDebugBar.DebugBar.Tab',
substr(json_encode($opts, JSON_FORCE_OBJECT), 1, -1),
- isset($options['widget']) ? sprintf('%s"widget": new %s()', count($opts) ? ', ' : '', $options['widget']) : ''
+ isset($options['widget']) ? sprintf('%s"widget": new %s()', count($opts) ? ', ' : '', $options['widget']) : '',
+ isset($options['position']) ? $options['position'] : 'left'
);
} elseif (isset($options['indicator']) || isset($options['icon'])) {
$js .= sprintf("%s.addIndicator(\"%s\", new %s(%s), \"%s\");\n",
diff --git a/src/DebugBar/Resources/debugbar.js b/src/DebugBar/Resources/debugbar.js
index 55c7b9d..668b417 100644
--- a/src/DebugBar/Resources/debugbar.js
+++ b/src/DebugBar/Resources/debugbar.js
@@ -544,13 +544,6 @@ if (typeof(PhpDebugBar) == 'undefined') {
});
});
- // select box for data sets
- this.$datasets = $('').addClass(csscls('datasets-switcher')).attr('name', 'datasets-switcher')
- .appendTo(this.$headerRight);
- this.$datasets.change(function() {
- self.dataChangeHandler(self.datasets[this.value]);
- self.showTab();
- });
},
/**
@@ -624,13 +617,13 @@ if (typeof(PhpDebugBar) == 'undefined') {
* @param {Tab} tab Tab object
* @return {Tab}
*/
- addTab: function(name, tab) {
+ addTab: function(name, tab, position) {
if (this.isControl(name)) {
throw new Error(name + ' already exists');
}
var self = this;
- tab.$tab.appendTo(this.$headerLeft).click(function() {
+ tab.$tab.appendTo(position == 'right' ? this.$headerRight : this.$headerLeft).click(function() {
if (!self.isMinimized() && self.activePanelName == name) {
self.minimize();
} else {
@@ -934,7 +927,7 @@ if (typeof(PhpDebugBar) == 'undefined') {
if (!suffix || ('(iframe)').indexOf(suffix) < 0) {
suffix = '(iframe)' + (suffix || '');
}
-
+
window.parent.phpdebugbar.addDataSet(data, id, suffix, show);
return;
}
@@ -943,10 +936,9 @@ if (typeof(PhpDebugBar) == 'undefined') {
id = id || (getObjectSize(this.datasets) + 1);
this.datasets[id] = data;
- this.$datasets.append($(''));
- if (this.$datasets.children().length > 1) {
- this.$datasets.show();
- }
+ var control = this.getControl('__datasets');
+ control.set('data', this.datasets);
+ control.set('badge', getObjectSize(this.datasets));
if (typeof(show) == 'undefined' || show) {
this.showDataSet(id);
@@ -991,7 +983,6 @@ if (typeof(PhpDebugBar) == 'undefined') {
*/
showDataSet: function(id) {
this.dataChangeHandler(this.datasets[id]);
- this.$datasets.val(id);
},
/**
diff --git a/src/DebugBar/Resources/widgets.js b/src/DebugBar/Resources/widgets.js
index b9228b6..49556bb 100644
--- a/src/DebugBar/Resources/widgets.js
+++ b/src/DebugBar/Resources/widgets.js
@@ -270,6 +270,26 @@ if (typeof(PhpDebugBar) == 'undefined') {
});
+ /**
+ * An extension of KVListWidget where the data represents incoming requsts
+ *
+ * Options:
+ * - data
+ */
+ var DatasetListWidget = PhpDebugBar.Widgets.DatasetListWidget = 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);
+ })
+ }
+
+ });
+
// ------------------------------------------------------------------
/**