Commit d121c0d3 by Qiang Xue

debugger furnishing

parent 34239ce3
......@@ -20,7 +20,7 @@ class SiteController extends Controller
}
public function actionIndex()
{
{Yii::error('test');
return $this->render('index');
}
......
......@@ -9,7 +9,6 @@ namespace yii\debug;
use Yii;
use yii\base\View;
use yii\helpers\Html;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
......@@ -54,6 +53,7 @@ class Module extends \yii\base\Module
foreach (array_merge($this->corePanels(), $this->panels) as $id => $config) {
$config['module'] = $this;
$config['id'] = $id;
$this->panels[$id] = Yii::createObject($config);
}
}
......@@ -75,14 +75,10 @@ class Module extends \yii\base\Module
public function renderToolbar($event)
{
$url = Yii::$app->getUrlManager()->createUrl('debug/default/toolbar', array(
$url = Yii::$app->getUrlManager()->createUrl($this->id . '/default/toolbar', array(
'tag' => $this->logTarget->tag,
));
echo Html::tag('div', '', array(
'id' => 'yii-debug-toolbar',
'data-url' => $url,
'style' => 'display: none',
));
echo '<div id="yii-debug-toolbar" data-url="' . $url . '" style="display:none"></div>';
/** @var View $view */
$view = $event->sender;
echo '<script>' . $view->renderFile(__DIR__ . '/views/default/toolbar.js') . '</script>';
......
......@@ -7,6 +7,7 @@
namespace yii\debug;
use Yii;
use yii\base\Component;
/**
......@@ -15,6 +16,8 @@ use yii\base\Component;
*/
class Panel extends Component
{
public $id;
public $tag;
/**
* @var Module
*/
......@@ -45,4 +48,12 @@ class Panel extends Component
{
$this->data = $data;
}
public function getUrl()
{
return Yii::$app->getUrlManager()->createUrl($this->module->id . '/default/view', array(
'panel' => $this->id,
'tag' => $this->tag,
));
}
}
#yii-debug-toolbar {
position: fixed;
left: 0;
right: 0;
bottom: 0;
margin: 0;
padding: 0;
z-index: 1000000;
font: 11px Verdana, Arial, sans-serif;
text-align: left;
height: 38px;
border-top: 1px solid #ccc;
background: rgb(237,237,237);
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2VkZWRlZCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUzJSIgc3RvcC1jb2xvcj0iI2Y2ZjZmNiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZmZmZmYiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
background: -moz-linear-gradient(top, rgba(237,237,237,1) 0%, rgba(246,246,246,1) 53%, rgba(255,255,255,1) 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(237,237,237,1)), color-stop(53%,rgba(246,246,246,1)), color-stop(100%,rgba(255,255,255,1)));
background: -webkit-linear-gradient(top, rgba(237,237,237,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
background: -o-linear-gradient(top, rgba(237,237,237,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
background: -ms-linear-gradient(top, rgba(237,237,237,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
background: linear-gradient(to bottom, rgba(237,237,237,1) 0%,rgba(246,246,246,1) 53%,rgba(255,255,255,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ededed', endColorstr='#ffffff',GradientType=0 );
}
.yii-debug-toolbar-block {
float: left;
margin: 0;
......@@ -29,9 +6,13 @@
line-height: 32px;
}
.yii-debug-toolbar-block .label {
font-weight: normal;
}
.yii-debug-toolbar-block a {
text-decoration: none;
color: black !important;
color: black;
}
.yii-debug-toolbar-block span {
......
......@@ -21,11 +21,17 @@ class DefaultController extends Controller
public $module;
public $layout = 'main';
public function actionIndex($tag = null, $panel = null)
public function actionIndex()
{
return $this->render('index', array(
));
}
public function actionView($tag = null, $panel = null)
{
if ($tag === null) {
$tags = array_keys($this->getManifest());
$tag = end($tags);
$tag = reset($tags);
}
$meta = $this->loadData($tag);
if (isset($this->module->panels[$panel])) {
......@@ -33,7 +39,7 @@ class DefaultController extends Controller
} else {
$activePanel = $this->module->panels['request'];
}
return $this->render('index', array(
return $this->render('view', array(
'tag' => $tag,
'meta' => $meta,
'manifest' => $this->getManifest(),
......@@ -63,22 +69,10 @@ class DefaultController extends Controller
if ($this->_manifest === null) {
$indexFile = $this->module->dataPath . '/index.json';
if (is_file($indexFile)) {
$this->_manifest = json_decode(file_get_contents($indexFile), true);
$this->_manifest = array_reverse(json_decode(file_get_contents($indexFile), true), true);
} else {
$this->_manifest = array();
}
if (count($this->_manifest) > $this->module->historySize) {
$n = count($this->_manifest) - $this->module->historySize;
foreach (array_keys($this->_manifest) as $tag) {
$file = $this->module->dataPath . "/$tag.json";
@unlink($file);
unset($this->_manifest[$tag]);
if (--$n <= 0) {
break;
}
}
file_put_contents($indexFile, json_encode($this->_manifest));
}
}
return $this->_manifest;
}
......@@ -91,6 +85,7 @@ class DefaultController extends Controller
$data = json_decode(file_get_contents($dataFile), true);
foreach ($this->module->panels as $id => $panel) {
if (isset($data[$id])) {
$panel->tag = $tag;
$panel->load($data[$id]);
} else {
// remove the panel since it has not received any data
......
......@@ -37,9 +37,10 @@ class LogPanel extends Panel
}
if (!empty($output)) {
$log = implode(', ', $output);
$url = $this->getUrl();
return <<<EOD
<div class="yii-debug-toolbar-block">
$log
<a href="$url">$log</a>
</div>
EOD;
} else {
......
......@@ -25,20 +25,21 @@ class RequestPanel extends Panel
public function getSummary()
{
$memory = '<span class="label">' . sprintf('%.1f MB', $this->data['memory'] / 1048576) . '</span>';
$time = '<span class="label">' . number_format($this->data['time'] * 1000) . ' ms</span>';
$memory = sprintf('%.1f MB', $this->data['memory'] / 1048576);
$time = number_format($this->data['time'] * 1000) . ' ms';
$url = $this->getUrl();
return <<<EOD
<div class="yii-debug-toolbar-block">
Peak memory: $memory
<a href="$url">Peak memory: <span class="label">$memory</span></a>
</div>
<div class="yii-debug-toolbar-block">
Time spent: $time
<a href="$url">Time spent: <span class="label">$time</span></a>
</div>
<div class="yii-debug-toolbar-block">
Action: {$this->data['action']}
<a href="$url">Action: <span class="label">{$this->data['action']}</span></a>
</div>
EOD;
}
......
......@@ -21,50 +21,6 @@ $this->title = 'Yii Debugger';
<div class="yii-debug-toolbar-block title">
Yii Debugger
</div>
<?php foreach ($panels as $panel): ?>
<?php echo $panel->getSummary(); ?>
<?php endforeach; ?>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span2">
<ul class="nav nav-tabs nav-list nav-stacked">
<?php
foreach ($panels as $id => $panel) {
$link = Html::a(Html::encode($panel->getName()), array('debug/default/index', 'tag' => $tag, 'panel' => $id));
echo Html::tag('li', $link, array('class' => $panel === $activePanel ? 'active' : null));
}
?>
</ul>
</div><!--/span-->
<div class="span10">
<div class="meta alert alert-info">
<div class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown">
View others
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<?php foreach ($manifest as $tag2 => $meta2) {
$label = $meta2['method'] . ' ' . $meta2['url'] . ($meta2['ajax'] ? ' (AJAX)' : '')
. ', ' . date('Y/m/d h:i:sa', $meta2['time'])
. ', ' . $meta2['ip'] . ', ' . $tag2;
$url = array('debug/default/index', 'tag' => $tag2);
echo '<li>' . Html::a(Html::encode($label), $url) . '</li>';
} ?>
</ul>
</div>
Debugging:
<?php echo $meta['method']; ?>
<?php echo Html::a(Html::encode($meta['url']), $meta['url']); ?>
<?php echo $meta['ajax'] ? ' (AJAX)' : ''; ?>
at <?php echo date('Y/m/d h:i:sa', $meta['time']); ?>
by <?php echo $meta['ip']; ?>
</div>
<?php echo $activePanel->getDetail(); ?>
</div>
</div>
</div>
......
......@@ -6,7 +6,7 @@
margin: 0;
padding: 0;
z-index: 1000000;
font: 12px Verdana, Arial, sans-serif;
font: 11px Verdana, Arial, sans-serif;
text-align: left;
height: 38px;
border-top: 1px solid #ccc;
......@@ -45,7 +45,7 @@
display: inline-block;
padding: 2px 4px;
font-size: 11.844px;
font-weight: bold;
font-weight: normal;
line-height: 14px;
color: #ffffff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
......@@ -113,9 +113,3 @@
#yii-debug-toolbar .badge-inverse[href] {
background-color: #1a1a1a;
}
#yii-debug-toolbar .debugger-link a {
padding: 3px 5px;
font-weight: normal;
color: white;
}
......@@ -10,9 +10,6 @@ use yii\helpers\Html;
<?php echo $this->renderFile(__DIR__ . '/toolbar.css'); ?>
</style>
<div id="yii-debug-toolbar">
<div class="yii-debug-toolbar-block debugger-link">
<?php echo Html::a('Yii Debugger', array('index', 'tag' => $tag), array('class' => 'label')); ?>
</div>
<?php foreach ($panels as $panel): ?>
<?php echo $panel->getSummary(); ?>
<?php endforeach; ?>
......
<?php
use yii\helpers\Html;
/**
* @var \yii\base\View $this
* @var array $meta
* @var string $tag
* @var array $manifest
* @var \yii\debug\Panel[] $panels
* @var \yii\debug\Panel $activePanel
*/
$this->registerAssetBundle('yii/bootstrap/dropdown');
$this->title = 'Yii Debugger';
?>
<div class="default-view">
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<div class="yii-debug-toolbar-block title">
Yii Debugger
</div>
<?php foreach ($panels as $panel): ?>
<?php echo $panel->getSummary(); ?>
<?php endforeach; ?>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span2">
<ul class="nav nav-tabs nav-list nav-stacked">
<?php
foreach ($panels as $id => $panel) {
$link = Html::a(Html::encode($panel->getName()), array('view', 'tag' => $tag, 'panel' => $id));
echo Html::tag('li', $link, array('class' => $panel === $activePanel ? 'active' : null));
}
?>
</ul>
</div><!--/span-->
<div class="span10">
<div class="meta alert alert-info">
<div class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown">
View others
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<?php foreach ($manifest as $tag2 => $meta2) {
$label = $meta2['method'] . ' ' . $meta2['url'] . ($meta2['ajax'] ? ' (AJAX)' : '')
. ', ' . date('Y/m/d h:i:sa', $meta2['time'])
. ', ' . $meta2['ip'] . ', ' . $tag2;
$url = array('view', 'tag' => $tag2);
echo '<li>' . Html::a(Html::encode($label), $url) . '</li>';
} ?>
</ul>
</div>
Debugging:
<?php echo $meta['method']; ?>
<?php echo Html::a(Html::encode($meta['url']), $meta['url']); ?>
<?php echo $meta['ajax'] ? ' (AJAX)' : ''; ?>
at <?php echo date('Y/m/d h:i:sa', $meta['time']); ?>
by <?php echo $meta['ip']; ?>
</div>
<?php echo $activePanel->getDetail(); ?>
</div>
</div>
</div>
</div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment