Skip to content

Commit a1a5140

Browse files
committed
ConnectionPanel: convert templates to Latte-like syntax
1 parent a5f2872 commit a1a5140

File tree

8 files changed

+196
-113
lines changed

8 files changed

+196
-113
lines changed

src/Bridges/DatabaseTracy/ConnectionPanel.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,13 @@
2121
class ConnectionPanel implements Tracy\IBarPanel
2222
{
2323
public int $maxQueries = 100;
24-
2524
public string $name;
26-
2725
public bool|string $explain = true;
28-
2926
public bool $disabled = false;
30-
3127
public float $performanceScale = 0.25;
32-
3328
private float $totalTime = 0;
34-
3529
private int $count = 0;
36-
3730
private array $queries = [];
38-
3931
private Tracy\BlueScreen $blueScreen;
4032

4133

@@ -132,7 +124,7 @@ public function getTab(): string
132124
$name = $this->name;
133125
$count = $this->count;
134126
$totalTime = $this->totalTime;
135-
require __DIR__ . '/templates/ConnectionPanel.tab.phtml';
127+
require __DIR__ . '/dist/tab.phtml';
136128
});
137129
}
138130

@@ -170,7 +162,7 @@ public function getPanel(): ?string
170162
$count = $this->count;
171163
$totalTime = $this->totalTime;
172164
$performanceScale = $this->performanceScale;
173-
require __DIR__ . '/templates/ConnectionPanel.panel.phtml';
165+
require __DIR__ . '/dist/panel.phtml';
174166
});
175167
}
176168
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
declare(strict_types=1);
3+
?>
4+
<style class="tracy-debug">
5+
#tracy-debug td.nette-DbConnectionPanel-sql { background: white !important }
6+
#tracy-debug .nette-DbConnectionPanel-source { color: #BBB !important }
7+
#tracy-debug .nette-DbConnectionPanel-explain td { white-space: pre }
8+
#tracy-debug td.nette-DbConnectionPanel-sql-insert { background: #E7ffE7 !important }
9+
#tracy-debug td.nette-DbConnectionPanel-sql-delete { background: #FFE7E7 !important }
10+
#tracy-debug td.nette-DbConnectionPanel-sql-update { background: #E7FBFF !important }
11+
</style>
12+
13+
<h1 title="<?= Tracy\Helpers::escapeHtml($connection->getDsn()) ?>">Queries: <?= Tracy\Helpers::escapeHtml($count) ?><?= Tracy\Helpers::escapeHtml($totalTime ? sprintf(', time: %0.3f ms', $totalTime * 1000) : '') ?>, <?= Tracy\Helpers::escapeHtml($name) ?></h1>
14+
15+
<div class="tracy-inner">
16+
<div class="tracy-inner-container">
17+
<table class="tracy-sortable">
18+
<tr>
19+
<th>Time&nbsp;ms</th>
20+
<th>SQL Query</th>
21+
<th>Rows</th>
22+
</tr>
23+
24+
<?php foreach ($queries as [$connection, $sql, $params, $source, $time, $rows, $error, $command, $explain]): ?>
25+
<tr>
26+
<td style="background:rgba(255, 95, 23, <?= Tracy\Helpers::escapeHtml(sprintf('%0.3f', log($time * 1000 + 1, 10) * $performanceScale)) ?>)" data-order="<?= Tracy\Helpers::escapeHtml((float) $time) ?>">
27+
<?php if ($error): ?>
28+
<span title="<?= Tracy\Helpers::escapeHtml($error) ?>">ERROR</span>
29+
<?php elseif ($time !== null): ?> <?= Tracy\Helpers::escapeHtml(sprintf('%0.3f', $time * 1000)) ?>
30+
31+
<?php endif ?>
32+
33+
<?php if ($explain): ?> <br/><a class="tracy-toggle tracy-collapsed" data-tracy-ref="^tr .nette-DbConnectionPanel-explain">explain</a><?php endif ?>
34+
35+
</td>
36+
37+
<td class="nette-DbConnectionPanel-sql nette-DbConnectionPanel-sql-<?= Tracy\Helpers::escapeHtml($command) ?>">
38+
<?= Nette\Database\Helpers::dumpSql($sql, $params, $connection) ?>
39+
40+
41+
<?php if ($explain): ?>
42+
<table class="tracy-collapsed nette-DbConnectionPanel-explain">
43+
<tr>
44+
<?php foreach ($explain[0] as $col => $foo): ?>
45+
<th><?= Tracy\Helpers::escapeHtml($col) ?></th>
46+
<?php endforeach ?>
47+
</tr>
48+
<?php foreach ($explain as $row): ?>
49+
<tr>
50+
<?php foreach ($row as $col): ?>
51+
<td><?= Tracy\Helpers::escapeHtml($col) ?></td>
52+
<?php endforeach ?>
53+
</tr>
54+
<?php endforeach ?>
55+
</table>
56+
<?php endif ?>
57+
58+
<?php if ($source): ?> <?= substr_replace(Tracy\Helpers::editorLink($source[0], $source[1]), ' class="nette-DbConnectionPanel-source"', 2, 0) ?><?php endif ?>
59+
60+
</td>
61+
62+
<td><?= Tracy\Helpers::escapeHtml($rows) ?></td>
63+
</tr>
64+
<?php endforeach ?>
65+
</table>
66+
67+
<?php if (count($queries) < $count): ?> <p>...and more</p><?php endif ?>
68+
69+
</div>
70+
</div>

