From d5cd823492f3fcc6a77b9d8ccb0c8380b6c5bae5 Mon Sep 17 00:00:00 2001
From: Qiang Xue <qiang.xue@gmail.com>
Date: Mon, 8 Jul 2013 11:21:14 -0400
Subject: [PATCH] minor fixes.

---
 framework/yii/debug/LogTarget.php                     |  6 ++++--
 framework/yii/debug/controllers/DefaultController.php | 16 +++++++++++-----
 framework/yii/debug/views/default/view.php            | 24 ++++++++++++------------
 3 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/framework/yii/debug/LogTarget.php b/framework/yii/debug/LogTarget.php
index 98c2624..3e36cd5 100644
--- a/framework/yii/debug/LogTarget.php
+++ b/framework/yii/debug/LogTarget.php
@@ -50,7 +50,8 @@ class LogTarget extends Target
 			$manifest = json_decode(file_get_contents($indexFile), true);
 		}
 		$request = Yii::$app->getRequest();
-		$manifest[$this->tag] = array(
+		$manifest[$this->tag] = $summary = array(
+			'tag' => $this->tag,
 			'url' => $request->getAbsoluteUrl(),
 			'ajax' => $request->getIsAjax(),
 			'method' => $request->getMethod(),
@@ -64,6 +65,7 @@ class LogTarget extends Target
 		foreach ($this->module->panels as $id => $panel) {
 			$data[$id] = $panel->save();
 		}
+		$data['summary'] = $summary;
 		file_put_contents($dataFile, json_encode($data));
 		file_put_contents($indexFile, json_encode($manifest));
 	}
@@ -86,7 +88,7 @@ class LogTarget extends Target
 
 	protected function gc(&$manifest)
 	{
-		if (rand(0, 100) < 5 && count($manifest) > $this->module->historySize) {
+		if (count($manifest) > $this->module->historySize + 10) {
 			$n = count($manifest) - $this->module->historySize;
 			foreach (array_keys($manifest) as $tag) {
 				$file = $this->module->dataPath . "/$tag.json";
diff --git a/framework/yii/debug/controllers/DefaultController.php b/framework/yii/debug/controllers/DefaultController.php
index d4102ee..dd01412 100644
--- a/framework/yii/debug/controllers/DefaultController.php
+++ b/framework/yii/debug/controllers/DefaultController.php
@@ -17,9 +17,15 @@ use yii\web\HttpException;
  */
 class DefaultController extends Controller
 {
-	/** @var  \yii\debug\Module */
-	public $module;
 	public $layout = 'main';
+	/**
+	 * @var  \yii\debug\Module
+	 */
+	public $module;
+	/**
+	 * @var array the summary data (e.g. URL, time)
+	 */
+	public $summary;
 
 	public function actionIndex()
 	{
@@ -34,7 +40,7 @@ class DefaultController extends Controller
 			$tags = array_keys($this->getManifest());
 			$tag = reset($tags);
 		}
-		$meta = $this->loadData($tag);
+		$this->loadData($tag);
 		if (isset($this->module->panels[$panel])) {
 			$activePanel = $this->module->panels[$panel];
 		} else {
@@ -42,7 +48,7 @@ class DefaultController extends Controller
 		}
 		return $this->render('view', array(
 			'tag' => $tag,
-			'meta' => $meta,
+			'summary' => $this->summary,
 			'manifest' => $this->getManifest(),
 			'panels' => $this->module->panels,
 			'activePanel' => $activePanel,
@@ -93,7 +99,7 @@ class DefaultController extends Controller
 					unset($this->module->panels[$id]);
 				}
 			}
-			return $manifest[$tag];
+			$this->summary = $data['summary'];
 		} else {
 			throw new HttpException(404, "Unable to find debug data tagged with '$tag'.");
 		}
diff --git a/framework/yii/debug/views/default/view.php b/framework/yii/debug/views/default/view.php
index 9775880..e71e13e 100644
--- a/framework/yii/debug/views/default/view.php
+++ b/framework/yii/debug/views/default/view.php
@@ -4,7 +4,7 @@ use yii\helpers\Html;
 
 /**
  * @var \yii\base\View $this
- * @var array $meta
+ * @var array $summary
  * @var string $tag
  * @var array $manifest
  * @var \yii\debug\Panel[] $panels
@@ -51,11 +51,11 @@ $this->title = 'Yii Debugger';
 						<ul class="dropdown-menu">
 							<?php
 							$count = 0;
-							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);
+							foreach ($manifest as $meta) {
+								$label = $meta['tag'] . ': ' . $meta['method'] . ' ' . $meta['url'] . ($meta['ajax'] ? ' (AJAX)' : '')
+									. ', ' . date('Y-m-d h:i:s a', $meta['time'])
+									. ', ' . $meta['ip'];
+								$url = array('view', 'tag' => $meta['tag']);
 								echo '<li>' . Html::a(Html::encode($label), $url) . '</li>';
 								if (++$count >= 10) {
 									break;
@@ -64,12 +64,12 @@ $this->title = 'Yii Debugger';
 							?>
 						</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']; ?>
+					<?php echo $summary['tag']; ?>:
+					<?php echo $summary['method']; ?>
+					<?php echo Html::a(Html::encode($summary['url']), $summary['url'], array('class' => 'label')); ?>
+					<?php echo $summary['ajax'] ? ' (AJAX)' : ''; ?>
+					at <?php echo date('Y-m-d h:i:s a', $summary['time']); ?>
+					by <?php echo $summary['ip']; ?>
 				</div>
 				<?php echo $activePanel->getDetail(); ?>
 			</div>
--
libgit2 0.27.1