1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-01-29 11:17:52 +01:00

started work on open handler

This commit is contained in:
maximebf 2013-08-14 11:23:25 +10:00
parent c5a145ad14
commit f686438050
9 changed files with 587 additions and 297 deletions

View File

@ -7,7 +7,8 @@ use DebugBar\StandardDebugBar;
$debugbar = new StandardDebugBar();
$debugbarRenderer = $debugbar->getJavascriptRenderer()->setBaseUrl('../src/DebugBar/Resources');
//$debugbar->setStorage(new DebugBar\Storage\FileStorage(__DIR__ . '/profiles'));
$debugbar->setStorage(new DebugBar\Storage\FileStorage(__DIR__ . '/profiles'));
$debugbarRenderer->setOpenHandlerUrl('open.php');
function render_demo_page(Closure $callback = null)
{

6
demo/open.php Normal file
View File

@ -0,0 +1,6 @@
<?php
include __DIR__ . '/bootstrap.php';
$openHandler = new DebugBar\OpenHandler($debugbar);
$openHandler->handle();

View File

@ -35,9 +35,9 @@ class JavascriptRenderer
protected $includeVendors = true;
protected $cssFiles = array('debugbar.css');
protected $cssFiles = array('debugbar.css', 'widgets.css', 'openhandler.css');
protected $jsFiles = array('debugbar.js', 'widgets.js');
protected $jsFiles = array('debugbar.js', 'widgets.js', 'openhandler.js');
protected $javascriptClass = 'PhpDebugBar.DebugBar';
@ -49,6 +49,10 @@ class JavascriptRenderer
protected $ignoredCollectors = array();
protected $openHandlerClassName = 'PhpDebugBar.OpenHandler';
protected $openHandlerUrl;
/**
* @param \DebugBar\DebugBar $debugBar
* @param string $baseUrl
@ -122,6 +126,12 @@ class JavascriptRenderer
$this->ignoreCollector($name);
}
}
if (array_key_exists('open_handler_classname', $options)) {
$this->setOpenHandlerClassName($options['open_handler_classname']);
}
if (array_key_exists('open_handler_url', $options)) {
$this->setOpenHandlerUrl($options['open_handler_url']);
}
}
/**
@ -344,6 +354,48 @@ class JavascriptRenderer
), $type);
}
/**
* Sets the class name of the js open handler
*
* @param string $className
*/
public function setOpenHandlerClassName($className)
{
$this->openHandlerClassName = $className;
return $this;
}
/**
* Returns the class name of the js open handler
*
* @return string
*/
public function getOpenHandlerClassName()
{
return $this->openHandlerClassName;
}
/**
* Sets the url of the open handler
*
* @param string $url
*/
public function setOpenHandlerUrl($url)
{
$this->openHandlerUrl = $url;
return $this;
}
/**
* Returns the url for the open handler
*
* @return string
*/
public function getOpenHandlerUrl()
{
return $this->openHandlerUrl;
}
/**
* Returns the list of asset files
*
@ -546,6 +598,12 @@ class JavascriptRenderer
$js .= $this->getJsControlsDefinitionCode($this->variableName);
}
if ($this->openHandlerUrl !== null) {
$js .= sprintf("%s.setOpenHandler(new %s(%s));\n", $this->variableName,
$this->openHandlerClassName,
json_encode(array("url" => $this->openHandlerUrl)));
}
return $js;
}

View File

@ -0,0 +1,103 @@
<?php
/*
* This file is part of the DebugBar package.
*
* (c) 2013 Maxime Bouroumeau-Fuseau
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace DebugBar;
/**
* Handler to list and open saved dataset
*/
class OpenHandler
{
protected $debugBar;
/**
* @param DebugBar $debugBar
*/
public function __construct(DebugBar $debugBar)
{
if (!$debugBar->isDataPersisted()) {
throw new DebugBarException("DebugBar must have a storage backend to use OpenHandler");
}
$this->debugBar = $debugBar;
}
/**
* Handles the current request
*
* @param array $request Request data
*/
public function handle(array $request = null, $echo = true, $sendHeader = true)
{
if ($request === null) {
$request = $_REQUEST;
}
if (!isset($request['op'])) {
$request['op'] = 'find';
}
if (!in_array($request['op'], array('find', 'get', 'clear'))) {
throw new DebugBarException("Invalid operation '{$request['op']}'");
}
if ($sendHeader) {
header('Content-Type: application/json');
}
$response = json_encode(call_user_func(array($this, $request['op']), $request));
if ($echo) {
echo $response;
}
return $response;
}
/**
* Find operation
*/
protected function find(array $request)
{
$max = 20;
if (isset($request['max'])) {
$max = $request['max'];
}
$offset = 0;
if (isset($request['offset'])) {
$offset = $request['offset'];
}
$filters = array();
foreach (array('utime', 'datetime', 'ip', 'uri') as $key) {
if (isset($request[$key])) {
$filters[$key] = $request[$key];
}
}
return $this->debugBar->getStorage()->find($filters, $max, $offset);
}
/**
* Get operation
*/
protected function get(array $request)
{
if (!isset($request['id'])) {
throw new DebugBarException("Missing 'id' parameter in 'get' operation");
}
return $this->debugBar->getStorage()->get($request['id']);
}
/**
* Clear operation
*/
protected function clear(array $request)
{
$this->debugBar->getStorage()->clear();
return array('success' => true);
}
}

View File

@ -32,6 +32,7 @@ div.phpdebugbar-header:after {
a.phpdebugbar-tab,
span.phpdebugbar-indicator,
a.phpdebugbar-indicator,
a.phpdebugbar-open-btn,
a.phpdebugbar-minimize-btn {
float: left;
padding: 5px 8px;
@ -41,6 +42,7 @@ a.phpdebugbar-minimize-btn {
}
span.phpdebugbar-indicator,
a.phpdebugbar-indicator,
a.phpdebugbar-open-btn,
a.phpdebugbar-minimize-btn {
float: right;
border-right: 1px solid #ddd;
@ -134,297 +136,3 @@ div.phpdebugbar-panel {
div.phpdebugbar-panel.active {
display: block;
}
/* -------------------------------------- */
ul.phpdebugbar-widgets-list {
margin: 0;
padding: 0;
list-style: none;
font-family: monospace;
}
ul.phpdebugbar-widgets-list li.list-item {
padding: 3px 6px;
border-bottom: 1px solid #eee;
position: relative;
}
ul.phpdebugbar-widgets-list li.list-item:hover {
background: #fafafa;
}
/* -------------------------------------- */
div.phpdebugbar-widgets-messages {
position: relative;
height: 100%;
}
div.phpdebugbar-widgets-messages div.phpdebugbar-widgets-list {
padding-bottom: 20px;
}
div.phpdebugbar-widgets-messages li.list-item span.value.warning:before {
font-family: FontAwesome;
content: "\f071";
margin-right: 8px;
font-size: 11px;
color: #ecb03d;
}
div.phpdebugbar-widgets-messages li.list-item span.value.error {
color: red;
}
div.phpdebugbar-widgets-messages li.list-item span.value.error:before {
font-family: FontAwesome;
content: "\f057";
margin-right: 8px;
font-size: 11px;
color: red;
}
div.phpdebugbar-widgets-messages li.list-item span.collector,
div.phpdebugbar-widgets-messages li.list-item span.label {
float: right;
font-size: 12px;
padding: 2px 4px;
color: #888;
margin: 0 2px;
text-decoration: none;
text-shadow: none;
background: none;
font-weight: normal;
}
div.phpdebugbar-widgets-messages li.list-item span.collector {
color: #555;
font-style: italic;
}
div.phpdebugbar-widgets-messages div.toolbar {
position: fixed;
bottom: 0;
width: 100%;
background: #fff;
}
div.phpdebugbar-widgets-messages div.toolbar input {
border: 0;
margin: 0;
margin-left: 7px;
width: 50%;
box-shadow: none;
}
div.phpdebugbar-widgets-messages div.toolbar input:focus {
outline: none;
}
div.phpdebugbar-widgets-messages div.toolbar a.filter {
float: right;
font-size: 12px;
padding: 2px 4px;
background: #7cacd5;
margin: 0 2px;
border-radius: 4px;
color: #fff;
text-decoration: none;
}
div.phpdebugbar-widgets-messages div.toolbar a.filter.excluded {
background: #eee;
color: #888;
}
/* -------------------------------------- */
dl.phpdebugbar-widgets-kvlist {
margin: 0;
}
dl.phpdebugbar-widgets-kvlist dt {
float: left;
width: 140px;
padding: 5px;
border-top: 1px solid #eee;
font-weight: bold;
clear: both;
}
dl.phpdebugbar-widgets-kvlist dd {
margin-left: 150px;
padding: 5px;
border-top: 1px solid #eee;
cursor: pointer;
}
/* -------------------------------------- */
dl.phpdebugbar-widgets-varlist {
font-family: monospace;
}
/* -------------------------------------- */
ul.phpdebugbar-widgets-timeline {
margin: 0;
padding: 0;
list-style: none;
}
ul.phpdebugbar-widgets-timeline li {
height: 20px;
position: relative;
border-bottom: 1px solid #eee;
}
ul.phpdebugbar-widgets-timeline li:hover {
background: #fafafa;
}
ul.phpdebugbar-widgets-timeline li span.label {
position: absolute;
font-size: 12px;
font-family: monospace;
color: #555;
top: 4px;
left: 5px;
background: none;
text-shadow: none;
font-weight: normal;
}
ul.phpdebugbar-widgets-timeline li span.value {
display: block;
position: absolute;
height: 10px;
background: #3db9ec;
top: 5px;
border-radius: 2px;
}
/* -------------------------------------- */
div.phpdebugbar-widgets-exceptions li.list-item {
cursor: pointer;
}
div.phpdebugbar-widgets-exceptions li.list-item span.message {
display: block;
color: red;
}
div.phpdebugbar-widgets-exceptions li.list-item span.filename {
display: block;
font-style: italic;
color: #555;
}
div.phpdebugbar-widgets-exceptions li.list-item span.type {
display: block;
position: absolute;
right: 4px;
top: 4px;
font-weight: bold;
}
div.phpdebugbar-widgets-exceptions li.list-item span.file {
display: none;
margin: 10px;
padding: 5px;
border: 1px solid #ddd;
font-family: monospace;
}
/* -------------------------------------- */
div.phpdebugbar-widgets-sqlqueries .status {
font-family: monospace;
padding: 6px 6px;
border-bottom: 1px solid #ddd;
font-weight: bold;
color: #555;
background: #fafafa;
}
div.phpdebugbar-widgets-sqlqueries li.list-item.error {
color: red;
}
div.phpdebugbar-widgets-sqlqueries span.duration,
div.phpdebugbar-widgets-sqlqueries span.memory,
div.phpdebugbar-widgets-sqlqueries span.row-count,
div.phpdebugbar-widgets-sqlqueries span.stmt-id {
float: right;
margin-left: 8px;
color: #888;
}
div.phpdebugbar-widgets-sqlqueries div.status span.duration,
div.phpdebugbar-widgets-sqlqueries div.status span.memory,
div.phpdebugbar-widgets-sqlqueries div.status span.row-count,
div.phpdebugbar-widgets-sqlqueries div.status span.stmt-id {
color: #555;
}
div.phpdebugbar-widgets-sqlqueries span.duration:before,
div.phpdebugbar-widgets-sqlqueries span.memory:before,
div.phpdebugbar-widgets-sqlqueries span.row-count:before,
div.phpdebugbar-widgets-sqlqueries span.stmt-id:before {
font-family: FontAwesome;
margin-right: 4px;
font-size: 12px;
}
div.phpdebugbar-widgets-sqlqueries span.duration:before {
content: "\f017";
}
div.phpdebugbar-widgets-sqlqueries span.memory:before {
content: "\f085";
}
div.phpdebugbar-widgets-sqlqueries span.row-count:before {
content: "\f0ce";
}
div.phpdebugbar-widgets-sqlqueries span.stmt-id:before {
content: "\f08d";
}
div.phpdebugbar-widgets-sqlqueries table.params {
display: none;
width: 70%;
margin: 10px;
border: 1px solid #ddd;
font-family: monospace;
border-collapse: collapse;
}
div.phpdebugbar-widgets-sqlqueries table.params td {
border: 1px solid #ddd;
text-align: center;
}
div.phpdebugbar-widgets-sqlqueries table.params .name {
width: 20%;
font-weight: bold;
}
div.phpdebugbar-widgets-sqlqueries li.list-item span.error {
display: block;
font-weight: bold;
}
/* -------------------------------------- */
div.phpdebugbar-widgets-templates div.status {
font-family: monospace;
padding: 6px 6px;
border-bottom: 1px solid #ddd;
font-weight: bold;
color: #555;
background: #fafafa;
}
div.phpdebugbar-widgets-templates span.render_time {
float: right;
}
div.phpdebugbar-widgets-templates span.render_time:before {
content: "\f017";
font-family: FontAwesome;
font-size: 12px;
margin-right: 4px;
}
div.phpdebugbar-widgets-templates div.status span.render_time {
color: #555;
}
/* -------------------------------------- */
div.phpdebugbar-widgets-mails span.subject {
display: block;
}
div.phpdebugbar-widgets-mails li.list-item pre.headers {
display: none;
margin: 10px;
padding: 5px;
border: 1px solid #ddd;
font-family: monospace;
}

View File

@ -333,6 +333,14 @@ if (typeof(localStorage) == 'undefined') {
self.minimize();
});
// open button
this.$openbtn = $('<a class="phpdebugbar-open-btn" href="javascript:"><i class="icon-folder-open"></i></a>').appendTo(this.$header).hide();
this.$openbtn.click(function() {
self.openHandler.show(function(id, dataset) {
self.addDataSet(dataset, id);
});
});
// select box for data sets
this.$datasets = $('<select class="phpdebugbar-datasets-switcher" />').appendTo(this.$header);
this.$datasets.change(function() {
@ -669,6 +677,31 @@ if (typeof(localStorage) == 'undefined') {
self.getControl(key).set('data', d);
}
});
},
/**
* Sets the handler to open past dataset
*
* @this {DebugBar}
* @param {object} handler
*/
setOpenHandler: function(handler) {
this.openHandler = handler;
if (handler !== null) {
this.$openbtn.show();
} else {
this.$openbtn.hide();
}
},
/**
* Returns the handler to open past dataset
*
* @this {DebugBar}
* @return {object}
*/
getOpenHandler: function() {
return this.openHandler;
}
});

View File

@ -0,0 +1,24 @@
div.phpdebugbar-openhandler-overlay {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: #000;
opacity: .3;
z-index: 20000;
}
div.phpdebugbar-openhandler {
position: absolute;
left: 0;
top: 0;
margin: auto;
width: 500px;
height: 300px;
padding: 10px;
background: #fff;
border: 2px solid #ccc;
overflow: scroll;
z-index: 20001;
}

View File

@ -0,0 +1,65 @@
if (typeof(PhpDebugBar) == 'undefined') {
// namespace
var PhpDebugBar = {};
}
(function($) {
PhpDebugBar.OpenHandler = PhpDebugBar.Widget.extend({
className: 'phpdebugbar-openhandler',
render: function() {
var self = this;
this.$el.appendTo('body').hide();
this.$ul = $('<ul />').appendTo(this.$el);
this.$overlay = $('<div class="phpdebugbar-openhandler-overlay" />').hide().appendTo('body');
this.$overlay.on('click', function() {
self.$overlay.hide();
self.$el.hide();
});
},
refresh: function() {
var self = this;
this.find({}, 20, 0, function(data) {
self.$ul.empty();
$.each(data, function(i, meta) {
var a = $('<a href="javascript:" />')
.text(meta['datetime'] + ' ' + meta['uri'])
.on('click', function(e) {
self.$el.hide();
self.load(meta['id'], function(data) {
self.callback(meta['id'], data);
});
e.preventDefault();
});
$('<li />').append(a).appendTo(self.$ul);
});
});
},
show: function(callback) {
this.callback = callback;
this.$el.show();
this.$overlay.show();
this.refresh();
},
find: function(filters, max, offset, callback)
{
var data = $.extend({max: max || 20, offset: offset || 0}, filters);
$.getJSON(this.get('url'), data, callback);
},
load: function(id, callback)
{
$.getJSON(this.get('url'), {op: "get", id: id}, callback);
}
});
})(jQuery);

View File

@ -0,0 +1,292 @@
ul.phpdebugbar-widgets-list {
margin: 0;
padding: 0;
list-style: none;
font-family: monospace;
}
ul.phpdebugbar-widgets-list li.list-item {
padding: 3px 6px;
border-bottom: 1px solid #eee;
position: relative;
}
ul.phpdebugbar-widgets-list li.list-item:hover {
background: #fafafa;
}
/* -------------------------------------- */
div.phpdebugbar-widgets-messages {
position: relative;
height: 100%;
}
div.phpdebugbar-widgets-messages div.phpdebugbar-widgets-list {
padding-bottom: 20px;
}
div.phpdebugbar-widgets-messages li.list-item span.value.warning:before {
font-family: FontAwesome;
content: "\f071";
margin-right: 8px;
font-size: 11px;
color: #ecb03d;
}
div.phpdebugbar-widgets-messages li.list-item span.value.error {
color: red;
}
div.phpdebugbar-widgets-messages li.list-item span.value.error:before {
font-family: FontAwesome;
content: "\f057";
margin-right: 8px;
font-size: 11px;
color: red;
}
div.phpdebugbar-widgets-messages li.list-item span.collector,
div.phpdebugbar-widgets-messages li.list-item span.label {
float: right;
font-size: 12px;
padding: 2px 4px;
color: #888;
margin: 0 2px;
text-decoration: none;
text-shadow: none;
background: none;
font-weight: normal;
}
div.phpdebugbar-widgets-messages li.list-item span.collector {
color: #555;
font-style: italic;
}
div.phpdebugbar-widgets-messages div.toolbar {
position: fixed;
bottom: 0;
width: 100%;
background: #fff;
}
div.phpdebugbar-widgets-messages div.toolbar input {
border: 0;
margin: 0;
margin-left: 7px;
width: 50%;
box-shadow: none;
}
div.phpdebugbar-widgets-messages div.toolbar input:focus {
outline: none;
}
div.phpdebugbar-widgets-messages div.toolbar a.filter {
float: right;
font-size: 12px;
padding: 2px 4px;
background: #7cacd5;
margin: 0 2px;
border-radius: 4px;
color: #fff;
text-decoration: none;
}
div.phpdebugbar-widgets-messages div.toolbar a.filter.excluded {
background: #eee;
color: #888;
}
/* -------------------------------------- */
dl.phpdebugbar-widgets-kvlist {
margin: 0;
}
dl.phpdebugbar-widgets-kvlist dt {
float: left;
width: 140px;
padding: 5px;
border-top: 1px solid #eee;
font-weight: bold;
clear: both;
}
dl.phpdebugbar-widgets-kvlist dd {
margin-left: 150px;
padding: 5px;
border-top: 1px solid #eee;
cursor: pointer;
}
/* -------------------------------------- */
dl.phpdebugbar-widgets-varlist {
font-family: monospace;
}
/* -------------------------------------- */
ul.phpdebugbar-widgets-timeline {
margin: 0;
padding: 0;
list-style: none;
}
ul.phpdebugbar-widgets-timeline li {
height: 20px;
position: relative;
border-bottom: 1px solid #eee;
}
ul.phpdebugbar-widgets-timeline li:hover {
background: #fafafa;
}
ul.phpdebugbar-widgets-timeline li span.label {
position: absolute;
font-size: 12px;
font-family: monospace;
color: #555;
top: 4px;
left: 5px;
background: none;
text-shadow: none;
font-weight: normal;
}
ul.phpdebugbar-widgets-timeline li span.value {
display: block;
position: absolute;
height: 10px;
background: #3db9ec;
top: 5px;
border-radius: 2px;
}
/* -------------------------------------- */
div.phpdebugbar-widgets-exceptions li.list-item {
cursor: pointer;
}
div.phpdebugbar-widgets-exceptions li.list-item span.message {
display: block;
color: red;
}
div.phpdebugbar-widgets-exceptions li.list-item span.filename {
display: block;
font-style: italic;
color: #555;
}
div.phpdebugbar-widgets-exceptions li.list-item span.type {
display: block;
position: absolute;
right: 4px;
top: 4px;
font-weight: bold;
}
div.phpdebugbar-widgets-exceptions li.list-item span.file {
display: none;
margin: 10px;
padding: 5px;
border: 1px solid #ddd;
font-family: monospace;
}
/* -------------------------------------- */
div.phpdebugbar-widgets-sqlqueries .status {
font-family: monospace;
padding: 6px 6px;
border-bottom: 1px solid #ddd;
font-weight: bold;
color: #555;
background: #fafafa;
}
div.phpdebugbar-widgets-sqlqueries li.list-item.error {
color: red;
}
div.phpdebugbar-widgets-sqlqueries span.duration,
div.phpdebugbar-widgets-sqlqueries span.memory,
div.phpdebugbar-widgets-sqlqueries span.row-count,
div.phpdebugbar-widgets-sqlqueries span.stmt-id {
float: right;
margin-left: 8px;
color: #888;
}
div.phpdebugbar-widgets-sqlqueries div.status span.duration,
div.phpdebugbar-widgets-sqlqueries div.status span.memory,
div.phpdebugbar-widgets-sqlqueries div.status span.row-count,
div.phpdebugbar-widgets-sqlqueries div.status span.stmt-id {
color: #555;
}
div.phpdebugbar-widgets-sqlqueries span.duration:before,
div.phpdebugbar-widgets-sqlqueries span.memory:before,
div.phpdebugbar-widgets-sqlqueries span.row-count:before,
div.phpdebugbar-widgets-sqlqueries span.stmt-id:before {
font-family: FontAwesome;
margin-right: 4px;
font-size: 12px;
}
div.phpdebugbar-widgets-sqlqueries span.duration:before {
content: "\f017";
}
div.phpdebugbar-widgets-sqlqueries span.memory:before {
content: "\f085";
}
div.phpdebugbar-widgets-sqlqueries span.row-count:before {
content: "\f0ce";
}
div.phpdebugbar-widgets-sqlqueries span.stmt-id:before {
content: "\f08d";
}
div.phpdebugbar-widgets-sqlqueries table.params {
display: none;
width: 70%;
margin: 10px;
border: 1px solid #ddd;
font-family: monospace;
border-collapse: collapse;
}
div.phpdebugbar-widgets-sqlqueries table.params td {
border: 1px solid #ddd;
text-align: center;
}
div.phpdebugbar-widgets-sqlqueries table.params .name {
width: 20%;
font-weight: bold;
}
div.phpdebugbar-widgets-sqlqueries li.list-item span.error {
display: block;
font-weight: bold;
}
/* -------------------------------------- */
div.phpdebugbar-widgets-templates div.status {
font-family: monospace;
padding: 6px 6px;
border-bottom: 1px solid #ddd;
font-weight: bold;
color: #555;
background: #fafafa;
}
div.phpdebugbar-widgets-templates span.render_time {
float: right;
}
div.phpdebugbar-widgets-templates span.render_time:before {
content: "\f017";
font-family: FontAwesome;
font-size: 12px;
margin-right: 4px;
}
div.phpdebugbar-widgets-templates div.status span.render_time {
color: #555;
}
/* -------------------------------------- */
div.phpdebugbar-widgets-mails span.subject {
display: block;
}
div.phpdebugbar-widgets-mails li.list-item pre.headers {
display: none;
margin: 10px;
padding: 5px;
border: 1px solid #ddd;
font-family: monospace;
}