dynamically filter Make/Model selectors by asset category

The Add Computer, Add Machine, and Add Printer forms offered the entire model catalog and vendor list regardless of what was being added, so a PC could be pointed at a printer model and every vendor showed up whether or not it made that kind of thing. Scope each form to its own asset category so the selectors only present sensible choices.

Add a ?category= filter to GET /api/models that joins modeltypes and matches on category (Equipment, PC, Network, Printer), and include the model's category in the list response so the forms can distinguish types client-side. Untyped models are excluded, since a null category cannot satisfy the filter.

Each subtype form now loads only its category: PCForm requests category PC (servers, which are Network, stay out); MachineForm requests category Equipment, with the main Model dropdown hiding Controller-type models and the Controller dropdown showing only those; PrinterForm requests category Printer, which also fixes its Model list that previously showed the whole catalog.

Vendor dropdowns are derived from the loaded models: a form only offers vendors that actually have a model in its category. Each dropdown keeps the record's own saved vendor even if it falls outside that set, so editing an existing asset never drops its vendor.
This commit is contained in:
benjamin.baker
2026-08-26 12:18:31 -04:00
parent 3cb15239dd
commit c7828e7873
4 changed files with 70 additions and 14 deletions

View File

@@ -134,7 +134,7 @@
>
<option value="">Select vendor...</option>
<option
v-for="v in vendors"
v-for="v in filteredVendors"
:key="v.vendorid"
:value="v.vendorid"
>
@@ -387,6 +387,17 @@ const filteredModels = computed(() => {
})
})
// Only offer vendors that actually have Printer-category models. models is
// already scoped to category Printer at load, so its vendorids are the printer
// vendor set. Keep the record's own vendor even if it falls outside that set,
// so editing an existing printer never silently drops its saved vendor.
const filteredVendors = computed(() => {
const printerVendorIds = new Set(models.value.map(m => m.vendorid))
return vendors.value.filter(
v => printerVendorIds.has(v.vendorid) || v.vendorid === form.value.vendorid
)
})
// Get short description from model number for naming
function getModelShortDesc(modelNumber) {
if (!modelNumber) return ''
@@ -493,7 +504,7 @@ onMounted(async () => {
printersApi.types.list({ perpage: 100 }),
assetsApi.statuses.list(),
vendorsApi.list({ perpage: 100 }),
modelsApi.listAll(),
modelsApi.listAll({ category: 'Printer' }),
locationsApi.list({ perpage: 100 })
])