Skip to content

Commit

Permalink
Merge pull request #421 from cakephp/panel-issue
Browse files Browse the repository at this point in the history
Fix history loading and sorting issues
  • Loading branch information
lorenzo committed May 28, 2016
2 parents 6775f56 + f8ee409 commit 5c35113
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 14 deletions.
8 changes: 5 additions & 3 deletions src/Controller/PanelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ public function beforeFilter(Event $event)
*/
public function beforeRender(Event $event)
{
$this->viewBuilder()
->layout('DebugKit.panel')
->className('DebugKit.Ajax');
$builder = $this->viewBuilder();
if (!$builder->className()) {
$builder->layout('DebugKit.panel')
->className('DebugKit.Ajax');
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Template/Requests/view.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use Cake\Core\Configure;
</ul>
<?php $this->Html->script('DebugKit.debug_kit', [
'block' => true,
'id' => '__debug_kit',
'id' => '__debug_kit_app',
'data-id' => $toolbar->id,
'data-url' => json_encode($this->Url->build('/')),
'data-full-url' => Router::url('/', true)
'data-url' => Router::url('/', true),
'data-webroot' => $this->request->webroot,
]) ?>
107 changes: 107 additions & 0 deletions tests/TestCase/View/Helper/SimpleGraphHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since DebugKit 0.1
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace DebugKit\Test\TestCase\View\Helper;

use Cake\Core\App;
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
use Cake\View\View;
use DebugKit\View\Helper\SimpleGraphHelper;

/**
* Class SimpleGraphHelperTestCase
*/
class SimpleGraphHelperTest extends TestCase
{

/**
* Setup
*
* @return void
*/
public function setUp()
{
parent::setUp();
Router::connect('/:controller/:action');

$request = new Request();
$request->addParams(['controller' => 'pages', 'action' => 'display']);

$this->View = new View($request);
$this->Graph = new SimpleGraphHelper($this->View);
}

/**
* Tear Down
*
* @return void
*/
public function tearDown()
{
parent::tearDown();
unset($this->Graph);
}

/**
* Test bar()
*
* @return void
*/
public function testBar()
{
$output = $this->Graph->bar(10, 0);
$expected = [
['div' => [
'class' => 'graph-bar',
'style' => 'width: 350px',
]],
['div' => [
'class' => 'graph-bar-value',
'style' => 'margin-left: 0px; width: 35px',
'title' => 'Starting 0ms into the request, taking 10ms'
]],
' ',
'/div',
'/div'
];
$this->assertHtml($expected, $output);
}

/**
* Test bar() with offset
*
* @return void
*/
public function testBarOffset()
{
$output = $this->Graph->bar(10, 10);
$expected = [
['div' => [
'class' => 'graph-bar',
'style' => 'width: 350px',
]],
['div' => [
'class' => 'graph-bar-value',
'style' => 'margin-left: 35px; width: 35px',
'title' => 'Starting 10ms into the request, taking 10ms'
]],
' ',
'/div',
'/div'
];
$this->assertHtml($expected, $output);
}
}
1 change: 0 additions & 1 deletion tests/TestCase/View/Helper/ToolbarHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use Cake\View\Helper\FormHelper;
use Cake\View\Helper\HtmlHelper;
use Cake\View\View;
use DebugKit\View\Helper\HtmlToolbarHelper;
use DebugKit\View\Helper\ToolbarHelper;
use StdClass;

Expand Down
7 changes: 4 additions & 3 deletions webroot/js/debug_kit.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var baseUrl, toolbar;

var elem = document.getElementById("__debug_kit");
var elem = document.getElementById("__debug_kit_app");
if (elem) {
window.__debug_kit_id = elem.getAttribute("data-id");
window.__debug_kit_base_url = elem.getAttribute("data-url");
baseUrl = elem.getAttribute("data-full-url");
window.__debug_kit_webroot = elem.getAttribute("data-webroot");
elem = null;
}

Expand All @@ -17,7 +17,8 @@ $(document).ready(function() {
keyboardScope : $(document),
currentRequest: __debug_kit_id,
originalRequest: __debug_kit_id,
baseUrl: __debug_kit_base_url
baseUrl: __debug_kit_base_url,
webroot: __debug_kit_webroot,
});

toolbar.initialize();
Expand Down
9 changes: 5 additions & 4 deletions webroot/js/toolbar-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function Toolbar(options) {
this.currentRequest = options.currentRequest;
this.originalRequest = options.originalRequest;
this.baseUrl = options.baseUrl;
this.webroot = options.webroot;
}

Toolbar.prototype = {
Expand Down Expand Up @@ -102,7 +103,7 @@ Toolbar.prototype = {
},

loadPanel: function(id) {
var url = baseUrl + 'debug_kit/panels/view/' + id;
var url = this.baseUrl + 'debug_kit/panels/view/' + id;
var contentArea = this.content.find('#panel-content');
var _this = this;
var timer;
Expand Down Expand Up @@ -134,10 +135,10 @@ Toolbar.prototype = {
var sortButton = this.content.find('.neat-array-sort');
var _this = this;
sortButton.click(function() {
if ($(this).attr('checked')) {
document.cookie = 'debugKit_sort=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=' + _this.baseUrl;
if (!$(this).prop('checked')) {
document.cookie = 'debugKit_sort=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=' + _this.webroot;
} else {
document.cookie = 'debugKit_sort=1; path=' + _this.baseUrl;
document.cookie = 'debugKit_sort=1; path=' + _this.webroot;
}
_this.loadPanel(_this.currentPanel());
});
Expand Down

0 comments on commit 5c35113

Please sign in to comment.