Skip to content

Commit 0676773

Browse files
authored
Merge pull request #851 from LordSimal/routes-panel-plugin-filter
add ability to filter plugin routes in routes tab
2 parents 578d362 + e5b3c27 commit 0676773

2 files changed

Lines changed: 87 additions & 16 deletions

File tree

templates/element/routes_panel.php

Lines changed: 72 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,44 @@
33
* @var \Cake\Routing\Route\Route[] $routes
44
* @var string $matchedRoute
55
*/
6+
7+
use Cake\Core\Plugin as CorePlugin;
68
use Cake\Utility\Hash;
9+
use Cake\Utility\Text;
710

811
$routes = Cake\Routing\Router::routes();
12+
13+
$amountOfRoutesPerGroup = [];
14+
foreach ($routes as $route) {
15+
$group = $route->defaults['plugin'] ?? 'app';
16+
if (!array_key_exists($group, $amountOfRoutesPerGroup)) {
17+
$amountOfRoutesPerGroup[$group] = 0;
18+
}
19+
$amountOfRoutesPerGroup[$group]++;
20+
}
21+
22+
$pluginNames = [];
23+
foreach (CorePlugin::loaded() as $pluginName) {
24+
if (!empty($amountOfRoutesPerGroup[$pluginName])) {
25+
$name = sprintf('%s (%s)', $pluginName, $amountOfRoutesPerGroup[$pluginName]);
26+
$pluginNames[$name] = Text::slug($pluginName);
27+
}
28+
}
29+
930
?>
10-
<button type="button" class="btn-primary" id="toggle-debugkit-routes">
11-
<?= __d('debug_kit', 'Toggle debugkit internal routes') ?>
12-
</button>
31+
<div class="debugkit-plugin-routes-button-wrapper">
32+
<button type="button" class="btn-primary js-debugkit-toggle-plugin-route" data-plugin=".route-entry--app">
33+
<?= __d('debug_kit', 'App') ?>
34+
<?= !empty($amountOfRoutesPerGroup['app']) ? ' (' . $amountOfRoutesPerGroup['app'] . ')' : '' ?>
35+
</button>
36+
<?php foreach ($pluginNames as $pluginName => $parsedName) : ?>
37+
<button type="button" class="btn-primary js-debugkit-toggle-plugin-route
38+
<?= strpos($pluginName, 'DebugKit') === 0 ? ' toggle-plugin-route-active' : '' ?>"
39+
data-plugin=".route-entry--plugin-<?= $parsedName ?>">
40+
<?= $pluginName ?>
41+
</button>
42+
<?php endforeach; ?>
43+
</div>
1344
<table cellspacing="0" cellpadding="0" class="debug-table">
1445
<thead>
1546
<tr>
@@ -19,14 +50,26 @@
1950
</tr>
2051
</thead>
2152
<tbody>
22-
<?php foreach ($routes as $route): ?>
23-
<?php
53+
<?php foreach ($routes as $route) : ?>
54+
<?php
2455
$class = '';
25-
if ($matchedRoute === $route->template):
26-
$class = 'highlighted';
27-
elseif ($route->defaults['plugin'] === 'DebugKit'):
28-
$class = 'debugkit-route hidden';
56+
if (empty($route->defaults['plugin'])) :
57+
$class = 'route-entry route-entry--app';
58+
else :
59+
$class = 'route-entry route-entry--plugin route-entry--plugin-' .
60+
Text::slug($route->defaults['plugin']);
61+
62+
// Hide DebugKit internal routes by default
63+
if ($route->defaults['plugin'] === 'DebugKit') {
64+
$class .= ' hidden';
65+
}
2966
endif;
67+
68+
// Highlight current route
69+
if ($matchedRoute === $route->template) {
70+
$class .= ' highlighted';
71+
}
72+
3073
?>
3174
<tr class="<?= $class ?>">
3275
<td><?= h(Hash::get($route->options, '_name', $route->getName())) ?></td>
@@ -38,11 +81,25 @@
3881
</table>
3982

4083
<script>
41-
$(document).ready(function() {
42-
$('#toggle-debugkit-routes').on('click', function (event) {
43-
event.preventDefault();
44-
var routes = $('.debugkit-route');
45-
routes.toggleClass('hidden');
84+
$(document).ready(function() {
85+
$('#toggle-debugkit-routes').on('click', function (event) {
86+
event.preventDefault();
87+
var routes = $('.debugkit-route');
88+
routes.toggleClass('hidden');
89+
});
90+
91+
$('.js-debugkit-toggle-plugin-route').on('click', function (event) {
92+
var $this = $(this);
93+
var plugin = $this.attr('data-plugin');
94+
95+
if($this.hasClass('toggle-plugin-route-active')) {
96+
$this.removeClass('toggle-plugin-route-active');
97+
$('.route-entry' + plugin).removeClass('hidden');
98+
} else {
99+
$this.addClass('toggle-plugin-route-active');
100+
$('.route-entry' + plugin).addClass('hidden');
101+
}
102+
103+
});
46104
});
47-
});
48105
</script>

webroot/css/toolbar.css

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,13 @@ pre,
512512
position: relative;
513513
top: 2px;
514514
}
515-
516515
.btn-primary:hover {
517516
cursor:pointer;
518517
}
518+
.toggle-plugin-route-active {
519+
background-color: #fff;
520+
color: #2a6496;
521+
}
519522

520523
#loader {
521524
background: rgba(255, 255, 255, 0.7);
@@ -613,3 +616,14 @@ pre,
613616
.terminal .success-message {
614617
color: #42bd41;
615618
}
619+
620+
.debugkit-plugin-routes-button-wrapper {
621+
display: flex;
622+
flex-wrap: wrap;
623+
justify-content: center;
624+
margin: 0 -5px;
625+
}
626+
627+
.debugkit-plugin-routes-button-wrapper button {
628+
margin: 5px;
629+
}

0 commit comments

Comments
 (0)