05/26 Add Contract filter in Inspections page
This commit is contained in:
@@ -216,8 +216,15 @@ def index():
|
|||||||
status_filter = request.args.get('status', '')
|
status_filter = request.args.get('status', '')
|
||||||
facility_filter = request.args.get('facility_id', '')
|
facility_filter = request.args.get('facility_id', '')
|
||||||
follow_up_filter = request.args.get('follow_up', '')
|
follow_up_filter = request.args.get('follow_up', '')
|
||||||
|
contract_filter = request.args.get('contract_id', '')
|
||||||
|
|
||||||
if status_filter:
|
if status_filter:
|
||||||
q = q.filter(Inspection.status == status_filter)
|
q = q.filter(Inspection.status == status_filter)
|
||||||
|
if contract_filter.isdigit():
|
||||||
|
_contract_fids = [
|
||||||
|
f.id for f in Facility.query.filter_by(project_id=int(contract_filter)).all()
|
||||||
|
]
|
||||||
|
q = q.filter(Inspection.facility_id.in_(_contract_fids)) if _contract_fids else q.filter(False)
|
||||||
if facility_filter.isdigit():
|
if facility_filter.isdigit():
|
||||||
q = q.filter(Inspection.facility_id == int(facility_filter))
|
q = q.filter(Inspection.facility_id == int(facility_filter))
|
||||||
if follow_up_filter == '1':
|
if follow_up_filter == '1':
|
||||||
@@ -227,21 +234,32 @@ def index():
|
|||||||
).filter(~Inspection.follow_ups.any())
|
).filter(~Inspection.follow_ups.any())
|
||||||
|
|
||||||
inspections = q.paginate(page=page, per_page=20, error_out=False)
|
inspections = q.paginate(page=page, per_page=20, error_out=False)
|
||||||
|
|
||||||
if current_user.role == 'inspector':
|
if current_user.role == 'inspector':
|
||||||
fids = get_inspector_scope(current_user) or []
|
fids = get_inspector_scope(current_user) or []
|
||||||
facilities = Facility.query.filter(Facility.id.in_(fids), Facility.active == True).order_by(Facility.name).all()
|
_fq = Facility.query.filter(Facility.id.in_(fids), Facility.active == True)
|
||||||
elif current_user.role == 'customer':
|
elif current_user.role == 'customer':
|
||||||
cids = get_customer_scope(current_user) or []
|
cids = get_customer_scope(current_user) or []
|
||||||
facilities = Facility.query.filter(Facility.id.in_(cids), Facility.active == True).order_by(Facility.name).all()
|
_fq = Facility.query.filter(Facility.id.in_(cids), Facility.active == True)
|
||||||
else:
|
else:
|
||||||
facilities = Facility.query.filter_by(active=True).order_by(Facility.name).all()
|
_fq = Facility.query.filter_by(active=True)
|
||||||
|
|
||||||
|
if contract_filter.isdigit():
|
||||||
|
_fq = _fq.filter(Facility.project_id == int(contract_filter))
|
||||||
|
|
||||||
|
facilities = _fq.order_by(Facility.name).all()
|
||||||
|
|
||||||
|
from app.models.project import Project
|
||||||
|
projects = Project.query.filter_by(active=True).order_by(Project.name).all()
|
||||||
|
|
||||||
return render_template('inspections/list.html',
|
return render_template('inspections/list.html',
|
||||||
inspections=inspections,
|
inspections=inspections,
|
||||||
facilities=facilities,
|
facilities=facilities,
|
||||||
|
projects=projects,
|
||||||
status_filter=status_filter,
|
status_filter=status_filter,
|
||||||
facility_filter=facility_filter,
|
facility_filter=facility_filter,
|
||||||
follow_up_filter=follow_up_filter,
|
follow_up_filter=follow_up_filter,
|
||||||
|
contract_filter=contract_filter,
|
||||||
now=now_eastern())
|
now=now_eastern())
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<div class="card shadow-sm mb-4">
|
<div class="card shadow-sm mb-4">
|
||||||
<div class="card-body py-2">
|
<div class="card-body py-2">
|
||||||
<form method="get" class="row g-2 align-items-end">
|
<form method="get" class="row g-2 align-items-end">
|
||||||
<div class="col-md-3">
|
<div class="col-md-2">
|
||||||
<label class="form-label small mb-1">Status</label>
|
<label class="form-label small mb-1">Status</label>
|
||||||
<select name="status" class="form-select form-select-sm">
|
<select name="status" class="form-select form-select-sm">
|
||||||
<option value="">All Statuses</option>
|
<option value="">All Statuses</option>
|
||||||
@@ -23,9 +23,18 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</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">
|
<div class="col-md-3">
|
||||||
<label class="form-label small mb-1">Facility</label>
|
<label class="form-label small mb-1">Facility</label>
|
||||||
<select name="facility_id" class="form-select form-select-sm">
|
<select name="facility_id" id="insp_filter_facility" class="form-select form-select-sm">
|
||||||
<option value="">All Facilities</option>
|
<option value="">All Facilities</option>
|
||||||
{% for f in facilities %}
|
{% for f in facilities %}
|
||||||
<option value="{{ f.id }}" {% if facility_filter == f.id|string %}selected{% endif %}>{{ f.name }}</option>
|
<option value="{{ f.id }}" {% if facility_filter == f.id|string %}selected{% endif %}>{{ f.name }}</option>
|
||||||
@@ -47,7 +56,7 @@
|
|||||||
<table class="table table-hover mb-0">
|
<table class="table table-hover mb-0">
|
||||||
<thead class="table-light">
|
<thead class="table-light">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Date</th><th>Facility</th><th>Area</th>
|
<th>Date</th><th>Contract</th><th>Facility</th><th>Area</th>
|
||||||
<th>Template</th><th>Inspector</th><th>Score</th>
|
<th>Template</th><th>Inspector</th><th>Score</th>
|
||||||
<th>Status</th><th></th>
|
<th>Status</th><th></th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -56,6 +65,7 @@
|
|||||||
{% for ins in inspections.items %}
|
{% for ins in inspections.items %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ ins.inspection_date.strftime('%Y-%m-%d %H:%M') }}</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>{{ ins.facility.name }}</td>
|
||||||
<td>{% if ins.area %}{{ ins.area.name }}{% else %}<span class="text-muted">—</span>{% endif %}</td>
|
<td>{% if ins.area %}{{ ins.area.name }}{% else %}<span class="text-muted">—</span>{% endif %}</td>
|
||||||
<td>{{ ins.template.name }}</td>
|
<td>{{ ins.template.name }}</td>
|
||||||
@@ -115,7 +125,7 @@
|
|||||||
{% for p in inspections.iter_pages(left_edge=1, right_edge=1, left_current=2, right_current=2) %}
|
{% for p in inspections.iter_pages(left_edge=1, right_edge=1, left_current=2, right_current=2) %}
|
||||||
{% if p %}
|
{% if p %}
|
||||||
<li class="page-item {{ 'active' if p == inspections.page }}">
|
<li class="page-item {{ 'active' if p == inspections.page }}">
|
||||||
<a class="page-link" href="{{ url_for('inspections.index', page=p, status=status_filter, facility_id=facility_filter) }}">{{ p }}</a>
|
<a class="page-link" href="{{ url_for('inspections.index', page=p, status=status_filter, contract_id=contract_filter, facility_id=facility_filter) }}">{{ p }}</a>
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li class="page-item disabled"><span class="page-link">…</span></li>
|
<li class="page-item disabled"><span class="page-link">…</span></li>
|
||||||
@@ -163,6 +173,39 @@
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
|
<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'] %}
|
{% if current_user.role in ['admin', 'director'] %}
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user