opencode/backend/static/review.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

496 lines
19 KiB
HTML

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Review Issues — Blueprint QC</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: 1400px; margin: 0 auto; padding: 20px; }
header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
padding-bottom: 20px;
border-bottom: 2px solid #0f3460;
}
h1 { color: #e94560; }
.project-info { opacity: 0.7; font-size: 14px; }
.filters {
display: flex;
gap: 15px;
margin-bottom: 25px;
flex-wrap: wrap;
align-items: center;
}
.filter-group {
display: flex;
gap: 8px;
align-items: center;
}
.filter-group label { font-size: 13px; opacity: 0.8; }
.filter-group select, .filter-group input {
background: #1a1a2e;
border: 1px solid #0f3460;
color: #eee;
padding: 6px 12px;
border-radius: 4px;
font-size: 13px;
}
.filter-btn {
background: #e94560;
border: none;
color: white;
padding: 6px 16px;
border-radius: 4px;
cursor: pointer;
font-size: 13px;
}
.filter-btn.secondary {
background: #1a1a2e;
border: 1px solid #0f3460;
}
.progress-bar {
width: 100%;
height: 6px;
background: #1a1a2e;
border-radius: 3px;
margin-bottom: 25px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #e94560, #ffaa00);
transition: width 0.5s;
}
.progress-text {
font-size: 12px;
opacity: 0.6;
margin-bottom: 8px;
}
.issues-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
gap: 15px;
}
.issue-card {
background: #16213e;
border-left: 4px solid var(--card-color, #888);
border-radius: 8px;
padding: 15px;
transition: all 0.2s;
position: relative;
}
.issue-card:hover {
background: #1a2847;
transform: translateY(-2px);
}
.issue-card.reviewed-tp { border-left-color: #00c864; }
.issue-card.reviewed-fp { opacity: 0.6; }
.issue-card.reviewed-fp .issue-text { text-decoration: line-through; }
.issue-card.reviewed-ns { border-left-color: #888; }
.issue-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
}
.issue-id {
font-size: 11px;
background: rgba(255,255,255,0.1);
padding: 2px 8px;
border-radius: 10px;
}
.issue-type {
font-size: 11px;
text-transform: uppercase;
opacity: 0.7;
}
.issue-severity {
font-size: 10px;
padding: 2px 8px;
border-radius: 10px;
font-weight: bold;
}
.severity-error { background: rgba(255,0,0,0.2); color: #ff4444; }
.severity-warning { background: rgba(255,170,0,0.2); color: #ffaa00; }
.severity-info { background: rgba(0,150,255,0.2); color: #44aaff; }
.issue-text {
font-size: 13px;
line-height: 1.5;
margin-bottom: 10px;
}
.issue-meta {
font-size: 11px;
opacity: 0.6;
margin-bottom: 12px;
}
.issue-meta span { margin-right: 15px; }
.feedback-bar {
display: flex;
gap: 8px;
}
.feedback-bar button {
flex: 1;
padding: 8px;
border: 1px solid #333;
background: #0d0d1a;
color: #ccc;
border-radius: 6px;
cursor: pointer;
font-size: 12px;
transition: all 0.2s;
}
.feedback-bar button:hover {
background: #1a1a2e;
color: #fff;
}
.feedback-bar button.tp:hover { background: rgba(0,200,100,0.2); border-color: #00c864; color: #00c864; }
.feedback-bar button.fp:hover { background: rgba(255,0,0,0.2); border-color: #ff4444; color: #ff4444; }
.feedback-bar button.ns:hover { background: rgba(150,150,150,0.2); border-color: #888; color: #888; }
.feedback-bar button:disabled { opacity: 0.5; cursor: not-allowed; }
.reviewed-badge {
position: absolute;
top: 10px;
right: 10px;
font-size: 11px;
padding: 2px 8px;
border-radius: 10px;
font-weight: bold;
}
.badge-tp { background: rgba(0,200,100,0.2); color: #00c864; }
.badge-fp { background: rgba(255,0,0,0.2); color: #ff4444; }
.badge-ns { background: rgba(150,150,150,0.2); color: #888; }
.empty-state {
text-align: center;
padding: 80px 20px;
opacity: 0.5;
}
.empty-state h2 { margin-bottom: 15px; }
.viewer-link {
color: #44aaff;
text-decoration: none;
font-size: 12px;
}
.viewer-link:hover { text-decoration: underline; }
#toast {
position: fixed;
bottom: 20px;
right: 20px;
background: rgba(0,0,0,0.95);
color: white;
padding: 14px 24px;
border-radius: 8px;
border: 1px solid #e94560;
z-index: 100000;
display: none;
font-size: 13px;
box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.stats-row {
display: flex;
gap: 20px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.stat-pill {
background: #1a1a2e;
padding: 8px 16px;
border-radius: 20px;
font-size: 13px;
}
.stat-pill .num { font-weight: bold; color: #e94560; }
</style>
</head>
<body>
<div class="container">
<header>
<div>
<h1>Review Issues</h1>
<div class="project-info" id="projectInfo">Loading...</div>
</div>
<a href="/" style="color:#44aaff; text-decoration:none;">← Dashboard</a>
</header>
<div class="stats-row" id="statsRow"></div>
<div class="progress-text" id="progressText">0% reviewed</div>
<div class="progress-bar">
<div class="progress-fill" id="progressFill" style="width:0%"></div>
</div>
<div class="filters">
<div class="filter-group">
<label>Project:</label>
<select id="projectSelect"><option value="">Select...</option></select>
</div>
<div class="filter-group">
<label>Severity:</label>
<select id="severityFilter">
<option value="all">All</option>
<option value="error">Error</option>
<option value="warning">Warning</option>
<option value="info">Info</option>
</select>
</div>
<div class="filter-group">
<label>Type:</label>
<select id="typeFilter"><option value="all">All</option></select>
</div>
<div class="filter-group">
<label>Status:</label>
<select id="statusFilter">
<option value="all">All</option>
<option value="unreviewed">Unreviewed</option>
<option value="reviewed">Reviewed</option>
</select>
</div>
<button class="filter-btn" onclick="loadIssues()">Apply</button>
<button class="filter-btn secondary" onclick="exportTrainingData()">📥 Export Training Data</button>
</div>
<div class="issues-grid" id="issuesGrid"></div>
<div class="empty-state" id="emptyState" style="display:none;">
<h2>No issues found</h2>
<p>Try adjusting filters or upload a new PDF.</p>
</div>
</div>
<div id="toast"></div>
<script>
const API = '/api';
let currentProjectId = null;
let allIssues = [];
let allProjects = [];
// Init
async function init() {
await loadProjects();
// Check URL param
const urlParams = new URLSearchParams(window.location.search);
const pid = urlParams.get('project');
if (pid) {
document.getElementById('projectSelect').value = pid;
await selectProject(pid);
}
}
async function loadProjects() {
try {
const res = await fetch(`${API}/projects`);
allProjects = await res.json();
const select = document.getElementById('projectSelect');
select.innerHTML = '<option value="">Select project...</option>' +
allProjects.map(p => `<option value="${p.id}">${p.name || p.pdf_filename} (#${p.id})</option>`).join('');
select.addEventListener('change', (e) => selectProject(e.target.value));
} catch(e) { console.error(e); }
}
async function selectProject(pid) {
if (!pid) return;
currentProjectId = pid;
const project = allProjects.find(p => p.id == pid);
if (project) {
document.getElementById('projectInfo').textContent =
`${project.name || project.pdf_filename} | Status: ${project.status}`;
}
await loadIssues();
}
async function loadIssues() {
if (!currentProjectId) {
showToast('Select a project first', 'warning');
return;
}
const severity = document.getElementById('severityFilter').value;
const typeFilter = document.getElementById('typeFilter').value;
const statusFilter = document.getElementById('statusFilter').value;
try {
let url = `${API}/projects/${currentProjectId}/issues`;
const params = [];
if (severity !== 'all') params.push(`severity=${severity}`);
if (typeFilter !== 'all') params.push(`issue_type=${typeFilter}`);
if (statusFilter === 'reviewed') params.push(`has_feedback=true`);
if (statusFilter === 'unreviewed') params.push(`has_feedback=false`);
if (params.length) url += '?' + params.join('&');
const res = await fetch(url);
allIssues = await res.json();
renderIssues();
updateStats();
updateTypeFilter();
} catch(e) { showToast('Error loading issues: ' + e.message, 'error'); }
}
function renderIssues() {
const grid = document.getElementById('issuesGrid');
const empty = document.getElementById('emptyState');
if (!allIssues.length) {
grid.innerHTML = '';
empty.style.display = 'block';
return;
}
empty.style.display = 'none';
grid.innerHTML = allIssues.map(issue => {
const color = issue.severity === 'error' ? '#ff4444' : (issue.severity === 'warning' ? '#ffaa00' : '#44aaff');
const reviewedClass = issue.feedback ?
(issue.feedback.is_true_positive === true ? 'reviewed-tp' :
(issue.feedback.is_true_positive === false ? 'reviewed-fp' : 'reviewed-ns')) : '';
const badge = issue.feedback ?
(issue.feedback.is_true_positive === true ? '<span class="reviewed-badge badge-tp">✅ TP</span>' :
(issue.feedback.is_true_positive === false ? '<span class="reviewed-badge badge-fp">❌ FP</span>' :
'<span class="reviewed-badge badge-ns">🤷 NS</span>')) : '';
return `
<div class="issue-card ${reviewedClass}" style="--card-color:${color}" data-issue-id="${issue.id}">
${badge}
<div class="issue-header">
<span class="issue-id">#${issue.id}</span>
<span class="issue-severity severity-${issue.severity}">${issue.severity}</span>
</div>
<div class="issue-type">${issue.issue_type}</div>
<div class="issue-text">${issue.message}</div>
<div class="issue-meta">
<span>Page ${issue.page_number || '?'}</span>
<span>Conf: ${issue.confidence ? issue.confidence.toFixed(2) : 'N/A'}</span>
${issue.dimension_text ? `<span>Dim: "${issue.dimension_text}"</span>` : ''}
<a href="/viewer/${issue.project_id}/${issue.page_number || 1}" class="viewer-link" target="_blank">Open Viewer →</a>
</div>
<div class="feedback-bar">
<button class="tp" onclick="submitFeedback(${issue.id}, true, this)" ${issue.feedback ? 'disabled' : ''}>✅ Real Issue</button>
<button class="fp" onclick="submitFeedback(${issue.id}, false, this)" ${issue.feedback ? 'disabled' : ''}>❌ False Positive</button>
<button class="ns" onclick="submitFeedback(${issue.id}, null, this)" ${issue.feedback ? 'disabled' : ''}>🤷 Not Sure</button>
</div>
</div>
`;
}).join('');
}
async function submitFeedback(issueId, isTP, btn) {
const card = btn.closest('.issue-card');
const btns = card.querySelectorAll('.feedback-bar button');
btns.forEach(b => b.disabled = true);
btn.textContent = '...';
try {
const res = await fetch(`${API}/feedback`, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
issue_id: issueId,
is_true_positive: isTP,
action_taken: isTP === true ? 'fixed' : (isTP === false ? 'ignored' : 'not_sure')
})
});
if (res.ok) {
// Update the issue in memory
const issue = allIssues.find(i => i.id === issueId);
if (issue) {
issue.feedback = { is_true_positive: isTP };
}
renderIssues();
updateStats();
showToast('Saved!', 'success');
} else {
const err = await res.text();
showToast('Error: ' + err, 'error');
btns.forEach(b => b.disabled = false);
btn.textContent = isTP === true ? '✅ Real Issue' : (isTP === false ? '❌ False Positive' : '🤷 Not Sure');
}
} catch(e) {
showToast('Network error: ' + e.message, 'error');
btns.forEach(b => b.disabled = false);
btn.textContent = isTP === true ? '✅ Real Issue' : (isTP === false ? '❌ False Positive' : '🤷 Not Sure');
}
}
function updateStats() {
const total = allIssues.length;
const reviewed = allIssues.filter(i => i.feedback).length;
const tp = allIssues.filter(i => i.feedback && i.feedback.is_true_positive === true).length;
const fp = allIssues.filter(i => i.feedback && i.feedback.is_true_positive === false).length;
const pct = total ? Math.round((reviewed / total) * 100) : 0;
document.getElementById('progressFill').style.width = pct + '%';
document.getElementById('progressText').textContent =
`${pct}% reviewed (${reviewed}/${total}) | ✅ TP: ${tp} | ❌ FP: ${fp}`;
document.getElementById('statsRow').innerHTML = `
<div class="stat-pill">Total: <span class="num">${total}</span></div>
<div class="stat-pill">Reviewed: <span class="num">${reviewed}</span></div>
<div class="stat-pill">True Positive: <span class="num" style="color:#00c864">${tp}</span></div>
<div class="stat-pill">False Positive: <span class="num" style="color:#ff4444">${fp}</span></div>
`;
}
function updateTypeFilter() {
const types = [...new Set(allIssues.map(i => i.issue_type))];
const select = document.getElementById('typeFilter');
const current = select.value;
select.innerHTML = '<option value="all">All</option>' +
types.map(t => `<option value="${t}">${t}</option>`).join('');
if (types.includes(current)) select.value = current;
}
async function exportTrainingData() {
if (!currentProjectId) {
showToast('Select a project first', 'warning');
return;
}
try {
const res = await fetch(`${API}/training/export?project_id=${currentProjectId}&only_labeled=true`);
const data = await res.json();
// Download as file
const blob = new Blob([JSON.stringify(data, null, 2)], {type: 'application/json'});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `training_data_project_${currentProjectId}_${new Date().toISOString().slice(0,10)}.json`;
a.click();
URL.revokeObjectURL(url);
showToast(`Exported ${data.total_samples} samples!`, 'success');
} catch(e) {
showToast('Export error: ' + e.message, 'error');
}
}
function showToast(msg, type) {
const toast = document.getElementById('toast');
toast.textContent = msg;
toast.style.borderColor = type === 'success' ? '#00c864' : (type === 'error' ? '#ff4444' : '#ffaa00');
toast.style.display = 'block';
setTimeout(() => toast.style.display = 'none', 3000);
}
init();
</script>
</body>
</html>