Aug 3 - Update the dashboard

This commit is contained in:
2026-08-03 14:09:10 -04:00
parent 991f242d12
commit d673d52f29
3 changed files with 221 additions and 288 deletions
+21
View File
@@ -294,6 +294,23 @@ def index():
stale_q = stale_q.filter(False)
stale_in_progress = stale_q.count()
# ── In-progress inspections (all, not just stale) — "In Progress" tile ─────
inprog_q = Inspection.query.filter(Inspection.status == 'in_progress')
if is_inspector:
if not inspector_facility_ids:
inprog_q = inprog_q.filter(False)
else:
inprog_q = inprog_q.filter(
Inspection.facility_id.in_(inspector_facility_ids),
Inspection.inspector_id == current_user.id,
)
elif is_customer:
if customer_facility_ids:
inprog_q = inprog_q.filter(Inspection.facility_id.in_(customer_facility_ids))
else:
inprog_q = inprog_q.filter(False)
in_progress_total = inprog_q.count()
# ── Unassigned open issues ────────────────────────────────────────────────
from app.models.facility import Area as _AreaU
unassigned_q = Issue.query.outerjoin(_AreaU, Issue.area_id == _AreaU.id).filter(
@@ -361,6 +378,7 @@ def index():
# ── Scheduled inspections (phase36): upcoming / overdue ──────────────
sched_upcoming = []
sched_overdue_count = 0
sched_total = 0
sched_open_inspections = {}
if not is_customer:
from app.models.scheduled_inspection import ScheduledInspection
@@ -370,6 +388,7 @@ def index():
if is_inspector:
_sq = _sq.filter(ScheduledInspection.inspector_id == current_user.id)
_all_sched = _sq.order_by(ScheduledInspection.next_due_date.asc()).all()
sched_total = len(_all_sched) # active scheduled inspection plans ("On Schedules")
sched_overdue_count = sum(1 for s in _all_sched if s.next_due_date < _today)
# Upcoming = due today through the next 7 days (overdue shown separately)
sched_upcoming = [
@@ -383,7 +402,9 @@ def index():
'dashboard.html',
sched_upcoming = sched_upcoming,
sched_overdue_count = sched_overdue_count,
sched_total = sched_total,
sched_open_inspections = sched_open_inspections,
in_progress_total = in_progress_total,
submitted_this_week = submitted_this_week,
completed_today = completed_today,
open_issues = open_issues,