diff --git a/lib/api.py b/lib/api.py index 653c80f..a739ec0 100644 --- a/lib/api.py +++ b/lib/api.py @@ -2198,19 +2198,20 @@ def _build_kiwix_sources(): for r in rows: source = dict(r) + zim_title = r['title'] or r['zim_filename'] total_articles += r['article_count'] or 0 total_processed += r['processed_count'] or 0 - # Get pipeline stats for this source's documents + # Get pipeline stats for THIS source's documents (filtered by category) pipeline = {} try: pipe_rows = conn.execute(""" SELECT d.status, COUNT(*) as cnt FROM documents d JOIN catalogue c ON d.hash = c.hash - WHERE c.source = 'kiwix' + WHERE c.source = 'kiwix' AND c.category = ? GROUP BY d.status - """).fetchall() + """, (zim_title,)).fetchall() for pr in pipe_rows: pipeline[pr['status']] = pr['cnt'] except Exception: @@ -2219,6 +2220,19 @@ def _build_kiwix_sources(): in_pipe = sum(v for k, v in pipeline.items() if k not in ('complete', 'failed')) total_in_pipeline += in_pipe source['pipeline'] = pipeline + + # Compute effective status reflecting full pipeline state + db_status = r['status'] + if db_status == 'complete' and pipeline: + if in_pipe > 0: + source['effective_status'] = 'processing' + else: + source['effective_status'] = 'complete' + elif db_status == 'ingesting': + source['effective_status'] = 'extracting' + else: + source['effective_status'] = db_status # 'detected' + sources.append(source) # Check kiwix-serve health diff --git a/static/css/recon.css b/static/css/recon.css index 9289f93..31d6306 100644 --- a/static/css/recon.css +++ b/static/css/recon.css @@ -329,3 +329,5 @@ tr:hover { background: var(--bg-secondary); } .badge-complete { background: #1a4a2e; color: #00ff41; padding: 2px 8px; border-radius: var(--radius); font-size: 11px; } .badge-ingesting { background: #1a3a5a; color: #0ea5e9; padding: 2px 8px; border-radius: var(--radius); font-size: 11px; } .badge-detected { background: #333; color: #888; padding: 2px 8px; border-radius: var(--radius); font-size: 11px; } +.badge-processing { background: #4a3a1a; color: #f59e0b; padding: 2px 8px; border-radius: var(--radius); font-size: 11px; } +.badge-extracting { background: #1a3a5a; color: #0ea5e9; padding: 2px 8px; border-radius: var(--radius); font-size: 11px; } diff --git a/static/js/kiwix.js b/static/js/kiwix.js index aab8552..5b21f66 100644 --- a/static/js/kiwix.js +++ b/static/js/kiwix.js @@ -20,9 +20,15 @@ var sources = data.sources || []; var html = ''; sources.forEach(function(s) { - var pctDone = s.article_count > 0 ? (s.processed_count / s.article_count * 100).toFixed(1) : 0; - var statusBadge = s.status === 'complete' ? 'COMPLETE' : - s.status === 'ingesting' ? 'INGESTING' : + var es = s.effective_status || s.status; + var pipe = s.pipeline || {}; + var pipeComplete = pipe.complete || 0; + var pipeTotal = 0; + for (var k in pipe) pipeTotal += pipe[k]; + var pctDone = pipeTotal > 0 ? (pipeComplete / pipeTotal * 100).toFixed(1) : 0; + var statusBadge = es === 'complete' ? 'COMPLETE' : + es === 'processing' ? 'PROCESSING' : + es === 'extracting' ? 'EXTRACTING' : 'DETECTED'; // Derive browse URL from zim_filename var zimName = s.zim_filename.replace(/_(?:maxi|mini|nopic)_[\d-]+\.zim$/, ''); @@ -38,8 +44,9 @@ '