src/Bridges/DatabaseTracy/templates/ConnectionPanel.tab.phtml renamed to src/Bridges/DatabaseTracy/dist/tab.phtml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<?php
22
declare(strict_types=1);
3-
4-
namespace Nette\Bridges\DatabaseTracy;
5-
6-
use Tracy\Helpers;
7-
83
?>
9-
<span title="Nette\Database <?= Helpers::escapeHtml($name) ?>">
10-
<svg viewBox="0 0 2048 2048"><path fill="<?= $count ? '#b079d6' : '#aaa' ?>" d="M1024 896q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0 768q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-384q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-1152q208 0 385 34.5t280 93.5 103 128v128q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-128q0-69 103-128t280-93.5 385-34.5z"/>
11-
</svg><span class="tracy-label"><?= ($totalTime ? sprintf('%0.1f ms / ', $totalTime * 1000) : '') . $count ?></span>
4+
<span title="Nette\Database <?= Tracy\Helpers::escapeHtml($name) ?>">
5+
<svg viewBox="0 0 2048 2048">
6+
<path fill="<?= Tracy\Helpers::escapeHtml($count ? '#b079d6' : '#aaa') ?>" d="M1024 896q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0 768q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-384q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-1152q208 0 385 34.5t280 93.5 103 128v128q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-128q0-69 103-128t280-93.5 385-34.5z"/>
7+
</svg
8+
><span class="tracy-label"><?= Tracy\Helpers::escapeHtml($totalTime ? sprintf('%0.1f ms / ', $totalTime * 1000) : '') ?><?= Tracy\Helpers::escapeHtml($count) ?></span>
129
</span>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<style class="tracy-debug">
2+
#tracy-debug td.nette-DbConnectionPanel-sql { background: white !important }
3+
#tracy-debug .nette-DbConnectionPanel-source { color: #BBB !important }
4+
#tracy-debug .nette-DbConnectionPanel-explain td { white-space: pre }
5+
#tracy-debug td.nette-DbConnectionPanel-sql-insert { background: #E7ffE7 !important }
6+
#tracy-debug td.nette-DbConnectionPanel-sql-delete { background: #FFE7E7 !important }
7+
#tracy-debug td.nette-DbConnectionPanel-sql-update { background: #E7FBFF !important }
8+
</style>
9+
10+
<h1 title="{$connection->getDsn()}">Queries: {$count}{$totalTime ? sprintf(', time: %0.3f ms', $totalTime * 1000) : ''}, {$name}</h1>
11+
12+
<div class="tracy-inner">
13+
<div class="tracy-inner-container">
14+
<table class="tracy-sortable">
15+
<tr>
16+
<th>Time&nbsp;ms</th>
17+
<th>SQL Query</th>
18+
<th>Rows</th>
19+
</tr>
20+
21+
{foreach $queries as [$connection, $sql, $params, $source, $time, $rows, $error, $command, $explain]}
22+
<tr>
23+
<td style="background:rgba(255, 95, 23, {sprintf('%0.3f', log($time * 1000 + 1, 10) * $performanceScale)})" data-order="{=(float) $time}">
24+
{if $error}
25+
<span title="{$error}">ERROR</span>
26+
{elseif $time !== null}{sprintf('%0.3f', $time * 1000)}
27+
{/if}
28+
29+
{if $explain}<br/><a class="tracy-toggle tracy-collapsed" data-tracy-ref="^tr .nette-DbConnectionPanel-explain">explain</a>{/if}
30+
</td>
31+
32+
<td class="nette-DbConnectionPanel-sql nette-DbConnectionPanel-sql-{$command}">
33+
{Nette\Database\Helpers::dumpSql($sql, $params, $connection)|noescape}
34+
35+
{if $explain}
36+
<table class="tracy-collapsed nette-DbConnectionPanel-explain">
37+
<tr>
38+
{foreach $explain[0] as $col => $foo}
39+
<th>{$col}</th>
40+
{/foreach}
41+
</tr>
42+
{foreach $explain as $row}
43+
<tr>
44+
{foreach $row as $col}
45+
<td>{$col}</td>
46+
{/foreach}
47+
</tr>
48+
{/foreach}
49+
</table>
50+
{/if}
51+
52+
{if $source}{substr_replace(Tracy\Helpers::editorLink($source[0], $source[1]), ' class="nette-DbConnectionPanel-source"', 2, 0)}{/if}
53+
</td>
54+
55+
<td>{$rows}</td>
56+
</tr>
57+
{/foreach}
58+
</table>
59+
60+
{if count($queries) < $count}<p>...and more</p>{/if}
61+
</div>
62+
</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<span title="Nette\Database {$name}">
2+
<svg viewBox="0 0 2048 2048">
3+
<path fill="{$count ? '#b079d6' : '#aaa'}" d="M1024 896q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0 768q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-384q237 0 443-43t325-127v170q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-170q119 84 325 127t443 43zm0-1152q208 0 385 34.5t280 93.5 103 128v128q0 69-103 128t-280 93.5-385 34.5-385-34.5-280-93.5-103-128v-128q0-69 103-128t280-93.5 385-34.5z"/>
4+
</svg
5+
><span class="tracy-label">{$totalTime ? sprintf('%0.1f ms / ', $totalTime * 1000) : ''}{$count}</span>
6+
</span>

