Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit 2bd6c05

Browse files
committed
Сделана рабочая дебаг-панель, улучшен код
1 parent 3fb4dd5 commit 2bd6c05

File tree

6 files changed

+142
-17
lines changed

6 files changed

+142
-17
lines changed

assets/DebugBar/js/initializer.js

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,39 @@ var Ggrach = {
44
document.addEventListener('DOMContentLoaded', function () {
55
if (Ggrach.Utils.User.isAdmin())
66
{
7-
var parent = document.querySelector("body");
8-
var debugBarWrapper = document.createElement("section");
9-
debugBarWrapper.classList.add('ggrach__debug_bar');
7+
var $logsItems = document.querySelectorAll('[data-click="show_notice_panel"]');
108

11-
parent.prepend(debugBarWrapper);
12-
13-
for (var typeNotice in GgrachDebuggerLogProvider)
9+
if ($logsItems)
1410
{
15-
var arrNotices = GgrachDebuggerLogProvider[typeNotice];
16-
var viewTypeNotice = document.createElement("div");
17-
viewTypeNotice.classList.add('ggrach__debug_bar__item');
18-
viewTypeNotice.classList.add('type-notice-' + typeNotice);
19-
viewTypeNotice.innerHTML = arrNotices.length;
20-
debugBarWrapper.prepend(viewTypeNotice);
11+
$logsItems.forEach(function (element) {
12+
element.addEventListener('click', function (e) {
13+
var type = e.target.dataset.typeNotice;
14+
15+
document.querySelectorAll('.ggrach__debug_bar__log').forEach(function (element) {
16+
17+
element.scrollTop = 0;
18+
19+
if (element.dataset.typeNotice !== type)
20+
{
21+
element.style.display = 'none';
22+
}
23+
24+
});
25+
26+
var $targetLogPanel = document.querySelector('.ggrach__debug_bar__log[data-type-notice="' + type + '"]');
27+
28+
if ($targetLogPanel.style.display === 'block')
29+
{
30+
31+
document.querySelector('body').style.overflow = null;
32+
$targetLogPanel.style.display = 'none';
33+
} else
34+
{
35+
document.querySelector('body').style.overflow = 'hidden';
36+
$targetLogPanel.style.display = 'block';
37+
}
38+
});
39+
});
2140
}
2241
}
2342
});

assets/DebugBar/themes/general.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,33 @@
2020
font-size: 16px !important;
2121
}
2222

23+
.ggrach__debug_bar__log {
24+
position: absolute !important;
25+
bottom: 30px !important;
26+
left: 0 !important;
27+
width: 100% !important;
28+
background: white !important;
29+
/* Отступы верхнего, правого, нижнего и левого края. */
30+
padding: 0px 15px 0px 0px !important;
31+
max-height: 500px !important;
32+
overflow: auto !important;
33+
}
34+
35+
.ggrach__debug_bar__log > pre {
36+
padding: 10px !important;
37+
border-bottom: 1px solid #c3c3c3 !important;
38+
font-size: 13px !important;
39+
line-height: 16px !important;
40+
}
41+
42+
.ggrach__debug_bar__log > pre > code {
43+
white-space: nowrap !important;
44+
}
45+
46+
.ggrach__debug_bar__log > pre:last-child {
47+
border-bottom: unset !important;
48+
}
49+
2350
.type-notice-notice {
2451
background-color: #93c7ec !important;
2552
}

assets/DebugBar/themes/light/theme.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
background: rgb(246,246,246) !important;
33
background: linear-gradient(180deg, rgba(246,246,246,1) 0%, rgba(255,255,255,1) 46%) !important;
44
border-top: 1px solid #b3b3b3 !important;
5+
}
6+
7+
.ggrach__debug_bar__log {
8+
border-top: 1px solid #b3b3b3 !important;
59
}

events.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,29 @@
33
// Добавляем дебаг-бар
44
AddEventHandler("main", "OnEndBufferContent", "GgrachAddDebugBar");
55

