Add View button to previous QC reports to open saved HTML report

- Add /hm-qc/report/<id> route to serve saved reports by database ID
- Create view_report.html template with score summary and embedded report iframe
- Add "View" button column to Previous QC Reports table

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
nickviljoen 2026-03-21 17:55:15 +02:00
parent 5e291723a0
commit 71ddf7892f
3 changed files with 114 additions and 0 deletions

View file

@ -381,6 +381,32 @@ def progress_poll(session_id):
return jsonify({'error': str(e)}), 500
@hm_qc_bp.route('/report/<int:report_id>')
def view_report(report_id):
"""View a saved QC report by database ID."""
try:
report = QCReport.query.get(report_id)
if not report:
return render_template('hm_qc/results.html', error='Report not found'), 404
# Read the HTML report file
html_content = None
if report.file_path and os.path.exists(report.file_path):
with open(report.file_path, 'r', encoding='utf-8') as f:
html_content = f.read()
return render_template(
'hm_qc/view_report.html',
active_tab='hm-qc',
report=report,
html_content=html_content
)
except Exception as e:
logger.error(f"Error viewing report {report_id}: {e}")
return render_template('hm_qc/results.html', error=str(e)), 500
@hm_qc_bp.route('/results/<session_id>')
def results(session_id):
"""

View file

@ -79,6 +79,7 @@
<th>Score</th>
<th>Status</th>
<th>Date</th>
<th></th>
</tr>
</thead>
<tbody>
@ -99,6 +100,11 @@
</span>
</td>
<td>{{ report.created_at.strftime('%Y-%m-%d %H:%M') if report.created_at }}</td>
<td>
<a href="{{ url_for('hm_qc.view_report', report_id=report.id) }}" class="btn btn-sm btn-outline-primary">
<i class="bi bi-eye me-1"></i>View
</a>
</td>
</tr>
{% endfor %}
</tbody>

View file

@ -0,0 +1,82 @@
{% extends "base.html" %}
{% block title %}QC Report - {{ report.filename }}{% endblock %}
{% block extra_head %}
<style>
.score-display {
font-size: 2.5rem;
font-weight: bold;
}
.report-iframe {
width: 100%;
min-height: 700px;
border: 1px solid #dee2e6;
border-radius: 4px;
}
</style>
{% endblock %}
{% block content %}
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<h2 class="mb-0"><i class="bi bi-file-earmark-check me-2"></i>QC Report</h2>
<a href="{{ url_for('hm_qc.index') }}" class="btn btn-outline-primary">
<i class="bi bi-arrow-left me-1"></i>Back to HM QC
</a>
</div>
<!-- Report Summary -->
<div class="row mb-4">
<div class="col-md-3">
<div class="card text-center">
<div class="card-body">
<div class="score-display text-{{ 'success' if report.status == 'passed' else 'warning' if report.status == 'warning' else 'danger' }}">
{{ '%.0f' % report.score if report.score is not none else '-' }}
</div>
<span class="badge bg-{{ 'success' if report.status == 'passed' else 'warning' if report.status == 'warning' else 'danger' }} fs-6">
{{ report.status | upper }}
</span>
</div>
</div>
</div>
<div class="col-md-9">
<div class="card">
<div class="card-body">
<table class="table table-borderless mb-0">
<tr>
<th style="width: 120px;">Filename</th>
<td>{{ report.filename }}</td>
</tr>
<tr>
<th>Job Number</th>
<td>{{ report.job_number or '-' }}</td>
</tr>
<tr>
<th>Date</th>
<td>{{ report.created_at.strftime('%Y-%m-%d %H:%M:%S') if report.created_at }}</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<!-- Embedded HTML Report -->
{% if html_content %}
<div class="card">
<div class="card-header">
<i class="bi bi-file-earmark-code me-2"></i>Detailed Report
</div>
<div class="card-body p-0">
<iframe srcdoc="{{ html_content | e }}" class="report-iframe"></iframe>
</div>
</div>
{% else %}
<div class="alert alert-warning">
<i class="bi bi-exclamation-triangle me-2"></i>
Report file not found on disk. The report may have been generated before the current deployment.
</div>
{% endif %}
</div>
{% endblock %}