Browse Source

debugger furnishing

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
d121c0d3e9
  1. 2
      apps/basic/controllers/SiteController.php
  2. 10
      framework/yii/debug/Module.php
  3. 11
      framework/yii/debug/Panel.php
  4. 29
      framework/yii/debug/assets/main.css
  5. 27
      framework/yii/debug/controllers/DefaultController.php
  6. 3
      framework/yii/debug/panels/LogPanel.php
  7. 11
      framework/yii/debug/panels/RequestPanel.php
  8. 44
      framework/yii/debug/views/default/index.php
  9. 10
      framework/yii/debug/views/default/toolbar.css
  10. 3
      framework/yii/debug/views/default/toolbar.php
  11. 71
      framework/yii/debug/views/default/view.php

2
apps/basic/controllers/SiteController.php

@ -20,7 +20,7 @@ class SiteController extends Controller
} }
public function actionIndex() public function actionIndex()
{ {Yii::error('test');
return $this->render('index'); return $this->render('index');
} }

10
framework/yii/debug/Module.php

@ -9,7 +9,6 @@ namespace yii\debug;
use Yii; use Yii;
use yii\base\View; use yii\base\View;
use yii\helpers\Html;
/** /**
* @author Qiang Xue <qiang.xue@gmail.com> * @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) { foreach (array_merge($this->corePanels(), $this->panels) as $id => $config) {
$config['module'] = $this; $config['module'] = $this;
$config['id'] = $id;
$this->panels[$id] = Yii::createObject($config); $this->panels[$id] = Yii::createObject($config);
} }
} }
@ -75,14 +75,10 @@ class Module extends \yii\base\Module
public function renderToolbar($event) 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, 'tag' => $this->logTarget->tag,
)); ));
echo Html::tag('div', '', array( echo '<div id="yii-debug-toolbar" data-url="' . $url . '" style="display:none"></div>';
'id' => 'yii-debug-toolbar',
'data-url' => $url,
'style' => 'display: none',
));
/** @var View $view */ /** @var View $view */
$view = $event->sender; $view = $event->sender;
echo '<script>' . $view->renderFile(__DIR__ . '/views/default/toolbar.js') . '</script>'; echo '<script>' . $view->renderFile(__DIR__ . '/views/default/toolbar.js') . '</script>';

11
framework/yii/debug/Panel.php

@ -7,6 +7,7 @@
namespace yii\debug; namespace yii\debug;
use Yii;
use yii\base\Component; use yii\base\Component;
/** /**
@ -15,6 +16,8 @@ use yii\base\Component;
*/ */
class Panel extends Component class Panel extends Component
{ {
public $id;
public $tag;
/** /**
* @var Module * @var Module
*/ */
@ -45,4 +48,12 @@ class Panel extends Component
{ {
$this->data = $data; $this->data = $data;
} }
public function getUrl()
{
return Yii::$app->getUrlManager()->createUrl($this->module->id . '/default/view', array(
'panel' => $this->id,
'tag' => $this->tag,
));
}
} }

29
framework/yii/debug/assets/main.css