6-
function GgrachAddDebugBar(&$content)
7-
{
8-
$logData = '<script> var GgrachDebuggerLogProvider = '.CUtil::PhpToJSObject(GD()->getLog()).'; </script>';
9-
$content = \str_replace('</body>', $logData.'</body>', $content);
10-
}
6+
function GgrachAddDebugBar(&$content) {
7+
8+
global $USER, $APPLICATION;
119

10+
if (
11+
strpos($APPLICATION->GetCurDir(), "/bitrix/") !== false) {
12+
return;
13+
}
14+
15+
if ($APPLICATION->GetProperty("save_kernel") == "Y") {
16+
return;
17+
}
18+
19+
if(!\is_object($USER))
20+
{
21+
return;
22+
}
23+
24+
if(!$USER->IsAdmin())
25+
{
26+
return;
27+
}
28+
29+
$logData = \GGrach\BitrixDebugger\Representer\DebugBarRepresenter::render(GD());
30+
$content = \str_replace('</body>', $logData . '</body>', $content);
31+
}

initializer.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"\GGrach\BitrixDebugger\Configurator\DebugBarConfigurator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Configurator/DebugBarConfigurator.php",
1717
"\GGrach\BitrixDebugger\Cache\RuntimeCache" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Cache/RuntimeCache.php",
1818
"\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Validator/ShowModeDebuggerValidator.php",
19+
"\GGrach\BitrixDebugger\Representer\DebugBarRepresenter" => $ggrachDebuggerRootPath . "/src/BitrixDebugger/Representer/DebugBarRepresenter.php",
20+
21+
1922
"\GGrach\Writer\FileWriter" => $ggrachDebuggerRootPath . "/src/Writer/FileWriter.php",
2023
"\GGrach\Writer\Contract\WritableContract" => $ggrachDebuggerRootPath . "/src/Writer/Contract/WritableContract.php"
2124
]);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace GGrach\BitrixDebugger\Representer;
4+
5+
use \GGrach\BitrixDebugger\Debugger\Debugger;
6+
7+
/**
8+
* Description of DebugBarRepresenter
9+
*
10+
* @author ggrachdev
11+
*/
12+
class DebugBarRepresenter {
13+
14+
public static function render(Debugger $debugger): string {
15+
16+
$log = $debugger->getLog();
17+
18+
if(empty($log)) return '';
19+
20+
$view = '<section class="ggrach__debug_bar">';
21+
22+
if (!empty($log)) {
23+
foreach ($log as $typeLog => $arLogs) {
24+
$view .= '<div class="ggrach__debug_bar__item type-notice-' . $typeLog . '" data-type-notice="' . $typeLog . '" data-click="show_notice_panel">';
25+
$view .= \sizeof($arLogs);
26+
$view .= '</div>';
27+
28+
$view .= '<div class="ggrach__debug_bar__log" data-type-notice="' . $typeLog . '" style="display: none;">';
29+
foreach ($arLogs as $logValue) {
30+
31+
$logValue = \strip_tags($logValue);
32+
33+
if (is_string($logValue)) {
34+
if (\strlen($logValue) > 200) {
35+
$logValue = '[String]';
36+
}
37+
}
38+
39+
$view .= str_replace(['<span style="color: #0000BB">&lt;?</span>', '<span style="color: #0000BB">?&gt;</span>', '&lt;?', '?&gt;', '&lt;?php'], ['', '', '', ''], '<pre>' . \highlight_string('<?' . \var_export($logValue, true) . '?>', true) . '</pre>');
40+
}
41+
$view .= '</div>';
42+
}
43+
}
44+
45+
$view .= '</section>';
46+
47+
$view .= '<script> var GgrachDebuggerLogProvider = ' . \CUtil::PhpToJSObject(GD()->getLog()) . '; </script>';
48+
49+
return $view;
50+
}
51+
52+
}

0 commit comments

Comments
 (0)