Make gauge/maintenance identifiers per-asset-type and extend to all types

Optional asset identifiers (gauge lab reference, maintenance reference, FQDN)
were global per-identifier and only surfaced on equipment. Now they are
toggleable per asset type and rendered on every asset type.

- settings: replace 3 global identifier toggles with a per-type matrix. New
  keys identifier_<name>_<assettype>_enabled (3 identifiers x 4 types).
  IDENTIFIER_LABELS / IDENTIFIER_ASSETTYPES constants drive the seed (API seed
  and CLI seed settings).
- composable: identifierSettings now exposes isEnabled(name, assettype),
  per-type flag winning over the legacy global key, defaulting on.
- backend writes: computers, network, printers asset create + update now
  accept gaugelabreference and maintenancereference (equipment already did).
  Reads already flowed through Asset.to_dict.
- frontend: Settings page renders an identifier x asset-type toggle matrix.
  Equipment, PC, printer, network forms and detail pages show gauge/maintenance
  (and FQDN where applicable) gated by isEnabled(name, type).

Legacy global identifier_<name>_enabled keys are still honored as a fallback
for older installs. SystemSettings toggles upsert (create on 404) so a deploy
that has not re-seeded still works on first toggle.

144 tests pass, naming/style check green, frontend builds. Verified live:
matrix renders, PC form shows the fields, PUT persists gauge/maintenance on a
PC and reads back.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-06-26 16:34:50 -04:00
parent b567de14ac
commit 37ffb4add5
15 changed files with 330 additions and 109 deletions

View File

@@ -1,36 +1,51 @@
// Global enable/disable flags for optional asset identifiers, read from the
// settings table. Loaded once and shared across components. Defaults to
// enabled when a flag is missing so a fresh install shows the identifiers.
// Per-type enable/disable flags for optional asset identifiers, read from the
// settings table. Keys follow identifier_<name>_<assettype>_enabled. A legacy
// global key identifier_<name>_enabled is honored as a fallback for older
// installs. Missing = enabled, so a fresh install shows every identifier.
import { reactive } from 'vue'
import { settingsApi } from '../api'
const identifierflags = reactive({
gaugelabreference: true,
maintenancereference: true,
fqdn: true,
// scope[name][assettype] = boolean. legacy[name] = boolean (old global flag).
const state = reactive({
scope: {},
legacy: {},
loaded: false
})
let inflight = null
export function useIdentifierFlags() {
if (!identifierflags.loaded && !inflight) {
function loadFlags() {
if (!state.loaded && !inflight) {
inflight = settingsApi.list()
.then(({ data }) => {
const map = {}
;(data.data || []).forEach(s => { map[s.key] = s.value })
if ('identifier_gaugelabreference_enabled' in map) {
identifierflags.gaugelabreference = map.identifier_gaugelabreference_enabled !== false
}
if ('identifier_maintenancereference_enabled' in map) {
identifierflags.maintenancereference = map.identifier_maintenancereference_enabled !== false
}
if ('identifier_fqdn_enabled' in map) {
identifierflags.fqdn = map.identifier_fqdn_enabled !== false
}
identifierflags.loaded = true
;(data.data || []).forEach(s => {
const match = /^identifier_(.+?)(?:_(equipment|computer|printer|network_device))?_enabled$/.exec(s.key)
if (!match) return
const name = match[1]
const assettype = match[2]
if (assettype) {
if (!state.scope[name]) state.scope[name] = {}
state.scope[name][assettype] = s.value !== false
} else {
state.legacy[name] = s.value !== false
}
})
state.loaded = true
})
.catch(() => { identifierflags.loaded = true })
.catch(() => { state.loaded = true })
}
return identifierflags
}
// True when identifier `name` should show on `assettype`. Per-type flag wins,
// then the legacy global flag, then default-on.
function isEnabled(name, assettype) {
const perType = state.scope[name]
if (perType && assettype in perType) return perType[assettype]
if (name in state.legacy) return state.legacy[name]
return true
}
export function useIdentifierFlags() {
loadFlags()
return { state, isEnabled }
}