@ -1,26 +1,3 @@
#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 { .yii-debug-toolbar-block {
float: left; float: left;
margin: 0; margin: 0;
@ -29,9 +6,13 @@
line-height: 32px; line-height: 32px;
} }
.yii-debug-toolbar-block .label {
font-weight: normal;
}
.yii-debug-toolbar-block a { .yii-debug-toolbar-block a {
text-decoration: none; text-decoration: none;
color: black !important; color: black;
} }
.yii-debug-toolbar-block span { .yii-debug-toolbar-block span {

27
framework/yii/debug/controllers/DefaultController.php

@ -21,11 +21,17 @@ class DefaultController extends Controller
public $module; public $module;
public $layout = 'main'; 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) { if ($tag === null) {
$tags = array_keys($this->getManifest()); $tags = array_keys($this->getManifest());
$tag = end($tags); $tag = reset($tags);
} }
$meta = $this->loadData($tag); $meta = $this->loadData($tag);
if (isset($this->module->panels[$panel])) { if (isset($this->module->panels[$panel])) {
@ -33,7 +39,7 @@ class DefaultController extends Controller
} else { } else {
$activePanel = $this->module->panels['request']; $activePanel = $this->module->panels['request'];
} }
return $this->render('index', array( return $this->render('view', array(
'tag' => $tag, 'tag' => $tag,
'meta' => $meta, 'meta' => $meta,
'manifest' => $this->getManifest(), 'manifest' => $this->getManifest(),
@ -63,22 +69,10 @@ class DefaultController extends Controller
if ($this->_manifest === null) { if ($this->_manifest === null) {
$indexFile = $this->module->dataPath . '/index.json'; $indexFile = $this->module->dataPath . '/index.json';
if (is_file($indexFile)) { 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 { } else {
$this->_manifest = array(); $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; return $this->_manifest;
} }
@ -91,6 +85,7 @@ class DefaultController extends Controller
$data = json_decode(file_get_contents($dataFile), true); $data = json_decode(file_get_contents($dataFile), true);
foreach ($this->module->panels as $id => $panel) { foreach ($this->module->panels as $id => $panel) {
if (isset($data[$id])) { if (isset($data[$id])) {
$panel->tag = $tag;
$panel->load($data[$id]); $panel->load($data[$id]);
} else { } else {
// remove the panel since it has not received any data // remove the panel since it has not received any data

3
framework/yii/debug/panels/LogPanel.php

@ -37,9 +37,10 @@ class LogPanel extends Panel
} }
if (!empty($output)) { if (!empty($output)) {
$log = implode(', ', $output); $log = implode(', ', $output);
$url = $this->getUrl();
return <<<EOD return <<<EOD
<div class="yii-debug-toolbar-block"> <div class="yii-debug-toolbar-block">
$log <a href="$url">$log</a>
</div> </div>
EOD; EOD;
} else { } else {

11
framework/yii/debug/panels/RequestPanel.php

@ -25,20 +25,21 @@ class RequestPanel extends Panel
public function getSummary() public function getSummary()
{ {
$memory = '<span class="label">' . sprintf('%.1f MB', $this->data['memory'] / 1048576) . '</span>'; $memory = sprintf('%.1f MB', $this->data['memory'] / 1048576);
$time = '<span class="label">' . number_format($this->data['time'] * 1000) . ' ms</span>'; $time = number_format($this->data['time'] * 1000) . ' ms';
$url = $this->getUrl();
return <<<EOD return <<<EOD
<div class="yii-debug-toolbar-block"> <div class="yii-debug-toolbar-block">
Peak memory: $memory <a href="$url">Peak memory: <span class="label">$memory</span></a>
</div> </div>
<div class="yii-debug-toolbar-block"> <div class="yii-debug-toolbar-block">
Time spent: $time <a href="$url">Time spent: <span class="label">$time</span></a>
</div> </div>
<div class="yii-debug-toolbar-block"> <div class="yii-debug-toolbar-block">
Action: {$this->data['action']} <a href="$url">Action: <span class="label">{$this->data['action']}</span></a>
</div> </div>
EOD; EOD;
} }

44
framework/yii/debug/views/default/index.php

@ -21,50 +21,6 @@ $this->title = 'Yii Debugger';
<div class="yii-debug-toolbar-block title"> <div class="yii-debug-toolbar-block title">
Yii Debugger Yii Debugger
</div> </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> </div>
</div> </div>

10
framework/yii/debug/views/default/toolbar.css

@ -6,7 +6,7 @@
margin: 0; margin: 0;
padding: 0; padding: 0;
z-index: 1000000; z-index: 1000000;
font: 12px Verdana, Arial, sans-serif; font: 11px Verdana, Arial, sans-serif;
text-align: left; text-align: left;
height: 38px; height: 38px;
border-top: 1px solid #ccc; border-top: 1px solid #ccc;
@ -45,7 +45,7 @@
display: inline-block; display: inline-block;
padding: 2px 4px; padding: 2px 4px;
font-size: 11.844px; font-size: 11.844px;
font-weight: bold; font-weight: normal;
line-height: 14px; line-height: 14px;
color: #ffffff; color: #ffffff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
@ -113,9 +113,3 @@
#yii-debug-toolbar .badge-inverse[href] { #yii-debug-toolbar .badge-inverse[href] {
background-color: #1a1a1a; background-color: #1a1a1a;
} }
#yii-debug-toolbar .debugger-link a {
padding: 3px 5px;
font-weight: normal;
color: white;
}

3
framework/yii/debug/views/default/toolbar.php

@ -10,9 +10,6 @@ use yii\helpers\Html;
<?php echo $this->renderFile(__DIR__ . '/toolbar.css'); ?> <?php echo $this->renderFile(__DIR__ . '/toolbar.css'); ?>
</style> </style>
<div id="yii-debug-toolbar"> <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 foreach ($panels as $panel): ?>
<?php echo $panel->getSummary(); ?> <?php echo $panel->getSummary(); ?>
<?php endforeach; ?> <?php endforeach; ?>

71
framework/yii/debug/views/default/view.php

@ -0,0 +1,71 @@
<?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>
Loading…
Cancel
Save