{% extends "base.html" %} {% block title %}Dashboard{% endblock %} {% block content %}

Welcome, {{ current_user.display_name }}!

{{ current_user.role.replace('_',' ')|title }}
{# ── Top stat cards ─────────────────────────────────────────────────────── #}
Today's Inspections
{{ today_inspections }}
Submitted Today
{{ completed_today }}
Open Issues
{{ open_issues }}
{% if open_issues > 0 %}
{% if severity_breakdown.critical > 0 %}{{ severity_breakdown.critical }} critical{% endif %} {% if severity_breakdown.high > 0 %}{{ severity_breakdown.high }} high{% endif %} {% if severity_breakdown.medium > 0 %}{{ severity_breakdown.medium }} med{% endif %} {% if severity_breakdown.low > 0 %}{{ severity_breakdown.low }} low{% endif %}
{% endif %}
Avg Score (30d)
{{ avg_score if avg_score else '--' }}{% if avg_score %}%{% endif %}
{# ── Pending Follow-ups alert (non-customer) ────────────────────────────── #} {% if pending_followups and pending_followups > 0 and current_user.role != 'customer' %}
{% endif %} {# ── SLA Summary ─────────────────────────────────────────────────────────── #} {% if sla_breached > 0 or sla_at_risk > 0 %}
{% if sla_breached > 0 %}
SLA Breached
{{ sla_breached }}
{% endif %} {% if sla_at_risk > 0 %}
SLA At Risk
{{ sla_at_risk }}
{% endif %}
{% endif %} {# ── Recent activity ─────────────────────────────────────────────────────── #}
Recent Activity
{% if recent_inspections %}
{% if current_user.role != 'inspector' %}{% endif %} {% for insp in recent_inspections %} {% if current_user.role != 'inspector' %}{% endif %} {% endfor %}
Date Facility AreaInspectorScore Status
{{ insp.inspection_date.strftime('%Y-%m-%d %H:%M') }} {{ insp.facility.name }} {{ insp.area.name if insp.area else '—' }}{{ insp.inspector.display_name }} {% if insp.overall_score %} {{ insp.overall_score }}% {% else %} {% endif %} {{ 'Submitted' if insp.status == 'completed' else insp.status|title }}
{% else %}
No recent inspections.
{% endif %}
{# ── Score trend chart + Facility performance ───────────────────────────── #}
Inspection Score Trend (Last 30 Days)
{% if trend_labels %} {% else %}
No completed inspections with scores in the last 30 days.
{% endif %}
{% if current_user.role in ['admin', 'director'] and facility_perf %}
Facility Performance (30d)
{% for f in facility_perf %} {% endfor %}
Facility Inspections Avg Score
{{ f.name }} {{ f.count }} {{ f.avg }}%
{% endif %}
{# ── Facility Score Trend (30/60/90 days) ─────────────────────────────────── #} {% if all_facilities %}
Facility Score Trend
Select a facility to view its score trend.
{% endif %} {# ── My open issues (inspector widget) ──────────────────────────────────── #} {% if my_issues %}
My Open Issues View all
{% for issue in my_issues %} {% set sla = sla_status(issue) %} {% endfor %}
ID Severity Facility / Description Status SLA
#{{ issue.id }} {{ issue.severity|title }}
{{ issue.resolved_facility.name if issue.resolved_facility else '—' }}
{{ issue.description[:60] }}{% if issue.description|length > 60 %}…{% endif %}
{{ issue.status|replace('_',' ')|title }} {% if sla == 'breached' %} Breached {% elif sla == 'at_risk' %} {{ sla_hours_remaining(issue)|abs|round(1) }}h left {% else %} OK {% endif %}
{% endif %} {# ── Customer portal: scoped facilities panel ───────────────────────────── #} {% if current_user.role == 'customer' %}
Your Facilities {% if customer_facilities %} {{ customer_facilities|length }} {% endif %}
{% if customer_facilities %}
{% if customer_facilities|length > 6 %}
{% endif %}
{% for f in customer_facilities %}
{{ f.name }}
{{ f.address or '—' }}
{{ f.project.name if f.project else '—' }}
{% endfor %}
{% if customer_facilities|length > 9 %}
{% endif %}
{% else %}
No facilities have been assigned to your account yet. Please contact your administrator.
{% endif %}
{% endif %} {% if trend_labels %} {% endif %} {# ── Facility trend chart (AJAX-driven) ── #} {% if all_facilities %} {% endif %} {% endblock %}