mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-07 02:31:40 +09:00
Also display debug information for previous AJAX request in panel
This commit is contained in:
parent
3391d87f57
commit
12673a29c6
2 changed files with 49 additions and 14 deletions
|
|
@ -195,11 +195,26 @@ class DisplayHandler extends Handler
|
|||
case 'HTML':
|
||||
$json_options = defined('JSON_PRETTY_PRINT') ? (JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) : 0;
|
||||
$panel_script = sprintf('<script src="%s%s?%s"></script>', RX_BASEURL, 'common/js/debug.js', filemtime(RX_BASEDIR . 'common/js/debug.js'));
|
||||
if (isset($_SESSION['_rx_debug_previous']))
|
||||
{
|
||||
$panel_script .= "\n<script>\nvar rhymix_debug_previous = " . json_encode($_SESSION['_rx_debug_previous'], $json_options) . ";\n</script>";
|
||||
unset($_SESSION['_rx_debug_previous']);
|
||||
}
|
||||
$panel_script .= "\n<script>\nvar rhymix_debug_content = " . json_encode($data, $json_options) . ";\n</script>";
|
||||
$body_end_position = strrpos($output, '</body>') ?: strlen($output);
|
||||
$output = substr($output, 0, $body_end_position) . "\n$panel_script\n" . substr($output, $body_end_position);
|
||||
return;
|
||||
case 'JSON':
|
||||
if (RX_POST && preg_match('/^proc/', Context::get('act')))
|
||||
{
|
||||
$data->ajax_module = Context::get('module');
|
||||
$data->ajax_act = Context::get('act');
|
||||
$_SESSION['_rx_debug_previous'] = $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($_SESSION['_rx_debug_previous']);
|
||||
}
|
||||
if (preg_match('/^(.+)\}$/', $output, $matches))
|
||||
{
|
||||
$output = $matches[1] . ',"_rx_debug":' . json_encode($data) . '}';
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ $(function() {
|
|||
// Initialize the debug button.
|
||||
$('<a href="#"></a>').text("DEBUG").appendTo(button).click(function(event) {
|
||||
event.preventDefault();
|
||||
panel.css({ width: 0 }).show().animate({ width: 640 }, 200);
|
||||
panel.css({ width: 0 }).show().animate({ width: 640 }, 200, function() {
|
||||
$(window).scrollTop(0);
|
||||
});
|
||||
button.hide();
|
||||
});
|
||||
|
||||
|
|
@ -34,19 +36,29 @@ $(function() {
|
|||
}));
|
||||
|
||||
// Define a function for adding debug data to the panel.
|
||||
window.rhymix_debug_add_data = function(data) {
|
||||
window.rhymix_debug_add_data = function(data, open) {
|
||||
|
||||
// Define loop variables.
|
||||
var i, j, entry, num, backtrace, description;
|
||||
|
||||
// New pages are open by default.
|
||||
if (open !== true && open !== false)
|
||||
{
|
||||
open = true;
|
||||
}
|
||||
|
||||
// Create the page.
|
||||
var page = $('<div class="debug_page"></div>').appendTo(panel);
|
||||
var page_body = $('<div class="debug_page_body"></div>').appendTo(page);
|
||||
if (!open)
|
||||
{
|
||||
page_body.hide();
|
||||
}
|
||||
|
||||
// Create the page header.
|
||||
var page_header = $('<div class="debug_page_header"></div>').prependTo(page);
|
||||
page_header.append($('<h3></h3>').text(data.page_title).attr("title", data.url));
|
||||
page_header.append($('<a class="debug_page_collapse" href="#"></a>').text("▲").click(function(event) {
|
||||
page_header.append($('<a class="debug_page_collapse" href="#"></a>').text(open ? "▲" : "▼").click(function(event) {
|
||||
event.preventDefault();
|
||||
if (page_body.is(":visible")) {
|
||||
page_body.slideUp(200);
|
||||
|
|
@ -99,25 +111,33 @@ $(function() {
|
|||
entry = $('<div class="debug_entry collapse_spaces"></div>').appendTo(page_body);
|
||||
num = parseInt(i) + 1; if (num < 10) num = "0" + num;
|
||||
description = "";
|
||||
description += "\nCaller: " + data.queries[i].file + ":" + data.queries[i].line + " (" + data.queries[i].method + ")";
|
||||
description += "\nConnection: " + data.queries[i].query_connection;
|
||||
description += "\nQuery Time: " + data.queries[i].query_time.toFixed(4) + " sec";
|
||||
description += "\nResult: " + ((data.queries[i].message === "success") ? "success" : ("error " + data.queries[i].error_code + " " + data.queries[i].message));
|
||||
if (data.queries[i].query_connection) {
|
||||
description += "\n- Caller: " + data.queries[i].file + ":" + data.queries[i].line + " (" + data.queries[i].method + ")";
|
||||
description += "\n- Connection: " + data.queries[i].query_connection;
|
||||
description += "\n- Query Time: " + (data.queries[i].query_time ? (data.queries[i].query_time.toFixed(4) + " sec") : "");
|
||||
}
|
||||
description += "\n- Result: " + ((data.queries[i].message === "success" || !data.queries[i].message) ? "success" : ("error " + data.queries[i].error_code + " " + data.queries[i].message));
|
||||
entry.text(num + ". " + data.queries[i].query_string + description);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Add debug data from the current page.
|
||||
if (rhymix_debug_content) {
|
||||
rhymix_debug_content.page_title = 'MAIN PAGE';
|
||||
rhymix_debug_add_data(rhymix_debug_content);
|
||||
// Add debug data from the previous request.
|
||||
if (window.rhymix_debug_previous) {
|
||||
window.rhymix_debug_previous.page_title = 'PREVIOUS POST: ' + window.rhymix_debug_previous.ajax_module + "." + window.rhymix_debug_previous.ajax_act;
|
||||
rhymix_debug_add_data(window.rhymix_debug_previous, false);
|
||||
}
|
||||
|
||||
// Add debug data from the current request.
|
||||
if (window.rhymix_debug_content) {
|
||||
window.rhymix_debug_content.page_title = 'MAIN PAGE';
|
||||
rhymix_debug_add_data(window.rhymix_debug_content, true);
|
||||
}
|
||||
|
||||
// Add debug data from pending AJAX requests.
|
||||
if (rhymix_debug_pending_data) {
|
||||
while (rhymix_debug_pending_data.length) {
|
||||
rhymix_debug_add_data(rhymix_debug_pending_data.shift());
|
||||
if (window.rhymix_debug_pending_data) {
|
||||
while (window.rhymix_debug_pending_data.length) {
|
||||
rhymix_debug_add_data(window.rhymix_debug_pending_data.shift());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue