From e4247a8639acbe99076278685dc4ac3859f261f2 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 29 Oct 2014 14:14:51 +0100 Subject: [PATCH] Extend Template widget Based on SQL Queries widget, this adds param_count, memory_str, type and expandable params. --- .../Resources/widgets/templates/widget.css | 57 +++++++++++++++---- .../Resources/widgets/templates/widget.js | 39 +++++++++++-- 2 files changed, 82 insertions(+), 14 deletions(-) diff --git a/src/DebugBar/Resources/widgets/templates/widget.css b/src/DebugBar/Resources/widgets/templates/widget.css index fde40c8..c29536f 100644 --- a/src/DebugBar/Resources/widgets/templates/widget.css +++ b/src/DebugBar/Resources/widgets/templates/widget.css @@ -8,16 +8,53 @@ div.phpdebugbar-widgets-templates div.phpdebugbar-widgets-status { background: #fafafa; } -div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-render_time { +div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-render-time, +div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-memory, +div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-param-count, +div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-type { float: right; + margin-left: 8px; + color: #888; } -div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-render_time:before { - content: "\f017"; - font-family: FontAwesome; - font-size: 12px; - margin-right: 4px; -} - -div.phpdebugbar-widgets-templates div.phpdebugbar-widgets-status span.phpdebugbar-widgets-render_time { +div.phpdebugbar-widgets-templates div.phpdebugbar-widgets-status span.phpdebugbar-widgets-render-time, +div.phpdebugbar-widgets-templates div.phpdebugbar-widgets-status span.phpdebugbar-widgets-memory, +div.phpdebugbar-widgets-templates div.phpdebugbar-widgets-status span.phpdebugbar-widgets-param-count, +div.phpdebugbar-widgets-templates div.phpdebugbar-widgets-status span.phpdebugbar-widgets-type { color: #555; -} \ No newline at end of file +} +div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-render-time:before, +div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-memory:before, +div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-param-count:before, +div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-type:before { + font-family: FontAwesome; + margin-right: 4px; + font-size: 12px; +} +div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-render-time:before { + content: "\f017"; +} +div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-memory:before { + content: "\f085"; +} +div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-param-count:before { + content: "\f0ce"; +} +div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-type:before { + content: "\f121"; +} +div.phpdebugbar-widgets-templates table.phpdebugbar-widgets-params { + display: none; + width: 70%; + margin: 10px; + border: 1px solid #ddd; + font-family: monospace; + border-collapse: collapse; +} +div.phpdebugbar-widgets-templates table.phpdebugbar-widgets-params td { + border: 1px solid #ddd; + text-align: left; +} +div.phpdebugbar-widgets-templates table.phpdebugbar-widgets-params .phpdebugbar-widgets-name { + width: 20%; + font-weight: bold; +} diff --git a/src/DebugBar/Resources/widgets/templates/widget.js b/src/DebugBar/Resources/widgets/templates/widget.js index 6fdecbe..e841228 100644 --- a/src/DebugBar/Resources/widgets/templates/widget.js +++ b/src/DebugBar/Resources/widgets/templates/widget.js @@ -18,21 +18,52 @@ this.$list = new PhpDebugBar.Widgets.ListWidget({ itemRenderer: function(li, tpl) { $('').addClass(csscls('name')).text(tpl.name).appendTo(li); if (tpl.render_time_str) { - $('').addClass(csscls('render_time')).text(tpl.render_time_str).appendTo(li); + $('').addClass(csscls('render-time')).text(tpl.render_time_str).appendTo(li); + } + if (tpl.memory_str) { + $('').addClass(csscls('memory')).text(tpl.memory_str).appendTo(li); + } + if (typeof(tpl.param_count) != 'undefined') { + $('').addClass(csscls('param-count')).text(tpl.param_count).appendTo(li); + } + if (typeof(tpl.type) != 'undefined') { + $('').addClass(csscls('type')).text(tpl.type).appendTo(li); + } + if (tpl.params && !$.isEmptyObject(tpl.params)) { + var table = $('
Params
').addClass(csscls('params')).appendTo(li); + for (var key in tpl.params) { + if (typeof tpl.params[key] !== 'function') { + table.append('' + key + '
' + tpl.params[key] + '
'); + } + } + li.css('cursor', 'pointer').click(function() { + if (table.is(':visible')) { + table.hide(); + } else { + table.show(); + } + }); } }}); this.$list.$el.appendTo(this.$el); this.bindAttr('data', function(data) { this.$list.set('data', data.templates); + this.$status.empty(); + var sentence = data.sentence || "templates were rendered"; - this.$status.empty().append($('').text(data.templates.length + " " + sentence)); + $('').text(data.templates.length + " " + sentence).appendTo(this.$status); + if (data.accumulated_render_time_str) { - this.$status.append($('').addClass(csscls('render_time')).text(data.accumulated_render_time_str)); + this.$status.append($('').addClass(csscls('render-time')).text(data.accumulated_render_time_str)); + } + if (data.memory_usage_str) { + this.$status.append($('').addClass(csscls('memory')).text(data.memory_usage_str)); } }); } }); -})(PhpDebugBar.$); \ No newline at end of file +})(PhpDebugBar.$);