diff --git a/src/DevbarAsset.php b/src/DevbarAsset.php
new file mode 100644
index 000000000..870503cd5
--- /dev/null
+++ b/src/DevbarAsset.php
@@ -0,0 +1,30 @@
+
+ * @since 2.0
+ */
+class DevbarAsset extends AssetBundle
+{
+ /**
+ * {@inheritdoc}
+ */
+ public $baseUrl = 'https://unpkg.com/@devbar/toolbar/dist/';
+ /**
+ * {@inheritdoc}
+ */
+ public $js = [
+ YII_DEBUG ? 'dev-bar.js' : 'dev-bar.min.js'
+ ];
+}
diff --git a/src/Module.php b/src/Module.php
index f22aa50bd..4844425f3 100644
--- a/src/Module.php
+++ b/src/Module.php
@@ -361,7 +361,7 @@ protected function resetGlobalSettings()
public function getToolbarHtml()
{
$url = Url::toRoute([
- '/' . $this->id . '/default/toolbar',
+ '/' . $this->id . '/default/toolbar-data',
'tag' => $this->logTarget->tag,
]);
@@ -370,7 +370,10 @@ public function getToolbarHtml()
$this->skipAjaxRequestUrl[$key] = Url::to($route);
}
}
- return '
';
+
+ DevbarAsset::register(Yii::$app->view);
+
+ return '';
}
/**
@@ -390,8 +393,8 @@ public function renderToolbar($event)
echo $view->renderDynamic('return Yii::$app->getModule("' . $this->id . '")->getToolbarHtml();');
// echo is used in order to support cases where asset manager is not available
- echo '';
- echo '';
+// echo '';
+// echo '';
}
/**
diff --git a/src/Panel.php b/src/Panel.php
index aafaaba1e..5492d8778 100644
--- a/src/Panel.php
+++ b/src/Panel.php
@@ -75,6 +75,14 @@ public function getSummary()
return '';
}
+ /**
+ * @return array variables for content that is displayed at debug toolbar
+ */
+ public function getSummaryData()
+ {
+ return [];
+ }
+
/**
* @return string content that is displayed in debugger detail view
*/
diff --git a/src/controllers/DefaultController.php b/src/controllers/DefaultController.php
index bfd87adbc..a5ba129a7 100644
--- a/src/controllers/DefaultController.php
+++ b/src/controllers/DefaultController.php
@@ -9,6 +9,7 @@
use Yii;
use yii\debug\models\search\Debug;
+use yii\debug\Module;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\web\Response;
@@ -147,6 +148,49 @@ public function actionToolbar($tag)
]);
}
+ /**
+ * Toolbar action
+ *
+ * @param string $tag
+ * @return string
+ * @throws NotFoundHttpException
+ */
+ public function actionToolbarData($tag)
+ {
+ $this->loadData($tag, 5);
+
+ Yii::$app->response->format = Response::FORMAT_JSON;
+
+ $tabs = [];
+ foreach ($this->module->panels as $panel) {
+ $data = $panel->getSummaryData();
+
+ if (!empty($data)) {
+ $tabs[] = $data;
+ } else {
+ $html = $panel->hasError() ? $panel->getError()->getMessage() : $panel->getSummary();
+
+ if ($html) {
+ $tabs[] = [
+ "title" => $panel->getName(),
+ "iframe" => $panel->getUrl(),
+ "html" => $panel->hasError() ? $panel->getError()->getMessage() : $panel->getSummary()
+ ];
+ }
+ }
+ }
+
+ return new Response([
+ "format" => "json",
+ "data" => [
+ "title" => "Yii 2 Devtools",
+ "logo" => Module::getYiiLogo(),
+ "placement" => "bottom-right",
+ "tabs" => $tabs,
+ ]
+ ]);
+ }
+
/**
* Download mail action
*
diff --git a/src/panels/AssetPanel.php b/src/panels/AssetPanel.php
index d06420329..df94f9c71 100644
--- a/src/panels/AssetPanel.php
+++ b/src/panels/AssetPanel.php
@@ -37,6 +37,27 @@ public function getSummary()
return Yii::$app->view->render('panels/assets/summary', ['panel' => $this]);
}
+ /**
+ * {@inheritdoc}
+ */
+ public function getSummaryData()
+ {
+
+ return [
+ "title" => "Assets",
+ "iframe" => $this->getUrl(),
+ "content" => [
+ [
+ "text" => "Asset Bundles",
+ ],
+ [
+ "label" => count($this->data),
+ "type" => "info"
+ ]
+ ]
+ ];
+ }
+
/**
* {@inheritdoc}
*/
diff --git a/src/panels/ConfigPanel.php b/src/panels/ConfigPanel.php
index 4ec5d1bf7..bf6060cb7 100644
--- a/src/panels/ConfigPanel.php
+++ b/src/panels/ConfigPanel.php
@@ -37,6 +37,44 @@ public function getSummary()
return Yii::$app->view->render('panels/config/summary', ['panel' => $this]);
}
+ /**
+ * {@inheritdoc}
+ */
+ public function getSummaryData()
+ {
+// {
+// "title": "Version",
+// "route": "config",
+// "content": [
+// {
+// "label": "2.0.15-dev"
+// },
+// {
+// "text": "PHP"
+// },
+// {
+// "label": "7.1.13"
+// }
+// ]
+// },
+
+ return [
+ "title" => "Config",
+ "iframe" => $this->getUrl(),
+ "content" => [
+ [
+ "label" => $this->data['application']['yii']
+ ],
+ [
+ "text" => "PHP",
+ ],
+ [
+ "label" => $this->data['php']['version']
+ ]
+ ]
+ ];
+ }
+
/**
* {@inheritdoc}
*/
diff --git a/src/panels/DbPanel.php b/src/panels/DbPanel.php
index 40dc2ff27..3fb23e72e 100644
--- a/src/panels/DbPanel.php
+++ b/src/panels/DbPanel.php
@@ -104,6 +104,30 @@ public function getSummary()
]);
}
+ public function getSummaryData()
+ {
+ $timings = $this->calculateTimings();
+ $queryCount = count($timings);
+ $queryTime = number_format($this->getTotalQueryTime($timings) * 1000) . ' ms';
+
+ return [
+ "title" => "DB",
+ "iframe" => $this->getUrl(),
+ "content" => [
+ [
+ "text" => $this->getSummaryName(),
+ ],
+ [
+ "label" => (string) $queryCount,
+ "type" => "info"
+ ],
+ [
+ "label" => (string) $queryTime,
+ ]
+ ]
+ ];
+ }
+
/**
* {@inheritdoc}
* @throws InvalidConfigException
diff --git a/src/panels/DumpPanel.php b/src/panels/DumpPanel.php
index 16ebe8377..16b261bac 100644
--- a/src/panels/DumpPanel.php
+++ b/src/panels/DumpPanel.php
@@ -65,6 +65,23 @@ public function getSummary()
return Yii::$app->view->render('panels/dump/summary', ['panel' => $this]);
}
+ public function getSummaryData()
+ {
+ return [
+ "title" => "Dump",
+ "iframe" => $this->getUrl(),
+ "content" => [
+ [
+ "text" => "Dump",
+ ],
+ [
+ "label" => (string) count($this->data),
+ "type" => "info"
+ ],
+ ]
+ ];
+ }
+
/**
* {@inheritdoc}
*/
diff --git a/src/panels/EventPanel.php b/src/panels/EventPanel.php
index 5eafcd3c0..df22572ed 100644
--- a/src/panels/EventPanel.php
+++ b/src/panels/EventPanel.php
@@ -68,6 +68,22 @@ public function getSummary()
]);
}
+ public function getSummaryData()
+ {
+ return [
+ "title" => "Events",
+ "iframe" => $this->getUrl(),
+ "content" => [
+ [
+ "text" => "Events"
+ ],
+ [
+ "label" => count($this->data)
+ ]
+ ]
+ ];
+ }
+
/**
* {@inheritdoc}
*/
diff --git a/src/panels/LogPanel.php b/src/panels/LogPanel.php
index ac6f277ec..f7d974fe1 100644
--- a/src/panels/LogPanel.php
+++ b/src/panels/LogPanel.php
@@ -11,6 +11,7 @@
use yii\debug\models\search\Log;
use yii\debug\Panel;
use yii\log\Logger;
+use yii\log\Target;
/**
* Debugger panel that collects and displays logs.
@@ -42,6 +43,43 @@ public function getSummary()
return Yii::$app->view->render('panels/log/summary', ['data' => $this->data, 'panel' => $this]);
}
+ public function getSummaryData()
+ {
+ $errorCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_ERROR));
+ $warningCount = count(Target::filterMessages($this->data['messages'], Logger::LEVEL_WARNING));
+
+ $content = [
+ [
+ "text" => "Logs"
+ ],
+ [
+ "label" => count($this->data['messages'])
+ ]
+ ];
+
+ if ($errorCount) {
+ $content[] = [
+ "url" => $this->getUrl(['Log[level]' => Logger::LEVEL_ERROR]),
+ "label" => $errorCount,
+ "type" => "danger",
+ ];
+ }
+
+ if ($warningCount) {
+ $content[] = [
+ "url" => $this->getUrl(['Log[level]' => Logger::LEVEL_WARNING]),
+ "label" => $warningCount,
+ "type" => "warning"
+ ];
+ }
+
+ return [
+ "title" => "Logs",
+ "iframe" => $this->getUrl(),
+ "content" => $content
+ ];
+ }
+
/**
* {@inheritdoc}
*/
diff --git a/src/panels/MailPanel.php b/src/panels/MailPanel.php
index ec99bc5bf..2a1b8b385 100644
--- a/src/panels/MailPanel.php
+++ b/src/panels/MailPanel.php
@@ -112,6 +112,24 @@ public function getSummary()
]);
}
+ public function getSummaryData()
+ {
+ $mailCount = is_array($this->data) ? count($this->data) : '⚠';
+
+ return [
+ "title" => "Mail",
+ "iframe" => $this->getUrl(),
+ "content" => [
+ [
+ "text" => "Mail"
+ ],
+ [
+ "label" => $mailCount,
+ ]
+ ]
+ ];
+ }
+
/**
* {@inheritdoc}
*/
diff --git a/src/panels/ProfilingPanel.php b/src/panels/ProfilingPanel.php
index 487ff59e1..ddbff6b2a 100644
--- a/src/panels/ProfilingPanel.php
+++ b/src/panels/ProfilingPanel.php
@@ -46,6 +46,33 @@ public function getSummary()
]);
}
+ public function getSummaryData()
+ {
+ $time = number_format($this->data['time'] * 1000) . ' ms';
+ $memory = sprintf('%.3f MB', $this->data['memory'] / 1048576);
+
+ return [
+ "title" => "Profile",
+ "iframe" => $this->getUrl(),
+ "content" => [
+ [
+ "icon" => "timer",
+ ],
+ [
+ "label" => $time,
+ "type" => "info"
+ ],
+ [
+ "icon" => "memory",
+ ],
+ [
+ "label" => $memory,
+ "type" => "info"
+ ]
+ ]
+ ];
+ }
+
/**
* {@inheritdoc}
*/
diff --git a/src/panels/RequestPanel.php b/src/panels/RequestPanel.php
index ba6228db9..0b2a11d16 100644
--- a/src/panels/RequestPanel.php
+++ b/src/panels/RequestPanel.php
@@ -10,6 +10,8 @@
use Yii;
use yii\base\InlineAction;
use yii\debug\Panel;
+use yii\helpers\Html;
+use yii\web\Response;
/**
* Debugger panel that collects and displays request data.
@@ -43,6 +45,36 @@ public function getSummary()
return Yii::$app->view->render('panels/request/summary', ['panel' => $this]);
}
+ public function getSummaryData()
+ {
+ $statusCode = $this->data['statusCode'];
+ if ($statusCode === null) {
+ $statusCode = 200;
+ }
+ if ($statusCode >= 200 && $statusCode < 300) {
+ $type = 'success';
+ } elseif ($statusCode >= 300 && $statusCode < 400) {
+ $type = 'info';
+ } else {
+ $type = 'danger';
+ }
+
+ $statusText = Html::encode(isset(Response::$httpStatuses[$statusCode]) ? Response::$httpStatuses[$statusCode] : '');
+
+ return [
+ "title" => "Request",
+ "content" => [
+ [
+ "text" => $statusText . " Status"
+ ],
+ [
+ "label" => $statusCode,
+ "type" => $type,
+ ]
+ ]
+ ];
+ }
+
/**
* {@inheritdoc}
*/
diff --git a/src/panels/RouterPanel.php b/src/panels/RouterPanel.php
index 84e73626c..1ff73fe7e 100644
--- a/src/panels/RouterPanel.php
+++ b/src/panels/RouterPanel.php
@@ -13,6 +13,7 @@
use yii\debug\models\router\CurrentRoute;
use yii\debug\models\router\RouterRules;
use yii\debug\Panel;
+use yii\helpers\Html;
use yii\log\Logger;
/**
@@ -73,6 +74,22 @@ public function getSummary()
return Yii::$app->view->render('panels/router/summary', ['panel' => $this]);
}
+ public function getSummaryData()
+ {
+ return [
+ "title" => "Router",
+ "iframe" => $this->getUrl(),
+ "content" => [
+ [
+ "text" => "Route"
+ ],
+ [
+ "label" => Html::encode($this->data['route'])
+ ]
+ ]
+ ];
+ }
+
/**
* {@inheritdoc}
*/
diff --git a/src/panels/UserPanel.php b/src/panels/UserPanel.php
index bb1fb3933..4deefee92 100644
--- a/src/panels/UserPanel.php
+++ b/src/panels/UserPanel.php
@@ -19,6 +19,7 @@
use yii\debug\Panel;
use yii\filters\AccessRule;
use yii\helpers\ArrayHelper;
+use yii\helpers\Html;
use yii\helpers\VarDumper;
use yii\web\IdentityInterface;
use yii\web\User;
@@ -212,6 +213,52 @@ public function getSummary()
return Yii::$app->view->render('panels/user/summary', ['panel' => $this]);
}
+ public function getSummaryData()
+ {
+ $content = [];
+
+ if (!$this->data['id']) {
+ $content[] = [
+ "label" => "Guest"
+ ];
+ } else {
+ if ($this->getUser()->isGuest || $this->userSwitch->isMainUser()) {
+ $content[] = [
+ [
+ "text" => Html::encode($this->getName())
+ ],
+ [
+ "label" => $this->data['id'],
+ "type" => "info"
+ ]
+ ];
+ } else {
+ $content[] = [
+ [
+ "text" => Html::encode($this->getName()) . " switching"
+ ],
+ [
+ "label" => $this->data['id'],
+ "type" => "warning",
+ ]
+ ];
+ }
+ if ($this->canSwitchUser()) {
+ $content[] = [
+ "icon" => "switch",
+ "action" => "userSwitch", // @TODO: execute global function
+ ];
+ }
+ }
+
+
+ return [
+ "title" => "User",
+ "iframe" => $this->getUrl(),
+ "content" => $content
+ ];
+ }
+
/**
* {@inheritdoc}
*/