web/static/index.html: Complete redesign with clean modern layout: - RTL Hebrew throughout - Two-column layout: upload zone + pending files - Cleaner drag & drop with visual feedback - Improved classification form with radio buttons - Better progress tracking display - Status bar with system metrics CLAUDE.md: Updated Gitea URL to new org ezer-mishpati/legal-ai Closes ezer-mishpati/legal-ai#1 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
808 lines
22 KiB
HTML
808 lines
22 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="he" dir="rtl">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>עוזר משפטי — העלאת מסמכים</title>
|
|
<style>
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
|
background: #f5f5f5;
|
|
color: #1a1a2e;
|
|
direction: rtl;
|
|
min-height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
/* Header */
|
|
header {
|
|
background: #1a1a2e;
|
|
color: #ffffff;
|
|
padding: 18px 32px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
header h1 {
|
|
font-size: 1.25em;
|
|
font-weight: 600;
|
|
letter-spacing: -0.01em;
|
|
}
|
|
header .sep {
|
|
width: 2px;
|
|
height: 20px;
|
|
background: rgba(255,255,255,0.2);
|
|
border-radius: 1px;
|
|
}
|
|
header .subtitle {
|
|
font-size: 0.85em;
|
|
opacity: 0.6;
|
|
}
|
|
|
|
/* Main Layout */
|
|
.main {
|
|
flex: 1;
|
|
max-width: 1200px;
|
|
width: 100%;
|
|
margin: 0 auto;
|
|
padding: 28px 24px;
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 24px;
|
|
align-items: start;
|
|
}
|
|
|
|
/* Cards */
|
|
.card {
|
|
background: #ffffff;
|
|
border-radius: 10px;
|
|
box-shadow: 0 1px 4px rgba(0,0,0,0.06), 0 0 1px rgba(0,0,0,0.08);
|
|
overflow: hidden;
|
|
}
|
|
.card-header {
|
|
padding: 14px 20px;
|
|
font-size: 0.9em;
|
|
font-weight: 600;
|
|
color: #1a1a2e;
|
|
border-bottom: 1px solid #eee;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
.card-header .icon {
|
|
font-size: 1.1em;
|
|
}
|
|
.card-body {
|
|
padding: 20px;
|
|
}
|
|
|
|
/* Upload Zone */
|
|
.upload-zone {
|
|
border: 2px dashed #ccc;
|
|
border-radius: 10px;
|
|
padding: 60px 24px;
|
|
text-align: center;
|
|
cursor: pointer;
|
|
transition: border-color 0.2s, background 0.2s;
|
|
background: #fafafa;
|
|
}
|
|
.upload-zone:hover,
|
|
.upload-zone.dragover {
|
|
border-color: #e94560;
|
|
background: #fff5f7;
|
|
}
|
|
.upload-zone .upload-icon {
|
|
font-size: 3em;
|
|
color: #ccc;
|
|
margin-bottom: 16px;
|
|
transition: color 0.2s;
|
|
}
|
|
.upload-zone:hover .upload-icon,
|
|
.upload-zone.dragover .upload-icon {
|
|
color: #e94560;
|
|
}
|
|
.upload-zone h2 {
|
|
font-size: 1em;
|
|
font-weight: 500;
|
|
color: #555;
|
|
margin-bottom: 6px;
|
|
}
|
|
.upload-zone p {
|
|
font-size: 0.8em;
|
|
color: #aaa;
|
|
}
|
|
.upload-zone input[type="file"] { display: none; }
|
|
|
|
.upload-progress {
|
|
margin-top: 16px;
|
|
display: none;
|
|
}
|
|
.upload-progress .bar {
|
|
height: 4px;
|
|
background: #eee;
|
|
border-radius: 2px;
|
|
overflow: hidden;
|
|
}
|
|
.upload-progress .bar-fill {
|
|
height: 100%;
|
|
background: #e94560;
|
|
width: 0;
|
|
transition: width 0.3s;
|
|
}
|
|
|
|
/* Pending Files */
|
|
.pending-file {
|
|
border: 1px solid #eee;
|
|
border-radius: 8px;
|
|
padding: 16px;
|
|
margin-bottom: 12px;
|
|
background: #fafafa;
|
|
transition: border-color 0.2s;
|
|
}
|
|
.pending-file:hover {
|
|
border-color: #ddd;
|
|
}
|
|
.pending-file .file-info {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 12px;
|
|
}
|
|
.pending-file .file-name {
|
|
font-weight: 600;
|
|
font-size: 0.9em;
|
|
word-break: break-all;
|
|
color: #1a1a2e;
|
|
}
|
|
.pending-file .file-size {
|
|
color: #999;
|
|
font-size: 0.78em;
|
|
white-space: nowrap;
|
|
margin-right: 12px;
|
|
}
|
|
.pending-file .file-actions {
|
|
display: flex;
|
|
gap: 8px;
|
|
align-items: center;
|
|
}
|
|
|
|
/* Empty State */
|
|
.empty {
|
|
text-align: center;
|
|
color: #bbb;
|
|
padding: 40px 20px;
|
|
font-size: 0.88em;
|
|
line-height: 1.6;
|
|
}
|
|
|
|
/* Radio Group */
|
|
.radio-group {
|
|
display: flex;
|
|
gap: 4px;
|
|
margin-bottom: 12px;
|
|
flex-wrap: wrap;
|
|
}
|
|
.radio-group label {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
font-size: 0.82em;
|
|
cursor: pointer;
|
|
padding: 6px 12px;
|
|
border-radius: 6px;
|
|
border: 1px solid #eee;
|
|
background: #fff;
|
|
transition: all 0.15s;
|
|
}
|
|
.radio-group label:hover {
|
|
border-color: #e94560;
|
|
}
|
|
.radio-group input[type="radio"] {
|
|
accent-color: #e94560;
|
|
}
|
|
.conditional { display: none; }
|
|
.conditional.active { display: block; }
|
|
|
|
/* Form Elements */
|
|
.form-row {
|
|
display: flex;
|
|
gap: 12px;
|
|
flex-wrap: wrap;
|
|
align-items: end;
|
|
margin-bottom: 10px;
|
|
}
|
|
.form-group {
|
|
flex: 1;
|
|
min-width: 140px;
|
|
}
|
|
.form-group label {
|
|
display: block;
|
|
font-size: 0.78em;
|
|
color: #888;
|
|
margin-bottom: 4px;
|
|
font-weight: 500;
|
|
}
|
|
.form-group select,
|
|
.form-group input[type="text"],
|
|
.form-group input[type="date"] {
|
|
width: 100%;
|
|
padding: 8px 10px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 6px;
|
|
font-size: 0.88em;
|
|
font-family: inherit;
|
|
direction: rtl;
|
|
background: #fff;
|
|
transition: border-color 0.15s;
|
|
}
|
|
.form-group select:focus,
|
|
.form-group input:focus {
|
|
outline: none;
|
|
border-color: #e94560;
|
|
}
|
|
|
|
/* Subject Grid */
|
|
.subject-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(3, 1fr);
|
|
gap: 6px;
|
|
}
|
|
.subject-grid label {
|
|
font-size: 0.78em;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
cursor: pointer;
|
|
}
|
|
.subject-grid input[type="checkbox"] {
|
|
accent-color: #e94560;
|
|
}
|
|
|
|
/* Buttons */
|
|
.btn {
|
|
padding: 8px 20px;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 0.88em;
|
|
font-family: inherit;
|
|
cursor: pointer;
|
|
transition: all 0.15s;
|
|
font-weight: 500;
|
|
}
|
|
.btn-primary {
|
|
background: #e94560;
|
|
color: #fff;
|
|
}
|
|
.btn-primary:hover {
|
|
background: #d6304a;
|
|
}
|
|
.btn-danger {
|
|
background: transparent;
|
|
color: #e94560;
|
|
border: 1px solid #e94560;
|
|
font-size: 0.78em;
|
|
padding: 4px 10px;
|
|
}
|
|
.btn-danger:hover {
|
|
background: #fff0f3;
|
|
}
|
|
.btn:disabled {
|
|
opacity: 0.4;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
/* Task Items */
|
|
.task-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
padding: 12px;
|
|
border: 1px solid #eee;
|
|
border-radius: 8px;
|
|
margin-bottom: 8px;
|
|
background: #fafafa;
|
|
}
|
|
.task-item .spinner {
|
|
width: 20px;
|
|
height: 20px;
|
|
border: 2.5px solid #eee;
|
|
border-top-color: #e94560;
|
|
border-radius: 50%;
|
|
animation: spin 0.8s linear infinite;
|
|
flex-shrink: 0;
|
|
}
|
|
.task-item.done .spinner {
|
|
border-color: #27ae60;
|
|
border-top-color: #27ae60;
|
|
animation: none;
|
|
}
|
|
.task-item.failed .spinner {
|
|
border-color: #e94560;
|
|
border-top-color: #e94560;
|
|
animation: none;
|
|
}
|
|
@keyframes spin { to { transform: rotate(360deg); } }
|
|
.task-info { flex: 1; min-width: 0; }
|
|
.task-info .task-name {
|
|
font-size: 0.88em;
|
|
font-weight: 500;
|
|
color: #1a1a2e;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
}
|
|
.task-info .task-status {
|
|
font-size: 0.78em;
|
|
color: #999;
|
|
margin-top: 2px;
|
|
}
|
|
|
|
/* Status Bar */
|
|
.status-bar {
|
|
background: #1a1a2e;
|
|
color: rgba(255,255,255,0.5);
|
|
font-size: 0.75em;
|
|
padding: 8px 32px;
|
|
display: flex;
|
|
gap: 24px;
|
|
align-items: center;
|
|
}
|
|
.status-bar .stat {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
}
|
|
.status-bar .stat-value {
|
|
color: rgba(255,255,255,0.85);
|
|
font-weight: 600;
|
|
}
|
|
|
|
/* Toast */
|
|
.toast {
|
|
position: fixed;
|
|
bottom: 60px;
|
|
left: 50%;
|
|
transform: translateX(-50%) translateY(10px);
|
|
background: #1a1a2e;
|
|
color: white;
|
|
padding: 10px 24px;
|
|
border-radius: 8px;
|
|
font-size: 0.85em;
|
|
z-index: 1000;
|
|
opacity: 0;
|
|
transition: opacity 0.3s, transform 0.3s;
|
|
pointer-events: none;
|
|
}
|
|
.toast.show {
|
|
opacity: 1;
|
|
transform: translateX(-50%) translateY(0);
|
|
}
|
|
.toast.error { background: #e94560; }
|
|
.toast.success { background: #27ae60; }
|
|
|
|
/* Responsive */
|
|
@media (max-width: 800px) {
|
|
.main {
|
|
grid-template-columns: 1fr;
|
|
padding: 16px;
|
|
}
|
|
header { padding: 14px 16px; }
|
|
.status-bar { padding: 8px 16px; flex-wrap: wrap; gap: 12px; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<header>
|
|
<h1>עוזר משפטי</h1>
|
|
<div class="sep"></div>
|
|
<span class="subtitle">העלאת מסמכים</span>
|
|
</header>
|
|
|
|
<div class="main">
|
|
<!-- Right Column (visually) — Upload -->
|
|
<div>
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<div class="upload-zone" id="dropZone">
|
|
<div class="upload-icon">📄</div>
|
|
<h2>גרור קבצים לכאן או לחץ לבחירה</h2>
|
|
<p>PDF, DOCX, RTF, TXT — עד 50MB</p>
|
|
<input type="file" id="fileInput" multiple accept=".pdf,.docx,.rtf,.txt">
|
|
<div class="upload-progress" id="uploadProgress">
|
|
<div class="bar"><div class="bar-fill" id="uploadBar"></div></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Processing Tasks -->
|
|
<div class="card" id="tasksCard" style="display:none; margin-top: 16px;">
|
|
<div class="card-header">עיבוד</div>
|
|
<div class="card-body" id="tasksList"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Left Column (visually) — Pending Files -->
|
|
<div>
|
|
<div class="card" id="pendingCard" style="display:none">
|
|
<div class="card-header">קבצים ממתינים לסיווג</div>
|
|
<div class="card-body" id="pendingList">
|
|
<div class="empty">אין קבצים ממתינים</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card" id="emptyCard">
|
|
<div class="card-body">
|
|
<div class="empty">
|
|
העלה מסמכים באמצעות אזור הגרירה<br>
|
|
הקבצים יופיעו כאן לסיווג ועיבוד
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Status Bar -->
|
|
<div class="status-bar" id="statusBar">
|
|
<div class="stat">תיקים: <span class="stat-value" id="statCases">—</span></div>
|
|
<div class="stat">מסמכים: <span class="stat-value" id="statDocs">—</span></div>
|
|
<div class="stat">קטעים: <span class="stat-value" id="statChunks">—</span></div>
|
|
</div>
|
|
|
|
<div class="toast" id="toast"></div>
|
|
|
|
<script>
|
|
const API = '/api';
|
|
|
|
// ── Upload Zone ───────────────────────────────────────────────
|
|
const dropZone = document.getElementById('dropZone');
|
|
const fileInput = document.getElementById('fileInput');
|
|
const uploadProgress = document.getElementById('uploadProgress');
|
|
const uploadBar = document.getElementById('uploadBar');
|
|
|
|
dropZone.addEventListener('click', () => fileInput.click());
|
|
dropZone.addEventListener('dragover', e => { e.preventDefault(); dropZone.classList.add('dragover'); });
|
|
dropZone.addEventListener('dragleave', () => dropZone.classList.remove('dragover'));
|
|
dropZone.addEventListener('drop', e => {
|
|
e.preventDefault();
|
|
dropZone.classList.remove('dragover');
|
|
handleFiles(e.dataTransfer.files);
|
|
});
|
|
fileInput.addEventListener('change', () => {
|
|
if (fileInput.files.length) handleFiles(fileInput.files);
|
|
fileInput.value = '';
|
|
});
|
|
|
|
async function handleFiles(files) {
|
|
for (const file of files) {
|
|
await uploadFile(file);
|
|
}
|
|
loadPending();
|
|
}
|
|
|
|
function uploadFile(file) {
|
|
return new Promise((resolve, reject) => {
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
|
|
const xhr = new XMLHttpRequest();
|
|
uploadProgress.style.display = 'block';
|
|
|
|
xhr.upload.onprogress = e => {
|
|
if (e.lengthComputable) {
|
|
uploadBar.style.width = (e.loaded / e.total * 100) + '%';
|
|
}
|
|
};
|
|
xhr.onload = () => {
|
|
uploadProgress.style.display = 'none';
|
|
uploadBar.style.width = '0';
|
|
if (xhr.status === 200) {
|
|
toast('הקובץ הועלה בהצלחה', 'success');
|
|
resolve();
|
|
} else {
|
|
const err = JSON.parse(xhr.responseText);
|
|
toast(err.detail || 'שגיאה בהעלאה', 'error');
|
|
reject();
|
|
}
|
|
};
|
|
xhr.onerror = () => {
|
|
uploadProgress.style.display = 'none';
|
|
toast('שגיאת רשת', 'error');
|
|
reject();
|
|
};
|
|
xhr.open('POST', API + '/upload');
|
|
xhr.send(formData);
|
|
});
|
|
}
|
|
|
|
// ── Pending Files ─────────────────────────────────────────────
|
|
let cases = [];
|
|
|
|
async function loadCases() {
|
|
try {
|
|
const res = await fetch(API + '/cases');
|
|
cases = await res.json();
|
|
} catch (e) {
|
|
cases = [];
|
|
}
|
|
}
|
|
|
|
async function loadPending() {
|
|
const res = await fetch(API + '/uploads');
|
|
const files = await res.json();
|
|
const card = document.getElementById('pendingCard');
|
|
const emptyCard = document.getElementById('emptyCard');
|
|
const list = document.getElementById('pendingList');
|
|
|
|
if (!files.length) {
|
|
card.style.display = 'none';
|
|
emptyCard.style.display = 'block';
|
|
return;
|
|
}
|
|
|
|
card.style.display = 'block';
|
|
emptyCard.style.display = 'none';
|
|
await loadCases();
|
|
|
|
list.innerHTML = files.map(f => `
|
|
<div class="pending-file" data-filename="${esc(f.filename)}">
|
|
<div class="file-info">
|
|
<span class="file-name">${esc(f.filename.replace(/^\d+_/, ''))}</span>
|
|
<div class="file-actions">
|
|
<span class="file-size">${formatSize(f.size)}</span>
|
|
<button class="btn btn-danger" onclick="deleteFile('${esc(f.filename)}')">מחק</button>
|
|
</div>
|
|
</div>
|
|
<div class="radio-group">
|
|
<label><input type="radio" name="cat_${esc(f.filename)}" value="case" onchange="showFields(this)"> מסמך תיק</label>
|
|
<label><input type="radio" name="cat_${esc(f.filename)}" value="training" onchange="showFields(this)"> החלטה לאימון</label>
|
|
<label><input type="radio" name="cat_${esc(f.filename)}" value="dinleumi" onchange="showFields(this)"> דין לאומי</label>
|
|
</div>
|
|
<div class="conditional case-fields" id="case_${esc(f.filename)}">
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label>תיק</label>
|
|
<select class="case-select">
|
|
<option value="">בחר תיק...</option>
|
|
${cases.map(c => `<option value="${esc(c.case_number)}">${esc(c.case_number)} — ${esc(c.title)}</option>`).join('')}
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>סוג מסמך</label>
|
|
<select class="doctype-select">
|
|
<option value="appeal">כתב ערר</option>
|
|
<option value="response">תשובה</option>
|
|
<option value="decision">החלטה</option>
|
|
<option value="exhibit">נספח</option>
|
|
<option value="reference">מסמך עזר</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="conditional training-fields" id="train_${esc(f.filename)}">
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label>מספר החלטה</label>
|
|
<input type="text" class="decision-number" placeholder="לדוגמה: 1180+1181">
|
|
</div>
|
|
<div class="form-group">
|
|
<label>תאריך החלטה</label>
|
|
<input type="date" class="decision-date">
|
|
</div>
|
|
</div>
|
|
<div class="form-group" style="margin-top:8px">
|
|
<label>קטגוריות</label>
|
|
<div class="subject-grid">
|
|
${['בנייה','שימוש חורג','תכנית','היתר','הקלה','חלוקה','תמ"א 38','היטל השבחה','פיצויים 197'].map(s =>
|
|
`<label><input type="checkbox" value="${s}"> ${s}</label>`
|
|
).join('')}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="conditional dinleumi-fields" id="dinleumi_${esc(f.filename)}">
|
|
<p style="font-size:0.82em;color:#999;margin:4px 0 8px">המטאדאטא (בית משפט, שופט, תאריך, נושא, תוצאה) תחולץ אוטומטית מתוך פסק הדין</p>
|
|
</div>
|
|
<div style="margin-top:12px">
|
|
<div class="form-group" style="max-width:300px;margin-bottom:10px">
|
|
<label>כותרת (אופציונלי)</label>
|
|
<input type="text" class="doc-title" placeholder="שם המסמך">
|
|
</div>
|
|
<button class="btn btn-primary process-btn" onclick="classifyFile('${esc(f.filename)}')" disabled>עבד</button>
|
|
</div>
|
|
</div>
|
|
`).join('');
|
|
}
|
|
|
|
function showFields(radio) {
|
|
const container = radio.closest('.pending-file');
|
|
const val = radio.value;
|
|
|
|
container.querySelector('.case-fields').classList.toggle('active', val === 'case');
|
|
container.querySelector('.training-fields').classList.toggle('active', val === 'training');
|
|
container.querySelector('.dinleumi-fields').classList.toggle('active', val === 'dinleumi');
|
|
container.querySelector('.process-btn').disabled = false;
|
|
}
|
|
|
|
async function deleteFile(filename) {
|
|
await fetch(API + '/uploads/' + encodeURIComponent(filename), { method: 'DELETE' });
|
|
loadPending();
|
|
toast('הקובץ נמחק');
|
|
}
|
|
|
|
async function classifyFile(filename) {
|
|
const container = document.querySelector(`.pending-file[data-filename="${filename}"]`);
|
|
const category = container.querySelector('input[type="radio"]:checked')?.value;
|
|
if (!category) return toast('יש לבחור סיווג', 'error');
|
|
|
|
let endpoint = API + '/classify';
|
|
let body;
|
|
|
|
if (category === 'dinleumi') {
|
|
endpoint = API + '/classify-dinleumi';
|
|
body = {
|
|
filename,
|
|
title: container.querySelector('.doc-title').value,
|
|
};
|
|
} else {
|
|
body = {
|
|
filename,
|
|
category,
|
|
title: container.querySelector('.doc-title').value,
|
|
};
|
|
if (category === 'case') {
|
|
body.case_number = container.querySelector('.case-select').value;
|
|
body.doc_type = container.querySelector('.doctype-select').value;
|
|
if (!body.case_number) return toast('יש לבחור תיק', 'error');
|
|
} else {
|
|
body.decision_number = container.querySelector('.decision-number').value;
|
|
body.decision_date = container.querySelector('.decision-date').value;
|
|
body.subject_categories = Array.from(container.querySelectorAll('.subject-grid input:checked')).map(cb => cb.value);
|
|
}
|
|
}
|
|
|
|
// Disable button
|
|
container.querySelector('.process-btn').disabled = true;
|
|
container.querySelector('.process-btn').textContent = 'מעבד...';
|
|
|
|
try {
|
|
const res = await fetch(endpoint, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(body),
|
|
});
|
|
if (!res.ok) {
|
|
const err = await res.json();
|
|
toast(err.detail || 'שגיאה', 'error');
|
|
container.querySelector('.process-btn').disabled = false;
|
|
container.querySelector('.process-btn').textContent = 'עבד';
|
|
return;
|
|
}
|
|
const data = await res.json();
|
|
trackTask(data.task_id, filename.replace(/^\d+_/, ''));
|
|
// Remove from pending after a short delay
|
|
setTimeout(loadPending, 500);
|
|
} catch (e) {
|
|
toast('שגיאת רשת', 'error');
|
|
}
|
|
}
|
|
|
|
// ── Task Tracking ─────────────────────────────────────────────
|
|
const activeTasks = new Map();
|
|
|
|
function trackTask(taskId, displayName) {
|
|
const card = document.getElementById('tasksCard');
|
|
const list = document.getElementById('tasksList');
|
|
card.style.display = 'block';
|
|
|
|
const STATUS_LABELS = {
|
|
queued: 'בתור...',
|
|
validating: 'מאמת...',
|
|
copying: 'מעתיק...',
|
|
registering: 'רושם...',
|
|
processing: 'מעבד...',
|
|
completed: 'הושלם',
|
|
failed: 'נכשל',
|
|
};
|
|
|
|
const STEP_LABELS = {
|
|
extracting: 'מחלץ טקסט',
|
|
extracting_metadata: 'מחלץ מטאדאטא מפסק הדין',
|
|
corpus: 'מוסיף לקורפוס',
|
|
chunking: 'מפצל לקטעים',
|
|
embedding: 'יוצר embeddings',
|
|
};
|
|
|
|
const div = document.createElement('div');
|
|
div.className = 'task-item';
|
|
div.id = 'task_' + taskId;
|
|
div.innerHTML = `
|
|
<div class="spinner"></div>
|
|
<div class="task-info">
|
|
<div class="task-name">${esc(displayName)}</div>
|
|
<div class="task-status">בתור...</div>
|
|
</div>
|
|
`;
|
|
list.prepend(div);
|
|
|
|
const es = new EventSource(API + '/progress/' + taskId);
|
|
es.onmessage = e => {
|
|
const data = JSON.parse(e.data);
|
|
const statusEl = div.querySelector('.task-status');
|
|
let label = STATUS_LABELS[data.status] || data.status;
|
|
if (data.step) label += ' — ' + (STEP_LABELS[data.step] || data.step);
|
|
statusEl.textContent = label;
|
|
|
|
if (data.status === 'completed') {
|
|
div.classList.add('done');
|
|
es.close();
|
|
const r = data.result || {};
|
|
const m = data.metadata;
|
|
if (m && data.system === 'din-leumi') {
|
|
// Show extracted metadata for din-leumi
|
|
let metaHtml = `הושלם — ${r.chunks || 0} קטעים, ${r.pages || '?'} עמודים`;
|
|
const parts = [];
|
|
if (m.court) parts.push(m.court);
|
|
if (m.judge) parts.push('שופט: ' + m.judge);
|
|
if (m.decision_date) parts.push(m.decision_date);
|
|
if (m.outcome) parts.push({accepted:'התקבלה',rejected:'נדחתה',partial:'חלקית',remanded:'הוחזרה'}[m.outcome] || m.outcome);
|
|
if (parts.length) metaHtml += '<br><small style="color:#999">' + esc(parts.join(' | ')) + '</small>';
|
|
if (m.topics && m.topics.length) metaHtml += '<br><small style="color:#e94560">' + m.topics.map(t => esc(t)).join(', ') + '</small>';
|
|
statusEl.innerHTML = metaHtml;
|
|
} else if (r.chunks !== undefined) {
|
|
statusEl.textContent = `הושלם — ${r.chunks} קטעים, ${r.pages || '?'} עמודים`;
|
|
}
|
|
toast('העיבוד הושלם: ' + esc(displayName), 'success');
|
|
loadStatus();
|
|
} else if (data.status === 'failed') {
|
|
div.classList.add('failed');
|
|
es.close();
|
|
statusEl.textContent = 'נכשל: ' + (data.error || 'שגיאה לא ידועה');
|
|
toast('העיבוד נכשל', 'error');
|
|
}
|
|
};
|
|
es.onerror = () => { es.close(); };
|
|
}
|
|
|
|
// ── Status Bar ────────────────────────────────────────────────
|
|
async function loadStatus() {
|
|
try {
|
|
const res = await fetch(API + '/processing-status');
|
|
const data = await res.json();
|
|
document.getElementById('statCases').textContent = data.cases ?? '—';
|
|
document.getElementById('statDocs').textContent = data.documents ?? '—';
|
|
document.getElementById('statChunks').textContent = data.chunks ?? '—';
|
|
} catch (e) {
|
|
// Silently ignore — status bar stays at default
|
|
}
|
|
}
|
|
|
|
// ── Helpers ───────────────────────────────────────────────────
|
|
function esc(s) {
|
|
const d = document.createElement('div');
|
|
d.textContent = s;
|
|
return d.innerHTML;
|
|
}
|
|
|
|
function formatSize(bytes) {
|
|
if (bytes < 1024) return bytes + ' B';
|
|
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
|
|
return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
|
|
}
|
|
|
|
function toast(msg, type = '') {
|
|
const el = document.getElementById('toast');
|
|
el.textContent = msg;
|
|
el.className = 'toast show ' + type;
|
|
setTimeout(() => el.className = 'toast', 3000);
|
|
}
|
|
|
|
// Initial load
|
|
loadPending();
|
|
loadStatus();
|
|
</script>
|
|
</body>
|
|
</html>
|