|
3 | 3 | * @var \Cake\Routing\Route\Route[] $routes |
4 | 4 | * @var string $matchedRoute |
5 | 5 | */ |
| 6 | + |
| 7 | +use Cake\Core\Plugin as CorePlugin; |
6 | 8 | use Cake\Utility\Hash; |
| 9 | +use Cake\Utility\Text; |
7 | 10 |
|
8 | 11 | $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 | + |
9 | 30 | ?> |
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> |
13 | 44 | <table cellspacing="0" cellpadding="0" class="debug-table"> |
14 | 45 | <thead> |
15 | 46 | <tr> |
|
19 | 50 | </tr> |
20 | 51 | </thead> |
21 | 52 | <tbody> |
22 | | - <?php foreach ($routes as $route): ?> |
23 | | - <?php |
| 53 | + <?php foreach ($routes as $route) : ?> |
| 54 | + <?php |
24 | 55 | $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 | + } |
29 | 66 | endif; |
| 67 | + |
| 68 | + // Highlight current route |
| 69 | + if ($matchedRoute === $route->template) { |
| 70 | + $class .= ' highlighted'; |
| 71 | + } |
| 72 | + |
30 | 73 | ?> |
31 | 74 | <tr class="<?= $class ?>"> |
32 | 75 | <td><?= h(Hash::get($route->options, '_name', $route->getName())) ?></td> |
|
38 | 81 | </table> |
39 | 82 |
|
40 | 83 | <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 | + }); |
46 | 104 | }); |
47 | | -}); |
48 | 105 | </script> |
0 commit comments