Add customer-to-jobs filtering navigation

This commit is contained in:
Ivo Oskamp 2026-02-16 15:12:10 +01:00
parent ecdb331c9b
commit dca117ed79
4 changed files with 51 additions and 4 deletions

View File

@ -13,12 +13,33 @@ from .routes_shared import (
@login_required
@roles_required("admin", "operator", "viewer")
def jobs():
# Join with customers for display
jobs = (
selected_customer_id = None
selected_customer_name = ""
customer_id_raw = (request.args.get("customer_id") or "").strip()
if customer_id_raw:
try:
selected_customer_id = int(customer_id_raw)
except ValueError:
selected_customer_id = None
base_query = (
Job.query
.filter(Job.archived.is_(False))
.outerjoin(Customer, Customer.id == Job.customer_id)
.filter(db.or_(Customer.id.is_(None), Customer.active.is_(True)))
)
if selected_customer_id is not None:
base_query = base_query.filter(Job.customer_id == selected_customer_id)
selected_customer = Customer.query.filter(Customer.id == selected_customer_id).first()
if selected_customer is not None:
selected_customer_name = selected_customer.name or ""
else:
# Default listing hides jobs for inactive customers.
base_query = base_query.filter(db.or_(Customer.id.is_(None), Customer.active.is_(True)))
# Join with customers for display
jobs = (
base_query
.add_columns(
Job.id,
Job.backup_software,
@ -54,6 +75,8 @@ def jobs():
"main/jobs.html",
jobs=rows,
can_manage_jobs=can_manage_jobs,
selected_customer_id=selected_customer_id,
selected_customer_name=selected_customer_name,
)

View File

@ -45,7 +45,11 @@
{% if customers %}
{% for c in customers %}
<tr>
<td>{{ c.name }}</td>
<td>
<a href="{{ url_for('main.jobs', customer_id=c.id) }}" class="link-primary text-decoration-none">
{{ c.name }}
</a>
</td>
<td>
{% if c.active %}
<span class="badge bg-success">Active</span>

View File

@ -2,6 +2,16 @@
{% block content %}
<h2 class="mb-3">Jobs</h2>
{% if selected_customer_id %}
<div class="alert alert-info d-flex justify-content-between align-items-center py-2" role="alert">
<span>
Filtered on customer:
<strong>{{ selected_customer_name or ('#' ~ selected_customer_id) }}</strong>
</span>
<a href="{{ url_for('main.jobs') }}" class="btn btn-sm btn-outline-primary">Clear filter</a>
</div>
{% endif %}
<div class="table-responsive">
<table class="table table-sm table-hover align-middle">
<thead class="table-light">

View File

@ -2,6 +2,16 @@
This file documents all changes made to this project via Claude Code.
## [2026-02-16]
### Added
- Added customer-to-jobs navigation by making customer names clickable on the Customers page, linking to `/jobs?customer_id=<id>`
- Added Jobs page customer filter context UI with an active filter banner and a "Clear filter" action
### Changed
- Changed `/jobs` route to accept optional `customer_id` query parameter and return only jobs for that customer when provided
- Changed default Jobs listing behavior to keep existing inactive-customer filtering only when no `customer_id` filter is applied
## [2026-02-13]
### Added