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

Commit a945add

Browse files
authored
Merge pull request #1 from ggrachdev/dev
Beta версия 0.01
2 parents 802ba0e + 1942d13 commit a945add

30 files changed

+961
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/nbproject/
2-
/vendor/
2+
/vendor/
3+
/todo.txt

assets/DebugBar/js/initializer.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
var Ggrach = {
2+
DebugBar: {
3+
init: function () {
4+
document.addEventListener('DOMContentLoaded', function () {
5+
if (Ggrach.Utils.User.isAdmin())
6+
{
7+
if (Ggrach.Utils.Screen.isMobile())
8+
{
9+
document.querySelector('.ggrach__debug_bar').remove();
10+
} else
11+
{
12+
var $logsItems = document.querySelectorAll('[data-click="show_notice_panel"]');
13+
14+
if ($logsItems)
15+
{
16+
$logsItems.forEach(function (element) {
17+
element.addEventListener('click', function (e) {
18+
var type = e.target.dataset.typeNotice;
19+
20+
document.querySelectorAll('.ggrach__debug_bar__log').forEach(function (element) {
21+
22+
element.scrollTop = 0;
23+
24+
if (element.dataset.typeNotice !== type)
25+
{
26+
element.style.display = 'none';
27+
}
28+
29+
});
30+
31+
var $targetLogPanel = document.querySelector('.ggrach__debug_bar__log[data-type-notice="' + type + '"]');
32+
33+
$logsItems.forEach(function (el) {
34+
el.classList.remove('active');
35+
});
36+
37+
if ($targetLogPanel.style.display === 'block')
38+
{
39+
e.target.classList.remove('active');
40+
document.querySelector('body').style.overflow = null;
41+
$targetLogPanel.style.display = 'none';
42+
document.querySelector('.ggrach__overlay').style.display = 'none';
43+
} else
44+
{
45+
e.target.classList.add('active');
46+
document.querySelector('body').style.overflow = 'hidden';
47+
$targetLogPanel.style.display = 'block';
48+
document.querySelector('.ggrach__overlay').style.display = 'block';
49+
}
50+
});
51+
});
52+
}
53+
}
54+
}
55+
});
56+
}
57+
}
58+
};
59+
60+
Ggrach.Utils = {
61+
User: {
62+
isAdmin: function () {
63+
return document.getElementById('panel') &&
64+
document.getElementById('bx-panel-admin-tab');
65+
}
66+
},
67+
68+
Screen: {
69+
isMobile: function () {
70+
return window.matchMedia("(max-width: 1100px)").matches;
71+
}
72+
}
73+
};
74+
75+
Ggrach.DebugBar.init();

assets/DebugBar/themes/dark/theme.css

Whitespace-only changes.

assets/DebugBar/themes/general.css

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
.ggrach__debug_bar {
2+
width: 100% !important;
3+
position: fixed !important;
4+
bottom: 0 !important;
5+
height: 30px !important;
6+
z-index: 9999 !important;
7+
display: flex !important;
8+
align-items: center !important;
9+
}
10+
11+
.ggrach__overlay {
12+
position: fixed;
13+
top: 0;
14+
left: 0;
15+
width: 100%;
16+
height: 100%;
17+
background: #000000cc;
18+
z-index: 9998;
19+
}
20+
21+
.ggrach__debug_bar__item {
22+
-webkit-touch-callout: none; /* iOS Safari */
23+
-webkit-user-select: none; /* Chrome/Safari/Opera */
24+
-khtml-user-select: none; /* Konqueror */
25+
-moz-user-select: none; /* Firefox */
26+
-ms-user-select: none; /* Internet Explorer/Edge */
27+
user-select: none; /* Non-prefixed version, currently
28+
not supported by any browser */
29+
}
30+
31+
.ggrach__debug_bar > .ggrach__debug_bar__item {
32+
display: flex !important;
33+
line-height: 33px !important;
34+
justify-content: center !important;
35+
padding-left: 5px;
36+
padding-right: 5px;
37+
height: 30px !important;
38+
min-width: 30px !important;
39+
cursor: pointer !important;
40+
font-size: 16px !important;
41+
}
42+
43+
.ggrach__debug_bar__log {
44+
position: absolute !important;
45+
bottom: 30px !important;
46+
left: 0 !important;
47+
width: 100% !important;
48+
background: white !important;
49+
/* Отступы верхнего, правого, нижнего и левого края. */
50+
padding: 0px 15px 0px 0px !important;
51+
max-height: 500px !important;
52+
overflow: auto !important;
53+
}
54+
55+
.ggrach__debug_bar__log > pre {
56+
padding: 10px !important;
57+
padding-bottom: 7px !important;
58+
border-bottom: 1px solid #c3c3c3 !important;
59+
font-size: 13px !important;
60+
line-height: 16px !important;
61+
}
62+
63+
.ggrach__debug_bar__log > pre > code {
64+
white-space: nowrap !important;
65+
}
66+
67+
.ggrach__debug_bar__log > pre:last-child {
68+
border-bottom: unset !important;
69+
}
70+
71+
.ggrach__debug_bar__item.active {
72+
font-weight: bold !important;
73+
}
74+
75+
.type-notice-notice {
76+
background-color: #93c7ec !important;
77+
}
78+
79+
.type-notice-warning {
80+
background-color: #d8ff00 !important;
81+
}
82+
83+
.type-notice-error {
84+
background-color: red !important;
85+
}
86+
87+
.type-notice-success {
88+
background-color: green !important;
89+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.ggrach__debug_bar {
2+
background: rgb(246,246,246) !important;
3+
background: linear-gradient(180deg, rgba(246,246,246,1) 0%, rgba(255,255,255,1) 46%) !important;
4+
border-top: 1px solid #b3b3b3 !important;
5+
}
6+
7+
.ggrach__debug_bar__log {
8+
border-top: 1px solid #b3b3b3 !important;
9+
}
10+
11+
.ggrach__debug_bar__log__line {
12+
font-size: 12px;
13+
color: darkgrey;
14+
}

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,11 @@
77
"email": "[email protected]"
88
}
99
],
10+
"autoload": {
11+
"psr-4": {
12+
"GGrach\\BitrixDebugger\\": "src/BitrixDebugger",
13+
"GGrach\\Writer\\": "src/Writer"
14+
}
15+
},
1016
"require": {}
1117
}

