Aug 7 - Update: UI change - MT16
This commit is contained in:
@@ -24,6 +24,10 @@ def index():
|
||||
now = now_eastern()
|
||||
today_start = now.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
today_end = today_start + timedelta(days=1)
|
||||
# MT-16 — Monday 00:00 of the current week, for the modern dashboard's
|
||||
# "submitted this week" tile. Derived from today_start so it inherits
|
||||
# now_eastern() rather than mixing in a second clock.
|
||||
week_start = today_start - timedelta(days=today_start.weekday())
|
||||
|
||||
is_inspector = current_user.is_inspector
|
||||
is_privileged = current_user.role in ['admin', 'director']
|
||||
@@ -62,6 +66,14 @@ def index():
|
||||
Inspection.inspection_date < today_end,
|
||||
).count()
|
||||
|
||||
# MT-16 — fully completed & submitted so far this week (Monday → now).
|
||||
# Reuses base_q, so it inherits the same role scoping as every other tile.
|
||||
submitted_this_week = base_q.filter(
|
||||
Inspection.status == 'completed',
|
||||
Inspection.inspection_date >= week_start,
|
||||
Inspection.inspection_date < today_end,
|
||||
).count()
|
||||
|
||||
# ── Open issues (inspector: all issues in contracted facilities) ───────
|
||||
open_issues_q = Issue.query.filter(Issue.status.in_(['open', 'in_progress']))
|
||||
if is_inspector:
|
||||
@@ -282,6 +294,26 @@ def index():
|
||||
stale_q = stale_q.filter(False)
|
||||
stale_in_progress = stale_q.count()
|
||||
|
||||
# ── In-progress inspections, all ages (MT-16) ─────────────────────────────
|
||||
# stale_in_progress above counts only those older than 24h. The modern
|
||||
# dashboard shows the full in-progress count as its own tile, so this is a
|
||||
# separate query with the SAME role scoping rather than a reuse of stale_q.
|
||||
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(
|
||||
@@ -349,6 +381,11 @@ def index():
|
||||
# inspections list, so surfacing them here would double-report the work.
|
||||
sched_upcoming = []
|
||||
sched_overdue_count = 0
|
||||
# MT-16 — the modern dashboard additionally shows the total number of active
|
||||
# plans ("On Schedules") and offers Continue instead of a duplicate Start
|
||||
# where an inspection is already underway for that plan.
|
||||
sched_total = 0
|
||||
sched_open_inspections = {}
|
||||
if not is_customer:
|
||||
from app.models.inspection_schedule import InspectionSchedule
|
||||
_today = now_eastern().date()
|
||||
@@ -365,11 +402,34 @@ def index():
|
||||
s for s in _all_sched
|
||||
if s.next_run_at and _today <= s.next_run_at.date() <= _today + timedelta(days=7)
|
||||
][:8]
|
||||
sched_total = len(_all_sched) # active plan-mode schedules
|
||||
# {schedule_id: inspection_id} for plans with an inspection already in
|
||||
# progress. MT's FK is Inspection.inspection_schedule_id (ST calls it
|
||||
# scheduled_inspection_id). Ordered ascending so that when a plan somehow
|
||||
# has more than one open inspection, the dict keeps the LOWEST id — the
|
||||
# original, not a later duplicate.
|
||||
_sched_ids = [s.id for s in sched_upcoming if s.id]
|
||||
if _sched_ids:
|
||||
_open_rows = (
|
||||
Inspection.query
|
||||
.filter(Inspection.inspection_schedule_id.in_(_sched_ids),
|
||||
Inspection.status == 'in_progress')
|
||||
.order_by(Inspection.id.desc())
|
||||
.all()
|
||||
)
|
||||
sched_open_inspections = {
|
||||
r.inspection_schedule_id: r.id for r in _open_rows
|
||||
}
|
||||
|
||||
return render_template(
|
||||
'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,
|
||||
week_start_str = week_start.strftime('%Y-%m-%d'),
|
||||
today_inspections = today_inspections,
|
||||
completed_today = completed_today,
|
||||
open_issues = open_issues,
|
||||
|
||||
Reference in New Issue
Block a user