Skip to content

Commit 9010755

Browse files
committed
Merge pull request php-debugbar#169 from maximebf/extended-template
Extend Template widget
2 parents eb3f0d4 + e4247a8 commit 9010755

File tree

2 files changed

+80
-12
lines changed

2 files changed

+80
-12
lines changed

src/DebugBar/Resources/widgets/templates/widget.css

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,53 @@ div.phpdebugbar-widgets-templates div.phpdebugbar-widgets-status {
88
background: #fafafa;
99
}
1010

11-
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-render_time {
11+
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-render-time,
12+
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-memory,
13+
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-param-count,
14+
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-type {
1215
float: right;
16+
margin-left: 8px;
17+
color: #888;
1318
}
14-
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-render_time:before {
15-
content: "\f017";
19+
div.phpdebugbar-widgets-templates div.phpdebugbar-widgets-status span.phpdebugbar-widgets-render-time,
20+
div.phpdebugbar-widgets-templates div.phpdebugbar-widgets-status span.phpdebugbar-widgets-memory,
21+
div.phpdebugbar-widgets-templates div.phpdebugbar-widgets-status span.phpdebugbar-widgets-param-count,
22+
div.phpdebugbar-widgets-templates div.phpdebugbar-widgets-status span.phpdebugbar-widgets-type {
23+
color: #555;
24+
}
25+
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-render-time:before,
26+
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-memory:before,
27+
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-param-count:before,
28+
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-type:before {
1629
font-family: FontAwesome;
17-
font-size: 12px;
1830
margin-right: 4px;
31+
font-size: 12px;
32+
}
33+
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-render-time:before {
34+
content: "\f017";
35+
}
36+
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-memory:before {
37+
content: "\f085";
38+
}
39+
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-param-count:before {
40+
content: "\f0ce";
41+
}
42+
div.phpdebugbar-widgets-templates span.phpdebugbar-widgets-type:before {
43+
content: "\f121";
44+
}
45+
div.phpdebugbar-widgets-templates table.phpdebugbar-widgets-params {
46+
display: none;
47+
width: 70%;
48+
margin: 10px;
49+
border: 1px solid #ddd;
50+
font-family: monospace;
51+
border-collapse: collapse;
52+
}
53+
div.phpdebugbar-widgets-templates table.phpdebugbar-widgets-params td {
54+
border: 1px solid #ddd;
55+
text-align: left;
56+
}
57+
div.phpdebugbar-widgets-templates table.phpdebugbar-widgets-params .phpdebugbar-widgets-name {
58+
width: 20%;
59+
font-weight: bold;
1960
}
20-
21-
div.phpdebugbar-widgets-templates div.phpdebugbar-widgets-status span.phpdebugbar-widgets-render_time {
22-
color: #555;
23-
}

src/DebugBar/Resources/widgets/templates/widget.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,52 @@
1818
this.$list = new PhpDebugBar.Widgets.ListWidget({ itemRenderer: function(li, tpl) {
1919
$('<span />').addClass(csscls('name')).text(tpl.name).appendTo(li);
2020
if (tpl.render_time_str) {
21-
$('<span title="Render time" />').addClass(csscls('render_time')).text(tpl.render_time_str).appendTo(li);
21+
$('<span title="Render time" />').addClass(csscls('render-time')).text(tpl.render_time_str).appendTo(li);
22+
}
23+
if (tpl.memory_str) {
24+
$('<span title="Memory usage" />').addClass(csscls('memory')).text(tpl.memory_str).appendTo(li);
25+
}
26+
if (typeof(tpl.param_count) != 'undefined') {
27+
$('<span title="Parameter count" />').addClass(csscls('param-count')).text(tpl.param_count).appendTo(li);
28+
}
29+
if (typeof(tpl.type) != 'undefined') {
30+
$('<span title="Type" />').addClass(csscls('type')).text(tpl.type).appendTo(li);
31+
}
32+
if (tpl.params && !$.isEmptyObject(tpl.params)) {
33+
var table = $('<table><tr><th colspan="2">Params</th></tr></table>').addClass(csscls('params')).appendTo(li);
34+
for (var key in tpl.params) {
35+
if (typeof tpl.params[key] !== 'function') {
36+
table.append('<tr><td class="' + csscls('name') + '">' + key + '</td><td class="' + csscls('value') +
37+
'"><pre><code>' + tpl.params[key] + '</code></pre></td></tr>');
38+
}
39+
}
40+
li.css('cursor', 'pointer').click(function() {
41+
if (table.is(':visible')) {
42+
table.hide();
43+
} else {
44+
table.show();
45+
}
46+
});
2247
}
2348
}});
2449
this.$list.$el.appendTo(this.$el);
2550

2651
this.bindAttr('data', function(data) {
2752
this.$list.set('data', data.templates);
53+
this.$status.empty();
54+
2855
var sentence = data.sentence || "templates were rendered";
29-
this.$status.empty().append($('<span />').text(data.templates.length + " " + sentence));
56+
$('<span />').text(data.templates.length + " " + sentence).appendTo(this.$status);
57+
3058
if (data.accumulated_render_time_str) {
31-
this.$status.append($('<span title="Accumulated render time" />').addClass(csscls('render_time')).text(data.accumulated_render_time_str));
59+
this.$status.append($('<span title="Accumulated render time" />').addClass(csscls('render-time')).text(data.accumulated_render_time_str));
60+
}
61+
if (data.memory_usage_str) {
62+
this.$status.append($('<span title="Memory usage" />').addClass(csscls('memory')).text(data.memory_usage_str));
3263
}
3364
});
3465
}
3566

3667
});
3768

38-
})(PhpDebugBar.$);
69+
})(PhpDebugBar.$);

0 commit comments

Comments
 (0)