events.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
// Добавляем дебаг-бар
4+
AddEventHandler("main", "OnEndBufferContent", "GgrachAddDebugBar");
5+
6+
function GgrachAddDebugBar(&$content) {
7+
8+
global $USER, $APPLICATION;
9+
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+
}

functions.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
/**
4+
* Красивая подстветка дебага
5+
*
6+
* @param type $data
7+
* @return type
8+
*/
9+
function ggrach_highlight_data($data = []) {
10+
11+
$viewResult = '';
12+
13+
$need_hide_blocks = true;
14+
15+
$ppr = function ($in, $opened, $margin = 5) use(&$ppr, $need_hide_blocks) {
16+
17+
$viewRes = '';
18+
19+
if (!\is_object($in) && !\is_array($in)) {
20+
return $in;
21+
}
22+
23+
if ($need_hide_blocks == true)
24+
$opened = '';
25+
26+
foreach ($in as $key => $value) {
27+
if (\is_object($value) || \is_array($value)) {
28+
$viewRes .= '<details style="margin-left:' . $margin . 'px" ' . $opened . '>';
29+
$viewRes .= '<summary style="cursor: pointer; margin-top: 5px; margin-bottom: 5px; text-decoration: underline;">';
30+
$viewRes .= (is_object($value)) ? $key . ' {' . count((array) $value) . '}' : $key . ' [' . count($value) . ']';
31+
$viewRes .= '</summary>';
32+
$viewRes .= $ppr($value, $opened, $margin + 5);
33+
$viewRes .= '</details>';
34+
} else {
35+
switch (gettype($value)) {
36+
case 'string':
37+
$bgc = 'red';
38+
$value = \strip_tags($value);
39+
if (\strlen($value) > 200) {
40+
$value = '[Очень длинная строка]';
41+
}
42+
43+
break;
44+
case 'integer':
45+
$bgc = 'green';
46+
break;
47+
}
48+
$viewRes .= '<div style="margin-left:' . $margin . 'px">' . $key . ' : <span style="color:' . $bgc . '">' . $value . '</span> <span style="color: blue;">(' . gettype($value) . ')</span></div>';
49+
}
50+
}
51+
52+
return $viewRes;
53+
};
54+
55+
$pp = function ($in, $opened = true) use ($ppr) {
56+
57+
$view = '';
58+
59+
if ($opened) {
60+
$opened = ' open';
61+
}
62+
63+
64+
$view .= '<div>';
65+
66+
if (is_object($in) or is_array($in)) {
67+
$view .= '<details' . $opened . '>';
68+
$view .= '<summary style="cursor: pointer; margin-top: 5px; margin-bottom: 5px; text-decoration: underline;">';
69+
$view .= (is_object($in)) ? 'Object {' . count((array) $in) . '}' : 'Array [' . count($in) . ']';
70+
$view .= '</summary>';
71+
$view .= $ppr($in, $opened);
72+
$view .= '</details>';
73+
} else {
74+
switch (gettype($in)) {
75+
case 'string':
76+
$bgc = 'red';
77+
78+
$in = \strip_tags($in);
79+
80+
if (\strlen($in) > 200) {
81+
$in = '[Очень длинная строка]';
82+
}
83+
84+
break;
85+
case 'integer':
86+
$bgc = 'green';
87+
break;
88+
}
89+
90+
$view .= '<div style="margin-left: 0px"><span style="color:' . $bgc . '">' . $in . '</span> <span style="color: blue;">(' . gettype($in) . ')</span></div>';
91+
}
92+
93+
94+
$view .= '</div>';
95+
96+
97+
return $view;
98+
};
99+
100+
$viewResult .= $pp($data, !$need_hide_blocks);
101+
102+
return $viewResult;
103+
}

0 commit comments

Comments
 (0)