first commit
This commit is contained in:
commit
c7fa91c8ce
34 files changed
+4631
No files matched your search
@@ -0,0 +1,193 @@
|
||||
// Részletes nézet panel - egy webhook kérés összes adata tabokba szervezve
|
||||
import { formatTimestamp, methodColor } from '../utils/formatters.js';
|
||||
|
||||
// Részletes panel komponens létrehozása
|
||||
// onClose: callback a panel bezárásakor
|
||||
export function createRequestDetail(onClose) {
|
||||
const panel = document.createElement('div');
|
||||
panel.className = 'flex flex-col h-full bg-gray-900 border-l border-gray-800';
|
||||
panel.innerHTML = `
|
||||
<div id="detail-empty" class="flex-1 flex items-center justify-center text-gray-600">
|
||||
<div class="text-center">
|
||||
<div class="text-3xl mb-2">👆</div>
|
||||
<p>Kattints egy sorra a részletekhez</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="detail-content" class="hidden flex-1 flex flex-col overflow-hidden">
|
||||
<!-- Fejléc -->
|
||||
<div class="flex items-center justify-between px-4 py-3 border-b border-gray-800 flex-shrink-0">
|
||||
<div class="flex items-center gap-3">
|
||||
<span id="detail-method" class="inline-block px-2 py-0.5 rounded border text-xs font-bold"></span>
|
||||
<span id="detail-path" class="text-gray-400 text-sm font-mono"></span>
|
||||
<span id="detail-time" class="text-gray-600 text-xs"></span>
|
||||
</div>
|
||||
<button id="detail-close" class="text-gray-600 hover:text-gray-300 transition-colors text-lg leading-none">✕</button>
|
||||
</div>
|
||||
<!-- Tab fejlécek -->
|
||||
<div class="flex border-b border-gray-800 flex-shrink-0 overflow-x-auto">
|
||||
<button class="detail-tab px-4 py-2 text-sm whitespace-nowrap" data-tab="payload">Payload</button>
|
||||
<button class="detail-tab px-4 py-2 text-sm whitespace-nowrap" data-tab="query">GET paraméterek</button>
|
||||
<button class="detail-tab px-4 py-2 text-sm whitespace-nowrap" data-tab="body">POST paraméterek</button>
|
||||
<button class="detail-tab px-4 py-2 text-sm whitespace-nowrap" data-tab="headers">Fejlécek</button>
|
||||
<button class="detail-tab px-4 py-2 text-sm whitespace-nowrap" data-tab="server">Szerver infó</button>
|
||||
</div>
|
||||
<!-- Tab tartalom -->
|
||||
<div id="detail-tab-content" class="flex-1 overflow-auto p-4"></div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const emptyEl = panel.querySelector('#detail-empty');
|
||||
const contentEl = panel.querySelector('#detail-content');
|
||||
const methodEl = panel.querySelector('#detail-method');
|
||||
const pathEl = panel.querySelector('#detail-path');
|
||||
const timeEl = panel.querySelector('#detail-time');
|
||||
const tabContent = panel.querySelector('#detail-tab-content');
|
||||
const closeBtn = panel.querySelector('#detail-close');
|
||||
const tabs = panel.querySelectorAll('.detail-tab');
|
||||
|
||||
let activeTab = 'payload';
|
||||
let currentData = null;
|
||||
|
||||
// Bezárás gomb
|
||||
closeBtn.addEventListener('click', () => onClose?.());
|
||||
|
||||
// Tab stílus frissítése
|
||||
function setActiveTab(tabName) {
|
||||
activeTab = tabName;
|
||||
tabs.forEach(tab => {
|
||||
const isActive = tab.dataset.tab === tabName;
|
||||
tab.className = `detail-tab px-4 py-2 text-sm whitespace-nowrap transition-colors ${
|
||||
isActive
|
||||
? 'text-indigo-400 border-b-2 border-indigo-400'
|
||||
: 'text-gray-500 hover:text-gray-300'
|
||||
}`;
|
||||
});
|
||||
renderTabContent();
|
||||
}
|
||||
|
||||
// Tab tartalom renderelése az aktuális adatokból
|
||||
function renderTabContent() {
|
||||
if (!currentData) return;
|
||||
const d = currentData;
|
||||
|
||||
switch (activeTab) {
|
||||
case 'payload':
|
||||
tabContent.innerHTML = d.rawPayload
|
||||
? `<pre class="json-display text-gray-300">${escapeHtml(d.rawPayload)}</pre>`
|
||||
: '<p class="text-gray-600 text-sm">Nincs payload</p>';
|
||||
break;
|
||||
|
||||
case 'query':
|
||||
tabContent.innerHTML = d.queryCount > 0
|
||||
? renderParamsTable(d.queryParams)
|
||||
: '<p class="text-gray-600 text-sm">Nincs GET paraméter</p>';
|
||||
break;
|
||||
|
||||
case 'body':
|
||||
tabContent.innerHTML = d.bodyCount > 0
|
||||
? renderParamsTable(d.bodyData)
|
||||
: '<p class="text-gray-600 text-sm">Nincs POST paraméter</p>';
|
||||
break;
|
||||
|
||||
case 'headers':
|
||||
tabContent.innerHTML = renderParamsTable(d.headers);
|
||||
break;
|
||||
|
||||
case 'server':
|
||||
tabContent.innerHTML = renderParamsTable({
|
||||
'Protokoll': d.serverInfo?.protocol || '—',
|
||||
'Host': d.serverInfo?.host || '—',
|
||||
'Teljes URL': d.serverInfo?.originalUrl || '—',
|
||||
'Content-Type': d.serverInfo?.contentType || '—',
|
||||
'Remote IP': d.remoteIp,
|
||||
'Időbélyeg': formatTimestamp(d.timestamp),
|
||||
'Kérés azonosító': d.id
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Paraméter táblázat HTML generálás
|
||||
function renderParamsTable(params) {
|
||||
if (!params || typeof params !== 'object') return '<p class="text-gray-600 text-sm">Nincs adat</p>';
|
||||
const entries = Object.entries(params);
|
||||
if (entries.length === 0) return '<p class="text-gray-600 text-sm">Nincs adat</p>';
|
||||
|
||||
const rows = entries.map(([key, val]) => {
|
||||
const valStr = typeof val === 'object' ? JSON.stringify(val, null, 2) : String(val);
|
||||
return `
|
||||
<tr class="border-b border-gray-800/50">
|
||||
<td class="py-2 pr-4 text-gray-400 font-mono text-xs whitespace-nowrap align-top">${escapeHtml(key)}</td>
|
||||
<td class="py-2 text-gray-200 font-mono text-xs break-all">
|
||||
<pre class="json-display whitespace-pre-wrap">${escapeHtml(valStr)}</pre>
|
||||
</td>
|
||||
</tr>`;
|
||||
}).join('');
|
||||
|
||||
return `
|
||||
<table class="w-full text-sm">
|
||||
<thead><tr class="text-left text-gray-600 border-b border-gray-800">
|
||||
<th class="pb-2 pr-4 font-medium w-1/3">Kulcs</th>
|
||||
<th class="pb-2 font-medium">Érték</th>
|
||||
</tr></thead>
|
||||
<tbody>${rows}</tbody>
|
||||
</table>`;
|
||||
}
|
||||
|
||||
// HTML escape biztonságos megjelenítéshez
|
||||
function escapeHtml(str) {
|
||||
return String(str)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
}
|
||||
|
||||
// Tab kattintás esemény
|
||||
tabs.forEach(tab => {
|
||||
tab.addEventListener('click', () => setActiveTab(tab.dataset.tab));
|
||||
});
|
||||
|
||||
// Adatok megjelenítése a panelen
|
||||
function show(data) {
|
||||
currentData = data;
|
||||
emptyEl.classList.add('hidden');
|
||||
contentEl.classList.remove('hidden');
|
||||
|
||||
// Fejléc frissítése
|
||||
methodEl.className = `inline-block px-2 py-0.5 rounded border text-xs font-bold ${methodColor(data.method)}`;
|
||||
methodEl.textContent = data.method;
|
||||
pathEl.textContent = data.serverInfo?.originalUrl || '/';
|
||||
timeEl.textContent = formatTimestamp(data.timestamp);
|
||||
|
||||
// Tab badge számok frissítése
|
||||
tabs.forEach(tab => {
|
||||
const counts = {
|
||||
query: data.queryCount,
|
||||
body: data.bodyCount,
|
||||
headers: Object.keys(data.headers || {}).length
|
||||
};
|
||||
const count = counts[tab.dataset.tab];
|
||||
const label = tab.dataset.tab === 'query' ? 'GET paraméterek'
|
||||
: tab.dataset.tab === 'body' ? 'POST paraméterek'
|
||||
: tab.dataset.tab === 'headers' ? 'Fejlécek'
|
||||
: tab.dataset.tab === 'payload' ? 'Payload'
|
||||
: 'Szerver infó';
|
||||
tab.textContent = count != null && count > 0 ? `${label} (${count})` : label;
|
||||
});
|
||||
|
||||
setActiveTab(activeTab);
|
||||
}
|
||||
|
||||
// Panel elrejtése
|
||||
function hide() {
|
||||
contentEl.classList.add('hidden');
|
||||
emptyEl.classList.remove('hidden');
|
||||
currentData = null;
|
||||
}
|
||||
|
||||
// Alapértelmezett tab stílus beállítása
|
||||
setActiveTab('payload');
|
||||
|
||||
return { show, hide, element: panel };
|
||||
}
|
||||
Reference in new issue
Block a user