index.php 3.14 KB
Newer Older
Qiang Xue committed
1 2 3
<?php

use yii\helpers\Html;
4 5
use yii\grid\GridView;
use yii\data\ArrayDataProvider;
Qiang Xue committed
6 7

/**
Alexander Makarov committed
8
 * @var \yii\web\View $this
Qiang Xue committed
9
 * @var array $manifest
Qiang Xue committed
10 11
 * @var \yii\debug\models\search\Debug $searchModel
 * @var ArrayDataProvider $dataProvider
Qiang Xue committed
12
 * @var \yii\debug\Panel[] $panels
Qiang Xue committed
13
 */
Qiang Xue committed
14

Qiang Xue committed
15
$this->title = 'Yii Debugger';
Qiang Xue committed
16
?>
Qiang Xue committed
17
<div class="default-index">
18 19


Tobias Munk committed
20 21 22 23 24 25 26 27 28 29
	<div id="yii-debug-toolbar" class="yii-debug-toolbar-top">
		<div class="yii-debug-toolbar-block title">
			<a href="#">
				<img width="29" height="30" alt="" src="<?= \yii\debug\Module::getYiiLogo() ?>">
				Yii Debugger
			</a>
		</div>
		<?php foreach ($panels as $panel): ?>
			<?= $panel->getSummary() ?>
		<?php endforeach; ?>
Qiang Xue committed
30
	</div>
Qiang Xue committed
31

32 33
	<div class="container">
		<div class="row">
34 35
<?php

36
if (isset($this->context->module->panels['db']) && isset($this->context->module->panels['request'])) {
37

38 39
	echo "			<h1>Available Debug Data</h1>";
	$timeFormatter = extension_loaded('intl') ? Yii::createObject(['class' => 'yii\i18n\Formatter']) : Yii::$app->formatter;
Mark committed
40

41 42 43 44 45
	echo GridView::widget([
		'dataProvider' => $dataProvider,
		'filterModel' => $searchModel,
		'rowOptions' => function ($model, $key, $index, $grid) use ($searchModel) {
			$dbPanel = $this->context->module->panels['db'];
Mark committed
46

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
			if ($searchModel->isCodeCritical($model['statusCode']) || $dbPanel->isQueryCountCritical($model['sqlCount'])) {
				return ['class'=>'danger'];
			} else {
				return [];
			}
		},
		'columns' => [
			['class' => 'yii\grid\SerialColumn'],
			[
				'attribute' => 'tag',
				'value' => function ($data) {
					return Html::a($data['tag'], ['view', 'tag' => $data['tag']]);
				},
				'format' => 'html',
			],
			[
				'attribute' => 'time',
				'value' => function ($data) use ($timeFormatter) {
					return $timeFormatter->asDateTime($data['time'], 'short');
				},
			],
			'ip',
			[
				'attribute' => 'sqlCount',
Mark committed
71
				'label' => 'Query Count',
72 73
				'value' => function ($data) {
					$dbPanel = $this->context->module->panels['db'];
Mark committed
74

75
					if ($dbPanel->isQueryCountCritical($data['sqlCount'])) {
Mark committed
76

77 78 79 80 81 82 83 84 85 86 87
						$content = Html::tag('b', $data['sqlCount']) . ' ' . Html::tag('span', '', ['class' => 'glyphicon glyphicon-exclamation-sign']);
						return Html::a($content, ['view', 'panel' => 'db', 'tag' => $data['tag']], [
							'title' => 'Too many queries. Allowed count is ' . $dbPanel->criticalQueryThreshold,
						]);

					} else {
						return $data['sqlCount'];
					}
				},
				'format' => 'html',
			],
Mark committed
88 89 90 91
			[
				'attribute' => 'mailCount',
				'visible' => isset($this->context->module->panels['mail']),
			],
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
			[
				'attribute' => 'method',
				'filter' => ['get' => 'GET', 'post' => 'POST', 'delete' => 'DELETE', 'put' => 'PUT', 'head' => 'HEAD']
			],
			[
				'attribute'=>'ajax',
				'value' => function ($data) {
					return $data['ajax'] ? 'Yes' : 'No';
				},
				'filter' => ['No', 'Yes'],
			],
			[
				'attribute' => 'url',
				'label' => 'URL',
			],
			[
				'attribute' => 'statusCode',
				'filter' => [200 => 200, 404 => 404, 403 => 403, 500 => 500],
				'label' => 'Status code'
			],
112
		],
113 114 115 116 117 118 119
	]);

} else {
	echo "<div class='alert alert-warning'>No data available. Panel <code>db</code> or <code>request</code> not found.</div>";
}

?>
Qiang Xue committed
120 121
		</div>
	</div>
Qiang Xue committed
122
</div>