No matches found.
';
return;
}
filtered.forEach(t => {
const btn = document.createElement('button');
btn.className = "w-full text-left px-3 py-2 text-sm text-slate-600 hover:bg-blue-50 hover:text-blue-700 rounded transition flex justify-between items-center group";
btn.innerHTML = `
${t.name}
${t.columns.length}
`;
btn.onclick = () => loadTableDetail(t);
tableListEl.appendChild(btn);
});
}
tableSearch.addEventListener('input', (e) => renderTableList(e.target.value));
function loadTableDetail(table) {
detailPlaceholder.classList.add('hidden');
detailContent.classList.remove('hidden');
detailContent.classList.add('flex');
detailName.textContent = table.name;
detailEngine.textContent = `Engine: ${table.engine}`;
detailCharset.textContent = `Charset: ${table.charset}`;
detailSql.textContent = table.sql;
if (window.Prism) Prism.highlightElement(detailSql);
columnsBody.innerHTML = table.columns.map(c => `
| ${c.name} |
${c.type} |
${c.isKey ? 'PK' : ''}
|
`).join('');
}
// 5. PDF Export
pdfBtn.addEventListener('click', () => {
if (!parsedTables.length) return alert("No data to export.");
if (!window.jspdf) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
const includeSql = document.getElementById('mda-cfg-include-sql').checked;
const dbName = document.getElementById('mda-cfg-dbname').value || "Database Export";
const author = document.getElementById('mda-cfg-author').value || "MySQL Analyzer";
// Title
doc.setFillColor(37, 99, 235);
doc.rect(0, 0, 210, 25, 'F');
doc.setFontSize(18);
doc.setTextColor(255, 255, 255);
doc.text("Database Schema Documentation", 14, 17);
doc.setFontSize(10);
doc.text(`Project: ${dbName}`, 14, 35);
doc.text(`Author: ${author}`, 14, 40);
doc.text(`Generated: ${new Date().toLocaleDateString()}`, 14, 45);
doc.text(`Total Tables: ${parsedTables.length}`, 14, 50);
let yPos = 60;
parsedTables.forEach((t, index) => {
// Check Page Break
if (yPos > 250) {
doc.addPage();
yPos = 20;
}
// Table Header
doc.setFillColor(241, 245, 249);
doc.rect(14, yPos, 182, 10, 'F');
doc.setFontSize(12);
doc.setTextColor(30, 41, 59);
doc.setFont("helvetica", "bold");
doc.text(`${index + 1}. Table: ${t.name}`, 16, yPos + 7);
doc.setFontSize(10);
doc.setFont("helvetica", "normal");
yPos += 15;
// Info
doc.text(`Engine: ${t.engine} | Charset: ${t.charset} | Columns: ${t.columns.length}`, 16, yPos);
yPos += 5;
// Column Table
const colData = t.columns.map(c => [c.name, c.type, c.isKey]);
doc.autoTable({
startY: yPos,
head: [['Column', 'Type', 'Key']],
body: colData,
theme: 'plain',
styles: { fontSize: 9, cellPadding: 1 },
headStyles: { fillColor: [255, 255, 255], textColor: [100, 116, 139], fontStyle: 'bold' },
columnStyles: { 0: { fontStyle: 'bold' } },
margin: { left: 14, right: 14 }
});
yPos = doc.lastAutoTable.finalY + 10;
// Optional SQL
if (includeSql) {
if (yPos > 240) { doc.addPage(); yPos = 20; }
doc.setFont("courier", "normal");
doc.setFontSize(8);
doc.setTextColor(100);
const splitSql = doc.splitTextToSize(t.sql, 180);
// Print only first 10 lines to save space if massive
const previewSql = splitSql.slice(0, 15);
doc.text(previewSql, 14, yPos);
if (splitSql.length > 15) doc.text("... (truncated)", 14, yPos + (15 * 3) + 5);
yPos += (previewSql.length * 4) + 10;
doc.setFont("helvetica", "normal"); // Reset font
doc.setTextColor(0);
}
});
doc.save(`${dbName.replace(/\s+/g, '_')}_Schema.pdf`);
});
});
// Tab Logic
window.mdaSwitchTab = function(tabId) {
document.querySelectorAll('.mda-tab-content').forEach(el => {
el.classList.remove('block');
el.classList.add('hidden');
});
document.getElementById(tabId).classList.remove('hidden');
document.getElementById(tabId).classList.add('block');
const btns = document.querySelectorAll('.mda-tab-btn');
btns.forEach(b => b.classList.remove('active'));
// Basic Mapping
const ids = ['mda-tab-dashboard', 'mda-tab-schema', 'mda-tab-config'];
const idx = ids.indexOf(tabId);
if (idx > -1 && btns[idx]) btns[idx].classList.add('active');
};