Skip to content

Commit

Permalink
Add collapsible request and response section on profiler. (#277)
Browse files Browse the repository at this point in the history
Closes #222
  • Loading branch information
RageZBla authored and gregurco committed Oct 31, 2019
1 parent 11814ce commit 3ebe480
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions src/Resources/views/profiler.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,14 @@
</tr>
</table>

<div>
<h4>Request</h4>

<table>
<div class="gb_request_request">
<h4>
<a href="javascript: void(0);">
Request
</a>
</h4>

<table class="gb_content">
<tr>
<th>Protocol Version</th>
<td>{{ message.request.protocolVersion }}</td>
Expand Down Expand Up @@ -96,11 +100,15 @@
</table>
</div>

<div>
<h4>Response</h4>
<div class="gb_request_response">
<h4>
<a href="javascript: void(0);">
Response
</a>
</h4>

{% if message.response %}
<table>
<table class="gb_content">
<tr>
<th>Protocol Version</th>
<td>{{ message.response.protocolVersion }}</td>
Expand Down Expand Up @@ -131,18 +139,32 @@
</div>

<script>
// Do requests block collapsable
var requests = document.querySelectorAll('.gb_request h3 a');
requests.forEach(function(request) {
request.onclick = function(el) {
var parent = findParentByClass(el.target, 'gb_request');
var content = parent.querySelector('.gb_content');
if (content) {
content.classList.toggle('gb_content--hide');
}
// Function to collapse elements
var collapseFn = function(el, parentClass) {
var parent = findParentByClass(el.target, parentClass);
var content = parent.querySelector('.gb_content');
if (content) {
content.classList.toggle('gb_content--hide');
}
});
};
var collapsibleElements = {
'gb_request': '.gb_request h3 a',
'gb_request_request': '.gb_request_request h4 a',
'gb_request_response': '.gb_request_response h4 a'
};
for (var parentClass in collapsibleElements) {
var elements = document.querySelectorAll(collapsibleElements[parentClass]);
elements.forEach(function(element) {
element.onclick = (function(parent) {
return function(el) {
collapseFn(el, parent);
};
}(parentClass))
});
}
function findParentByClass(el, cls) {
while ((el = el.parentNode) && el.classList.contains(cls) === false) {}
Expand Down

0 comments on commit 3ebe480

Please sign in to comment.