Skip to content

Commit

Permalink
[WebProfiler] Add copy button on runnable queries
Browse files Browse the repository at this point in the history
  • Loading branch information
fancyweb committed Nov 18, 2019
1 parent f91e0c3 commit 36015ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Resources/views/Collector/clipboard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions Resources/views/Collector/db.html.twig
Expand Up @@ -144,6 +144,12 @@
.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-formatted, .sql-runnable { background: var(--base-1, #f5f5f5); margin: .5em 0; padding: 1em; }
.sql-explain { overflow-x: auto; max-width: 920px; }
.sql-explain table td, .sql-explain table tr { word-break: normal;}
.queries-table pre { margin: 0; white-space: pre-wrap; -ms-word-break: break-all; word-break: break-all; word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; }
.sql-runnable.sf-toggle-content.sf-toggle-visible { display: flex; flex-direction: column; }
.sql-runnable button { align-self: end; }
</style>

{% if profiler_markup_version > 1 %}
Expand Down Expand Up @@ -262,13 +268,15 @@
{% endif %}
</div>

<div id="formatted-query-{{ i }}-{{ loop.parent.loop.index }}" class="sql-runnable hidden">
<div id="formatted-query-{{ i }}-{{ loop.parent.loop.index }}" class="sql-formatted hidden">
{{ query.sql|doctrine_pretty_query }}
</div>

{% if query.runnable %}
<div id="original-query-{{ i }}-{{ loop.parent.loop.index }}" class="sql-runnable hidden">
{{ (query.sql ~ ';')|doctrine_replace_query_parameters(query.params)|doctrine_pretty_query(highlight_only = true) }}
{% set runnable_sql = (query.sql ~ ';')|doctrine_replace_query_parameters(query.params) %}
{{ runnable_sql|doctrine_pretty_query(highlight_only = true) }}
<button class="btn btn-sm" data-clipboard-text="{{ runnable_sql|e('html_attr') }}">Copy</button>
</div>
{% endif %}

Expand Down Expand Up @@ -506,6 +514,12 @@
{% endif %}
//]]></script>
{% if collector.queries|length %}
<script type="text/javascript">
{% include '@Doctrine/Collector/clipboard.min.js' %}
new ClipboardJS('.sql-runnable button');
</script>
{% endif %}
{% endblock %}

{% macro render_simple_table(label1, label2, data) %}
Expand Down

0 comments on commit 36015ff

Please sign in to comment.