Commit 4a31628b by Qiang Xue

Fixes #5089: Added asset debugger panel

parent 4b328374
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
"bower-asset/punycode": ">=1.3.0", "bower-asset/punycode": ">=1.3.0",
"bower-asset/yii2-pjax": ">=2.0.0", "bower-asset/yii2-pjax": ">=2.0.0",
"bower-asset/bootstrap": ">=3.0.0", "bower-asset/bootstrap": ">=3.0.0",
"bower-asset/jquery.ui": ">=1.10.0" "bower-asset/jquery-ui": ">=1.10.0"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "3.7.*", "phpunit/phpunit": "3.7.*",
......
...@@ -13,6 +13,7 @@ Yii Framework 2 debug extension Change Log ...@@ -13,6 +13,7 @@ Yii Framework 2 debug extension Change Log
- Enh #3108: Added `yii\debug\Module::enableDebugLogs` to disable logging debug logs by default (qiangxue) - Enh #3108: Added `yii\debug\Module::enableDebugLogs` to disable logging debug logs by default (qiangxue)
- Enh #3810: Added "Latest" button on panels page (thiagotalma) - Enh #3810: Added "Latest" button on panels page (thiagotalma)
- Enh #4031: Http status codes were hardcoded in filter (sdkiller) - Enh #4031: Http status codes were hardcoded in filter (sdkiller)
- Enh #5089: Added asset debugger panel (arturf, qiangxue)
2.0.0-beta April 13, 2014 2.0.0-beta April 13, 2014
------------------------- -------------------------
......
...@@ -209,8 +209,8 @@ class Module extends \yii\base\Module implements BootstrapInterface ...@@ -209,8 +209,8 @@ class Module extends \yii\base\Module implements BootstrapInterface
'log' => ['class' => 'yii\debug\panels\LogPanel'], 'log' => ['class' => 'yii\debug\panels\LogPanel'],
'profiling' => ['class' => 'yii\debug\panels\ProfilingPanel'], 'profiling' => ['class' => 'yii\debug\panels\ProfilingPanel'],
'db' => ['class' => 'yii\debug\panels\DbPanel'], 'db' => ['class' => 'yii\debug\panels\DbPanel'],
'mail' => ['class' => 'yii\debug\panels\MailPanel'],
'assets' => ['class' => 'yii\debug\panels\AssetPanel'], 'assets' => ['class' => 'yii\debug\panels\AssetPanel'],
'mail' => ['class' => 'yii\debug\panels\MailPanel'],
]; ];
} }
} }
...@@ -11,6 +11,13 @@ ul.trace { ...@@ -11,6 +11,13 @@ ul.trace {
white-space: normal; white-space: normal;
} }
ul.assets {
margin: 2px 0 0 0;
padding: 0;
list-style: none;
white-space: normal;
}
.callout-danger { .callout-danger {
background-color: #fcf2f2; background-color: #fcf2f2;
border-color: #dFb5b4; border-color: #dFb5b4;
...@@ -96,4 +103,4 @@ a.desc:after { ...@@ -96,4 +103,4 @@ a.desc:after {
.nowrap { .nowrap {
white-space: nowrap; white-space: nowrap;
} }
\ No newline at end of file
...@@ -24,34 +24,11 @@ use yii\web\AssetManager; ...@@ -24,34 +24,11 @@ use yii\web\AssetManager;
class AssetPanel extends Panel class AssetPanel extends Panel
{ {
/** /**
* @var integer
*/
private $cssCount = 0;
/**
* @var integer
*/
private $jsCount = 0;
/**
* @var AssetBundle[]
*/
private $bundles = [];
/**
* @inheritdoc
*/
public function init()
{
parent::init();
Event::on(Application::className(), Application::EVENT_AFTER_ACTION, function () {
$this->bundles = $this->format(Yii::$app->view->assetManager->bundles);
});
}
/**
* @inheritdoc * @inheritdoc
*/ */
public function getName() public function getName()
{ {
return 'Asset bundles'; return 'Asset Bundles';
} }
/** /**
...@@ -75,6 +52,42 @@ class AssetPanel extends Panel ...@@ -75,6 +52,42 @@ class AssetPanel extends Panel
*/ */
public function save() public function save()
{ {
$bundles = Yii::$app->view->assetManager->bundles;
if (empty($bundles)) {
return [];
}
$data = [];
foreach ($bundles as $name => $bundle) {
if ($bundle instanceof AssetBundle) {
$data[$name] = (array) $bundle;
}
}
return $data;
$cssCount = 0;
$jsCount = 0;
foreach ($bundles as $bundle) {
$cssCount += count($bundle->css);
$jsCount += count($bundle->js);
array_walk($bundle->css, function(&$file, $key, $data) {
$file = Html::a($file, $data->baseUrl . '/' . $file, ['target' => '_blank']);
}, $bundle);
array_walk($bundle->js, function(&$file, $key, $data) {
$file = Html::a($file, $data->baseUrl . '/' . $file, ['target' => '_blank']);
}, $bundle);
array_walk($bundle->depends, function(&$depend) {
$depend = Html::a($depend, '#' . $depend);
});
$this->formatOptions($bundle->publishOptions);
$this->formatOptions($bundle->jsOptions);
$this->formatOptions($bundle->cssOptions);
}
$data = [ $data = [
'totalBundles' => count($this->bundles), 'totalBundles' => count($this->bundles),
'totalCssFiles' => $this->cssCount, 'totalCssFiles' => $this->cssCount,
......
<?php <?php
/* @var $panel yii\debug\panels\AssetPanel */ /* @var $panel yii\debug\panels\AssetPanel */
/* @var $bundles \yii\web\AssetBundle[] array */
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\Inflector;
?> ?>
<h1>Asset bundles</h1> <h1>Asset Bundles</h1>
<?php if (empty($panel->data)) {
echo '<p>No asset bundle was used.</p>';
return;
} ?>
<table class="table table-striped table-bordered"> <table class="table table-striped table-bordered">
<caption> <caption>
<p><b>Total bundles: <?= $panel->data['totalBundles'] ?></b>.</p> <p>Total <b><?= count($panel->data) ?></b> asset bundles were loaded.</p>
<p>CSS files: <?= $panel->data['totalCssFiles'] ?>, JS files: <?= $panel->data['totalJsFiles'] ?></p>
</caption> </caption>
<?php <?php
foreach ($panel->data['bundles'] as $key => $bundle) { foreach ($panel->data as $name => $bundle) {
?> ?>
<thead> <thead>
<tr> <tr>
<td colspan="2"><h3 id="<?= $key ?>"><?= $key ?></h3></td> <td colspan="2"><h3 id="<?= Inflector::camel2id($name) ?>"><?= $name ?></h3></td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<th>sourcePath</th> <th>sourcePath</th>
<td><?= Html::ul([$bundle->sourcePath], ['class' => 'trace', 'encode' => false]) ?></td> <td><?= Html::encode($bundle['sourcePath'] !== null ? $bundle['sourcePath'] : $bundle['basePath']) ?></td>
</tr> </tr>
<?php if ($bundle['basePath'] !== null): ?>
<tr>
<th>basePath</th>
<td><?= Html::encode($bundle['basePath']) ?></td>
</tr>
<?php endif; ?>
<?php if ($bundle['baseUrl'] !== null): ?>
<tr>
<th>baseUrl</th>
<td><?= Html::encode($bundle['baseUrl']) ?></td>
</tr>
<?php endif; ?>
<?php if (!empty($bundle['css'])): ?>
<tr> <tr>
<th>css</th> <th>css</th>
<td><?= Html::ul($bundle->css, ['class' => 'trace', 'encode' => false]) ?></td> <td><?= Html::ul($bundle['css'], ['class' => 'assets']) ?></td>
</tr> </tr>
<?php endif; ?>
<?php if (!empty($bundle['js'])): ?>
<tr> <tr>
<th>js</th> <th>js</th>
<td><?= Html::ul($bundle->js, ['class' => 'trace', 'encode' => false]) ?></td> <td><?= Html::ul($bundle['js'], ['class' => 'assets']) ?></td>
</tr> </tr>
<?php endif; ?>
<?php if (!empty($bundle['depends'])): ?>
<tr> <tr>
<th>depends</th> <th>depends</th>
<td><?= Html::ul($bundle->depends, ['class' => 'trace', 'encode' => false]) ?></td> <td><ul class="assets">
</tr> <?php foreach ($bundle['depends'] as $depend): ?>
<tr> <li><?= Html::a($depend, '#' . Inflector::camel2id($depend)) ?></li>
<th>publishOptions</th> <?php endforeach; ?>
<td><?= Html::ul($bundle->publishOptions, ['class' => 'trace', 'encode' => false]) ?></td> </ul></td>
</tr>
<tr>
<th>basePath</th>
<td><?= Html::ul([$bundle->basePath], ['class' => 'trace', 'encode' => false]) ?></td>
</tr>
<tr>
<th>baseUrl</th>
<td><?= Html::ul([$bundle->baseUrl], ['class' => 'trace', 'encode' => false]) ?></td>
</tr>
<tr>
<th>jsOptions</th>
<td><?= Html::ul($bundle->jsOptions, ['class' => 'trace']) ?></td>
</tr>
<tr>
<th>cssOptions</th>
<td><?= Html::ul($bundle->cssOptions, ['class' => 'trace']) ?></td>
</tr> </tr>
<?php endif; ?>
</tbody> </tbody>
<?php <?php
} }
......
<?php <?php
/* @var $panel yii\debug\panels\AssetPanel */ /* @var $panel yii\debug\panels\AssetPanel */
if (!empty($panel->data)):
?> ?>
<div class="yii-debug-toolbar-block"> <div class="yii-debug-toolbar-block">
<a href="<?= $panel->getUrl() ?>" title="Asset bundles count">Asset bundles <span class="label label-info"><?= $panel->data['totalBundles'] ?></span></a> <a href="<?= $panel->getUrl() ?>" title="Number of asset bundles loaded">Asset Bundles <span class="label label-info"><?= count($panel->data) ?></span></a>
</div> </div>
<?php endif; ?>
...@@ -212,6 +212,7 @@ Yii Framework 2 Change Log ...@@ -212,6 +212,7 @@ Yii Framework 2 Change Log
- Enh #4740: Added `yii\web\Session::addFlash()` (restyler) - Enh #4740: Added `yii\web\Session::addFlash()` (restyler)
- Enh #4897: Added `yii\helpers\FileHelper::mimeMagicFile` (qiangxue) - Enh #4897: Added `yii\helpers\FileHelper::mimeMagicFile` (qiangxue)
- Enh #5058: Added `$pageSize` parameter to `Pagination::createUrl()` to allow creating URLs with arbitrary page sizes (cdcchen, qiangxue) - Enh #5058: Added `$pageSize` parameter to `Pagination::createUrl()` to allow creating URLs with arbitrary page sizes (cdcchen, qiangxue)
- Enh #5089: Added asset debugger panel (arturf, qiangxue)
- Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue) - Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue)
- Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue) - Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue)
- Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue) - Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue)
......
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