Skip to content

Commit 5c35113

Browse files
committed
Merge pull request #421 from cakephp/panel-issue
Fix history loading and sorting issues
2 parents 6775f56 + f8ee409 commit 5c35113

File tree

6 files changed

+124
-14
lines changed

6 files changed

+124
-14
lines changed

src/Controller/PanelsController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ public function beforeFilter(Event $event)
5353
*/
5454
public function beforeRender(Event $event)
5555
{
56-
$this->viewBuilder()
57-
->layout('DebugKit.panel')
58-
->className('DebugKit.Ajax');
56+
$builder = $this->viewBuilder();
57+
if (!$builder->className()) {
58+
$builder->layout('DebugKit.panel')
59+
->className('DebugKit.Ajax');
60+
}
5961
}
6062

6163
/**

src/Template/Requests/view.ctp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ use Cake\Core\Configure;
3131
</ul>
3232
<?php $this->Html->script('DebugKit.debug_kit', [
3333
'block' => true,
34-
'id' => '__debug_kit',
34+
'id' => '__debug_kit_app',
3535
'data-id' => $toolbar->id,
36-
'data-url' => json_encode($this->Url->build('/')),
37-
'data-full-url' => Router::url('/', true)
36+
'data-url' => Router::url('/', true),
37+
'data-webroot' => $this->request->webroot,
3838
]) ?>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
/**
3+
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4+
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5+
*
6+
* Licensed under The MIT License
7+
* Redistributions of files must retain the above copyright notice.
8+
*
9+
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
10+
* @link http://cakephp.org CakePHP(tm) Project
11+
* @since DebugKit 0.1
12+
* @license http://www.opensource.org/licenses/mit-license.php MIT License
13+
*/
14+
namespace DebugKit\Test\TestCase\View\Helper;
15+
16+
use Cake\Core\App;
17+
use Cake\Network\Request;
18+
use Cake\Network\Response;
19+
use Cake\Routing\Router;
20+
use Cake\TestSuite\TestCase;
21+
use Cake\View\View;
22+
use DebugKit\View\Helper\SimpleGraphHelper;
23+
24+
/**
25+
* Class SimpleGraphHelperTestCase
26+
*/
27+
class SimpleGraphHelperTest extends TestCase
28+
{
29+
30+
/**
31+
* Setup
32+
*
33+
* @return void
34+
*/
35+
public function setUp()
36+
{
37+
parent::setUp();
38+
Router::connect('/:controller/:action');
39+
40+
$request = new Request();
41+
$request->addParams(['controller' => 'pages', 'action' => 'display']);
42+
43+
$this->View = new View($request);
44+
$this->Graph = new SimpleGraphHelper($this->View);
45+
}
46+
47+
/**
48+
* Tear Down
49+
*
50+
* @return void
51+
*/
52+
public function tearDown()
53+
{
54+
parent::tearDown();
55+
unset($this->Graph);
56+
}
57+
58+
/**
59+
* Test bar()
60+
*
61+
* @return void
62+
*/
63+
public function testBar()
64+
{
65+
$output = $this->Graph->bar(10, 0);
66+
$expected = [
67+
['div' => [
68+
'class' => 'graph-bar',
69+
'style' => 'width: 350px',
70+
]],
71+
['div' => [
72+
'class' => 'graph-bar-value',
73+
'style' => 'margin-left: 0px; width: 35px',
74+
'title' => 'Starting 0ms into the request, taking 10ms'
75+
]],
76+
' ',
77+
'/div',
78+
'/div'
79+
];
80+
$this->assertHtml($expected, $output);
81+
}
82+
83+
/**
84+
* Test bar() with offset
85+
*
86+
* @return void
87+
*/
88+
public function testBarOffset()
89+
{
90+
$output = $this->Graph->bar(10, 10);
91+
$expected = [
92+
['div' => [
93+
'class' => 'graph-bar',
94+
'style' => 'width: 350px',
95+
]],
96+
['div' => [
97+
'class' => 'graph-bar-value',
98+
'style' => 'margin-left: 35px; width: 35px',
99+
'title' => 'Starting 10ms into the request, taking 10ms'
100+
]],
101+
' ',
102+
'/div',
103+
'/div'
104+
];
105+
$this->assertHtml($expected, $output);
106+
}
107+
}

tests/TestCase/View/Helper/ToolbarHelperTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Cake\View\Helper\FormHelper;
2222
use Cake\View\Helper\HtmlHelper;
2323
use Cake\View\View;
24-
use DebugKit\View\Helper\HtmlToolbarHelper;
2524
use DebugKit\View\Helper\ToolbarHelper;
2625
use StdClass;
2726

webroot/js/debug_kit.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
var baseUrl, toolbar;
22

3-
var elem = document.getElementById("__debug_kit");
3+
var elem = document.getElementById("__debug_kit_app");
44
if (elem) {
55
window.__debug_kit_id = elem.getAttribute("data-id");
66
window.__debug_kit_base_url = elem.getAttribute("data-url");
7-
baseUrl = elem.getAttribute("data-full-url");
7+
window.__debug_kit_webroot = elem.getAttribute("data-webroot");
88
elem = null;
99
}
1010

@@ -17,7 +17,8 @@ $(document).ready(function() {
1717
keyboardScope : $(document),
1818
currentRequest: __debug_kit_id,
1919
originalRequest: __debug_kit_id,
20-
baseUrl: __debug_kit_base_url
20+
baseUrl: __debug_kit_base_url,
21+
webroot: __debug_kit_webroot,
2122
});
2223

2324
toolbar.initialize();

webroot/js/toolbar-app.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function Toolbar(options) {
77
this.currentRequest = options.currentRequest;
88
this.originalRequest = options.originalRequest;
99
this.baseUrl = options.baseUrl;
10+
this.webroot = options.webroot;
1011
}
1112

1213
Toolbar.prototype = {
@@ -102,7 +103,7 @@ Toolbar.prototype = {
102103
},
103104

104105
loadPanel: function(id) {
105-
var url = baseUrl + 'debug_kit/panels/view/' + id;
106+
var url = this.baseUrl + 'debug_kit/panels/view/' + id;
106107
var contentArea = this.content.find('#panel-content');
107108
var _this = this;
108109
var timer;
@@ -134,10 +135,10 @@ Toolbar.prototype = {
134135
var sortButton = this.content.find('.neat-array-sort');
135136
var _this = this;
136137
sortButton.click(function() {
137-
if ($(this).attr('checked')) {
138-
document.cookie = 'debugKit_sort=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=' + _this.baseUrl;
138+
if (!$(this).prop('checked')) {
139+
document.cookie = 'debugKit_sort=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=' + _this.webroot;
139140
} else {
140-
document.cookie = 'debugKit_sort=1; path=' + _this.baseUrl;
141+
document.cookie = 'debugKit_sort=1; path=' + _this.webroot;
141142
}
142143
_this.loadPanel(_this.currentPanel());
143144
});

0 commit comments

Comments
 (0)