diff --git a/config/routes.php b/config/routes.php index bd5052c90..624414af3 100644 --- a/config/routes.php +++ b/config/routes.php @@ -15,6 +15,10 @@ '/toolbar/*', ['controller' => 'Requests', 'action' => 'view'] ); + $routes->connect( + '/panels/view/latest-history', + ['controller' => 'Panels', 'action' => 'latestHistory'] + ); $routes->connect( '/panels/view/*', ['controller' => 'Panels', 'action' => 'view'] diff --git a/src/Controller/PanelsController.php b/src/Controller/PanelsController.php index 536bb1091..0f5a0f1a8 100644 --- a/src/Controller/PanelsController.php +++ b/src/Controller/PanelsController.php @@ -83,11 +83,40 @@ public function index($requestId = null) public function view($id = null) { $this->set('sort', $this->request->getCookie('debugKit_sort')); - $panel = $this->Panels->get($id); + $panel = $this->Panels->get($id, ['contain' => ['Requests']]); $this->set('panel', $panel); // @codingStandardsIgnoreStart $this->set(@unserialize($panel->content)); // @codingStandardsIgnoreEnd } + + /** + * Get Latest request history panel + * + * @return \Cake\Http\Response|null + */ + public function latestHistory() + { + /** @var array{id:string}|null $request */ + $request = $this->Panels->Requests->find('recent') + ->select(['id']) + ->disableHydration() + ->first(); + if (!$request) { + throw new NotFoundException('No requests found'); + } + /** @var array{id:string}|null $historyPanel */ + $historyPanel = $this->Panels->find('byRequest', ['requestId' => $request['id']]) + ->where(['title' => 'History']) + ->select(['id']) + ->first(); + if (!$historyPanel) { + throw new NotFoundException('History Panel from latest request not found'); + } + + return $this->redirect([ + 'action' => 'view', $historyPanel['id'], + ]); + } } diff --git a/src/Model/Entity/Panel.php b/src/Model/Entity/Panel.php index 6ed488189..f862fd959 100644 --- a/src/Model/Entity/Panel.php +++ b/src/Model/Entity/Panel.php @@ -23,6 +23,8 @@ * @property string $title * @property string $element * @property string $content + * + * @property \DebugKit\Model\Entity\Request $request */ class Panel extends Entity { diff --git a/src/Model/Table/PanelsTable.php b/src/Model/Table/PanelsTable.php index 60d6777e3..f70b773fc 100644 --- a/src/Model/Table/PanelsTable.php +++ b/src/Model/Table/PanelsTable.php @@ -21,6 +21,7 @@ * The panels table collects the information for each panel on * each request. * + * @property \DebugKit\Model\Table\RequestsTable&\Cake\ORM\Association\BelongsTo $Requests * @method \DebugKit\Model\Entity\Panel get($primaryKey, $options = []) * @method \DebugKit\Model\Entity\Panel newEntity($data = null, array $options = []) * @method \DebugKit\Model\Entity\Panel[] newEntities(array $data, array $options = []) diff --git a/src/ToolbarService.php b/src/ToolbarService.php index 301652ec9..668507355 100644 --- a/src/ToolbarService.php +++ b/src/ToolbarService.php @@ -230,19 +230,23 @@ public function initializePanels() */ public function saveData(ServerRequest $request, ResponseInterface $response) { - $ignorePathsPattern = $this->getConfig('ignorePathsPattern'); $path = $request->getUri()->getPath(); - $statusCode = $response->getStatusCode(); + $dashboardUrl = '/debug-kit'; + if (strpos($path, 'debug_kit') !== false || strpos($path, 'debug-kit') !== false) { + if (!($path === $dashboardUrl || $path === $dashboardUrl . '/')) { + // internal debug-kit request + return false; + } + // debug-kit dashboard, save request and show toolbar + } + $ignorePathsPattern = $this->getConfig('ignorePathsPattern'); + $statusCode = $response->getStatusCode(); if ( - strpos($path, 'debug_kit') !== false || - strpos($path, 'debug-kit') !== false || - ( - $ignorePathsPattern && - $statusCode >= 200 && - $statusCode <= 299 && - preg_match($ignorePathsPattern, $path) - ) + $ignorePathsPattern && + $statusCode >= 200 && + $statusCode <= 299 && + preg_match($ignorePathsPattern, $path) ) { return false; } diff --git a/templates/element/history_panel.php b/templates/element/history_panel.php index cf2f65759..1ace07940 100644 --- a/templates/element/history_panel.php +++ b/templates/element/history_panel.php @@ -11,7 +11,6 @@ * @since DebugKit 1.1 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ - /** * @var \DebugKit\View\AjaxView $this * @var \DebugKit\Model\Entity\Panel $panel @@ -20,16 +19,25 @@ ?>
-

+

+ + +

-

+

+ + +

diff --git a/tests/TestCase/Controller/PanelsControllerTest.php b/tests/TestCase/Controller/PanelsControllerTest.php index ed7bb695b..b5369e5bb 100644 --- a/tests/TestCase/Controller/PanelsControllerTest.php +++ b/tests/TestCase/Controller/PanelsControllerTest.php @@ -95,4 +95,21 @@ public function testViewNotExists() $this->assertResponseError(); $this->assertResponseContains('Error page'); } + + /** + * @return void + */ + public function testLatestHistory() + { + $request = $this->getTableLocator()->get('DebugKit.Requests')->find('recent')->first(); + if (!$request) { + $request = $this->makeRequest(); + } + $panel = $this->makePanel($request, 'DebugKit.History', 'History'); + + $this->get('/debug-kit/panels/view/latest-history'); + $this->assertRedirect([ + 'action' => 'view', $panel->id, + ]); + } } diff --git a/tests/TestCase/ToolbarServiceTest.php b/tests/TestCase/ToolbarServiceTest.php index ea3d56dde..55b12562b 100644 --- a/tests/TestCase/ToolbarServiceTest.php +++ b/tests/TestCase/ToolbarServiceTest.php @@ -162,6 +162,19 @@ public function testSaveDataIgnoreDebugKitDashedUrl() $bar = new ToolbarService($this->events, []); $this->assertFalse($bar->saveData($request, $response)); + + $request = new Request([ + 'url' => '/debug-kit', + 'params' => [], + ]); + $response = new Response([ + 'statusCode' => 200, + 'type' => 'text/html', + 'body' => 'test

some text

', + ]); + + $bar = new ToolbarService($this->events, []); + $this->assertNotEmpty($bar->saveData($request, $response)); } /**