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

Commit 3fb4dd5

Browse files
committed
Сделан набросок дебаг-бара для светлой темы
1 parent 50c4d69 commit 3fb4dd5

File tree

8 files changed

+116
-17
lines changed

8 files changed

+116
-17
lines changed

assets/DebugBar/js/initializer.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
1-
var GDB = {
2-
1+
var Ggrach = {
2+
DebugBar: {
3+
init: function () {
4+
document.addEventListener('DOMContentLoaded', function () {
5+
if (Ggrach.Utils.User.isAdmin())
6+
{
7+
var parent = document.querySelector("body");
8+
var debugBarWrapper = document.createElement("section");
9+
debugBarWrapper.classList.add('ggrach__debug_bar');
10+
11+
parent.prepend(debugBarWrapper);
12+
13+
for (var typeNotice in GgrachDebuggerLogProvider)
14+
{
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);
21+
}
22+
}
23+
});
24+
}
25+
}
26+
};
27+
28+
Ggrach.Utils = {
29+
User: {
30+
isAdmin: function () {
31+
return document.getElementById('panel') &&
32+
document.getElementById('bx-panel-admin-tab');
33+
}
34+
}
335
};
436

5-
console.log(12345);
37+
Ggrach.DebugBar.init();

assets/DebugBar/themes/general.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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__debug_bar > .ggrach__debug_bar__item {
12+
display: flex !important;
13+
align-items: center !important;
14+
justify-content: center !important;
15+
padding-left: 5px;
16+
padding-right: 5px;
17+
height: 30px !important;
18+
min-width: 30px !important;
19+
cursor: pointer !important;
20+
font-size: 16px !important;
21+
}
22+
23+
.type-notice-notice {
24+
background-color: #93c7ec !important;
25+
}
26+
27+
.type-notice-warning {
28+
background-color: #d8ff00 !important;
29+
}
30+
31+
.type-notice-error {
32+
background-color: red !important;
33+
}
34+
35+
.type-notice-success {
36+
background-color: green !important;
37+
}

assets/DebugBar/themes/light/light.css

Whitespace-only changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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+
}

events.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
// Добавляем дебаг-бар
4+
AddEventHandler("main", "OnEndBufferContent", "GgrachAddDebugBar");
5+
6+
function GgrachAddDebugBar(&$content)
7+
{
8+
$logData = '<script> var GgrachDebuggerLogProvider = '.CUtil::PhpToJSObject(GD()->getLog()).'; </script>';
9+
$content = \str_replace('</body>', $logData.'</body>', $content);
10+
}
11+

initializer.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
// Need include this file in init.php
4+
// include 'BitrixDebugger/initializer.php';
45

56
use Bitrix\Main\Loader;
67
use Bitrix\Main\Page\Asset;
@@ -36,26 +37,33 @@
3637
*/
3738
$GD->setShowModes(['code', 'debug_bar']);
3839

39-
global $USER;
40-
41-
if ($USER && $USER->IsAdmin()) {
42-
Asset::getInstance()->addJs($ggrachDebuggerRootPath . "/assets/DebugBar/js/initializer.js");
43-
Asset::getInstance()->addCss($ggrachDebuggerRootPath . "/assets/DebugBar/themes/${$ggrachDebugBarConfigurator->getColorTheme()}/fix.css");
40+
function GD() {
41+
global $GD;
42+
return $GD;
4443
}
4544

45+
46+
Asset::getInstance()->addJs($ggrachDebuggerRootPath . "/assets/DebugBar/js/initializer.js");
47+
Asset::getInstance()->addCss($ggrachDebuggerRootPath . '/assets/DebugBar/themes/general.css');
48+
Asset::getInstance()->addCss($ggrachDebuggerRootPath . '/assets/DebugBar/themes/'.$ggrachDebugBarConfigurator->getColorTheme().'/theme.css');
49+
4650
/**
4751
* Пример дебага:
4852
*
49-
* $GD->notice("Моя переменная', 'Моя переменная 2');
50-
* $GD->error('Моя переменная', 'Моя переменная 2');
51-
* $GD->warning('Моя переменная', 'Моя переменная 2');
52-
* $GD->success('Моя переменная', 'Моя переменная 2');
53+
* GD()->notice('Моя переменная', 'Моя переменная 2');
54+
* GD()->error('Моя переменная', 'Моя переменная 2');
55+
* GD()->warning('Моя переменная', 'Моя переменная 2');
56+
* GD()->success('Моя переменная', 'Моя переменная 2');
5357
*
5458
* Залогировать в файлы
55-
* $GD->noticeLog("Моя переменная', 'Моя переменная 2');
56-
* $GD->errorLog('Моя переменная', 'Моя переменная 2');
57-
* $GD->warningLog('Моя переменная', 'Моя переменная 2');
58-
* $GD->successLog('Моя переменная', 'Моя переменная 2');
59+
* GD()->noticeLog('Моя переменная', 'Моя переменная 2');
60+
* GD()->errorLog('Моя переменная', 'Моя переменная 2');
61+
* GD()->warningLog('Моя переменная', 'Моя переменная 2');
62+
* GD()->successLog('Моя переменная', 'Моя переменная 2');
5963
*
6064
*/
6165
include 'inizializer_alias.php';
66+
67+
if (\GGrach\BitrixDebugger\Validator\ShowModeDebuggerValidator::needShowInDebugBar($GD)) {
68+
include 'events.php';
69+
}

src/BitrixDebugger/Debugger/Debugger.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,13 @@ public function debug($typeNotice, ...$item) {
145145
protected function noticeRaw(string $type, $arLogItems) {
146146

147147
if (ShowModeDebuggerValidator::needShowInDebugBar($this)) {
148-
$this->log = array_merge($this->log, $arLogItems);
148+
149+
if(!\array_key_exists($type, $this->getLog()))
150+
{
151+
$this->log[$type] = [];
152+
}
153+
154+
$this->log[$type] = array_merge($this->getLog()[$type], $arLogItems);
149155
}
150156

151157
if (ShowModeDebuggerValidator::needShowInCode($this)) {

0 commit comments

Comments
 (0)