First commit
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,44 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Flag Issue{% endblock %}
|
||||
{% block content %}
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-6">
|
||||
<div class="card shadow-sm border-danger">
|
||||
<div class="card-header bg-danger text-white">
|
||||
<h5 class="mb-0"><i class="bi bi-exclamation-triangle"></i> Flag Issue During Inspection</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="alert alert-light border mb-3">
|
||||
<strong>Inspection:</strong> {{ inspection.template.name }}<br>
|
||||
<strong>Facility:</strong> {{ inspection.facility.name }}
|
||||
</div>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
{{ form.facility_id(type="hidden") }}
|
||||
<div class="mb-3">
|
||||
{{ form.severity.label(class="form-label fw-semibold") }}
|
||||
{{ form.severity(class="form-select") }}
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
{{ form.description.label(class="form-label fw-semibold") }}
|
||||
{{ form.description(class="form-control", rows=4, placeholder="Describe the issue in detail…") }}
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
{{ form.photo.label(class="form-label fw-semibold") }}
|
||||
{{ form.photo(class="form-control") }}
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
{{ form.assigned_to.label(class="form-label fw-semibold") }}
|
||||
{{ form.assigned_to(class="form-select") }}
|
||||
</div>
|
||||
<div class="d-flex gap-2">
|
||||
<button type="submit" class="btn btn-danger"><i class="bi bi-flag"></i> Log Issue</button>
|
||||
<a href="{{ url_for('inspections.execute', inspection_id=inspection.id) }}"
|
||||
class="btn btn-outline-secondary">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,286 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Inspections{% endblock %}
|
||||
{% block content %}
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h2><i class="bi bi-clipboard-data"></i> Inspections</h2>
|
||||
{% if current_user.role != 'customer' %}
|
||||
<a href="{{ url_for('inspections.start') }}" class="btn btn-primary">
|
||||
<i class="bi bi-plus-circle"></i> New Inspection
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{# Filters #}
|
||||
<div class="card shadow-sm mb-4">
|
||||
<div class="card-body py-2">
|
||||
<form method="get">
|
||||
<div class="row g-2 align-items-end">
|
||||
<div class="col-md-1">
|
||||
<label class="form-label small mb-1">Inspection #</label>
|
||||
<input type="number" name="inspection_id" class="form-control form-control-sm"
|
||||
min="1" placeholder="ID" value="{{ inspection_id_filter }}">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small mb-1">Status</label>
|
||||
<select name="status" class="form-select form-select-sm">
|
||||
<option value="">All Statuses</option>
|
||||
{% for s in ['in_progress','completed','flagged'] %}
|
||||
<option value="{{ s }}" {% if status_filter == s %}selected{% endif %}>{{ 'Submitted' if s == 'completed' else s|replace('_',' ')|title }}</option>
|
||||
{% endfor %}
|
||||
<option value="follow_up" {% if status_filter == 'follow_up' %}selected{% endif %}>Flagged Follow-up</option>
|
||||
<option value="has_issues" {% if status_filter == 'has_issues' %}selected{% endif %}>Has Logged Issues</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label small mb-1">Contract</label>
|
||||
<select name="contract_id" id="insp_filter_contract" class="form-select form-select-sm">
|
||||
<option value="">All Contracts</option>
|
||||
{% for p in projects %}
|
||||
<option value="{{ p.id }}" {% if contract_filter == p.id|string %}selected{% endif %}>{{ p.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label small mb-1">Facility</label>
|
||||
<select name="facility_id" id="insp_filter_facility" class="form-select form-select-sm">
|
||||
<option value="">All Facilities</option>
|
||||
{% for f in facilities %}
|
||||
<option value="{{ f.id }}" {% if facility_filter == f.id|string %}selected{% endif %}>{{ f.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
{% if inspectors %}
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small mb-1">Inspector</label>
|
||||
<select name="inspector_id" class="form-select form-select-sm">
|
||||
<option value="">All Inspectors</option>
|
||||
{% for u in inspectors %}
|
||||
<option value="{{ u.id }}" {% if inspector_filter == u.id|string %}selected{% endif %}>{{ u.display_name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="row g-2 align-items-end mt-1">
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small mb-1">Date From</label>
|
||||
<input type="date" name="date_from" class="form-control form-control-sm"
|
||||
value="{{ date_from_filter }}">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label small mb-1">Date To</label>
|
||||
<input type="date" name="date_to" class="form-control form-control-sm"
|
||||
value="{{ date_to_filter }}">
|
||||
</div>
|
||||
<div class="col-md-1">
|
||||
<label class="form-label small mb-1">Min Score</label>
|
||||
<input type="number" name="score_min" class="form-control form-control-sm"
|
||||
min="0" max="100" placeholder="0"
|
||||
value="{{ score_min_filter }}">
|
||||
</div>
|
||||
<div class="col-md-1">
|
||||
<label class="form-label small mb-1">Max Score</label>
|
||||
<input type="number" name="score_max" class="form-control form-control-sm"
|
||||
min="0" max="100" placeholder="100"
|
||||
value="{{ score_max_filter }}">
|
||||
</div>
|
||||
<div class="col-auto d-flex align-items-end gap-2 flex-wrap">
|
||||
<button type="submit" class="btn btn-sm btn-outline-primary">Filter</button>
|
||||
<a href="{{ url_for('inspections.index') }}" class="btn btn-sm btn-outline-secondary">Clear</a>
|
||||
<a id="exportPdfBtn"
|
||||
href="{{ url_for('inspections.export_list_pdf', **request.args) }}"
|
||||
class="btn btn-sm btn-outline-danger">
|
||||
<i class="bi bi-file-earmark-pdf"></i> Export PDF
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body p-0">
|
||||
{% if inspections.items %}
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover mb-0">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>#</th><th>Date</th><th>Contract</th><th>Facility</th><th>Area</th>
|
||||
<th>Template</th><th>Inspector</th><th>Score</th>
|
||||
<th>Status</th><th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for ins in inspections.items %}
|
||||
<tr>
|
||||
<td><small class="text-muted">#{{ ins.id }}</small></td>
|
||||
<td>{{ ins.inspection_date.strftime('%Y-%m-%d %H:%M') }}</td>
|
||||
<td><small>{{ ins.facility.project.name if ins.facility and ins.facility.project else '—' }}</small></td>
|
||||
<td>{{ ins.facility.name }}</td>
|
||||
<td>{% if ins.area %}{{ ins.area.name }}{% else %}<span class="text-muted">—</span>{% endif %}</td>
|
||||
<td>{{ ins.template.name }}</td>
|
||||
<td>{{ ins.inspector.display_name }}</td>
|
||||
<td>
|
||||
{% if ins.overall_score %}
|
||||
<span class="badge bg-{{ 'success' if ins.overall_score >= 90 else 'warning' if ins.overall_score >= 70 else 'danger' }}">
|
||||
{{ ins.overall_score }}%
|
||||
</span>
|
||||
{% else %}<span class="text-muted">—</span>{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge bg-{{ 'success' if ins.status == 'completed' else 'danger' if ins.status == 'flagged' else 'secondary' }}">
|
||||
{{ 'Submitted' if ins.status == 'completed' else ins.status|replace('_',' ')|title }}
|
||||
</span>
|
||||
{% if ins.status == 'in_progress' %}
|
||||
{% set hours_open = ((now - ins.inspection_date).total_seconds() / 3600) %}
|
||||
{% if hours_open > 24 %}
|
||||
<span class="badge bg-warning text-dark ms-1" title="In progress for over 24 hours — may be stale">
|
||||
<i class="bi bi-clock-history"></i> Stale
|
||||
</span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if ins.follow_up_required and not ins.follow_ups.count() %}
|
||||
<span class="badge bg-danger ms-1" title="Follow-up re-inspection required">
|
||||
<i class="bi bi-arrow-repeat"></i> Follow-up
|
||||
</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="text-nowrap">
|
||||
{% if ins.status == 'in_progress' or ins.status == 'flagged' %}
|
||||
<a href="{{ url_for('inspections.execute', inspection_id=ins.id) }}" class="btn btn-sm btn-outline-primary insp-list-link">Continue</a>
|
||||
{% else %}
|
||||
<a href="{{ url_for('inspections.view', inspection_id=ins.id) }}" class="btn btn-sm btn-outline-secondary insp-list-link">View</a>
|
||||
{% endif %}
|
||||
{% if current_user.role in ['admin', 'director'] %}
|
||||
<button type="button"
|
||||
class="btn btn-sm btn-outline-danger ms-1"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#deleteInspectionModal"
|
||||
data-inspection-id="{{ ins.id }}"
|
||||
data-inspection-label="{{ ins.template.name }} — {{ ins.facility.name }} ({{ ins.inspection_date.strftime('%Y-%m-%d') }})"
|
||||
title="Delete inspection">
|
||||
<i class="bi bi-trash3"></i>
|
||||
</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{# Pagination #}
|
||||
{% if inspections.pages > 1 %}
|
||||
<div class="d-flex justify-content-center py-3">
|
||||
<nav><ul class="pagination pagination-sm mb-0">
|
||||
{% for p in inspections.iter_pages(left_edge=1, right_edge=1, left_current=2, right_current=2) %}
|
||||
{% if p %}
|
||||
<li class="page-item {{ 'active' if p == inspections.page }}">
|
||||
<a class="page-link" href="{{ url_for('inspections.index', page=p, inspection_id=inspection_id_filter, status=status_filter, contract_id=contract_filter, facility_id=facility_filter, date_from=date_from_filter, date_to=date_to_filter, score_min=score_min_filter, score_max=score_max_filter, inspector_id=inspector_filter) }}">{{ p }}</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="page-item disabled"><span class="page-link">…</span></li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</ul></nav>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div class="alert alert-info m-3"><i class="bi bi-info-circle"></i> No inspections found.</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% if current_user.role in ['admin', 'director'] %}
|
||||
<!-- Delete Inspection Confirmation Modal -->
|
||||
<div class="modal fade" id="deleteInspectionModal" tabindex="-1" aria-labelledby="deleteInspectionModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header bg-danger text-white">
|
||||
<h5 class="modal-title" id="deleteInspectionModalLabel">
|
||||
<i class="bi bi-exclamation-triangle-fill"></i> Confirm Deletion
|
||||
</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>You are about to permanently delete the following inspection:</p>
|
||||
<p class="fw-bold" id="deleteInspectionLabel"></p>
|
||||
<p class="text-muted mb-0">This will also remove all associated results, flagged issues, and uploaded photos. This action is <strong>irreversible</strong>.</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
||||
<i class="bi bi-x-circle"></i> Cancel
|
||||
</button>
|
||||
<form id="deleteInspectionForm" method="POST" action="" class="d-inline">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button type="submit" class="btn btn-danger">
|
||||
<i class="bi bi-trash3-fill"></i> Delete Permanently
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script>
|
||||
(function () {
|
||||
'use strict';
|
||||
// Save current filtered URL so view/execute pages can restore it on Back
|
||||
var links = document.querySelectorAll('.insp-list-link');
|
||||
links.forEach(function (a) {
|
||||
a.addEventListener('click', function () {
|
||||
sessionStorage.setItem('insp_list_back_url', window.location.href);
|
||||
});
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
'use strict';
|
||||
var contractSel = document.getElementById('insp_filter_contract');
|
||||
var facilitySel = document.getElementById('insp_filter_facility');
|
||||
if (!contractSel || !facilitySel) return;
|
||||
|
||||
var FACILITIES_URL = '{{ url_for("inspections.facilities_for_project", project_id=0) }}'.replace('/0', '/');
|
||||
|
||||
contractSel.addEventListener('change', function () {
|
||||
var projectId = this.value;
|
||||
facilitySel.value = '';
|
||||
if (!projectId) {
|
||||
facilitySel.innerHTML = '<option value="">All Facilities</option>';
|
||||
return;
|
||||
}
|
||||
facilitySel.disabled = true;
|
||||
facilitySel.innerHTML = '<option value="">Loading…</option>';
|
||||
fetch(FACILITIES_URL + projectId)
|
||||
.then(function (r) { return r.json(); })
|
||||
.then(function (data) {
|
||||
var html = '<option value="">All Facilities</option>';
|
||||
data.forEach(function (f) {
|
||||
html += '<option value="' + f.id + '">' + f.name + '</option>';
|
||||
});
|
||||
facilitySel.innerHTML = html;
|
||||
facilitySel.disabled = false;
|
||||
})
|
||||
.catch(function () { facilitySel.disabled = false; });
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
|
||||
{% if current_user.role in ['admin', 'director'] %}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const modal = document.getElementById('deleteInspectionModal');
|
||||
modal.addEventListener('show.bs.modal', function (event) {
|
||||
const btn = event.relatedTarget;
|
||||
const id = btn.getAttribute('data-inspection-id');
|
||||
const label = btn.getAttribute('data-inspection-label');
|
||||
document.getElementById('deleteInspectionLabel').textContent = label;
|
||||
document.getElementById('deleteInspectionForm').action = '/inspections/' + id + '/delete';
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,153 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}New Inspection{% endblock %}
|
||||
{% block content %}
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-6">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header bg-primary text-white">
|
||||
<h5 class="mb-0"><i class="bi bi-play-circle"></i> New Inspection</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="post">
|
||||
{{ form.hidden_tag() }}
|
||||
|
||||
<div class="mb-3">
|
||||
{{ form.template_id.label(class="form-label fw-semibold") }}
|
||||
{{ form.template_id(class="form-select" + (" is-invalid" if form.template_id.errors else "")) }}
|
||||
{% for e in form.template_id.errors %}<div class="invalid-feedback">{{ e }}</div>{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
{{ form.project_id.label(class="form-label fw-semibold") }}
|
||||
{{ form.project_id(class="form-select" + (" is-invalid" if form.project_id.errors else ""), id="projectSelect") }}
|
||||
{% for e in form.project_id.errors %}<div class="invalid-feedback">{{ e }}</div>{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
{{ form.facility_id.label(class="form-label fw-semibold") }}
|
||||
{{ form.facility_id(class="form-select" + (" is-invalid" if form.facility_id.errors else ""), id="facilitySelect") }}
|
||||
{% for e in form.facility_id.errors %}<div class="invalid-feedback">{{ e }}</div>{% endfor %}
|
||||
<div id="facilitySpinner" class="form-text text-muted d-none">
|
||||
<span class="spinner-border spinner-border-sm" role="status"></span> Loading facilities…
|
||||
</div>
|
||||
<div id="facilityEmpty" class="form-text text-warning d-none">
|
||||
No active facilities found for this contract.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3" id="areaGroup" style="display:none;">
|
||||
{{ form.area_id.label(class="form-label fw-semibold") }}
|
||||
{{ form.area_id(class="form-select", id="areaSelect") }}
|
||||
</div>
|
||||
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary btn-lg">
|
||||
<i class="bi bi-play-fill"></i> Begin Inspection
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
const projectSel = document.getElementById('projectSelect');
|
||||
const facilitySel = document.getElementById('facilitySelect');
|
||||
const spinner = document.getElementById('facilitySpinner');
|
||||
const emptyMsg = document.getElementById('facilityEmpty');
|
||||
const areaGroup = document.getElementById('areaGroup');
|
||||
const areaSel = document.getElementById('areaSelect');
|
||||
|
||||
const FACILITIES_URL = `{{ url_for('inspections.facilities_for_project', project_id=0) }}`.replace('/0', '/');
|
||||
const AREAS_URL = `{{ url_for('inspections.areas_for_facility', facility_id=0) }}`.replace('/0', '/');
|
||||
|
||||
function loadAreas(facilityId, selectedAreaId) {
|
||||
if (!facilityId) {
|
||||
areaGroup.style.display = 'none';
|
||||
areaSel.innerHTML = '<option value="0">— No specific area —</option>';
|
||||
return;
|
||||
}
|
||||
fetch(AREAS_URL + facilityId)
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.length === 0) {
|
||||
areaGroup.style.display = 'none';
|
||||
areaSel.innerHTML = '<option value="0">— No specific area —</option>';
|
||||
} else {
|
||||
areaSel.innerHTML = '<option value="0">— No specific area —</option>';
|
||||
data.forEach(a => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = a.id;
|
||||
opt.textContent = a.name;
|
||||
if (selectedAreaId && a.id === selectedAreaId) opt.selected = true;
|
||||
areaSel.appendChild(opt);
|
||||
});
|
||||
areaGroup.style.display = '';
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
areaGroup.style.display = 'none';
|
||||
});
|
||||
}
|
||||
|
||||
function loadFacilities(projectId, selectedFacilityId, selectedAreaId) {
|
||||
if (!projectId) return;
|
||||
spinner.classList.remove('d-none');
|
||||
emptyMsg.classList.add('d-none');
|
||||
facilitySel.disabled = true;
|
||||
areaGroup.style.display = 'none';
|
||||
|
||||
fetch(FACILITIES_URL + projectId)
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
facilitySel.innerHTML = '';
|
||||
if (data.length === 0) {
|
||||
emptyMsg.classList.remove('d-none');
|
||||
facilitySel.innerHTML = '<option value="">— no facilities —</option>';
|
||||
} else {
|
||||
data.forEach(f => {
|
||||
const opt = document.createElement('option');
|
||||
opt.value = f.id;
|
||||
opt.textContent = f.name;
|
||||
if (selectedFacilityId && f.id === selectedFacilityId) opt.selected = true;
|
||||
facilitySel.appendChild(opt);
|
||||
});
|
||||
loadAreas(facilitySel.value, selectedAreaId);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
facilitySel.innerHTML = '<option value="">— error loading facilities —</option>';
|
||||
})
|
||||
.finally(() => {
|
||||
spinner.classList.add('d-none');
|
||||
facilitySel.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
projectSel.addEventListener('change', function () {
|
||||
loadFacilities(this.value, null, null);
|
||||
});
|
||||
|
||||
facilitySel.addEventListener('change', function () {
|
||||
loadAreas(this.value, null);
|
||||
});
|
||||
|
||||
// On page load: if project already selected (e.g. validation error or reinspect),
|
||||
// reload facility list preserving the currently selected facility and area values.
|
||||
const initProject = projectSel.value;
|
||||
const initFacility = facilitySel.value ? parseInt(facilitySel.value, 10) : null;
|
||||
const initArea = areaSel.value ? parseInt(areaSel.value, 10) : null;
|
||||
if (initProject) {
|
||||
const hasRealOptions = Array.from(facilitySel.options).some(o => parseInt(o.value, 10) > 0);
|
||||
if (!hasRealOptions) {
|
||||
loadFacilities(initProject, initFacility, initArea);
|
||||
} else {
|
||||
// Facilities already rendered server-side — just load areas for the selected facility
|
||||
if (initFacility) loadAreas(initFacility, initArea);
|
||||
}
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,903 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Inspection #{{ inspection.id }} — Results{% endblock %}
|
||||
|
||||
{% block extra_css %}
|
||||
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
body { font-family:'DM Sans', sans-serif; background:#eef0f4; }
|
||||
.insp-wrap { max-width:1000px; margin:0 auto; padding:0 1rem 4rem; }
|
||||
.insp-header {
|
||||
background:#1a1d23; color:#fff; padding:1.1rem 1.75rem;
|
||||
border-radius:12px 12px 0 0;
|
||||
display:flex; align-items:center; justify-content:space-between; gap:1rem;
|
||||
}
|
||||
.insp-header h4 { margin:0; font-weight:600; font-size:1.05rem; }
|
||||
.insp-header .sub { font-size:.78rem; color:#94a3b8; margin-top:.2rem; }
|
||||
.score-badge {
|
||||
font-size:1.5rem; font-weight:700; padding:.4rem 1rem;
|
||||
border-radius:8px; min-width:80px; text-align:center;
|
||||
}
|
||||
.insp-body {
|
||||
background:#fff; border:1px solid #e2e8f0; border-top:none;
|
||||
border-radius:0 0 12px 12px; padding:1.75rem; padding-bottom:3rem; overflow-x:auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
.meta-row { display:flex; flex-wrap:wrap; gap:1.5rem; margin-bottom:1.5rem; padding-bottom:1rem; border-bottom:1px solid #e2e8f0; }
|
||||
.meta-item { display:flex; flex-direction:column; }
|
||||
.meta-item .lbl { font-size:.72rem; color:#94a3b8; font-weight:500; text-transform:uppercase; letter-spacing:.04em; }
|
||||
.meta-item .val { font-size:.9rem; color:#0f172a; font-weight:500; margin-top:.1rem; }
|
||||
|
||||
/* ── Grid: 12 cols × 36px rows, tight 3px gap ── */
|
||||
.form-grid {
|
||||
display:grid;
|
||||
grid-template-columns: repeat(12, 72px);
|
||||
grid-auto-rows: minmax(36px, auto);
|
||||
gap: 3px 8px;
|
||||
width: max-content;
|
||||
}
|
||||
|
||||
/* iPad fluid grid override */
|
||||
@media (max-width: 1194px) {
|
||||
.form-grid {
|
||||
--_cell: calc((min(calc(100vw - 2rem), 900px) - 11 * 8px) / 12);
|
||||
grid-template-columns: repeat(12, var(--_cell));
|
||||
grid-auto-rows: minmax(calc(var(--_cell) * 0.5), auto);
|
||||
width: 100%;
|
||||
}
|
||||
.insp-body { padding: 1rem; }
|
||||
}
|
||||
.fg-cell {
|
||||
overflow:hidden; display:flex; flex-direction:column;
|
||||
padding:.1rem .4rem;
|
||||
}
|
||||
.fg-cell .field-lbl {
|
||||
font-size:.68rem; font-weight:600; color:#94a3b8;
|
||||
display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
|
||||
flex-shrink:0; line-height:1.3;
|
||||
}
|
||||
.fg-cell .field-val {
|
||||
font-size:.78rem; color:#0f172a; background:#f8fafc;
|
||||
border:1px solid #e2e8f0; border-radius:4px;
|
||||
padding:.1rem .35rem; flex:1; min-height:0;
|
||||
overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
|
||||
display:flex; align-items:center;
|
||||
}
|
||||
.fg-cell .field-val.empty { color:#94a3b8; font-style:italic; }
|
||||
/* Textarea values: wrap text, scroll vertically, align to top */
|
||||
.fg-cell .field-val.multiline {
|
||||
white-space:pre-wrap; overflow-y:auto; overflow-x:hidden;
|
||||
text-overflow:clip; align-items:flex-start; word-break:break-word;
|
||||
min-height:calc(0.78rem * 1.5 * 4 + 0.2rem * 2); /* 4 lines × line-height + padding */
|
||||
flex:none;
|
||||
}
|
||||
|
||||
/* Section heading — spans full width, single row */
|
||||
.section-head {
|
||||
display:flex; align-items:flex-end; padding-bottom:.15rem;
|
||||
border-bottom:2px solid #e2e8f0; height:100%;
|
||||
}
|
||||
.section-head strong { font-weight:700; color:#374151; font-size:.88rem; }
|
||||
|
||||
/* Rating — inline stars */
|
||||
.rating-line { display:flex; align-items:center; gap:.28rem; flex:1; min-height:0; }
|
||||
.rating-stars-ro { color:#f59e0b; font-size:.9rem; letter-spacing:.02rem; line-height:1; white-space:nowrap; }
|
||||
.rating-score { font-size:.7rem; color:#64748b; white-space:nowrap; }
|
||||
|
||||
/* View Photo / Signature button */
|
||||
.btn-view-media {
|
||||
display:inline-flex; align-items:center; gap:.2rem;
|
||||
font-size:.68rem; padding:.1rem .42rem; border-radius:4px;
|
||||
border:1px solid #cbd5e1; background:#f8fafc; color:#374151;
|
||||
cursor:pointer; white-space:nowrap;
|
||||
transition:border-color .12s, background .12s;
|
||||
}
|
||||
.btn-view-media:hover { border-color:#2563eb; background:#eff6ff; color:#2563eb; }
|
||||
|
||||
/* Media lightbox */
|
||||
.media-backdrop {
|
||||
display:none; position:fixed; inset:0; z-index:1055;
|
||||
background:rgba(0,0,0,.65); align-items:center; justify-content:center;
|
||||
}
|
||||
.media-backdrop.open { display:flex; }
|
||||
.media-modal {
|
||||
background:#fff; border-radius:10px; overflow:hidden;
|
||||
max-width:min(92vw,700px); max-height:90vh;
|
||||
display:flex; flex-direction:column;
|
||||
box-shadow:0 8px 40px rgba(0,0,0,.35);
|
||||
}
|
||||
.media-modal-head {
|
||||
display:flex; align-items:center; justify-content:space-between;
|
||||
padding:.5rem .9rem; border-bottom:1px solid #e2e8f0;
|
||||
font-size:.8rem; font-weight:600; color:#374151;
|
||||
}
|
||||
.media-modal-close { border:none; background:none; font-size:1.1rem; color:#64748b; cursor:pointer; line-height:1; padding:0; }
|
||||
.media-modal-close:hover { color:#dc2626; }
|
||||
.media-modal img { display:block; max-width:100%; max-height:calc(90vh - 46px); object-fit:contain; }
|
||||
|
||||
/* Issues */
|
||||
.tbl-view { width:100%; border-collapse:collapse; font-size:.76rem; }
|
||||
.tbl-view th { background:#f1f5f9; font-weight:600; color:#374151; padding:.2rem .4rem; border:1px solid #e2e8f0; }
|
||||
.tbl-view td { border:1px solid #e2e8f0; padding:.15rem .4rem; color:#0f172a; }
|
||||
/* ── Print styles ── */
|
||||
@media print {
|
||||
|
||||
/* ── 1. Hide all screen-only chrome ── */
|
||||
nav, .navbar, header,
|
||||
.d-flex.justify-content-between.align-items-center.mb-3,
|
||||
.alert-warning,
|
||||
.modal, .modal-backdrop,
|
||||
.media-backdrop,
|
||||
a.btn, button,
|
||||
.btn { display: none !important; }
|
||||
|
||||
/* ── 2. Page / body reset ── */
|
||||
html, body { background: #fff !important;
|
||||
font-family: Helvetica, Arial, sans-serif;
|
||||
font-size: 9pt; color: #1a1d23; }
|
||||
.insp-wrap { max-width: 100% !important;
|
||||
padding: 0 !important; margin: 0 !important; }
|
||||
@page { margin: 0.65in; size: letter; }
|
||||
|
||||
/* ── 3. Dark header band (matches PDF header) ── */
|
||||
.insp-header { background: #1a1d23 !important;
|
||||
color: #fff !important;
|
||||
border-radius: 0 !important;
|
||||
padding: 10pt 14pt !important;
|
||||
display: flex !important;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
page-break-after: avoid;
|
||||
-webkit-print-color-adjust: exact;
|
||||
print-color-adjust: exact; }
|
||||
.insp-header h4 { font-size: 12pt !important;
|
||||
color: #fff !important; margin: 0; }
|
||||
.insp-header .sub { font-size: 8pt !important;
|
||||
color: #94a3b8 !important; }
|
||||
/* Score badge in header */
|
||||
.score-badge { font-size: 13pt !important;
|
||||
font-weight: 700;
|
||||
padding: 4pt 10pt !important;
|
||||
border-radius: 6pt !important;
|
||||
-webkit-print-color-adjust: exact;
|
||||
print-color-adjust: exact; }
|
||||
|
||||
/* ── 4. Body panel ── */
|
||||
.insp-body { border: 1pt solid #e2e8f0 !important;
|
||||
border-top: none !important;
|
||||
border-radius: 0 !important;
|
||||
box-shadow: none !important;
|
||||
padding: 12pt !important; }
|
||||
|
||||
/* ── 5. Meta row — render as a bordered grid (matches PDF _meta_table) ── */
|
||||
.meta-row { display: grid !important;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
gap: 0 !important;
|
||||
border: 0.5pt solid #e2e8f0;
|
||||
background: #f1f5f9 !important;
|
||||
margin-bottom: 10pt !important;
|
||||
-webkit-print-color-adjust: exact;
|
||||
print-color-adjust: exact; }
|
||||
.meta-item { padding: 4pt 6pt !important;
|
||||
border: 0.25pt solid #e2e8f0 !important;
|
||||
background: #f1f5f9 !important; }
|
||||
.meta-item .lbl { font-size: 7pt !important;
|
||||
color: #64748b !important;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
display: block; }
|
||||
.meta-item .val { font-size: 9pt !important;
|
||||
color: #1a1d23 !important;
|
||||
font-weight: 700;
|
||||
display: block; margin-top: 1pt; }
|
||||
|
||||
/* ── 6. Score / status comparison alerts (parent/child links) ── */
|
||||
.alert-info, .alert-secondary { display: block !important;
|
||||
font-size: 7.5pt;
|
||||
border: 0.5pt solid #e2e8f0 !important;
|
||||
padding: 4pt 8pt !important;
|
||||
margin-bottom: 6pt !important;
|
||||
background: #f8fafc !important;
|
||||
border-radius: 0 !important; }
|
||||
|
||||
/* ── 7. Section headings (matches PDF SectionHead + HR rule) ── */
|
||||
.section-head { background: none !important;
|
||||
border-bottom: 1.5pt solid #e2e8f0 !important;
|
||||
padding: 0 0 2pt 0 !important;
|
||||
margin: 10pt 0 4pt 0 !important;
|
||||
page-break-after: avoid; }
|
||||
.section-head strong { font-size: 9.5pt !important;
|
||||
font-weight: 700 !important;
|
||||
color: #1a1d23 !important; }
|
||||
|
||||
/* ── 8. Form grid — keep CSS grid, scale columns to page width ──
|
||||
Letter page at 0.65in margins → ~7.7in usable.
|
||||
12 equal columns: each unit = 7.7in / 12 ≈ 0.642in.
|
||||
We replicate the iPad fluid override pattern but for print. ── */
|
||||
.form-grid { display: grid !important;
|
||||
--_cell: calc((100% - 11 * 6pt) / 12);
|
||||
grid-template-columns: repeat(12, var(--_cell)) !important;
|
||||
grid-auto-rows: minmax(28pt, auto) !important;
|
||||
gap: 3pt 6pt !important;
|
||||
width: 100% !important; }
|
||||
.fg-cell { overflow: visible !important;
|
||||
display: flex !important;
|
||||
flex-direction: column !important;
|
||||
padding: 2pt 3pt !important;
|
||||
min-height: 0 !important; }
|
||||
|
||||
/* Field label (matches PDF FieldLabel: 7.5pt, slate) */
|
||||
.fg-cell .field-lbl { font-size: 7pt !important;
|
||||
color: #64748b !important;
|
||||
font-weight: 600;
|
||||
display: block !important;
|
||||
white-space: nowrap !important;
|
||||
overflow: hidden !important;
|
||||
text-overflow: ellipsis !important;
|
||||
flex-shrink: 0;
|
||||
margin-bottom: 1pt; }
|
||||
|
||||
/* Field value box (matches PDF: light border + #f8fafc bg) */
|
||||
.fg-cell .field-val { font-size: 8pt !important;
|
||||
color: #1a1d23 !important;
|
||||
background: #f8fafc !important;
|
||||
border: 0.5pt solid #e2e8f0 !important;
|
||||
border-radius: 2pt !important;
|
||||
padding: 2pt 4pt !important;
|
||||
display: flex !important;
|
||||
align-items: center !important;
|
||||
white-space: nowrap !important;
|
||||
overflow: hidden !important;
|
||||
text-overflow: ellipsis !important;
|
||||
flex: 1 !important;
|
||||
min-height: 0 !important;
|
||||
-webkit-print-color-adjust: exact;
|
||||
print-color-adjust: exact; }
|
||||
.fg-cell .field-val.multiline { white-space: pre-wrap !important;
|
||||
overflow: auto !important; }
|
||||
.fg-cell .field-val.empty { color: #94a3b8 !important;
|
||||
font-style: italic; }
|
||||
|
||||
/* Rating stars */
|
||||
.rating-stars-ro { font-size: 9pt !important;
|
||||
color: #f59e0b !important;
|
||||
-webkit-print-color-adjust: exact;
|
||||
print-color-adjust: exact; }
|
||||
.rating-line { display: flex !important;
|
||||
align-items: center;
|
||||
gap: 4pt; }
|
||||
.rating-score { font-size: 7pt !important;
|
||||
color: #64748b !important; }
|
||||
|
||||
/* Images: show inline, constrained */
|
||||
.fg-cell img { max-width: 2.8in !important;
|
||||
max-height: 1.8in !important;
|
||||
object-fit: contain;
|
||||
display: block;
|
||||
margin-top: 3pt; }
|
||||
|
||||
/* Photo/signature view buttons — replace with static label */
|
||||
.btn-view-media { display: none !important; }
|
||||
|
||||
/* ── 9. Issues table (matches PDF dark header, alternating rows) ── */
|
||||
.tbl-view { width: 100%; border-collapse: collapse;
|
||||
font-size: 7.5pt; margin-top: 4pt; }
|
||||
.tbl-view thead th { background: #1a1d23 !important;
|
||||
color: #fff !important;
|
||||
font-weight: 700;
|
||||
padding: 3pt 5pt !important;
|
||||
border: 0.25pt solid #e2e8f0 !important;
|
||||
-webkit-print-color-adjust: exact;
|
||||
print-color-adjust: exact; }
|
||||
.tbl-view tbody tr:nth-child(even) td
|
||||
{ background: #f1f5f9 !important;
|
||||
-webkit-print-color-adjust: exact;
|
||||
print-color-adjust: exact; }
|
||||
.tbl-view td { padding: 3pt 5pt !important;
|
||||
border: 0.25pt solid #e2e8f0 !important;
|
||||
vertical-align: top; }
|
||||
/* Severity badge colours in issues table */
|
||||
.badge.bg-danger { color: #dc2626 !important;
|
||||
background: none !important;
|
||||
font-weight: 700; }
|
||||
.badge.bg-warning { color: #d97706 !important;
|
||||
background: none !important;
|
||||
font-weight: 700; }
|
||||
.badge.bg-secondary { color: #64748b !important;
|
||||
background: none !important; }
|
||||
.badge.bg-success { color: #16a34a !important;
|
||||
background: none !important;
|
||||
font-weight: 700; }
|
||||
|
||||
/* ── 10. Notes block (matches PDF #fffbeb background) ── */
|
||||
[style*="white-space:pre-wrap"]
|
||||
{ white-space: pre-wrap !important;
|
||||
background: #fffbeb !important;
|
||||
border: 0.5pt solid #e2e8f0 !important;
|
||||
padding: 5pt 7pt !important;
|
||||
font-size: 8.5pt !important;
|
||||
-webkit-print-color-adjust: exact;
|
||||
print-color-adjust: exact; }
|
||||
|
||||
/* ── 11. Print sign-off block ── */
|
||||
.print-signoff { display: block !important;
|
||||
margin-top: 24pt;
|
||||
page-break-inside: avoid; }
|
||||
|
||||
/* ── 12. Page-break hints ── */
|
||||
.insp-header { page-break-after: avoid; }
|
||||
.section-head { page-break-after: avoid; }
|
||||
hr { border-color: #e2e8f0 !important; }
|
||||
}
|
||||
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="insp-wrap mt-3">
|
||||
|
||||
{# Action bar #}
|
||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||
<a id="backToInspectionsBtn" href="{{ url_for('inspections.index') }}" class="btn btn-sm btn-outline-secondary">
|
||||
<i class="bi bi-arrow-left"></i> Back to Inspections
|
||||
</a>
|
||||
<div class="d-flex gap-2">
|
||||
<a href="{{ url_for('inspections.export_pdf', inspection_id=inspection.id) }}"
|
||||
class="btn btn-sm btn-danger">
|
||||
<i class="bi bi-file-earmark-pdf"></i> Export PDF
|
||||
</a>
|
||||
<button onclick="window.print()" class="btn btn-sm btn-outline-secondary">
|
||||
<i class="bi bi-printer"></i> Print
|
||||
</button>
|
||||
{% if current_user.role not in ['customer'] %}
|
||||
<a href="{{ url_for('inspections.reinspect', inspection_id=inspection.id) }}"
|
||||
class="btn btn-sm btn-outline-primary"
|
||||
title="Start a follow-up re-inspection with the same template and facility">
|
||||
<i class="bi bi-arrow-repeat"></i> Re-inspect
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if current_user.role in ['admin','director'] %}
|
||||
{% if not inspection.follow_up_required %}
|
||||
<button type="button" class="btn btn-sm btn-outline-warning"
|
||||
data-bs-toggle="modal" data-bs-target="#followupModal"
|
||||
title="Flag this inspection as requiring a follow-up">
|
||||
<i class="bi bi-flag"></i> Flag Follow-up
|
||||
</button>
|
||||
{% else %}
|
||||
<form method="post"
|
||||
action="{{ url_for('inspections.clear_followup', inspection_id=inspection.id) }}"
|
||||
class="d-inline">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button class="btn btn-sm btn-warning">
|
||||
<i class="bi bi-flag-fill"></i> Clear Follow-up
|
||||
</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
<form method="post" action="{{ url_for('inspections.delete', inspection_id=inspection.id) }}"
|
||||
onsubmit="return confirm('Delete this inspection permanently?')">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button class="btn btn-sm btn-outline-danger"><i class="bi bi-trash3"></i> Delete</button>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# ── Follow-up required alert ── #}
|
||||
{% if inspection.follow_up_required %}
|
||||
<div class="alert alert-warning d-flex align-items-start gap-2 mb-3">
|
||||
<i class="bi bi-flag-fill mt-1"></i>
|
||||
<div>
|
||||
<strong>Follow-up Inspection Required</strong>
|
||||
{% if inspection.follow_up_note %}<br><span class="small">{{ inspection.follow_up_note }}</span>{% endif %}
|
||||
<div class="mt-2">
|
||||
<a href="{{ url_for('inspections.reinspect', inspection_id=inspection.id) }}"
|
||||
class="btn btn-sm btn-warning">
|
||||
<i class="bi bi-arrow-repeat me-1"></i>Start Re-inspection
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# ── Parent/child inspection links ── #}
|
||||
{% if inspection.parent %}
|
||||
<div class="alert alert-info small mb-3">
|
||||
<i class="bi bi-arrow-up-circle me-1"></i>
|
||||
This is a re-inspection of
|
||||
<a href="{{ url_for('inspections.view', inspection_id=inspection.parent.id) }}"
|
||||
class="alert-link">Inspection #{{ inspection.parent.id }}</a>
|
||||
({{ inspection.parent.inspection_date.strftime('%Y-%m-%d') }},
|
||||
score: {{ inspection.parent.overall_score|round(1) if inspection.parent.overall_score else 'N/A' }}%).
|
||||
</div>
|
||||
{% endif %}
|
||||
{% set followups = inspection.follow_ups.all() %}
|
||||
{% if followups %}
|
||||
<div class="alert alert-secondary small mb-3">
|
||||
<i class="bi bi-arrow-down-circle me-1"></i>
|
||||
Follow-up inspection(s):
|
||||
{% for fu in followups %}
|
||||
<a href="{{ url_for('inspections.view', inspection_id=fu.id) }}" class="alert-link">
|
||||
#{{ fu.id }} ({{ fu.inspection_date.strftime('%Y-%m-%d') }},
|
||||
score: {{ fu.overall_score|round(1) if fu.overall_score else 'N/A' }}%)
|
||||
</a>{% if not loop.last %}, {% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# ── Score comparison card (re-inspections only) ── #}
|
||||
{% if comparison %}
|
||||
<div class="card shadow-sm mb-3 border-0">
|
||||
<div class="card-header d-flex justify-content-between align-items-center
|
||||
bg-{{ 'success' if comparison.score_delta and comparison.score_delta > 0
|
||||
else 'danger' if comparison.score_delta and comparison.score_delta < 0
|
||||
else 'secondary' }} text-white">
|
||||
<span class="fw-semibold">
|
||||
<i class="bi bi-arrow-left-right me-1"></i>
|
||||
Score Comparison vs. Inspection #{{ comparison.parent_id }}
|
||||
<span class="small opacity-75 ms-2">
|
||||
{{ comparison.parent_date.strftime('%Y-%m-%d') }}
|
||||
</span>
|
||||
</span>
|
||||
<span class="d-flex gap-3 align-items-center">
|
||||
{# Overall delta badge #}
|
||||
{% if comparison.score_delta is not none %}
|
||||
{% if comparison.score_delta > 0 %}
|
||||
<span class="badge bg-white text-success fw-bold fs-6">
|
||||
<i class="bi bi-arrow-up-short"></i>+{{ comparison.score_delta }}%
|
||||
</span>
|
||||
{% elif comparison.score_delta < 0 %}
|
||||
<span class="badge bg-white text-danger fw-bold fs-6">
|
||||
<i class="bi bi-arrow-down-short"></i>{{ comparison.score_delta }}%
|
||||
</span>
|
||||
{% else %}
|
||||
<span class="badge bg-white text-secondary fw-bold fs-6">No change</span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{# Score pills #}
|
||||
<span class="small opacity-75">
|
||||
{{ comparison.parent_score|round(1) if comparison.parent_score else '—' }}%
|
||||
→
|
||||
{{ comparison.current_score|round(1) if comparison.current_score else '—' }}%
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# Header #}
|
||||
<div class="insp-header">
|
||||
<div>
|
||||
<h4><i class="bi bi-clipboard-check"></i> {{ inspection.template.name }}</h4>
|
||||
<div class="sub">
|
||||
{{ inspection.facility.name }}{% if inspection.area %} · {{ inspection.area.name }}{% endif %}
|
||||
· Inspector: <strong style="color:#e2e8f0;">{{ inspection.inspector.display_name }}</strong>
|
||||
</div>
|
||||
</div>
|
||||
<div class="d-flex align-items-center gap-2">
|
||||
<span class="badge bg-{{ 'success' if inspection.status == 'completed' else 'danger' if inspection.status == 'flagged' else 'secondary' }} fs-6">
|
||||
{{ inspection.status|replace('_',' ')|title }}
|
||||
</span>
|
||||
{% if inspection.overall_score is not none %}
|
||||
<div class="score-badge bg-{{ 'success' if inspection.overall_score >= 90 else 'warning' if inspection.overall_score >= 70 else 'danger' }} text-white">
|
||||
{{ inspection.overall_score }}%
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="insp-body">
|
||||
|
||||
{# Meta row #}
|
||||
<div class="meta-row">
|
||||
<div class="meta-item">
|
||||
<span class="lbl">Start Date</span>
|
||||
<span class="val">{{ inspection.inspection_date.strftime('%B %d, %Y %H:%M') }}</span>
|
||||
</div>
|
||||
{% if inspection.completed_at %}
|
||||
<div class="meta-item">
|
||||
<span class="lbl">Completed</span>
|
||||
<span class="val">{{ inspection.completed_at.strftime('%B %d, %Y %H:%M') }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="meta-item">
|
||||
<span class="lbl">Template</span>
|
||||
<span class="val">{{ inspection.template.name }}</span>
|
||||
</div>
|
||||
<div class="meta-item">
|
||||
<span class="lbl">Frequency</span>
|
||||
<span class="val">{{ inspection.template.frequency|title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# ── Submission GPS (admin / director only) ──────────────────────────── #}
|
||||
{% if current_user.role in ['admin', 'director'] and inspection.submit_latitude and inspection.submit_longitude %}
|
||||
{% set _lat = inspection.submit_latitude | float %}
|
||||
{% set _lng = inspection.submit_longitude | float %}
|
||||
<div class="mb-4">
|
||||
<div class="lbl mb-1" style="font-size:.72rem;color:#94a3b8;font-weight:500;text-transform:uppercase;letter-spacing:.04em;">
|
||||
<i class="bi bi-geo-alt-fill text-danger me-1"></i>Submission Location
|
||||
</div>
|
||||
<div style="border-radius:10px;overflow:hidden;border:1px solid #e2e8f0;max-width:420px;">
|
||||
<iframe
|
||||
src="https://maps.google.com/maps?q={{ _lat }},{{ _lng }}&z=15&output=embed"
|
||||
width="420" height="220"
|
||||
style="border:0;display:block;width:100%;"
|
||||
allowfullscreen="" loading="lazy"
|
||||
referrerpolicy="no-referrer-when-downgrade">
|
||||
</iframe>
|
||||
</div>
|
||||
<div class="mt-1" style="font-size:.8rem;color:#64748b;">
|
||||
{{ '%.6f' | format(_lat) }}, {{ '%.6f' | format(_lng) }}
|
||||
<a href="https://www.google.com/maps?q={{ _lat }},{{ _lng }}" target="_blank"
|
||||
class="ms-2 text-decoration-none small">
|
||||
<i class="bi bi-box-arrow-up-right"></i> Open in Maps
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# ── Build the filtered field set ──────────────────────────────────────
|
||||
Strategy:
|
||||
1. Find all grid rows that contain at least one rated rating field.
|
||||
2. Collect every field whose grid row overlaps a rated row.
|
||||
3. Also collect section fields that immediately precede a rated group.
|
||||
4. Re-number rows sequentially (1-based) so there are no gaps.
|
||||
#}
|
||||
{% if form_fields %}
|
||||
|
||||
{# Pass 1: find all rated rows AND which label IDs have a rated field after them #}
|
||||
{% set ns = namespace(rated_rows=[], visible_label_ids=[]) %}
|
||||
|
||||
{# 1a: collect rows that have any answered/filled field (not just ratings) #}
|
||||
{% set _skip_types = ['label', 'section', 'button_submit', 'button_print', 'button_email'] %}
|
||||
{% for field in form_fields %}
|
||||
{% if field.type not in _skip_types %}
|
||||
{% set fval = form_data.get(field.id | string, '') %}
|
||||
{# A row is "visible" if: rating has score>0, OR any other field has a non-empty value #}
|
||||
{% if field.type == 'rating' %}
|
||||
{% set score = fval | int %}
|
||||
{% if score > 0 %}
|
||||
{% for r in range(field.row, field.row + field.rowSpan) %}
|
||||
{% if r not in ns.rated_rows %}{% set ns.rated_rows = ns.rated_rows + [r] %}{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% elif fval and fval != '' and fval != [] %}
|
||||
{% for r in range(field.row, field.row + field.rowSpan) %}
|
||||
{% if r not in ns.rated_rows %}{% set ns.rated_rows = ns.rated_rows + [r] %}{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{# 1b: walk fields in order; accumulate label IDs.
|
||||
When we hit any answered field (rating > 0, pass_fail answered, text filled, etc.),
|
||||
mark ALL accumulated label IDs as visible and clear the buffer. #}
|
||||
{% set lbuf = namespace(ids=[]) %}
|
||||
{% for field in form_fields %}
|
||||
{% if field.type == 'label' %}
|
||||
{% set lbuf.ids = lbuf.ids + [field.id] %}
|
||||
{% elif field.type not in _skip_types %}
|
||||
{% set fval = form_data.get(field.id | string, '') %}
|
||||
{% set answered = namespace(v=false) %}
|
||||
{% if field.type == 'rating' %}
|
||||
{% if fval | int > 0 %}{% set answered.v = true %}{% endif %}
|
||||
{% elif fval and fval != '' and fval != [] %}
|
||||
{% set answered.v = true %}
|
||||
{% endif %}
|
||||
{% if answered.v %}
|
||||
{% for lid in lbuf.ids %}
|
||||
{% if lid not in ns.visible_label_ids %}
|
||||
{% set ns.visible_label_ids = ns.visible_label_ids + [lid] %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% set lbuf.ids = [] %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{# Pass 2: render — labels only if in visible_label_ids,
|
||||
data fields only if row overlaps rated_rows, sections always buffered. #}
|
||||
{% set remap = namespace(out_row=1, last_orig_row=-1, pending_sec=none) %}
|
||||
|
||||
<div class="form-grid">
|
||||
|
||||
{% for field in form_fields %}
|
||||
{% set ftype = field.type %}
|
||||
|
||||
{# Track pending section #}
|
||||
{% if ftype == 'section' %}
|
||||
{% set remap.pending_sec = field %}
|
||||
|
||||
{% elif ftype in ('button_submit', 'button_print', 'button_email') %}
|
||||
{# skip — action buttons not shown in read-only view #}
|
||||
|
||||
{% elif ftype == 'label' %}
|
||||
{# Only show labels that are ancestors of rated fields #}
|
||||
{% if field.id in ns.visible_label_ids %}
|
||||
{# Advance row only when original row actually changes #}
|
||||
{% if field.row != remap.last_orig_row %}
|
||||
{% if remap.last_orig_row != -1 %}{% set remap.out_row = remap.out_row + 1 %}{% endif %}
|
||||
{# Flush pending section before the first field on this new row #}
|
||||
{% if remap.pending_sec is not none %}
|
||||
<div class="fg-cell" style="grid-column:1 / span 12; grid-row:{{ remap.out_row }} / span 1;">
|
||||
<div class="section-head"><strong>{{ remap.pending_sec.label }}</strong></div>
|
||||
</div>
|
||||
{% set remap.out_row = remap.out_row + 1 %}
|
||||
{% set remap.pending_sec = none %}
|
||||
{% endif %}
|
||||
{% set remap.last_orig_row = field.row %}
|
||||
{% endif %}
|
||||
{% set fs_map = {'small':'0.72rem','normal':'0.82rem','large':'0.96rem','x-large':'1.1rem'} %}
|
||||
<div class="fg-cell"
|
||||
style="grid-column: {{ field.col }} / span {{ field.colSpan }};
|
||||
grid-row: {{ remap.out_row }} / span 1;">
|
||||
<div style="font-size:{{ fs_map.get(field.font_size or 'normal','0.82rem') }};
|
||||
font-weight:{{ field.font_weight or 'normal' }};
|
||||
color:#374151; overflow:hidden; display:flex; align-items:center; height:100%;">
|
||||
{{ field.text_content or '' }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
{# Check if this field overlaps any rated row #}
|
||||
{% set vis = namespace(show=false) %}
|
||||
{% for r in range(field.row, field.row + field.rowSpan) %}
|
||||
{% if r in ns.rated_rows %}{% set vis.show = true %}{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
{% if vis.show %}
|
||||
{# Advance row only when original row actually changes.
|
||||
Section flush is also guarded here so a label already placed on
|
||||
this row at the same out_row cannot be displaced. #}
|
||||
{% if field.row != remap.last_orig_row %}
|
||||
{% if remap.last_orig_row != -1 %}{% set remap.out_row = remap.out_row + 1 %}{% endif %}
|
||||
{% if remap.pending_sec is not none %}
|
||||
<div class="fg-cell" style="grid-column:1 / span 12; grid-row:{{ remap.out_row }} / span 1;">
|
||||
<div class="section-head"><strong>{{ remap.pending_sec.label }}</strong></div>
|
||||
</div>
|
||||
{% set remap.out_row = remap.out_row + 1 %}
|
||||
{% set remap.pending_sec = none %}
|
||||
{% endif %}
|
||||
{% set remap.last_orig_row = field.row %}
|
||||
{% endif %}
|
||||
|
||||
{# Render the field at its original col/colSpan but remapped row #}
|
||||
<div class="fg-cell"
|
||||
style="grid-column: {{ field.col }} / span {{ field.colSpan }};
|
||||
grid-row: {{ remap.out_row }} / span 1;">
|
||||
|
||||
{% set fid = field.id | string %}
|
||||
{% set val = form_data.get(fid, '') %}
|
||||
|
||||
{% if ftype == 'rating' %}
|
||||
<span class="field-lbl">{{ field.label }}</span>
|
||||
<div class="rating-line">
|
||||
{% set score = val | int %}
|
||||
{% if score > 0 %}
|
||||
<span class="rating-stars-ro">{% for i in range(1,6) %}{{ '★' if i <= score else '☆' }}{% endfor %}</span>
|
||||
<span class="rating-score">{{ score }}/5</span>
|
||||
{% else %}
|
||||
<span style="font-size:.72rem;color:#94a3b8;font-style:italic;">Not rated</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% elif ftype == 'image' %}
|
||||
<span class="field-lbl">{{ field.label }}</span>
|
||||
<div style="display:flex;align-items:center;flex:1;min-height:0;">
|
||||
{% if val %}
|
||||
<button type="button" class="btn-view-media"
|
||||
onclick="openMedia('{{ url_for('static', filename=val) }}','{{ field.label | e }}')">
|
||||
<i class="bi bi-image"></i> View Photo
|
||||
</button>
|
||||
{% else %}
|
||||
<span style="font-size:.72rem;color:#94a3b8;font-style:italic;">No photo</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% elif ftype == 'signature' %}
|
||||
<span class="field-lbl">{{ field.label }}</span>
|
||||
<div style="display:flex;align-items:center;flex:1;min-height:0;">
|
||||
{% if val and val.startswith('data:') %}
|
||||
<button type="button" class="btn-view-media"
|
||||
onclick="openMedia('{{ val }}','{{ field.label | e }}')">
|
||||
<i class="bi bi-pen"></i> View Signature
|
||||
</button>
|
||||
{% else %}
|
||||
<span style="font-size:.72rem;color:#94a3b8;font-style:italic;">No signature</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% elif ftype == 'pass_fail' %}
|
||||
<span class="field-lbl">{{ field.label }}</span>
|
||||
<div class="field-val">
|
||||
{% if val and val.lower() in ('pass','yes','ok','good','acceptable','compliant') %}
|
||||
<span class="text-success"><i class="bi bi-check-circle-fill"></i> {{ val }}</span>
|
||||
{% elif val %}
|
||||
<span class="text-danger"><i class="bi bi-x-circle-fill"></i> {{ val }}</span>
|
||||
{% else %}
|
||||
<span style="font-size:.72rem;color:#94a3b8;font-style:italic;">Not answered</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% elif ftype == 'checkbox' %}
|
||||
<span class="field-lbl">{{ field.label }}</span>
|
||||
<div class="field-val">
|
||||
{% if val == 'yes' %}<span class="text-success"><i class="bi bi-check-circle-fill"></i> Yes</span>
|
||||
{% else %}<span class="text-muted"><i class="bi bi-circle"></i> No</span>{% endif %}
|
||||
</div>
|
||||
|
||||
{% elif ftype == 'checkbox_group' %}
|
||||
<span class="field-lbl">{{ field.label }}</span>
|
||||
<div class="field-val" style="white-space:normal;overflow:auto;">
|
||||
{% if val and val is iterable and val is not string %}
|
||||
{% for item in val %}<span class="badge bg-primary me-1" style="font-size:.62rem;">{{ item }}</span>{% endfor %}
|
||||
{% else %}<span class="empty">None</span>{% endif %}
|
||||
</div>
|
||||
|
||||
{% elif ftype == 'table' %}
|
||||
<span class="field-lbl">{{ field.label }}</span>
|
||||
<div style="overflow:auto;flex:1;min-height:0;">
|
||||
{% if val and val is iterable and val is not string %}
|
||||
<table class="tbl-view">
|
||||
<thead><tr>{% for hdr in (field.col_headers or ['Col']) %}<th>{{ hdr }}</th>{% endfor %}</tr></thead>
|
||||
<tbody>{% for row in val %}<tr>{% for hdr in (field.col_headers or ['Col']) %}<td>{{ row.get(hdr,'') }}</td>{% endfor %}</tr>{% endfor %}</tbody>
|
||||
</table>
|
||||
{% else %}<span style="font-size:.72rem;color:#94a3b8;">No data</span>{% endif %}
|
||||
</div>
|
||||
|
||||
{% else %}
|
||||
{# text, number, date, email, radio, select, textarea #}
|
||||
<span class="field-lbl">{{ field.label }}</span>
|
||||
<div class="field-val {{ 'multiline' if ftype == 'textarea' }} {{ 'empty' if not val }}">{{ val or '—' }}</div>
|
||||
{% endif %}
|
||||
|
||||
</div>{# /fg-cell #}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
</div>{# /form-grid #}
|
||||
|
||||
{% if not ns.rated_rows %}
|
||||
<p class="text-muted">No rated fields in this inspection.</p>
|
||||
{% endif %}
|
||||
|
||||
{% else %}
|
||||
<p class="text-muted">No form fields found for this template.</p>
|
||||
{% endif %}
|
||||
|
||||
{# Issues #}
|
||||
{% if issues %}
|
||||
<hr class="mt-4">
|
||||
<h6 class="text-danger"><i class="bi bi-exclamation-triangle"></i> Issues Logged ({{ issues|length }})</h6>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-hover">
|
||||
<thead class="table-light">
|
||||
<tr><th>Severity</th><th>Area</th><th>Description</th><th>Status</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for issue in issues %}
|
||||
<tr>
|
||||
<td><span class="badge bg-{{ 'danger' if issue.severity in ['critical','high'] else 'warning text-dark' if issue.severity == 'medium' else 'secondary' }}">{{ issue.severity|title }}</span></td>
|
||||
<td>{{ issue.area.name }}</td>
|
||||
<td>{{ issue.description[:80] }}{% if issue.description|length > 80 %}…{% endif %}</td>
|
||||
<td><span class="badge bg-{{ 'success' if issue.status == 'resolved' else 'warning text-dark' if issue.status == 'in_progress' else 'secondary' }}">{{ issue.status|replace('_',' ')|title }}</span></td>
|
||||
<td><a href="{{ url_for('issues.view', issue_id=issue.id) }}" class="btn btn-sm btn-outline-secondary">View</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# ── Print-only sign-off block (hidden on screen, visible @media print) ── #}
|
||||
<div class="print-signoff" style="display:none; font-family:Helvetica,Arial,sans-serif;">
|
||||
|
||||
<table style="width:100%; border-collapse:collapse; font-size:8pt; color:#64748b;
|
||||
margin-top:10pt;">
|
||||
<tr>
|
||||
<td colspan="6" style="font-size:9.5pt; font-weight:700; color:#1a1d23;
|
||||
padding-bottom:6pt; border-bottom:0.5pt solid #e2e8f0;">
|
||||
Sign-off
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td colspan="6" style="height:18pt;"></td></tr>
|
||||
|
||||
{# Inspector row #}
|
||||
<tr>
|
||||
<td style="width:18%; border-top:0.75pt solid #1a1d23; padding-top:3pt;
|
||||
font-size:7.5pt; color:#64748b;">Inspector Signature</td>
|
||||
<td style="width:4%;"></td>
|
||||
<td style="width:38%; border-top:0.75pt solid #1a1d23; padding-top:3pt;
|
||||
font-size:7.5pt; color:#64748b;">Printed Name</td>
|
||||
<td style="width:4%;"></td>
|
||||
<td style="width:32%; border-top:0.75pt solid #1a1d23; padding-top:3pt;
|
||||
font-size:7.5pt; color:#64748b;">Date</td>
|
||||
<td style="width:4%;"></td>
|
||||
</tr>
|
||||
<tr><td colspan="6" style="height:22pt;"></td></tr>
|
||||
|
||||
{# Supervisor row #}
|
||||
<tr>
|
||||
<td style="border-top:0.75pt solid #1a1d23; padding-top:3pt;
|
||||
font-size:7.5pt; color:#64748b;">Supervisor Signature</td>
|
||||
<td></td>
|
||||
<td style="border-top:0.75pt solid #1a1d23; padding-top:3pt;
|
||||
font-size:7.5pt; color:#64748b;">Printed Name</td>
|
||||
<td></td>
|
||||
<td style="border-top:0.75pt solid #1a1d23; padding-top:3pt;
|
||||
font-size:7.5pt; color:#64748b;">Date</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{# Media lightbox #}
|
||||
<div class="media-backdrop" id="mediaModal" onclick="if(event.target.id==='mediaModal')closeMedia()">
|
||||
<div class="media-modal">
|
||||
<div class="media-modal-head">
|
||||
<span id="mediaLabel">Photo</span>
|
||||
<button class="media-modal-close" onclick="closeMedia()">×</button>
|
||||
</div>
|
||||
<img id="mediaImg" src="" alt="">
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
<script>
|
||||
(function () {
|
||||
var backUrl = sessionStorage.getItem('insp_list_back_url');
|
||||
if (backUrl) {
|
||||
var btn = document.getElementById('backToInspectionsBtn');
|
||||
if (btn) btn.href = backUrl;
|
||||
}
|
||||
}());
|
||||
</script>
|
||||
|
||||
<script>
|
||||
function openMedia(src, label) {
|
||||
document.getElementById('mediaImg').src = src;
|
||||
document.getElementById('mediaLabel').textContent = label;
|
||||
document.getElementById('mediaModal').classList.add('open');
|
||||
}
|
||||
function closeMedia() {
|
||||
document.getElementById('mediaModal').classList.remove('open');
|
||||
document.getElementById('mediaImg').src = '';
|
||||
}
|
||||
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeMedia(); });
|
||||
</script>
|
||||
|
||||
{# ── Flag follow-up modal ── #}
|
||||
<div class="modal fade" id="followupModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<form method="POST" action="{{ url_for('inspections.flag_followup', inspection_id=inspection.id) }}">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title"><i class="bi bi-flag me-2"></i>Flag Follow-up Required</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<label class="form-label fw-semibold">Reason / Notes <span class="text-muted small">(optional)</span></label>
|
||||
<textarea name="follow_up_note" class="form-control" rows="3"
|
||||
placeholder="Describe what needs to be addressed in the follow-up inspection…"></textarea>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
||||
<button type="submit" class="btn btn-warning">
|
||||
<i class="bi bi-flag me-1"></i>Flag Follow-up
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user