Add color family filter to inventory index

Adds an 'All Colors' dropdown to the inventory filter bar populated from
the ColorFamilies values already stored on inventory items. Selecting a
family (e.g. 'Red') returns only items tagged with that family.

Also refactors the 16-branch if/else filter builder into a single
composable predicate, making future filter additions trivial.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-24 17:25:14 -04:00
parent 1722cd4124
commit b7fcefa765
2 changed files with 57 additions and 61 deletions
@@ -124,8 +124,9 @@
@{
var lowStockOnly = (bool)(ViewBag.LowStockOnly ?? false);
var activeLocation = ViewBag.Location as string;
var activeColorFamily = ViewBag.ColorFamily as string;
}
@if (!string.IsNullOrEmpty(ViewBag.SearchTerm) || !string.IsNullOrEmpty(ViewBag.Category) || !string.IsNullOrEmpty(activeLocation) || lowStockOnly)
@if (!string.IsNullOrEmpty(ViewBag.SearchTerm) || !string.IsNullOrEmpty(ViewBag.Category) || !string.IsNullOrEmpty(activeLocation) || !string.IsNullOrEmpty(activeColorFamily) || lowStockOnly)
{
<div class="alert @(lowStockOnly ? "alert-warning" : "alert-info") alert-permanent d-flex justify-content-between align-items-center flex-wrap gap-2">
<div>
@@ -149,6 +150,10 @@
{
<span> in bin "<strong>@activeLocation</strong>"</span>
}
@if (!string.IsNullOrEmpty(activeColorFamily))
{
<span> in color family "<strong>@activeColorFamily</strong>"</span>
}
}
</div>
<div class="d-flex gap-2 flex-wrap">
@@ -182,6 +187,16 @@
<option value="@cat" selected="@(cat == ViewBag.Category)">@cat</option>
}
</select>
@if (((IEnumerable<string>)ViewBag.ColorFamilies).Any())
{
<select name="colorFamily" class="form-select" style="max-width: 160px; min-width: 120px;" onchange="this.form.submit()">
<option value="">All Colors</option>
@foreach (var family in ViewBag.ColorFamilies)
{
<option value="@family" selected="@(family == activeColorFamily)">@family</option>
}
</select>
}
@if (((IEnumerable<string?>)ViewBag.Locations).Any())
{
<select name="location" class="form-select" style="max-width: 180px; min-width: 130px;" onchange="this.form.submit()">
@@ -215,7 +230,7 @@
<div class="card-body p-0">
@if (!Model.Items.Any())
{
var isInventoryFiltered = !string.IsNullOrEmpty(ViewBag.SearchTerm as string) || !string.IsNullOrEmpty(ViewBag.Category as string) || lowStockOnly;
var isInventoryFiltered = !string.IsNullOrEmpty(ViewBag.SearchTerm as string) || !string.IsNullOrEmpty(ViewBag.Category as string) || !string.IsNullOrEmpty(activeColorFamily) || lowStockOnly;
<div class="text-center py-5">
<i class="bi bi-inbox" style="font-size: 4rem; color: #d1d5db;"></i>
<h5 class="mt-3 text-muted">No inventory items found</h5>