-
-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a "run query" option in the profiler #1826
base: 2.13.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,13 @@ | |
connectionName: request.query.get('connection'), | ||
query: request.query.get('query') | ||
})) }} | ||
{% elseif 'run' == page %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like that most of the lines are duplicated now. Something like this could be done instead: {% if page in ['explain', 'page'] %}
{{ render(controller('Doctrine\\Bundle\\DoctrineBundle\\Controller\\ProfilerController::' ~ page ~ 'Action', {
token: token,
panel: 'db',
connectionName: request.query.get('connection'),
query: request.query.get('query')
})) }} |
||
{{ render(controller('Doctrine\\Bundle\\DoctrineBundle\\Controller\\ProfilerController::runAction', { | ||
token: token, | ||
panel: 'db', | ||
connectionName: request.query.get('connection'), | ||
query: request.query.get('query') | ||
})) }} | ||
{% else %} | ||
{{ block('queries') }} | ||
{% endif %} | ||
|
@@ -100,8 +107,8 @@ | |
.time-container { position: relative; } | ||
.time-container .nowrap { position: relative; z-index: 1; text-shadow: 0 0 2px #fff; } | ||
.time-bar { display: block; position: absolute; top: 0; left: 0; bottom: 0; background: #e0e0e0; } | ||
.sql-runnable.sf-toggle-content.sf-toggle-visible { display: flex; flex-direction: column; } | ||
.sql-runnable button { align-self: end; } | ||
.sql-runnable.sf-toggle-content.sf-toggle-visible { display: flex; flex-direction: row; align-items: center} | ||
.sql-runnable pre { flex-grow: 1} | ||
Comment on lines
-104
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of this design change. Let's have buttons next to each other, instead on top of each other |
||
{% if profiler_markup_version >= 3 %} | ||
.highlight .keyword { color: var(--highlight-keyword); font-weight: bold; } | ||
.highlight .word { color: var(--color-text); } | ||
|
@@ -252,17 +259,22 @@ | |
</div> | ||
|
||
{% if query.runnable %} | ||
<div id="original-query-{{ i }}-{{ loop.parent.loop.index }}" class="sql-runnable hidden"> | ||
<div id="original-query-{{ i }}-{{ loop.parent.loop.index }}" class="sql-runnable"> | ||
{% set runnable_sql = (query.sql ~ ';')|doctrine_replace_query_parameters(query.params) %} | ||
{{ runnable_sql|doctrine_prettify_sql }} | ||
<button class="btn btn-sm hidden" data-clipboard-text="{{ runnable_sql|e('html_attr') }}">Copy</button> | ||
<div> | ||
<button class="btn btn-sm hidden" data-clipboard-text="{{ runnable_sql|e('html_attr') }}">Copy</button> | ||
<a class="btn btn-sm" href="{{ path('_profiler', { panel: 'db', token: token, page: 'run', connection: connection, query: i }) }}" onclick="return run(this);" data-target-id="run-{{ i }}-{{ loop.parent.loop.index }}">Run</a> | ||
</div> | ||
</div> | ||
{% endif %} | ||
|
||
{% if query.explainable %} | ||
<div id="explain-{{ i }}-{{ loop.parent.loop.index }}" class="sql-explain"></div> | ||
{% endif %} | ||
|
||
<div id="run-{{ i }}-{{ loop.parent.loop.index }}" class="sql-explain"></div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't this be wrapped in |
||
|
||
{% if query.backtrace is defined %} | ||
<div id="backtrace-{{ i }}-{{ loop.parent.loop.index }}" class="hidden"> | ||
<table> | ||
|
@@ -468,6 +480,34 @@ | |
return false; | ||
} | ||
|
||
function run(link) { | ||
"use strict"; | ||
|
||
var targetId = link.getAttribute('data-target-id'); | ||
var targetElement = document.getElementById(targetId); | ||
|
||
if (targetElement.style.display != 'block') { | ||
if (targetElement.getAttribute('data-sfurl') !== link.href) { | ||
fetch(link.href, { | ||
headers: {'X-Requested-With': 'XMLHttpRequest'} | ||
}).then(async function (response) { | ||
targetElement.innerHTML = await response.text() | ||
targetElement.setAttribute('data-sfurl', link.href) | ||
}, function () { | ||
targetElement.innerHTML = 'An error occurred while loading the query explanation.'; | ||
}) | ||
} | ||
|
||
targetElement.style.display = 'block'; | ||
link.innerHTML = 'Hide query result'; | ||
} else { | ||
targetElement.style.display = 'none'; | ||
link.innerHTML = 'Run query'; | ||
} | ||
|
||
return false; | ||
} | ||
Comment on lines
+483
to
+509
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please parametrize the function that was copied instead of copying whole thing and just changing few lines |
||
|
||
function sortTable(header, column, targetId) { | ||
"use strict"; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{% if result is not empty %} | ||
<table> | ||
<thead> | ||
<tr> | ||
{% for key, value in result[0] %} | ||
<th>{{ key }}</th> | ||
{% endfor %} | ||
</tr> | ||
|
||
</thead> | ||
<tbody> | ||
{% for row in result %} | ||
<tr> | ||
{% for key, value in row %} | ||
<td>{{ value }}</td> | ||
{% endfor %} | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% else %} | ||
Result is empty | ||
{% endif %} | ||
Comment on lines
+1
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was also copied (explain.html.twig), please modularize through block/embed it if you believe some stuff have to be different |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is old school PHP 5 style code, we don't use it for new stuff