{% extends "base.html" %} {% block title %}Inspection #{{ inspection.id }} — Results{% endblock %} {% block extra_css %} {% endblock %} {% block content %}
{# Action bar #}
Back to Inspections
{% if current_user.role in ['admin','supervisor'] %}
{% endif %}
{# Header #}

{{ inspection.template.name }}

{{ inspection.facility.name }}{% if inspection.area %} · {{ inspection.area.name }}{% endif %}  ·  Inspector: {{ inspection.inspector.username }}
{{ inspection.status|replace('_',' ')|title }} {% if inspection.overall_score is not none %}
{{ inspection.overall_score }}%
{% endif %}
{# Meta row #}
Date {{ inspection.inspection_date.strftime('%B %d, %Y %H:%M') }}
{% if inspection.completed_at %}
Completed {{ inspection.completed_at.strftime('%B %d, %Y %H:%M') }}
{% endif %}
Template {{ inspection.template.name }}
Frequency {{ inspection.template.frequency|title }}
{# ── 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: collect grid row numbers that contain a rated (score>0) rating field #} {% set ns = namespace(rated_rows=[]) %} {% for field in form_fields %} {% if field.type == 'rating' %} {% set score = form_data.get(field.id | string, '0') | 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 %} {% endif %} {% endfor %} {# Pass 2: render in form_fields order. - section fields: buffer as pending; flush before the first visible data field that follows. - data fields: emit only if their row overlaps rated_rows; remap rows sequentially. #} {% set remap = namespace(out_row=1, last_orig_row=-1, pending_sec=none) %}
{% for field in form_fields %} {% set ftype = field.type %} {# Track pending section #} {% if ftype == 'section' %} {% set remap.pending_sec = field %} {% elif ftype in ('label', 'button_submit', 'button_print', 'button_email') %} {# skip #} {% 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 %} {# Flush pending section first #} {% if remap.pending_sec is not none %} {# Section: 1 row tall, spanning all 12 cols #}
{{ remap.pending_sec.label }}
{% set remap.out_row = remap.out_row + 1 %} {% set remap.pending_sec = none %} {% set remap.last_orig_row = -1 %} {% endif %} {# Advance out_row when the original row changes #} {% if field.row != remap.last_orig_row and remap.last_orig_row != -1 %} {% set remap.out_row = remap.out_row + 1 %} {% endif %} {% set remap.last_orig_row = field.row %} {# Render the field at its original col/colSpan but remapped row #}
{% set fid = field.id | string %} {% set val = form_data.get(fid, '') %} {% if ftype == 'rating' %} {{ field.label }}
{% set score = val | int %} {% if score > 0 %} {% for i in range(1,6) %}{{ '★' if i <= score else '☆' }}{% endfor %} {{ score }}/5 {% else %} Not rated {% endif %}
{% elif ftype == 'image' %} {{ field.label }}
{% if val %} {% else %} No photo {% endif %}
{% elif ftype == 'signature' %} {{ field.label }}
{% if val and val.startswith('data:') %} {% else %} No signature {% endif %}
{% elif ftype == 'checkbox' %} {{ field.label }}
{% if val == 'yes' %} Yes {% else %} No{% endif %}
{% elif ftype == 'checkbox_group' %} {{ field.label }}
{% if val and val is iterable and val is not string %} {% for item in val %}{{ item }}{% endfor %} {% else %}None{% endif %}
{% elif ftype == 'table' %} {{ field.label }}
{% if val and val is iterable and val is not string %} {% for hdr in (field.col_headers or ['Col']) %}{% endfor %}{% for row in val %}{% for hdr in (field.col_headers or ['Col']) %}{% endfor %}{% endfor %}
{{ hdr }}
{{ row.get(hdr,'') }}
{% else %}No data{% endif %}
{% else %} {# text, number, date, email, radio, select, textarea #} {{ field.label }}
{{ val or '—' }}
{% endif %}
{# /fg-cell #} {% endif %} {% endif %} {% endfor %}
{# /form-grid #} {% if not ns.rated_rows %}

No rated fields in this inspection.

{% endif %} {% else %}

No form fields found for this template.

{% endif %} {# Issues #} {% if issues %}
Issues Logged ({{ issues|length }})
{% for issue in issues %} {% endfor %}
SeverityAreaDescriptionStatus
{{ issue.severity|title }} {{ issue.area.name }} {{ issue.description[:80] }}{% if issue.description|length > 80 %}…{% endif %} {{ issue.status|replace('_',' ')|title }} View
{% endif %}
{# Media lightbox #}
Photo
{% endblock %} {% block extra_js %} {% endblock %}