diff --git a/app/routes/facilities.py b/app/routes/facilities.py index cf1cd07..ea6ca2f 100644 --- a/app/routes/facilities.py +++ b/app/routes/facilities.py @@ -23,7 +23,28 @@ def list_facilities(): ).order_by(Facility.name).all() else: facilities = Facility.query.order_by(Facility.name).all() - return render_template('facilities/list.html', facilities=facilities) + + # Group facilities by Contract (Project) for the collapsible list view. + # Facilities with no contract are collected under key '__none__' and + # rendered last as "No Contract Assigned". + from collections import OrderedDict + grouped = OrderedDict() + ungrouped = [] + for f in facilities: + if f.project: + key = f.project.name + grouped.setdefault(key, {'project': f.project, 'facilities': []}) + grouped[key]['facilities'].append(f) + else: + ungrouped.append(f) + + grouped = OrderedDict(sorted(grouped.items())) + if ungrouped: + grouped['__none__'] = {'project': None, 'facilities': ungrouped} + + logger.info('FACILITIES | list | user=%s | total=%s | groups=%s', + current_user.username, len(facilities), len(grouped)) + return render_template('facilities/list.html', facilities=facilities, grouped=grouped) @bp.route('/new', methods=['GET', 'POST']) @login_required diff --git a/app/templates/facilities/list.html b/app/templates/facilities/list.html index 418af8d..5e6db75 100644 --- a/app/templates/facilities/list.html +++ b/app/templates/facilities/list.html @@ -16,58 +16,94 @@ -
- {% for facility in facilities %} -
-
+{% if grouped %} + {% for group_key, group in grouped.items() %} + {# ── Contract group header ────────────────────────────────────────────── #} + {% set collapse_id = 'contract-' ~ loop.index %} +
+
+ + {{ group.facilities|length }} + {% if group.project and current_user.role in ['admin', 'director', 'project_manager'] %} + + + + {% endif %} +
+ + {# ── Collapsible card grid ─────────────────────────────────────────── #} +
+
+ {% for facility in group.facilities %} +
+
-
- - {{ facility.name }} - - {% if not facility.active %} - Inactive - {% endif %} -
- - {% if facility.address %} -

- {{ facility.address }} -

+
+ + {{ facility.name }} + + {% if not facility.active %} + Inactive {% endif %} +
-
- - {{ facility.areas.count() }} areas - -
+ {% if facility.address %} +

+ {{ facility.address }} +

+ {% endif %} + +
+ + {{ facility.areas.count() }} areas + +
+
+ {% endfor %} +
- {% else %} -
-
- No facilities configured yet. -
-
- {% endfor %} +
+ {% endfor %} + +{% else %} +
+ No facilities configured yet.
+{% endif %} {% if current_user.role == 'admin' %} @@ -110,9 +146,24 @@ {% endblock %} {% block extra_js %} -{% if current_user.role == 'admin' %} -{% endif %} {% endblock %} \ No newline at end of file diff --git a/app/templates/facilities/view.html b/app/templates/facilities/view.html index f500736..8bf212e 100644 --- a/app/templates/facilities/view.html +++ b/app/templates/facilities/view.html @@ -8,6 +8,9 @@

{{ facility.name }}

+ + Back to Facilities + {% if current_user.role in ['admin', 'director', 'project_manager', 'customer'] %}