src/Bridges/DatabaseTracy/templates/ConnectionPanel.panel.phtml

Lines changed: 0 additions & 66 deletions
This file was deleted.

tests/Database.Tracy/panel.html

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,54 @@ <h1 title="sqlite::memory:">Queries: 4, time: %a% ms, foo</h1>
55
<div class="tracy-inner-container">
66
<table class="tracy-sortable">
77
%A%
8-
<td %a%>%A%</td>
9-
<td class="nette-DbConnectionPanel-sql nette-DbConnectionPanel-sql-"><pre class="dump">::beginTransaction</pre>
10-
<a class="nette-DbConnectionPanel-source" href="%a%" title="%a%Connection.php:%d%" class="tracy-editor">%a%<b>Connection.php</b>:%d%</a> </td>
11-
<td></td>
12-
</tr>
13-
<tr>
14-
<td %a%>%A%</td>
15-
<td class="nette-DbConnectionPanel-sql nette-DbConnectionPanel-sql-select"><pre class="dump"><strong style="color:blue">SELECT</strong> 1</pre>
16-
<table class="tracy-collapsed nette-DbConnectionPanel-explain">%A%</table>
17-
<a class="nette-DbConnectionPanel-source" href="%a%" title="%a%Connection.php:%d%" class="tracy-editor">%a%<b>Connection.php</b>:%d%</a> </td>
18-
<td>0</td>
19-
</tr>
20-
<tr>
21-
<td %a%>%A%</td>
22-
<td class="nette-DbConnectionPanel-sql nette-DbConnectionPanel-sql-"><pre class="dump">::commit</pre>
23-
<a class="nette-DbConnectionPanel-source" href="%a%" title="%a%Connection.php:%d%" class="tracy-editor">%a%<b>Connection.php</b>:%d%</a> </td>
24-
<td></td>
25-
</tr>
26-
<tr>
27-
<td %a%>
28-
<span title="SQLSTATE[HY000]: %a%">ERROR</span>
29-
</td>
30-
<td class="nette-DbConnectionPanel-sql nette-DbConnectionPanel-sql-"><pre class="dump"><strong style="color:blue">SELECT</strong></pre>
31-
<a class="nette-DbConnectionPanel-source" href="%a%" title="%a%SqliteDriver.php:%d%" class="tracy-editor">%a%<b>SqliteDriver.php</b>:%d%</a> </td>
32-
<td></td>
33-
</tr>
34-
</table>
35-
</div>
8+
<td %a%>%A%</td>
9+
10+
<td class="nette-DbConnectionPanel-sql nette-DbConnectionPanel-sql-">
11+
<pre class="dump">::beginTransaction</pre>
12+
13+
<a class="nette-DbConnectionPanel-source" href="%a%" title="%a%Connection.php:%d%" class="tracy-editor">%a%<b>Connection.php</b>:%d%</a>
14+
</td>
15+
16+
<td></td>
17+
</tr>
18+
<tr>
19+
<td %a%>%A%</td>
20+
21+
<td class="nette-DbConnectionPanel-sql nette-DbConnectionPanel-sql-select">
22+
<pre class="dump"><strong style="color:blue">SELECT</strong> 1</pre>
23+
24+
<table class="tracy-collapsed nette-DbConnectionPanel-explain">%A%</table>
25+
<a class="nette-DbConnectionPanel-source" href="%a%" title="%a%Connection.php:%d%" class="tracy-editor">%a%<b>Connection.php</b>:%d%</a>
26+
</td>
27+
28+
<td>0</td>
29+
</tr>
30+
<tr>
31+
<td %a%>%A%</td>
32+
33+
<td class="nette-DbConnectionPanel-sql nette-DbConnectionPanel-sql-">
34+
<pre class="dump">::commit</pre>
35+
36+
<a class="nette-DbConnectionPanel-source" href="%a%" title="%a%Connection.php:%d%" class="tracy-editor">%a%<b>Connection.php</b>:%d%</a>
37+
</td>
38+
39+
<td></td>
40+
</tr>
41+
<tr>
42+
<td %a%>
43+
<span title="SQLSTATE[HY000]: General error: 1 incomplete input">ERROR</span>
44+
45+
</td>
46+
47+
<td class="nette-DbConnectionPanel-sql nette-DbConnectionPanel-sql-">
48+
<pre class="dump"><strong style="color:blue">SELECT</strong></pre>
49+
50+
<a class="nette-DbConnectionPanel-source" href="%a%" title="%a%SqliteDriver.php:%d%" class="tracy-editor">%a%<b>SqliteDriver.php</b>:%d%</a>
51+
</td>
52+
53+
<td></td>
54+
</tr>
55+
</table>
56+
57+
</div>
3658
</div>

tests/Database.Tracy/tab.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<span title="Nette\Database foo">
2-
<svg %A%</svg><span class="tracy-label">%a% ms / 4</span>
2+
<svg %A%><span class="tracy-label">%a% ms / 4</span>
33
</span>

0 commit comments

Comments
 (0)