Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: new devbar web component data support
  • Loading branch information
JiLiZART committed Sep 28, 2020
commit 722adcdebe046572f2a6aa78d286aecef15f026c
30 changes: 30 additions & 0 deletions src/DevbarAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace yii\debug;

use yii\web\AssetBundle;

/**
* Debugger asset bundle
*
* @author Nikolay Kostyurin <[email protected]>
* @since 2.0
*/
class DevbarAsset extends AssetBundle
{
/**
* {@inheritdoc}
*/
public $sourcePath = '@npm/yii2-devtools.js/dist';
/**
* {@inheritdoc}
*/
public $js = [
YII_DEBUG ? 'dev-bar.js' : 'dev-bar.min.js'
];
}
11 changes: 7 additions & 4 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);

Expand All @@ -370,7 +370,10 @@ public function getToolbarHtml()
$this->skipAjaxRequestUrl[$key] = Url::to($route);
}
}
return '<div id="yii-debug-toolbar" data-url="' . Html::encode($url) . '" data-skip-urls="' . htmlspecialchars(json_encode($this->skipAjaxRequestUrl)) . '" style="display:none" class="yii-debug-toolbar-bottom"></div>';

DevbarAsset::register(Yii::$app->view);

return '<dev-bar url="' . Html::encode($url) . '" skip-urls="' . htmlspecialchars(json_encode($this->skipAjaxRequestUrl)) . '"></dev-bar>';
}

/**
Expand All @@ -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 '<style>' . $view->renderPhpFile(__DIR__ . '/assets/css/toolbar.css') . '</style>';
echo '<script>' . $view->renderPhpFile(__DIR__ . '/assets/js/toolbar.js') . '</script>';
// echo '<style>' . $view->renderPhpFile(__DIR__ . '/assets/css/toolbar.css') . '</style>';
// echo '<script>__YII2_DEVTOOLS__ = ' . json_encode($data) . '</script>';
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
44 changes: 44 additions & 0 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down
21 changes: 21 additions & 0 deletions src/panels/AssetPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
38 changes: 38 additions & 0 deletions src/panels/ConfigPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
24 changes: 24 additions & 0 deletions src/panels/DbPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions src/panels/DumpPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
16 changes: 16 additions & 0 deletions src/panels/EventPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ public function getSummary()
]);
}

public function getSummaryData()
{
return [
"title" => "Events",
"iframe" => $this->getUrl(),
"content" => [
[
"text" => "Events"
],
[
"label" => count($this->data)
]
]
];
}

/**
* {@inheritdoc}
*/
Expand Down
38 changes: 38 additions & 0 deletions src/panels/LogPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}
*/
Expand Down
18 changes: 18 additions & 0 deletions src/panels/MailPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
27 changes: 27 additions & 0 deletions src/panels/ProfilingPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down
Loading