Add customer-to-jobs filtering navigation
This commit is contained in:
parent
ecdb331c9b
commit
dca117ed79
@ -13,12 +13,33 @@ from .routes_shared import (
|
|||||||
@login_required
|
@login_required
|
||||||
@roles_required("admin", "operator", "viewer")
|
@roles_required("admin", "operator", "viewer")
|
||||||
def jobs():
|
def jobs():
|
||||||
# Join with customers for display
|
selected_customer_id = None
|
||||||
jobs = (
|
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
|
Job.query
|
||||||
.filter(Job.archived.is_(False))
|
.filter(Job.archived.is_(False))
|
||||||
.outerjoin(Customer, Customer.id == Job.customer_id)
|
.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(
|
.add_columns(
|
||||||
Job.id,
|
Job.id,
|
||||||
Job.backup_software,
|
Job.backup_software,
|
||||||
@ -54,6 +75,8 @@ def jobs():
|
|||||||
"main/jobs.html",
|
"main/jobs.html",
|
||||||
jobs=rows,
|
jobs=rows,
|
||||||
can_manage_jobs=can_manage_jobs,
|
can_manage_jobs=can_manage_jobs,
|
||||||
|
selected_customer_id=selected_customer_id,
|
||||||
|
selected_customer_name=selected_customer_name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,11 @@
|
|||||||
{% if customers %}
|
{% if customers %}
|
||||||
{% for c in customers %}
|
{% for c in customers %}
|
||||||
<tr>
|
<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>
|
<td>
|
||||||
{% if c.active %}
|
{% if c.active %}
|
||||||
<span class="badge bg-success">Active</span>
|
<span class="badge bg-success">Active</span>
|
||||||
|
|||||||
@ -2,6 +2,16 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<h2 class="mb-3">Jobs</h2>
|
<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">
|
<div class="table-responsive">
|
||||||
<table class="table table-sm table-hover align-middle">
|
<table class="table table-sm table-hover align-middle">
|
||||||
<thead class="table-light">
|
<thead class="table-light">
|
||||||
|
|||||||
@ -2,6 +2,16 @@
|
|||||||
|
|
||||||
This file documents all changes made to this project via Claude Code.
|
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]
|
## [2026-02-13]
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user