opencode/backend/static/index.html
Кирилл Блинов f37c477a0a Add FastAPI backend with DZI viewer and feedback system
- FastAPI app with SQLite DB (projects, pages, issues, feedback)
- OpenSeadragon DZI viewer with inline SVG overlays
- Dashboard: upload, project list, tiling toggle, review mode
- Pipeline integration: tiling OCR → layout → elements → rules QC → DZI → DB
- Feedback collection: true_positive / false_positive / not_sure per issue
2026-06-01 12:29:41 +03:00

330 lines
14 KiB
HTML

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blueprint QC Dashboard</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Segoe UI', system-ui, sans-serif;
background: #0d0d1a;
color: #eee;
min-height: 100vh;
}
.container { max-width: 1200px; margin: 0 auto; padding: 40px 20px; }
h1 { color: #e94560; margin-bottom: 30px; }
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-bottom: 40px;
}
.stat-card {
background: #16213e;
border: 1px solid #0f3460;
padding: 20px;
border-radius: 8px;
}
.stat-value { font-size: 32px; font-weight: bold; color: #e94560; }
.stat-label { font-size: 13px; opacity: 0.7; margin-top: 8px; }
.upload-zone {
border: 2px dashed #0f3460;
border-radius: 12px;
padding: 60px 40px;
text-align: center;
margin-bottom: 40px;
transition: all 0.3s;
}
.upload-zone:hover, .upload-zone.dragover {
border-color: #e94560;
background: rgba(233, 69, 96, 0.05);
}
.spinner {
display: inline-block;
width: 16px;
height: 16px;
border: 2px solid rgba(255,170,0,0.3);
border-top-color: #ffaa00;
border-radius: 50%;
animation: spin 1s linear infinite;
vertical-align: middle;
margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.processing-row { animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }
.delete-btn {
background: transparent;
border: none;
color: #ff4444;
cursor: pointer;
font-size: 16px;
margin-left: 10px;
opacity: 0.5;
}
.delete-btn:hover { opacity: 1; }
.upload-zone input { display: none; }
.upload-btn {
background: #e94560;
color: white;
border: none;
padding: 12px 32px;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
margin-top: 15px;
}
.projects-table {
width: 100%;
border-collapse: collapse;
}
.projects-table th {
text-align: left;
padding: 15px;
border-bottom: 2px solid #0f3460;
font-size: 13px;
text-transform: uppercase;
opacity: 0.7;
}
.projects-table td {
padding: 15px;
border-bottom: 1px solid #1a1a2e;
}
.projects-table tr:hover { background: rgba(255,255,255,0.03); }
.status {
display: inline-block;
padding: 4px 12px;
border-radius: 20px;
font-size: 12px;
font-weight: 600;
}
.status-completed { background: rgba(0,200,100,0.2); color: #00c864; }
.status-processing { background: rgba(255,170,0,0.2); color: #ffaa00; }
.status-error { background: rgba(255,0,0,0.2); color: #ff4444; }
.status-uploaded { background: rgba(100,100,255,0.2); color: #8888ff; }
.view-link { color: #44aaff; text-decoration: none; }
.view-link:hover { text-decoration: underline; }
#progress-bar {
display: none;
width: 100%;
height: 4px;
background: #1a1a2e;
border-radius: 2px;
margin-top: 15px;
overflow: hidden;
}
#progress-fill {
width: 0%;
height: 100%;
background: #e94560;
transition: width 0.3s;
}
.error-msg { color: #ff4444; margin-top: 10px; font-size: 14px; }
</style>
</head>
<body>
<div class="container">
<h1>Blueprint QC Dashboard</h1>
<div class="stats" id="stats">
<div class="stat-card">
<div class="stat-value" id="stat-projects">-</div>
<div class="stat-label">Проектов</div>
</div>
<div class="stat-card">
<div class="stat-value" id="stat-issues">-</div>
<div class="stat-label">Замечаний</div>
</div>
<div class="stat-card">
<div class="stat-value" id="stat-feedback">-</div>
<div class="stat-label">Размечено</div>
</div>
<div class="stat-card">
<div class="stat-value" id="stat-accuracy">-</div>
<div class="stat-label">Точность</div>
</div>
</div>
<div class="upload-zone" id="uploadZone">
<h3>Перетащите PDF сюда или кликните для выбора</h3>
<p style="opacity:0.6; margin-top:10px;">Максимальный размер: 100 МБ</p>
<input type="file" id="fileInput" accept=".pdf">
<button class="upload-btn" onclick="document.getElementById('fileInput').click()">Выбрать файл</button>
<div id="progress-bar"><div id="progress-fill"></div></div>
<div id="upload-error" class="error-msg"></div>
</div>
<h2 style="margin-bottom:20px;">Проекты</h2>
<table class="projects-table" id="projectsTable">
<thead>
<tr>
<th>ID</th>
<th>Название</th>
<th>Файл</th>
<th>Статус</th>
<th>Создан</th>
<th>Замечаний</th>
<th>Действия</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<script>
const API = '/api';
// Stats
async function loadStats() {
try {
const res = await fetch(`${API}/stats`);
const data = await res.json();
document.getElementById('stat-projects').textContent = data.total_projects;
document.getElementById('stat-issues').textContent = data.total_issues;
document.getElementById('stat-feedback').textContent = data.feedback_stats.true_positive + data.feedback_stats.false_positive;
document.getElementById('stat-accuracy').textContent = data.accuracy_estimate ? (data.accuracy_estimate * 100).toFixed(1) + '%' : '-';
} catch (e) { console.error('Stats error:', e); }
}
// Track previous statuses for detecting completion
let prevStatuses = {};
// Projects
async function loadProjects() {
try {
const res = await fetch(`${API}/projects`);
const projects = await res.json();
const tbody = document.querySelector('#projectsTable tbody');
// Check for newly completed projects
projects.forEach(p => {
if (prevStatuses[p.id] === 'processing' && p.status === 'completed') {
showToast(`Project "${p.name || p.pdf_filename}" обработан!`, 'success');
}
prevStatuses[p.id] = p.status;
});
tbody.innerHTML = projects.map(p => {
const isProcessing = p.status === 'processing' || p.status === 'uploaded';
const statusHtml = isProcessing
? `<span class="status status-${p.status}"><span class="spinner"></span>${p.status}</span>`
: `<span class="status status-${p.status}">${p.status}</span>`;
let actions;
if (p.status === 'completed') {
actions = `<a href="/viewer/${p.id}/1" class="view-link" target="_blank">Viewer</a> | <a href="/review.html?project=${p.id}" class="view-link">Review</a> <button class="delete-btn" onclick="deleteProject(${p.id})" title="Удалить">🗑</button>`;
} else if (p.status === 'processing') {
actions = '<span style="opacity:0.5"><span class="spinner"></span> Обработка...</span>';
} else {
actions = `
<label style="font-size:11px; margin-right:6px; cursor:pointer;">
<input type="checkbox" id="tiling-${p.id}" style="vertical-align:middle;"> tiling
</label>
<button class="upload-btn" style="padding:4px 12px; font-size:12px;" onclick="analyzeProject(${p.id})">🔬 Анализировать</button>
<button class="delete-btn" onclick="deleteProject(${p.id})" title="Удалить">🗑</button>
`;
}
return `
<tr class="${isProcessing ? 'processing-row' : ''}">
<td>${p.id}</td>
<td>${p.name || '-'}</td>
<td>${p.pdf_filename}</td>
<td>${statusHtml}</td>
<td>${new Date(p.created_at).toLocaleString()}</td>
<td>${p.issues ? p.issues.length : (isProcessing ? '<span class="spinner"></span>' : '0')}</td>
<td>${actions}</td>
</tr>
`}).join('');
} catch (e) { console.error('Projects error:', e); }
}
async function deleteProject(id) {
if (!confirm('Удалить проект?')) return;
try {
const res = await fetch(`${API}/projects/${id}`, { method: 'DELETE' });
if (res.ok) {
loadProjects();
loadStats();
showToast('Проект удалён', 'success');
}
} catch(e) { showToast('Ошибка удаления', 'error'); }
}
// Upload
const uploadZone = document.getElementById('uploadZone');
const fileInput = document.getElementById('fileInput');
const progressBar = document.getElementById('progress-bar');
const progressFill = document.getElementById('progress-fill');
const uploadError = document.getElementById('upload-error');
uploadZone.addEventListener('dragover', (e) => { e.preventDefault(); uploadZone.classList.add('dragover'); });
uploadZone.addEventListener('dragleave', () => uploadZone.classList.remove('dragover'));
uploadZone.addEventListener('drop', (e) => {
e.preventDefault();
uploadZone.classList.remove('dragover');
if (e.dataTransfer.files.length) handleFile(e.dataTransfer.files[0]);
});
fileInput.addEventListener('change', (e) => { if (e.target.files.length) handleFile(e.target.files[0]); });
async function analyzeProject(id) {
try {
const useTiling = document.getElementById(`tiling-${id}`)?.checked || false;
const url = useTiling ? `${API}/projects/${id}/analyze?use_tiling=true` : `${API}/projects/${id}/analyze`;
const res = await fetch(url, { method: 'POST' });
if (res.ok) {
const data = await res.json();
showToast(`Анализ запущен (${data.ocr_engine})!`, 'success');
loadProjects();
} else {
const err = await res.text();
showToast('Ошибка запуска: ' + err, 'error');
}
} catch(e) { showToast('Ошибка сети', 'error'); }
}
async function handleFile(file) {
if (!file.name.endsWith('.pdf')) {
uploadError.textContent = 'Только PDF файлы';
return;
}
uploadError.textContent = '';
progressBar.style.display = 'block';
progressFill.style.width = '30%';
const form = new FormData();
form.append('file', file);
form.append('name', file.name);
try {
const res = await fetch(`${API}/projects/upload`, { method: 'POST', body: form });
progressFill.style.width = '100%';
if (res.ok) {
setTimeout(() => { progressBar.style.display = 'none'; progressFill.style.width = '0%'; loadProjects(); loadStats(); }, 500);
} else {
uploadError.textContent = 'Ошибка загрузки: ' + res.statusText;
progressBar.style.display = 'none';
}
} catch (e) {
uploadError.textContent = 'Ошибка сети';
progressBar.style.display = 'none';
}
}
// Toast notification
function showToast(msg, type) {
const toast = document.createElement('div');
toast.style.cssText = `position:fixed; bottom:20px; right:20px; background:rgba(0,0,0,0.95); color:white; padding:14px 24px; border-radius:8px; border:1px solid ${type==='success'?'#00c864':'#ff4444'}; z-index:100000; font-size:13px; box-shadow:0 4px 20px rgba(0,0,0,0.5);`;
toast.textContent = msg;
document.body.appendChild(toast);
setTimeout(() => toast.remove(), 4000);
}
// Init
loadStats();
loadProjects();
setInterval(() => { loadProjects(); loadStats(); }, 5000); // Обновление каждые 5 сек
</script>
</body>
</html>