diff --git a/src/DebugBar/JavascriptRenderer.php b/src/DebugBar/JavascriptRenderer.php index 1cdb2fc..4660d41 100644 --- a/src/DebugBar/JavascriptRenderer.php +++ b/src/DebugBar/JavascriptRenderer.php @@ -662,11 +662,12 @@ class JavascriptRenderer if ($renderStackedData && $this->debugBar->hasStackedData()) { foreach ($this->debugBar->getStackedData() as $id => $data) { - $js .= $this->getAddDatasetCode($id, $data); + $js .= $this->getAddDatasetCode($id, $data, '(stacked)'); } } - $js .= $this->getAddDatasetCode($this->debugBar->getCurrentRequestId(), $this->debugBar->getData()); + $suffix = !$initialize ? '(ajax)' : null; + $js .= $this->getAddDatasetCode($this->debugBar->getCurrentRequestId(), $this->debugBar->getData(), $suffix); return "\n"; } @@ -782,12 +783,14 @@ class JavascriptRenderer * @param array $data * @return string */ - protected function getAddDatasetCode($requestId, $data) + protected function getAddDatasetCode($requestId, $data, $suffix = null) { - $js = sprintf("%s.addDataSet(%s, \"%s\");\n", + $js = sprintf("%s.addDataSet(%s, \"%s\"%s);\n", $this->variableName, json_encode($data), - $requestId); + $requestId, + $suffix ? ", " . json_encode($suffix) : '' + ); return $js; } } diff --git a/src/DebugBar/Resources/debugbar.css b/src/DebugBar/Resources/debugbar.css index 8a52386..c4d3269 100644 --- a/src/DebugBar/Resources/debugbar.css +++ b/src/DebugBar/Resources/debugbar.css @@ -105,6 +105,7 @@ select.phpdebugbar-datasets-switcher { float: right; display: none; margin: 2px 0 0 7px; + max-width: 200px; } /* -------------------------------------- */ diff --git a/src/DebugBar/Resources/debugbar.js b/src/DebugBar/Resources/debugbar.js index 17f4a93..edfca9d 100644 --- a/src/DebugBar/Resources/debugbar.js +++ b/src/DebugBar/Resources/debugbar.js @@ -34,6 +34,25 @@ if (typeof(PhpDebugBar) == 'undefined') { return d; } + /** + * Counts the number of properties in an object + * + * @param {Object} obj + * @return {Integer} + */ + function getObjectSize(obj) { + if (Object.keys) { + return Object.keys(obj).length; + } + var count = 0; + for (var k in obj) { + if (obj.hasOwnProperty(k)) { + count++; + } + } + return count; + } + // ------------------------------------------------------------------ /** @@ -274,6 +293,48 @@ if (typeof(PhpDebugBar) == 'undefined') { // ------------------------------------------------------------------ + /** + * Dataset title formater + * + * Formats the title of a dataset for the select box + */ + var DatasetTitleFormater = PhpDebugBar.DatasetTitleFormater = function(debugbar) { + this.debugbar = debugbar; + }; + + $.extend(DatasetTitleFormater.prototype, { + + /** + * Formats the title of a dataset + * + * @this {DatasetTitleFormater} + * @param {String} id + * @param {Object} data + * @param {String} suffix + * @return {String} + */ + format: function(id, data, suffix) { + if (suffix) { + suffix = ' ' + suffix; + } else { + suffix = ''; + } + + var nb = getObjectSize(this.debugbar.datasets) + 1; + + if (typeof(data['__meta']) === 'undefined') { + return "Request #" + nb + suffix; + } + + var filename = data['__meta']['uri'].substr(data['__meta']['uri'].lastIndexOf('/') + 1); + var label = "#" + nb + " " + filename + suffix + ' (' + data['__meta']['datetime'] + ')'; + return label; + } + + }); + + // ------------------------------------------------------------------ + /** * DebugBar @@ -299,6 +360,7 @@ if (typeof(PhpDebugBar) == 'undefined') { this.datasets = {}; this.firstTabName = null; this.activePanelName = null; + this.datesetTitleFormater = new DatasetTitleFormater(this); }, /** @@ -344,7 +406,8 @@ if (typeof(PhpDebugBar) == 'undefined') { this.$openbtn = $('').appendTo(this.$header).hide(); this.$openbtn.click(function() { self.openHandler.show(function(id, dataset) { - self.addDataSet(dataset, id, id + " (opened)"); + self.addDataSet(dataset, id, "(opened)"); + self.showTab(); }); }); @@ -352,6 +415,7 @@ if (typeof(PhpDebugBar) == 'undefined') { this.$datasets = $('