Rename the equipment domain to machines; retype the models catalog (ADR-011)
All checks were successful
CI / backend (push) Successful in 23s
CI / naming (push) Successful in 2s
CI / frontend (push) Successful in 8s

The equipment plugin is now the machines plugin, ending the UI-vs-code
vocabulary split while the contract is pre-1.0 and nothing external
depends on the old names.

- plugins/equipment -> plugins/machines: manifest, class, /api/machines,
  machines.* permissions, registry key (with an auto-migrating load shim
  for existing installs).
- Tables: equipment -> machines (equipmentid -> machineid) and
  equipmenttypes -> machinetypes, renamed in the plugin's own migration
  chain (machines0002rename), idempotent for both upgrading and fresh
  installs.
- The legacy core machinetypes lookup actually types the vendor MODELS
  catalog, so it is renamed losslessly to modeltypes
  (models.modeltypeid, /api/modeltypes, Model Types settings page)
  rather than collapsed, freeing the machinetypes name. Core migration
  7d17_machines_rename also flips data in place: assettypes row
  equipment -> machine, auditlog entitytype, identifier_/search_
  settings keys, permission rows, and renames alembic_version_equipment.
- Frontend: machinesApi/modeltypesApi, item.machine response shape,
  assettype value compares 'equipment' -> 'machine' (map, search,
  custom fields, relationships), routes machines.js with plugin gating
  retagged, /print/machine-badge, Machine Types (subtypes) and Model
  Types (catalog) settings pages, machines-by-type report id.
- Docs swept; ADRs left as history per the authoring rule.

Upgrade: flask db upgrade then flask plugin upgrade-all.

Verified: dev DB flipped live (262 machines, 35 modeltypes, 95 models
retyped, zero equipment tables remain); fresh scratch-MySQL install
produces the new names; 341 tests green; naming/style green; frontend
builds; live E2E on machines list/detail, PC relationships, map,
reports, and both settings pages.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-07-11 15:17:42 -04:00
parent 3c43c8d5c8
commit 48d3160bc5
84 changed files with 4755 additions and 4317 deletions

View File

@@ -15,7 +15,7 @@
</div>
<div class="stat-card success">
<div class="label">Active</div>
<div class="value">{{ stats.activemachines || 0 }}</div>
<div class="value">{{ stats.activeassets || 0 }}</div>
</div>
<div class="stat-card warning">
<div class="label">In Repair</div>

View File

@@ -14,7 +14,7 @@
<h3>Assets</h3>
<select v-model="filterType" class="form-control">
<option value="">All Types</option>
<option value="equipment">Machines</option>
<option value="machine">Machines</option>
<option value="computer">Computers</option>
<option value="printer">Printers</option>
<option value="network_device">Network Devices</option>
@@ -155,7 +155,7 @@ async function loadAssets() {
function getTypeIcon(assettype) {
const icons = {
'equipment': Cog,
'machine': Cog,
'computer': Monitor,
'printer': Printer,
'network_device': Globe

View File

@@ -130,7 +130,7 @@ const subtypeLabel = computed(() => {
if (!selectedType.value) return 'Select type first'
if (!currentSubtypes.value.length) return 'No subtypes'
const labels = {
'equipment': 'All Machine Types',
'machine': 'All Machine Types',
'computer': 'All Computer Types',
'network device': 'All Device Types',
'printer': 'All Printer Types'
@@ -182,8 +182,8 @@ const filteredAssets = computed(() => {
result = result.filter(a => {
if (!a.typedata) return false
// Check different ID fields based on asset type
if (typeLower === 'equipment') {
return a.typedata.equipmenttypeid === subtypeId
if (typeLower === 'machine') {
return a.typedata.machinetypeid === subtypeId
} else if (typeLower === 'computer') {
return a.typedata.computertypeid === subtypeId
} else if (typeLower === 'network device') {

View File

@@ -110,7 +110,6 @@ const copiedId = ref(null)
const typeLabels = {
machine: 'Machine',
equipment: 'Machine',
pc: 'PC',
computer: 'PC',
application: 'App',
@@ -124,7 +123,7 @@ const typeLabels = {
const filterTypeMap = {
all: null,
equipment: ['equipment'],
machines: ['machine'],
computers: ['computer'],
printers: ['printer'],
network: ['network_device', 'subnet'],
@@ -136,7 +135,7 @@ const filterTypeMap = {
const filterList = [
{ key: 'all', label: 'All' },
{ key: 'equipment', label: 'Machines' },
{ key: 'machines', label: 'Machines' },
{ key: 'computers', label: 'PCs' },
{ key: 'printers', label: 'Printers' },
{ key: 'network', label: 'Network' },
@@ -383,8 +382,7 @@ watch(results, () => {
flex-shrink: 0;
}
.result-type.machine,
.result-type.equipment {
.result-type.machine {
background: #e3f2fd;
color: #1565c0;
}
@@ -484,8 +482,7 @@ watch(results, () => {
}
@media (prefers-color-scheme: dark) {
.result-type.machine,
.result-type.equipment {
.result-type.machine {
background: rgba(21, 101, 192, 0.2);
color: #64b5f6;
}

View File

@@ -1,348 +1,352 @@
<template>
<div class="detail-page">
<div class="page-header">
<h2>Machine Details</h2>
<div class="header-actions">
<router-link :to="`/print/equipment-badge/${equipment?.equipment?.equipmentid}`" class="btn btn-secondary" v-if="equipment" target="_blank">
Print Badge
</router-link>
<router-link :to="`/machines/${equipment?.equipment?.equipmentid}/edit`" class="btn btn-primary" v-if="equipment">
Edit
</router-link>
<router-link to="/machines" class="btn btn-secondary">Back to List</router-link>
</div>
</div>
<div v-if="loading" class="loading">Loading...</div>
<template v-else-if="equipment">
<!-- Hero Section -->
<div class="hero-card">
<div class="hero-content">
<div class="hero-title">
<h1>{{ equipment.assetnumber }}</h1>
<span v-if="equipment.name" class="hero-alias">{{ equipment.name }}</span>
</div>
<div class="hero-meta">
<span class="badge badge-lg badge-primary">
{{ equipment.assettypename || 'Machine' }}
</span>
<span class="badge badge-lg" :class="getStatusClass(equipment.statusname)">
{{ equipment.statusname || 'Unknown' }}
</span>
<span v-if="heroWarranty" class="badge badge-lg" :style="{ background: heroWarranty.statuscolor, color: '#fff' }"
:title="heroWarranty.enddate ? `Warranty ends ${warrantyDate(heroWarranty.enddate)}` : 'Warranty'">
{{ heroWarranty.label }}<template v-if="heroWarranty.enddate"> - {{ warrantyDate(heroWarranty.enddate) }}</template>
</span>
</div>
<div class="hero-details">
<div class="hero-detail" v-if="equipment.equipment?.equipmenttypename">
<span class="hero-detail-label">Type</span>
<span class="hero-detail-value">{{ equipment.equipment.equipmenttypename }}</span>
</div>
<div class="hero-detail" v-if="equipment.equipment?.vendorname">
<span class="hero-detail-label">Vendor</span>
<span class="hero-detail-value">{{ equipment.equipment.vendorname }}</span>
</div>
<div class="hero-detail" v-if="equipment.equipment?.modelname">
<span class="hero-detail-label">Model</span>
<span class="hero-detail-value">{{ equipment.equipment.modelname }}</span>
</div>
<div class="hero-detail" v-if="equipment.locationname">
<span class="hero-detail-label">Location</span>
<span class="hero-detail-value">{{ equipment.locationname }}</span>
</div>
</div>
</div>
</div>
<!-- Main Content Grid -->
<div class="content-grid">
<!-- Left Column -->
<div class="content-column">
<!-- Identity Section -->
<div class="section-card">
<h3 class="section-title">Identity</h3>
<div class="info-list">
<div class="info-row">
<span class="info-label">Asset Number</span>
<span class="info-value">{{ equipment.assetnumber }}</span>
</div>
<div class="info-row" v-if="equipment.name">
<span class="info-label">Name</span>
<span class="info-value">{{ equipment.name }}</span>
</div>
<div class="info-row" v-if="isEnabled('gaugelabreference', 'equipment') && equipment.gaugelabreference">
<span class="info-label">Gauge Lab Reference</span>
<span class="info-value mono">{{ equipment.gaugelabreference }}</span>
</div>
<div class="info-row" v-if="isEnabled('maintenancereference', 'equipment') && equipment.maintenancereference">
<span class="info-label">Maintenance Reference</span>
<span class="info-value mono">{{ equipment.maintenancereference }}</span>
</div>
<div class="info-row" v-if="equipment.serialnumber">
<span class="info-label">Serial Number</span>
<span class="info-value mono">{{ equipment.serialnumber }}</span>
</div>
</div>
</div>
<!-- Hardware Section -->
<div class="section-card">
<h3 class="section-title">Hardware</h3>
<div class="info-list">
<div class="info-row">
<span class="info-label">Type</span>
<span class="info-value">{{ equipment.equipment?.equipmenttypename || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">Vendor</span>
<span class="info-value">{{ equipment.equipment?.vendorname || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">Model</span>
<span class="info-value">{{ equipment.equipment?.modelname || '-' }}</span>
</div>
</div>
</div>
<!-- Controller Section (for CNC machines) -->
<div class="section-card" v-if="equipment.equipment?.controllervendorname || equipment.equipment?.controllermodelname">
<h3 class="section-title">Controller</h3>
<div class="info-list">
<div class="info-row">
<span class="info-label">Vendor</span>
<span class="info-value">{{ equipment.equipment?.controllervendorname || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">Model</span>
<span class="info-value">{{ equipment.equipment?.controllermodelname || '-' }}</span>
</div>
</div>
</div>
<!-- Equipment Configuration -->
<div class="section-card">
<h3 class="section-title">Configuration</h3>
<div class="info-list">
<div class="info-row">
<span class="info-label">Requires Manual Config</span>
<span class="info-value">
<span class="feature-tag" :class="{ active: equipment.equipment?.requiresmanualconfig }">
{{ equipment.equipment?.requiresmanualconfig ? 'Yes' : 'No' }}
</span>
</span>
</div>
</div>
</div>
<!-- Maintenance Section -->
<div class="section-card" v-if="equipment.equipment?.lastmaintenancedate || equipment.equipment?.nextmaintenancedate">
<h3 class="section-title">Maintenance</h3>
<div class="info-list">
<div class="info-row" v-if="equipment.equipment?.lastmaintenancedate">
<span class="info-label">Last Maintenance</span>
<span class="info-value">{{ formatDate(equipment.equipment.lastmaintenancedate) }}</span>
</div>
<div class="info-row" v-if="equipment.equipment?.nextmaintenancedate">
<span class="info-label">Next Maintenance</span>
<span class="info-value">{{ formatDate(equipment.equipment.nextmaintenancedate) }}</span>
</div>
<div class="info-row" v-if="equipment.equipment?.maintenanceintervaldays">
<span class="info-label">Interval</span>
<span class="info-value">{{ equipment.equipment.maintenanceintervaldays }} days</span>
</div>
</div>
</div>
</div>
<!-- Right Column -->
<div class="content-column">
<!-- Location & Organization -->
<div class="section-card">
<h3 class="section-title">Location & Organization</h3>
<div class="info-list">
<div class="info-row">
<span class="info-label">Location</span>
<span class="info-value">
<LocationMapTooltip
v-if="equipment.mapx != null && equipment.mapy != null"
:left="equipment.mapx"
:top="equipment.mapy"
:machineName="equipment.assetnumber"
>
<span class="location-link">{{ equipment.locationname || 'On Map' }}</span>
</LocationMapTooltip>
<span v-else>{{ equipment.locationname || '-' }}</span>
</span>
</div>
<div class="info-row">
<span class="info-label">Business Unit</span>
<span class="info-value">{{ equipment.businessunitname || '-' }}</span>
</div>
</div>
</div>
<!-- Connected PC -->
<div class="section-card">
<h3 class="section-title">Connected PC</h3>
<div v-if="!controllingPc" class="empty-message">
No controlling PC assigned
</div>
<div v-else class="connected-device">
<router-link :to="`/pcs/${controllingPc.pluginid || controllingPc.assetid}`" class="device-link">
<div class="device-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="2" y="3" width="20" height="14" rx="2" ry="2"></rect>
<line x1="8" y1="21" x2="16" y2="21"></line>
<line x1="12" y1="17" x2="12" y2="21"></line>
</svg>
</div>
<div class="device-info">
<span class="device-name">{{ controllingPc.assetnumber }}</span>
<span class="device-alias" v-if="controllingPc.name">{{ controllingPc.name }}</span>
</div>
</router-link>
<span class="connection-type">{{ controllingPc.relationshipType }}</span>
</div>
</div>
<!-- Custom Fields -->
<CustomFieldsSection :assetid="equipment.assetid" />
<!-- Warranty -->
<WarrantyPanel :assetid="equipment.assetid" :items="warranties" />
<!-- Notes -->
<div class="section-card" v-if="equipment.notes">
<h3 class="section-title">Notes</h3>
<p class="notes-text">{{ equipment.notes }}</p>
</div>
</div>
</div>
<!-- Audit Footer -->
<div class="audit-footer">
<span>Created {{ formatDate(equipment.createddate) }}<template v-if="equipment.createdby"> by {{ equipment.createdby }}</template></span>
<span>Modified {{ formatDate(equipment.modifieddate) }}<template v-if="equipment.modifiedby"> by {{ equipment.modifiedby }}</template></span>
</div>
</template>
<div v-else class="card">
<p style="text-align: center; color: var(--text-light);">Machine not found</p>
</div>
</div>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { equipmentApi, assetsApi } from '../../api'
import LocationMapTooltip from '../../components/LocationMapTooltip.vue'
import CustomFieldsSection from '../../components/CustomFieldsSection.vue'
import WarrantyPanel from '../../components/WarrantyPanel.vue'
import { useWarrantyBadge } from '../../composables/warrantyBadge'
import { useIdentifierFlags } from '../../composables/identifierSettings'
const route = useRoute()
const { isEnabled } = useIdentifierFlags()
const loading = ref(true)
const equipment = ref(null)
const { warranties, heroWarranty, warrantyDate } = useWarrantyBadge(() => equipment.value?.assetid)
const relationships = ref({ incoming: [], outgoing: [] })
// type name is data, sites may seed 'controls' or 'Controls' - compare folded
function isControls(rel) {
return (rel.relationshiptypename || '').toLowerCase() === 'controls'
}
const controllingPc = computed(() => {
// For equipment, find a related computer in any "Controls" relationship
// Check both incoming (computer controls this) and outgoing (legacy data may have equipment -> computer)
// First check incoming - computer as source controlling this equipment
for (const rel of relationships.value.incoming || []) {
if (rel.sourceasset?.assettypename === 'computer' && isControls(rel)) {
return {
...rel.sourceasset,
relationshipType: rel.relationshiptypename
}
}
}
// Also check outgoing - legacy data may have equipment -> computer Controls relationships
for (const rel of relationships.value.outgoing || []) {
if (rel.targetasset?.assettypename === 'computer' && isControls(rel)) {
return {
...rel.targetasset,
relationshipType: rel.relationshiptypename
}
}
}
return null
})
onMounted(async () => {
try {
const response = await equipmentApi.get(route.params.id)
equipment.value = response.data.data
// Load relationships using asset ID
if (equipment.value?.assetid) {
try {
const relResponse = await assetsApi.getRelationships(equipment.value.assetid)
relationships.value = relResponse.data.data || { incoming: [], outgoing: [] }
} catch (e) {
console.log('Relationships not available')
}
}
} catch (error) {
console.error('Error loading equipment:', error)
} finally {
loading.value = false
}
})
function getStatusClass(status) {
if (!status) return 'badge-info'
const s = status.toLowerCase()
if (s === 'in use' || s === 'active') return 'badge-success'
if (s === 'in repair' || s === 'spare') return 'badge-warning'
if (s === 'retired' || s === 'disposed') return 'badge-danger'
return 'badge-info'
}
function formatDate(dateStr) {
if (!dateStr) return '-'
return new Date(dateStr).toLocaleString()
}
</script>
<style scoped>
.mono {
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}
.feature-tag {
display: inline-block;
padding: 0.3rem 0.625rem;
font-size: 0.875rem;
border-radius: 5px;
background: var(--bg);
color: var(--text-light);
}
.feature-tag.active {
background: #e3f2fd;
color: #1976d2;
}
@media (prefers-color-scheme: dark) {
.feature-tag.active {
background: #1e3a5f;
color: #60a5fa;
}
}
</style>
<template>
<div class="detail-page">
<div class="page-header">
<h2>Machine Details</h2>
<div class="header-actions">
<router-link :to="`/print/machine-badge/${machine?.machine?.machineid}`" class="btn btn-secondary" v-if="machine" target="_blank">
Print Badge
</router-link>
<router-link :to="`/machines/${machine?.machine?.machineid}/edit`" class="btn btn-primary" v-if="machine">
Edit
</router-link>
<router-link to="/machines" class="btn btn-secondary">Back to List</router-link>
</div>
</div>
<div v-if="loading" class="loading">Loading...</div>
<template v-else-if="machine">
<!-- Hero Section -->
<div class="hero-card">
<div class="hero-content">
<div class="hero-title">
<h1>{{ machine.assetnumber }}</h1>
<span v-if="machine.name" class="hero-alias">{{ machine.name }}</span>
</div>
<div class="hero-meta">
<span class="badge badge-lg badge-primary">
{{ machine.assettypename || 'Machine' }}
</span>
<span class="badge badge-lg" :class="getStatusClass(machine.statusname)">
{{ machine.statusname || 'Unknown' }}
</span>
<span v-if="heroWarranty" class="badge badge-lg" :style="{ background: heroWarranty.statuscolor, color: '#fff' }"
:title="heroWarranty.enddate ? `Warranty ends ${warrantyDate(heroWarranty.enddate)}` : 'Warranty'">
{{ heroWarranty.label }}<template v-if="heroWarranty.enddate"> - {{ warrantyDate(heroWarranty.enddate) }}</template>
</span>
</div>
<div class="hero-details">
<div class="hero-detail" v-if="machine.machine?.machinetypename">
<span class="hero-detail-label">Type</span>
<span class="hero-detail-value">{{ machine.machine.machinetypename }}</span>
</div>
<div class="hero-detail" v-if="machine.machine?.vendorname">
<span class="hero-detail-label">Vendor</span>
<span class="hero-detail-value">{{ machine.machine.vendorname }}</span>
</div>
<div class="hero-detail" v-if="machine.machine?.modelname">
<span class="hero-detail-label">Model</span>
<span class="hero-detail-value">{{ machine.machine.modelname }}</span>
</div>
<div class="hero-detail" v-if="machine.locationname">
<span class="hero-detail-label">Location</span>
<span class="hero-detail-value">{{ machine.locationname }}</span>
</div>
</div>
</div>
</div>
<!-- Main Content Grid -->
<div class="content-grid">
<!-- Left Column -->
<div class="content-column">
<!-- Identity Section -->
<div class="section-card">
<h3 class="section-title">Identity</h3>
<div class="info-list">
<div class="info-row">
<span class="info-label">Asset Number</span>
<span class="info-value">{{ machine.assetnumber }}</span>
</div>
<div class="info-row" v-if="machine.name">
<span class="info-label">Name</span>
<span class="info-value">{{ machine.name }}</span>
</div>
<div class="info-row" v-if="isEnabled('gaugelabreference', 'machine') && machine.gaugelabreference">
<span class="info-label">Gauge Lab Reference</span>
<span class="info-value mono">{{ machine.gaugelabreference }}</span>
</div>
<div class="info-row" v-if="isEnabled('maintenancereference', 'machine') && machine.maintenancereference">
<span class="info-label">Maintenance Reference</span>
<span class="info-value mono">{{ machine.maintenancereference }}</span>
</div>
<div class="info-row" v-if="machine.serialnumber">
<span class="info-label">Serial Number</span>
<span class="info-value mono">{{ machine.serialnumber }}</span>
</div>
</div>
</div>
<!-- Hardware Section -->
<div class="section-card">
<h3 class="section-title">Hardware</h3>
<div class="info-list">
<div class="info-row">
<span class="info-label">Type</span>
<span class="info-value">{{ machine.machine?.machinetypename || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">Vendor</span>
<span class="info-value">{{ machine.machine?.vendorname || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">Model</span>
<span class="info-value">{{ machine.machine?.modelname || '-' }}</span>
</div>
</div>
</div>
<!-- Controller Section (for CNC machines) -->
<div class="section-card" v-if="machine.machine?.controllervendorname || machine.machine?.controllermodelname">
<h3 class="section-title">Controller</h3>
<div class="info-list">
<div class="info-row">
<span class="info-label">Vendor</span>
<span class="info-value">{{ machine.machine?.controllervendorname || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">Model</span>
<span class="info-value">{{ machine.machine?.controllermodelname || '-' }}</span>
</div>
</div>
</div>
<!-- Machine Configuration -->
<div class="section-card">
<h3 class="section-title">Configuration</h3>
<div class="info-list">
<div class="info-row">
<span class="info-label">Requires Manual Config</span>
<span class="info-value">
<span class="feature-tag" :class="{ active: machine.machine?.requiresmanualconfig }">
{{ machine.machine?.requiresmanualconfig ? 'Yes' : 'No' }}
</span>
</span>
</div>
</div>
</div>
<!-- Maintenance Section -->
<div class="section-card" v-if="machine.machine?.lastmaintenancedate || machine.machine?.nextmaintenancedate">
<h3 class="section-title">Maintenance</h3>
<div class="info-list">
<div class="info-row" v-if="machine.machine?.lastmaintenancedate">
<span class="info-label">Last Maintenance</span>
<span class="info-value">{{ formatDate(machine.machine.lastmaintenancedate) }}</span>
</div>
<div class="info-row" v-if="machine.machine?.nextmaintenancedate">
<span class="info-label">Next Maintenance</span>
<span class="info-value">{{ formatDate(machine.machine.nextmaintenancedate) }}</span>
</div>
<div class="info-row" v-if="machine.machine?.maintenanceintervaldays">
<span class="info-label">Interval</span>
<span class="info-value">{{ machine.machine.maintenanceintervaldays }} days</span>
</div>
</div>
</div>
</div>
<!-- Right Column -->
<div class="content-column">
<!-- Location & Organization -->
<div class="section-card">
<h3 class="section-title">Location & Organization</h3>
<div class="info-list">
<div class="info-row">
<span class="info-label">Location</span>
<span class="info-value">
<LocationMapTooltip
v-if="machine.mapx != null && machine.mapy != null"
:left="machine.mapx"
:top="machine.mapy"
:machineName="machine.assetnumber"
>
<span class="location-link">{{ machine.locationname || 'On Map' }}</span>
</LocationMapTooltip>
<span v-else>{{ machine.locationname || '-' }}</span>
</span>
</div>
<div class="info-row">
<span class="info-label">Business Unit</span>
<span class="info-value">{{ machine.businessunitname || '-' }}</span>
</div>
</div>
</div>
<!-- Connected PC -->
<div class="section-card">
<h3 class="section-title">Connected PC</h3>
<div v-if="!controllingPc" class="empty-message">
No controlling PC assigned
</div>
<div v-else class="connected-device">
<router-link :to="`/pcs/${controllingPc.pluginid || controllingPc.assetid}`" class="device-link">
<div class="device-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="2" y="3" width="20" height="14" rx="2" ry="2"></rect>
<line x1="8" y1="21" x2="16" y2="21"></line>
<line x1="12" y1="17" x2="12" y2="21"></line>
</svg>
</div>
<div class="device-info">
<span class="device-name">{{ controllingPc.assetnumber }}</span>
<span class="device-alias" v-if="controllingPc.name">{{ controllingPc.name }}</span>
</div>
</router-link>
<span class="connection-type">{{ controllingPc.relationshipType }}</span>
</div>
</div>
<!-- Custom Fields -->
<CustomFieldsSection :assetid="machine.assetid" />
<!-- Warranty -->
<WarrantyPanel :assetid="machine.assetid" :items="warranties" />
<!-- All relationships (dualpath, controls, ...) -->
<AssetRelationships v-if="machine.assetid" :assetId="machine.assetid" />
<!-- Notes -->
<div class="section-card" v-if="machine.notes">
<h3 class="section-title">Notes</h3>
<p class="notes-text">{{ machine.notes }}</p>
</div>
</div>
</div>
<!-- Audit Footer -->
<div class="audit-footer">
<span>Created {{ formatDate(machine.createddate) }}<template v-if="machine.createdby"> by {{ machine.createdby }}</template></span>
<span>Modified {{ formatDate(machine.modifieddate) }}<template v-if="machine.modifiedby"> by {{ machine.modifiedby }}</template></span>
</div>
</template>
<div v-else class="card">
<p style="text-align: center; color: var(--text-light);">Machine not found</p>
</div>
</div>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { machinesApi, assetsApi } from '../../api'
import LocationMapTooltip from '../../components/LocationMapTooltip.vue'
import CustomFieldsSection from '../../components/CustomFieldsSection.vue'
import WarrantyPanel from '../../components/WarrantyPanel.vue'
import AssetRelationships from '../../components/AssetRelationships.vue'
import { useWarrantyBadge } from '../../composables/warrantyBadge'
import { useIdentifierFlags } from '../../composables/identifierSettings'
const route = useRoute()
const { isEnabled } = useIdentifierFlags()
const loading = ref(true)
const machine = ref(null)
const { warranties, heroWarranty, warrantyDate } = useWarrantyBadge(() => machine.value?.assetid)
const relationships = ref({ incoming: [], outgoing: [] })
// type name is data, sites may seed 'controls' or 'Controls' - compare folded
function isControls(rel) {
return (rel.relationshiptypename || '').toLowerCase() === 'controls'
}
const controllingPc = computed(() => {
// For a machine, find a related computer in any "Controls" relationship
// Check both incoming (computer controls this) and outgoing (legacy data may have machine -> computer)
// First check incoming - computer as source controlling this machine
for (const rel of relationships.value.incoming || []) {
if (rel.sourceasset?.assettypename === 'computer' && isControls(rel)) {
return {
...rel.sourceasset,
relationshipType: rel.relationshiptypename
}
}
}
// Also check outgoing - legacy data may have machine -> computer Controls relationships
for (const rel of relationships.value.outgoing || []) {
if (rel.targetasset?.assettypename === 'computer' && isControls(rel)) {
return {
...rel.targetasset,
relationshipType: rel.relationshiptypename
}
}
}
return null
})
onMounted(async () => {
try {
const response = await machinesApi.get(route.params.id)
machine.value = response.data.data
// Load relationships using asset ID
if (machine.value?.assetid) {
try {
const relResponse = await assetsApi.getRelationships(machine.value.assetid)
relationships.value = relResponse.data.data || { incoming: [], outgoing: [] }
} catch (e) {
console.log('Relationships not available')
}
}
} catch (error) {
console.error('Error loading machine:', error)
} finally {
loading.value = false
}
})
function getStatusClass(status) {
if (!status) return 'badge-info'
const s = status.toLowerCase()
if (s === 'in use' || s === 'active') return 'badge-success'
if (s === 'in repair' || s === 'spare') return 'badge-warning'
if (s === 'retired' || s === 'disposed') return 'badge-danger'
return 'badge-info'
}
function formatDate(dateStr) {
if (!dateStr) return '-'
return new Date(dateStr).toLocaleString()
}
</script>
<style scoped>
.mono {
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}
.feature-tag {
display: inline-block;
padding: 0.3rem 0.625rem;
font-size: 0.875rem;
border-radius: 5px;
background: var(--bg);
color: var(--text-light);
}
.feature-tag.active {
background: #e3f2fd;
color: #1976d2;
}
@media (prefers-color-scheme: dark) {
.feature-tag.active {
background: #1e3a5f;
color: #60a5fa;
}
}
</style>

View File

@@ -7,7 +7,7 @@
<div class="card">
<div v-if="loading" class="loading">Loading...</div>
<form v-else @submit.prevent="saveEquipment">
<form v-else @submit.prevent="saveMachine">
<!-- Identity Section -->
<h3 class="form-section-title">Identity</h3>
<div class="form-row">
@@ -34,8 +34,8 @@
</div>
</div>
<div class="form-row" v-if="isEnabled('gaugelabreference', 'equipment') || isEnabled('maintenancereference', 'equipment')">
<div class="form-group" v-if="isEnabled('gaugelabreference', 'equipment')">
<div class="form-row" v-if="isEnabled('gaugelabreference', 'machine') || isEnabled('maintenancereference', 'machine')">
<div class="form-group" v-if="isEnabled('gaugelabreference', 'machine')">
<label for="gaugelabreference">Gauge Lab Reference</label>
<input
id="gaugelabreference"
@@ -46,7 +46,7 @@
<small class="form-help">Authoritative gauge lab asset reference (if tracked)</small>
</div>
<div class="form-group" v-if="isEnabled('maintenancereference', 'equipment')">
<div class="form-group" v-if="isEnabled('maintenancereference', 'machine')">
<label for="maintenancereference">Maintenance Reference</label>
<input
id="maintenancereference"
@@ -88,23 +88,23 @@
</div>
</div>
<!-- Equipment Hardware Section -->
<!-- Machine Hardware Section -->
<h3 class="form-section-title">Machine Hardware</h3>
<div class="form-row">
<div class="form-group">
<label for="equipmenttypeid">Equipment Type</label>
<label for="machinetypeid">Machine Type</label>
<select
id="equipmenttypeid"
v-model="form.equipmenttypeid"
id="machinetypeid"
v-model="form.machinetypeid"
class="form-control"
>
<option value="">Select type...</option>
<option
v-for="et in equipmentTypes"
:key="et.equipmenttypeid"
:value="et.equipmenttypeid"
v-for="mt in machineTypes"
:key="mt.machinetypeid"
:value="mt.machinetypeid"
>
{{ et.equipmenttype }}
{{ mt.machinetype }}
</option>
</select>
</div>
@@ -294,7 +294,7 @@
{{ pc.assetnumber }}{{ pc.name ? ` (${pc.name})` : '' }}
</option>
</select>
<small class="form-help">Select the PC that controls this equipment</small>
<small class="form-help">Select the PC that controls this machine</small>
</div>
<div class="form-group" v-if="controllingPcId">
@@ -312,7 +312,7 @@
{{ rt.relationshiptype }}
</option>
</select>
<small class="form-help">How the PC connects to this equipment</small>
<small class="form-help">How the PC connects to this machine</small>
</div>
</div>
@@ -328,8 +328,8 @@
></textarea>
</div>
<!-- Site-defined custom fields for equipment -->
<CustomFieldsInputs ref="customFieldsRef" :assettypeid="EQUIPMENT_ASSETTYPEID" :assetid="currentAssetId" />
<!-- Site-defined custom fields for machines -->
<CustomFieldsInputs ref="customFieldsRef" :assettypeid="MACHINE_ASSETTYPEID" :assetid="currentAssetId" />
<div v-if="error" class="error-message">{{ error }}</div>
@@ -347,7 +347,7 @@
<script setup>
import { ref, onMounted, computed, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { equipmentApi, vendorsApi, locationsApi, modelsApi, businessunitsApi, computersApi, assetsApi } from '../../api'
import { machinesApi, vendorsApi, locationsApi, modelsApi, businessunitsApi, computersApi, assetsApi } from '../../api'
import ShopFloorMap from '../../components/ShopFloorMap.vue'
import Modal from '../../components/Modal.vue'
import CustomFieldsInputs from '../../components/CustomFieldsInputs.vue'
@@ -362,8 +362,8 @@ const router = useRouter()
const isEdit = computed(() => !!route.params.id)
// Seeded asset-type id for equipment (see /api/assets/types).
const EQUIPMENT_ASSETTYPEID = 1
// Seeded asset-type id for machines (see /api/assets/types).
const MACHINE_ASSETTYPEID = 1
const customFieldsRef = ref(null)
const currentAssetId = ref(null)
@@ -380,7 +380,7 @@ const form = ref({
maintenancereference: '',
serialnumber: '',
statusid: 1,
equipmenttypeid: '',
machinetypeid: '',
vendorid: '',
modelnumberid: '',
controllervendorid: '',
@@ -394,7 +394,7 @@ const form = ref({
mapy: null
})
const equipmentTypes = ref([])
const machineTypes = ref([])
const statuses = ref([])
const vendors = ref([])
const locations = ref([])
@@ -405,9 +405,9 @@ const relationshipTypes = ref([])
const controllingPcId = ref(null)
const relationshipTypeId = ref(null)
const existingRelationshipId = ref(null)
const currentEquipment = ref(null)
const currentMachine = ref(null)
// Filter models by selected equipment vendor
// Filter models by selected machine vendor
const filteredModels = computed(() => {
if (!form.value.vendorid) return models.value
return models.value.filter(m => m.vendorid === form.value.vendorid)
@@ -443,7 +443,7 @@ onMounted(async () => {
try {
// Load reference data in parallel
const [typesRes, statusRes, vendorRes, locRes, allModels, buRes, pcsRes, relTypesRes] = await Promise.all([
equipmentApi.types.list(),
machinesApi.types.list(),
assetsApi.statuses.list(),
vendorsApi.list({ perpage: 500 }),
locationsApi.list({ perpage: 500 }),
@@ -453,7 +453,7 @@ onMounted(async () => {
assetsApi.types.list() // Used for relationship types, will fix below
])
equipmentTypes.value = typesRes.data.data || []
machineTypes.value = typesRes.data.data || []
statuses.value = statusRes.data.data || []
vendors.value = vendorRes.data.data || []
locations.value = locRes.data.data || []
@@ -479,12 +479,12 @@ onMounted(async () => {
relationshipTypeId.value = controlsType.relationshiptypeid
}
// Load equipment if editing
// Load machine if editing
if (isEdit.value) {
const response = await equipmentApi.get(route.params.id)
const response = await machinesApi.get(route.params.id)
const data = response.data.data
currentAssetId.value = data.assetid || null
currentEquipment.value = data
currentMachine.value = data
form.value = {
assetnumber: data.assetnumber || '',
@@ -493,15 +493,15 @@ onMounted(async () => {
maintenancereference: data.maintenancereference || '',
serialnumber: data.serialnumber || '',
statusid: data.statusid || 1,
equipmenttypeid: data.equipment?.equipmenttypeid || '',
vendorid: data.equipment?.vendorid || '',
modelnumberid: data.equipment?.modelnumberid || '',
controllervendorid: data.equipment?.controllervendorid || '',
controllermodelid: data.equipment?.controllermodelid || '',
machinetypeid: data.machine?.machinetypeid || '',
vendorid: data.machine?.vendorid || '',
modelnumberid: data.machine?.modelnumberid || '',
controllervendorid: data.machine?.controllervendorid || '',
controllermodelid: data.machine?.controllermodelid || '',
locationid: data.locationid || '',
businessunitid: data.businessunitid || '',
requiresmanualconfig: data.equipment?.requiresmanualconfig || false,
islocationonly: data.equipment?.islocationonly || false,
requiresmanualconfig: data.machine?.requiresmanualconfig || false,
islocationonly: data.machine?.islocationonly || false,
notes: data.notes || '',
mapx: data.mapx ?? null,
mapy: data.mapy ?? null
@@ -553,7 +553,7 @@ function clearMapPosition() {
tempMapPosition.value = null
}
async function saveEquipment() {
async function saveMachine() {
error.value = ''
saving.value = true
@@ -565,7 +565,7 @@ async function saveEquipment() {
maintenancereference: form.value.maintenancereference || null,
serialnumber: form.value.serialnumber || null,
statusid: form.value.statusid || 1,
equipmenttypeid: form.value.equipmenttypeid || null,
machinetypeid: form.value.machinetypeid || null,
vendorid: form.value.vendorid || null,
modelnumberid: form.value.modelnumberid || null,
controllervendorid: form.value.controllervendorid || null,
@@ -579,17 +579,17 @@ async function saveEquipment() {
mapy: form.value.mapy
}
let savedEquipment
let savedMachine
let assetId
if (isEdit.value) {
const response = await equipmentApi.update(route.params.id, data)
savedEquipment = response.data.data
assetId = savedEquipment.assetid
const response = await machinesApi.update(route.params.id, data)
savedMachine = response.data.data
assetId = savedMachine.assetid
} else {
const response = await equipmentApi.create(data)
savedEquipment = response.data.data
assetId = savedEquipment.assetid
const response = await machinesApi.create(data)
savedMachine = response.data.data
assetId = savedMachine.assetid
}
// Handle relationship (controlling PC)
@@ -604,10 +604,10 @@ async function saveEquipment() {
}
}
router.push(`/machines/${savedEquipment.equipment?.equipmentid || route.params.id}`)
router.push(`/machines/${savedMachine.machine?.machineid || route.params.id}`)
} catch (err) {
console.error('Error saving equipment:', err)
error.value = apiError(err, 'Failed to save equipment')
console.error('Error saving machine:', err)
error.value = apiError(err, 'Failed to save machine')
} finally {
saving.value = false
}
@@ -632,7 +632,7 @@ async function saveRelationship(assetId) {
await assetsApi.deleteRelationship(existingRelationshipId.value)
}
// Create new relationship (PC controls Equipment, so PC is source, Equipment is target)
// Create new relationship (PC controls Machine, so PC is source, Machine is target)
await assetsApi.createRelationship({
sourceassetid: controllingPcId.value,
targetassetid: assetId,

View File

@@ -35,12 +35,12 @@
</tr>
</thead>
<tbody>
<tr v-for="item in equipment" :key="item.assetid">
<tr v-for="item in machines" :key="item.assetid">
<td>{{ item.assetnumber }}</td>
<td>{{ item.name || '-' }}</td>
<td class="mono">{{ item.serialnumber || '-' }}</td>
<td>{{ item.equipment?.equipmenttypename || '-' }}</td>
<td>{{ item.equipment?.vendorname || '-' }}</td>
<td>{{ item.machine?.machinetypename || '-' }}</td>
<td>{{ item.machine?.vendorname || '-' }}</td>
<td>
<span class="badge" :style="colorStyle(item.statuscolor)">
{{ item.statusname || 'Unknown' }}
@@ -49,16 +49,16 @@
<td>{{ item.locationname || '-' }}</td>
<td class="actions">
<router-link
:to="`/machines/${item.equipment?.equipmentid || item.assetid}`"
:to="`/machines/${item.machine?.machineid || item.assetid}`"
class="btn btn-secondary btn-sm"
>
View
</router-link>
</td>
</tr>
<tr v-if="equipment.length === 0">
<tr v-if="machines.length === 0">
<td colspan="8" style="text-align: center; color: var(--text-light);">
No equipment found
No machines found
</td>
</tr>
</tbody>
@@ -82,10 +82,10 @@
<script setup>
import { ref, onMounted } from 'vue'
import { colorStyle } from "@/utils/colorStyle"
import { equipmentApi } from '../../api'
import { machinesApi } from '../../api'
import PaginationBar from '../../components/PaginationBar.vue'
const equipment = ref([])
const machines = ref([])
const loading = ref(true)
const search = ref('')
const page = ref(1)
@@ -95,10 +95,10 @@ const perPage = ref(20)
let searchTimeout = null
onMounted(() => {
loadEquipment()
loadMachines()
})
async function loadEquipment() {
async function loadMachines() {
loading.value = true
try {
const params = {
@@ -107,11 +107,11 @@ async function loadEquipment() {
}
if (search.value) params.search = search.value
const response = await equipmentApi.list(params)
equipment.value = response.data.data || []
const response = await machinesApi.list(params)
machines.value = response.data.data || []
totalPages.value = response.data.meta?.pagination?.totalpages || response.data.meta?.pagination?.total_pages || 1
} catch (error) {
console.error('Error loading equipment:', error)
console.error('Error loading machines:', error)
} finally {
loading.value = false
}
@@ -121,19 +121,19 @@ function debouncedSearch() {
clearTimeout(searchTimeout)
searchTimeout = setTimeout(() => {
page.value = 1
loadEquipment()
loadMachines()
}, 300)
}
function goToPage(p) {
page.value = p
loadEquipment()
loadMachines()
}
function changePerPage(newPerPage) {
perPage.value = newPerPage
page.value = 1
loadEquipment()
loadMachines()
}
</script>

View File

@@ -131,6 +131,9 @@
<!-- Warranty -->
<WarrantyPanel :assetid="tool.assetid" :items="warranties" />
<!-- All relationships (partof, connectedto, ...) -->
<AssetRelationships v-if="tool.assetid" :assetId="tool.assetid" />
<!-- Notes -->
<div class="section-card" v-if="tool.notes">
<h3 class="section-title">Notes</h3>
@@ -159,6 +162,7 @@ import { colorStyle } from '@/utils/colorStyle'
import { measuringtoolsApi } from '../../api'
import CustomFieldsSection from '../../components/CustomFieldsSection.vue'
import WarrantyPanel from '../../components/WarrantyPanel.vue'
import AssetRelationships from '../../components/AssetRelationships.vue'
import { useWarrantyBadge } from '../../composables/warrantyBadge'
const route = useRoute()

File diff suppressed because it is too large Load Diff

View File

@@ -1,168 +1,168 @@
<template>
<div>
<button class="print-btn" @click="print" v-if="!loading">Print Badge</button>
<div v-if="loading" class="loading-msg">Loading...</div>
<div v-else-if="equipment" class="badge-container">
<div class="model-name">{{ modelName }}</div>
<img
v-if="isInspection"
class="machine-image"
:src="geLogo"
alt="GE Logo"
/>
<img
v-else-if="imageUrl"
class="machine-image"
:src="imageUrl"
:alt="modelName"
/>
<div class="barcode-container">
<svg ref="barcodeEl"></svg>
<div class="machine-number">*{{ equipment.assetnumber }}*</div>
</div>
</div>
<div v-else class="error-msg">Equipment not found</div>
</div>
</template>
<script setup>
import { ref, computed, onMounted, nextTick } from 'vue'
import { useRoute } from 'vue-router'
import { equipmentApi } from '../../api'
import { getBadgeLogo } from '@/utils/siteSettings'
import JsBarcode from 'jsbarcode'
const route = useRoute()
const loading = ref(true)
const equipment = ref(null)
const barcodeEl = ref(null)
const geLogo = ref('/ge-aerospace-logo.svg')
const isInspection = computed(() => {
if (!equipment.value) return false
return equipment.value.assetnumber?.startsWith('06')
})
const modelName = computed(() => {
if (!equipment.value) return ''
if (isInspection.value) return 'Inspection'
return equipment.value.equipment?.modelname || ''
})
const imageUrl = computed(() => {
if (!equipment.value) return null
const img = equipment.value.equipment?.imageurl
if (img) return img.startsWith('/') ? img : `/images/models/machines/${img}`
return null
})
onMounted(async () => {
getBadgeLogo().then(logo => { geLogo.value = logo })
try {
const response = await equipmentApi.get(route.params.id)
equipment.value = response.data.data
} catch (error) {
console.error('Error loading equipment:', error)
} finally {
loading.value = false
await nextTick()
generateBarcode()
}
})
function generateBarcode() {
if (!barcodeEl.value || !equipment.value) return
try {
JsBarcode(barcodeEl.value, equipment.value.assetnumber, {
format: 'CODE39',
displayValue: false,
width: 2,
height: 70,
margin: 0
})
} catch (e) {
console.error('Barcode generation error:', e)
}
}
function print() {
window.print()
}
</script>
<style scoped>
@page { size: 2.13in 3.38in; margin: 0; }
body { font-family: Arial, sans-serif; }
.badge-container {
width: 2.13in;
height: 3.38in;
background: white;
margin: 0 auto;
border: 1px solid #ccc;
display: flex;
flex-direction: column;
align-items: center;
padding: 0.15in;
box-sizing: border-box;
}
.model-name {
font-size: 12pt;
font-weight: bold;
text-align: center;
margin-bottom: 0.1in;
color: #000;
}
.machine-image {
max-width: 1.8in;
max-height: 1.5in;
object-fit: contain;
margin-bottom: 0.1in;
}
.barcode-container {
text-align: center;
margin-top: auto;
}
.barcode-container svg {
width: 1.8in;
height: 0.9in;
}
.machine-number {
font-size: 14pt;
font-weight: bold;
font-family: monospace;
margin-top: -0.1in;
color: #000;
}
.print-btn {
display: block;
margin: 20px auto;
padding: 10px 30px;
font-size: 16px;
cursor: pointer;
background: #667eea;
color: white;
border: none;
border-radius: 5px;
}
.loading-msg, .error-msg {
text-align: center;
padding: 2rem;
font-size: 1.125rem;
color: #666;
}
@media print {
.print-btn { display: none; }
.badge-container { border: none; margin: 0; }
}
</style>
<template>
<div>
<button class="print-btn" @click="print" v-if="!loading">Print Badge</button>
<div v-if="loading" class="loading-msg">Loading...</div>
<div v-else-if="machine" class="badge-container">
<div class="model-name">{{ modelName }}</div>
<img
v-if="isInspection"
class="machine-image"
:src="geLogo"
alt="GE Logo"
/>
<img
v-else-if="imageUrl"
class="machine-image"
:src="imageUrl"
:alt="modelName"
/>
<div class="barcode-container">
<svg ref="barcodeEl"></svg>
<div class="machine-number">*{{ machine.assetnumber }}*</div>
</div>
</div>
<div v-else class="error-msg">Machine not found</div>
</div>
</template>
<script setup>
import { ref, computed, onMounted, nextTick } from 'vue'
import { useRoute } from 'vue-router'
import { machinesApi } from '../../api'
import { getBadgeLogo } from '@/utils/siteSettings'
import JsBarcode from 'jsbarcode'
const route = useRoute()
const loading = ref(true)
const machine = ref(null)
const barcodeEl = ref(null)
const geLogo = ref('/ge-aerospace-logo.svg')
const isInspection = computed(() => {
if (!machine.value) return false
return machine.value.assetnumber?.startsWith('06')
})
const modelName = computed(() => {
if (!machine.value) return ''
if (isInspection.value) return 'Inspection'
return machine.value.machine?.modelname || ''
})
const imageUrl = computed(() => {
if (!machine.value) return null
const img = machine.value.machine?.imageurl
if (img) return img.startsWith('/') ? img : `/images/models/machines/${img}`
return null
})
onMounted(async () => {
getBadgeLogo().then(logo => { geLogo.value = logo })
try {
const response = await machinesApi.get(route.params.id)
machine.value = response.data.data
} catch (error) {
console.error('Error loading machine:', error)
} finally {
loading.value = false
await nextTick()
generateBarcode()
}
})
function generateBarcode() {
if (!barcodeEl.value || !machine.value) return
try {
JsBarcode(barcodeEl.value, machine.value.assetnumber, {
format: 'CODE39',
displayValue: false,
width: 2,
height: 70,
margin: 0
})
} catch (e) {
console.error('Barcode generation error:', e)
}
}
function print() {
window.print()
}
</script>
<style scoped>
@page { size: 2.13in 3.38in; margin: 0; }
body { font-family: Arial, sans-serif; }
.badge-container {
width: 2.13in;
height: 3.38in;
background: white;
margin: 0 auto;
border: 1px solid #ccc;
display: flex;
flex-direction: column;
align-items: center;
padding: 0.15in;
box-sizing: border-box;
}
.model-name {
font-size: 12pt;
font-weight: bold;
text-align: center;
margin-bottom: 0.1in;
color: #000;
}
.machine-image {
max-width: 1.8in;
max-height: 1.5in;
object-fit: contain;
margin-bottom: 0.1in;
}
.barcode-container {
text-align: center;
margin-top: auto;
}
.barcode-container svg {
width: 1.8in;
height: 0.9in;
}
.machine-number {
font-size: 14pt;
font-weight: bold;
font-family: monospace;
margin-top: -0.1in;
color: #000;
}
.print-btn {
display: block;
margin: 20px auto;
padding: 10px 30px;
font-size: 16px;
cursor: pointer;
background: #667eea;
color: white;
border: none;
border-radius: 5px;
}
.loading-msg, .error-msg {
text-align: center;
padding: 2rem;
font-size: 1.125rem;
color: #666;
}
@media print {
.print-btn { display: none; }
.badge-container { border: none; margin: 0; }
}
</style>

View File

@@ -127,6 +127,9 @@
<!-- Warranty -->
<WarrantyPanel :assetid="printer.assetid" :items="warranties" />
<!-- All relationships (defaultprinter, connectedto, ...) -->
<AssetRelationships v-if="printer.assetid" :assetId="printer.assetid" />
<!-- Notes -->
<div class="section-card" v-if="printer.notes">
<h3 class="section-title">Notes</h3>
@@ -267,6 +270,7 @@ import { printersApi } from '../../api'
import LocationMapTooltip from '../../components/LocationMapTooltip.vue'
import CustomFieldsSection from '../../components/CustomFieldsSection.vue'
import WarrantyPanel from '../../components/WarrantyPanel.vue'
import AssetRelationships from '../../components/AssetRelationships.vue'
import { useWarrantyBadge } from '../../composables/warrantyBadge'
import { useIdentifierFlags } from '../../composables/identifierSettings'

View File

@@ -107,8 +107,8 @@
<div v-if="loading" class="loading">Loading report...</div>
<div v-else-if="reportData">
<!-- Equipment by Type -->
<div v-if="currentReport.id === 'equipment-by-type'" class="report-content">
<!-- Machines by Type -->
<div v-if="currentReport.id === 'machines-by-type'" class="report-content">
<p class="report-summary">Total: {{ reportData.total }}</p>
<table>
<thead>
@@ -119,8 +119,8 @@
</tr>
</thead>
<tbody>
<tr v-for="item in reportData.data" :key="item.equipmenttype">
<td>{{ item.equipmenttype }}</td>
<tr v-for="item in reportData.data" :key="item.machinetype">
<td>{{ item.machinetype }}</td>
<td>{{ item.description }}</td>
<td>{{ item.count }}</td>
</tr>
@@ -235,7 +235,7 @@ const categoryOrder = ['inventory', 'compliance', 'usage']
// server-side filters each inline report accepts (query params on its endpoint)
const reportFilterFields = {
'equipment-by-type': ['businessunit'],
'machines-by-type': ['businessunit'],
'assets-by-status': ['assettype', 'businessunit'],
'asset-inventory': ['businessunit', 'location'],
'kb-popularity': ['limit'],
@@ -388,8 +388,8 @@ async function runReport(report) {
try {
let response
switch (report.id) {
case 'equipment-by-type':
response = await reportsApi.equipmentByType(params)
case 'machines-by-type':
response = await reportsApi.machinesByType(params)
break
case 'assets-by-status':
response = await reportsApi.assetsByStatus(params)

View File

@@ -70,7 +70,7 @@ const bucketOrder = [
function formatDate(d) { return new Date(d + 'T00:00:00').toLocaleDateString() }
function cardStyle(color) { return { borderTop: `3px solid ${color}` } }
function assetLink(a) {
const map = { computer: '/pcs/', printer: '/printers/', network_device: '/network/', equipment: '/machines/' }
const map = { computer: '/pcs/', printer: '/printers/', network_device: '/network/', machine: '/machines/' }
return (map[a.assettypename] || '/assets/') + a.assetid
}

View File

@@ -1,367 +1,367 @@
<template>
<div class="page-header">
<h1>Audit Logs</h1>
</div>
<div class="filters">
<input
type="text"
v-model="search"
placeholder="Search by name or user..."
@input="debouncedSearch"
>
<select v-model="filterAction" @change="loadLogs">
<option value="">All Actions</option>
<option value="created">Created</option>
<option value="updated">Updated</option>
<option value="deleted">Deleted</option>
</select>
<select v-model="filterEntity" @change="loadLogs">
<option value="">All Entities</option>
<option v-for="e in entityTypes" :key="e" :value="e">{{ e }}</option>
</select>
</div>
<div class="card">
<div class="table-container">
<table>
<thead>
<tr>
<th style="width: 160px">Timestamp</th>
<th style="width: 100px">Action</th>
<th style="width: 100px">Entity</th>
<th>Name/ID</th>
<th style="width: 120px">User</th>
<th style="width: 130px">IP Address</th>
<th>Changes</th>
</tr>
</thead>
<tbody>
<tr v-if="loading">
<td colspan="7" class="loading">Loading...</td>
</tr>
<tr v-else-if="!logs.length">
<td colspan="7" class="empty">No audit logs found</td>
</tr>
<tr v-for="log in logs" :key="log.auditlogid">
<td class="timestamp">{{ formatDate(log.timestamp) }}</td>
<td>
<span class="badge" :class="actionClass(log.action)">
{{ log.action }}
</span>
</td>
<td>{{ log.entitytype }}</td>
<td>
<router-link
v-if="getEntityLink(log)"
:to="getEntityLink(log)"
class="entity-link"
>
{{ log.entityname || `#${log.entityid}` }}
</router-link>
<span v-else>{{ log.entityname || `#${log.entityid}` }}</span>
</td>
<td>{{ log.username || '-' }}</td>
<td class="ip">{{ log.ipaddress || '-' }}</td>
<td>
<button
v-if="log.changes && Object.keys(log.changes).length"
class="changes-btn"
@click="showChanges(log)"
>
{{ Object.keys(log.changes).length }} field(s)
</button>
<span v-else class="no-changes">-</span>
</td>
</tr>
</tbody>
</table>
</div>
<div class="pagination" v-if="totalPages > 1">
<button :disabled="page <= 1" @click="page--; loadLogs()">Prev</button>
<span>Page {{ page }} of {{ totalPages }}</span>
<button :disabled="page >= totalPages" @click="page++; loadLogs()">Next</button>
</div>
</div>
<!-- Changes Modal -->
<div v-if="selectedLog" class="modal-overlay" @click.self="selectedLog = null">
<div class="modal">
<div class="modal-header">
<h3>Changes - {{ selectedLog.entitytype }} {{ selectedLog.entityname }}</h3>
<button class="close-btn" @click="selectedLog = null">&times;</button>
</div>
<div class="modal-body">
<table class="changes-table">
<thead>
<tr>
<th>Field</th>
<th>Old Value</th>
<th>New Value</th>
</tr>
</thead>
<tbody>
<tr v-for="(change, field) in selectedLog.changes" :key="field">
<td>{{ field }}</td>
<td class="old-value">{{ formatValue(change.old) }}</td>
<td class="new-value">{{ formatValue(change.new) }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<script setup>
import { ref, onMounted, computed } from 'vue'
import { auditLogsApi } from '../../api'
const logs = ref([])
const loading = ref(true)
const page = ref(1)
const perpage = 50
const total = ref(0)
const search = ref('')
const filterAction = ref('')
const filterEntity = ref('')
const selectedLog = ref(null)
const entityTypes = ['Asset', 'Printer', 'Computer', 'Equipment', 'Network', 'Setting', 'User', 'Application', 'KnowledgeBase']
const totalPages = computed(() => Math.ceil(total.value / perpage))
let debounceTimer = null
function debouncedSearch() {
clearTimeout(debounceTimer)
debounceTimer = setTimeout(() => {
page.value = 1
loadLogs()
}, 300)
}
async function loadLogs() {
loading.value = true
try {
const params = {
page: page.value,
perpage
}
if (search.value) params.search = search.value
if (filterAction.value) params.action = filterAction.value
if (filterEntity.value) params.entitytype = filterEntity.value
const { data } = await auditLogsApi.list(params)
logs.value = data.data
total.value = data.meta.total
} catch (e) {
console.error('Failed to load audit logs:', e)
} finally {
loading.value = false
}
}
function formatDate(isoString) {
if (!isoString) return '-'
const d = new Date(isoString)
return d.toLocaleString()
}
function actionClass(action) {
switch (action) {
case 'created': return 'badge-success'
case 'updated': return 'badge-warning'
case 'deleted': return 'badge-danger'
default: return ''
}
}
function getEntityLink(log) {
if (!log.entityid) return null
const type = log.entitytype?.toLowerCase()
switch (type) {
case 'printer': return `/printers/${log.entityid}`
case 'computer': return `/pcs/${log.entityid}`
case 'equipment': return `/equipment/${log.entityid}`
case 'asset': return `/assets/${log.entityid}`
case 'application': return `/applications/${log.entityid}`
case 'knowledgebase': return `/kb/${log.entityid}`
default: return null
}
}
function showChanges(log) {
selectedLog.value = log
}
function formatValue(val) {
if (val === null || val === undefined) return '(empty)'
if (typeof val === 'boolean') return val ? 'Yes' : 'No'
if (typeof val === 'object') return JSON.stringify(val)
return String(val)
}
onMounted(loadLogs)
</script>
<style scoped>
.filters {
display: flex;
gap: 1rem;
margin-bottom: 1rem;
flex-wrap: wrap;
}
.filters input,
.filters select {
padding: 0.5rem;
border: 1px solid var(--border);
border-radius: 4px;
background: var(--bg-card);
color: var(--text);
}
.filters input {
min-width: 250px;
}
.timestamp {
font-size: 0.85rem;
color: var(--text-light);
white-space: nowrap;
}
.ip {
font-family: monospace;
font-size: 0.85rem;
}
.badge {
padding: 0.2rem 0.5rem;
border-radius: 4px;
font-size: 0.8rem;
text-transform: capitalize;
}
.badge-success { background: var(--success); color: white; }
.badge-warning { background: var(--warning); color: #000; }
.badge-danger { background: var(--danger); color: white; }
.entity-link {
color: var(--link);
text-decoration: none;
}
.entity-link:hover {
text-decoration: underline;
}
.changes-btn {
padding: 0.2rem 0.5rem;
font-size: 0.8rem;
background: var(--primary);
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.changes-btn:hover {
background: var(--primary-dark);
}
.no-changes {
color: var(--text-light);
}
.loading, .empty {
text-align: center;
color: var(--text-light);
padding: 2rem;
}
/* Modal */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.modal {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 8px;
min-width: 500px;
max-width: 90vw;
max-height: 80vh;
overflow: hidden;
display: flex;
flex-direction: column;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem;
border-bottom: 1px solid var(--border);
}
.modal-header h3 {
margin: 0;
font-size: 1rem;
}
.close-btn {
background: none;
border: none;
font-size: 1.5rem;
cursor: pointer;
color: var(--text-light);
padding: 0;
line-height: 1;
}
.close-btn:hover {
color: var(--text);
}
.modal-body {
padding: 1rem;
overflow-y: auto;
}
.changes-table {
width: 100%;
border-collapse: collapse;
}
.changes-table th,
.changes-table td {
padding: 0.5rem;
text-align: left;
border-bottom: 1px solid var(--border);
}
.changes-table th {
background: var(--bg);
font-weight: 600;
}
.old-value {
color: var(--danger);
text-decoration: line-through;
}
.new-value {
color: var(--success);
}
</style>
<template>
<div class="page-header">
<h1>Audit Logs</h1>
</div>
<div class="filters">
<input
type="text"
v-model="search"
placeholder="Search by name or user..."
@input="debouncedSearch"
>
<select v-model="filterAction" @change="loadLogs">
<option value="">All Actions</option>
<option value="created">Created</option>
<option value="updated">Updated</option>
<option value="deleted">Deleted</option>
</select>
<select v-model="filterEntity" @change="loadLogs">
<option value="">All Entities</option>
<option v-for="e in entityTypes" :key="e" :value="e">{{ e }}</option>
</select>
</div>
<div class="card">
<div class="table-container">
<table>
<thead>
<tr>
<th style="width: 160px">Timestamp</th>
<th style="width: 100px">Action</th>
<th style="width: 100px">Entity</th>
<th>Name/ID</th>
<th style="width: 120px">User</th>
<th style="width: 130px">IP Address</th>
<th>Changes</th>
</tr>
</thead>
<tbody>
<tr v-if="loading">
<td colspan="7" class="loading">Loading...</td>
</tr>
<tr v-else-if="!logs.length">
<td colspan="7" class="empty">No audit logs found</td>
</tr>
<tr v-for="log in logs" :key="log.auditlogid">
<td class="timestamp">{{ formatDate(log.timestamp) }}</td>
<td>
<span class="badge" :class="actionClass(log.action)">
{{ log.action }}
</span>
</td>
<td>{{ log.entitytype }}</td>
<td>
<router-link
v-if="getEntityLink(log)"
:to="getEntityLink(log)"
class="entity-link"
>
{{ log.entityname || `#${log.entityid}` }}
</router-link>
<span v-else>{{ log.entityname || `#${log.entityid}` }}</span>
</td>
<td>{{ log.username || '-' }}</td>
<td class="ip">{{ log.ipaddress || '-' }}</td>
<td>
<button
v-if="log.changes && Object.keys(log.changes).length"
class="changes-btn"
@click="showChanges(log)"
>
{{ Object.keys(log.changes).length }} field(s)
</button>
<span v-else class="no-changes">-</span>
</td>
</tr>
</tbody>
</table>
</div>
<div class="pagination" v-if="totalPages > 1">
<button :disabled="page <= 1" @click="page--; loadLogs()">Prev</button>
<span>Page {{ page }} of {{ totalPages }}</span>
<button :disabled="page >= totalPages" @click="page++; loadLogs()">Next</button>
</div>
</div>
<!-- Changes Modal -->
<div v-if="selectedLog" class="modal-overlay" @click.self="selectedLog = null">
<div class="modal">
<div class="modal-header">
<h3>Changes - {{ selectedLog.entitytype }} {{ selectedLog.entityname }}</h3>
<button class="close-btn" @click="selectedLog = null">&times;</button>
</div>
<div class="modal-body">
<table class="changes-table">
<thead>
<tr>
<th>Field</th>
<th>Old Value</th>
<th>New Value</th>
</tr>
</thead>
<tbody>
<tr v-for="(change, field) in selectedLog.changes" :key="field">
<td>{{ field }}</td>
<td class="old-value">{{ formatValue(change.old) }}</td>
<td class="new-value">{{ formatValue(change.new) }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<script setup>
import { ref, onMounted, computed } from 'vue'
import { auditLogsApi } from '../../api'
const logs = ref([])
const loading = ref(true)
const page = ref(1)
const perpage = 50
const total = ref(0)
const search = ref('')
const filterAction = ref('')
const filterEntity = ref('')
const selectedLog = ref(null)
const entityTypes = ['Asset', 'Printer', 'Computer', 'Machine', 'Network', 'Setting', 'User', 'Application', 'KnowledgeBase']
const totalPages = computed(() => Math.ceil(total.value / perpage))
let debounceTimer = null
function debouncedSearch() {
clearTimeout(debounceTimer)
debounceTimer = setTimeout(() => {
page.value = 1
loadLogs()
}, 300)
}
async function loadLogs() {
loading.value = true
try {
const params = {
page: page.value,
perpage
}
if (search.value) params.search = search.value
if (filterAction.value) params.action = filterAction.value
if (filterEntity.value) params.entitytype = filterEntity.value
const { data } = await auditLogsApi.list(params)
logs.value = data.data
total.value = data.meta.total
} catch (e) {
console.error('Failed to load audit logs:', e)
} finally {
loading.value = false
}
}
function formatDate(isoString) {
if (!isoString) return '-'
const d = new Date(isoString)
return d.toLocaleString()
}
function actionClass(action) {
switch (action) {
case 'created': return 'badge-success'
case 'updated': return 'badge-warning'
case 'deleted': return 'badge-danger'
default: return ''
}
}
function getEntityLink(log) {
if (!log.entityid) return null
const type = log.entitytype?.toLowerCase()
switch (type) {
case 'printer': return `/printers/${log.entityid}`
case 'computer': return `/pcs/${log.entityid}`
case 'machine': return `/machines/${log.entityid}`
case 'asset': return `/assets/${log.entityid}`
case 'application': return `/applications/${log.entityid}`
case 'knowledgebase': return `/kb/${log.entityid}`
default: return null
}
}
function showChanges(log) {
selectedLog.value = log
}
function formatValue(val) {
if (val === null || val === undefined) return '(empty)'
if (typeof val === 'boolean') return val ? 'Yes' : 'No'
if (typeof val === 'object') return JSON.stringify(val)
return String(val)
}
onMounted(loadLogs)
</script>
<style scoped>
.filters {
display: flex;
gap: 1rem;
margin-bottom: 1rem;
flex-wrap: wrap;
}
.filters input,
.filters select {
padding: 0.5rem;
border: 1px solid var(--border);
border-radius: 4px;
background: var(--bg-card);
color: var(--text);
}
.filters input {
min-width: 250px;
}
.timestamp {
font-size: 0.85rem;
color: var(--text-light);
white-space: nowrap;
}
.ip {
font-family: monospace;
font-size: 0.85rem;
}
.badge {
padding: 0.2rem 0.5rem;
border-radius: 4px;
font-size: 0.8rem;
text-transform: capitalize;
}
.badge-success { background: var(--success); color: white; }
.badge-warning { background: var(--warning); color: #000; }
.badge-danger { background: var(--danger); color: white; }
.entity-link {
color: var(--link);
text-decoration: none;
}
.entity-link:hover {
text-decoration: underline;
}
.changes-btn {
padding: 0.2rem 0.5rem;
font-size: 0.8rem;
background: var(--primary);
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.changes-btn:hover {
background: var(--primary-dark);
}
.no-changes {
color: var(--text-light);
}
.loading, .empty {
text-align: center;
color: var(--text-light);
padding: 2rem;
}
/* Modal */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
}
.modal {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: 8px;
min-width: 500px;
max-width: 90vw;
max-height: 80vh;
overflow: hidden;
display: flex;
flex-direction: column;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem;
border-bottom: 1px solid var(--border);
}
.modal-header h3 {
margin: 0;
font-size: 1rem;
}
.close-btn {
background: none;
border: none;
font-size: 1.5rem;
cursor: pointer;
color: var(--text-light);
padding: 0;
line-height: 1;
}
.close-btn:hover {
color: var(--text);
}
.modal-body {
padding: 1rem;
overflow-y: auto;
}
.changes-table {
width: 100%;
border-collapse: collapse;
}
.changes-table th,
.changes-table td {
padding: 0.5rem;
text-align: left;
border-bottom: 1px solid var(--border);
}
.changes-table th {
background: var(--bg);
font-weight: 600;
}
.old-value {
color: var(--danger);
text-decoration: line-through;
}
.new-value {
color: var(--success);
}
</style>

View File

@@ -1,145 +0,0 @@
<template>
<div>
<div class="page-header">
<h2>Equipment Types</h2>
<label class="show-inactive"><input type="checkbox" v-model="showInactive" /> Show inactive</label>
<button class="btn btn-primary" @click="openModal()">+ Add Equipment Type</button>
</div>
<div class="card">
<div v-if="loading" class="loading">Loading...</div>
<template v-else>
<div class="table-container">
<table>
<thead>
<tr>
<th>Equipment Type</th>
<th>Description</th>
<th>Color</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr v-for="t in visibleItems" :key="t.equipmenttypeid">
<td>{{ t.equipmenttype }}</td>
<td class="cell-truncate" :title="t.description">{{ t.description || '-' }}</td>
<td><span class="badge" :style="colorStyle(t.color)">{{ t.color || 'auto' }}</span></td>
<td class="actions">
<span v-if="t.isactive === false" class="badge badge-secondary" style="margin-right:6px;">inactive</span>
<button class="btn btn-secondary btn-sm" @click="openModal(t)">Edit</button>
<button class="btn btn-danger btn-sm" @click="deleteType(t)">Delete</button>
</td>
</tr>
<tr v-if="visibleItems.length === 0">
<td colspan="4" style="text-align: center; color: var(--text-light);">No equipment types found</td>
</tr>
</tbody>
</table>
</div>
</template>
</div>
<div v-if="showModal" class="modal-overlay" @click.self="closeModal">
<div class="modal">
<div class="modal-header"><h3>{{ editing ? 'Edit' : 'Add' }} Equipment Type</h3></div>
<form @submit.prevent="save">
<div class="modal-body">
<div class="form-group">
<label>Equipment Type *</label>
<input v-model="form.equipmenttype" type="text" class="form-control" required />
</div>
<div class="form-group">
<label>Description</label>
<textarea v-model="form.description" class="form-control" rows="3"></textarea>
</div>
<div class="form-group">
<label>Color <span class="hint">(map markers; blank = auto)</span></label>
<ColorSwatchPicker v-model="form.color" />
</div>
<div class="form-group">
<label class="checkbox-label"><input type="checkbox" v-model="form.isactive" /> Active</label>
</div>
<div v-if="error" class="error-message">{{ error }}</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" @click="closeModal">Cancel</button>
<button type="submit" class="btn btn-primary" :disabled="saving">{{ saving ? 'Saving...' : 'Save' }}</button>
</div>
</form>
</div>
</div>
</div>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { equipmentApi } from '../../api'
import ColorSwatchPicker from '@/components/ColorSwatchPicker.vue'
import { colorStyle } from '@/utils/colorStyle'
import { useToast } from '../../composables/toast'
import { apiError } from '../../utils/apiError'
const toast = useToast()
const items = ref([])
const showInactive = ref(false)
const visibleItems = computed(() => showInactive.value ? items.value : items.value.filter(x => x.isactive !== false))
const loading = ref(true)
const showModal = ref(false)
const editing = ref(null)
const saving = ref(false)
const error = ref('')
const form = ref({ equipmenttype: '', description: '', color: '', isactive: true })
onMounted(loadData)
async function loadData() {
loading.value = true
try {
const response = await equipmentApi.types.list({ perpage: 200, active: false })
items.value = response.data.data || []
} catch (err) {
console.error('Error loading equipment types:', err)
} finally {
loading.value = false
}
}
function openModal(item = null) {
editing.value = item
form.value = item
? { equipmenttype: item.equipmenttype || '', description: item.description || '', color: item.color || '', isactive: item.isactive !== false }
: { equipmenttype: '', description: '', color: '', isactive: true }
error.value = ''
showModal.value = true
}
function closeModal() { showModal.value = false; editing.value = null }
async function save() {
error.value = ''
saving.value = true
try {
if (editing.value) {
await equipmentApi.types.update(editing.value.equipmenttypeid, form.value)
} else {
await equipmentApi.types.create(form.value)
}
closeModal()
loadData()
} catch (err) {
error.value = apiError(err, 'Failed to save')
} finally {
saving.value = false
}
}
async function deleteType(t) {
if (!confirm(`Delete equipment type "${t.equipmenttype}"?`)) return
try {
await equipmentApi.types.remove(t.equipmenttypeid)
loadData()
} catch (err) {
toast.error(apiError(err, 'Failed to delete'))
}
}
</script>

View File

@@ -2,188 +2,101 @@
<div>
<div class="page-header">
<h2>Machine Types</h2>
<button class="btn btn-primary" @click="openModal()">+ Add Type</button>
<label class="show-inactive"><input type="checkbox" v-model="showInactive" /> Show inactive</label>
<button class="btn btn-primary" @click="openModal()">+ Add Machine Type</button>
</div>
<div class="card">
<div v-if="loading" class="loading">Loading...</div>
<template v-else>
<div class="table-container">
<table>
<thead>
<tr>
<th>Machine Type</th>
<th>Category</th>
<th>Description</th>
<th>Color</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr v-for="mt in machineTypes" :key="mt.machinetypeid">
<td>{{ mt.machinetype }}</td>
<td>
<span class="badge" :class="getCategoryClass(mt.category)">
{{ mt.category }}
</span>
</td>
<td class="cell-truncate" :title="mt.description">{{ mt.description || '-' }}</td>
<tr v-for="t in visibleItems" :key="t.machinetypeid">
<td>{{ t.machinetype }}</td>
<td class="cell-truncate" :title="t.description">{{ t.description || '-' }}</td>
<td><span class="badge" :style="colorStyle(t.color)">{{ t.color || 'auto' }}</span></td>
<td class="actions">
<button
class="btn btn-secondary btn-sm"
@click="openModal(mt)"
>
Edit
</button>
<button
class="btn btn-danger btn-sm"
@click="confirmDelete(mt)"
>
Delete
</button>
<span v-if="t.isactive === false" class="badge badge-secondary" style="margin-right:6px;">inactive</span>
<button class="btn btn-secondary btn-sm" @click="openModal(t)">Edit</button>
<button class="btn btn-danger btn-sm" @click="deleteType(t)">Delete</button>
</td>
</tr>
<tr v-if="machineTypes.length === 0">
<td colspan="4" style="text-align: center; color: var(--text-light);">
No machine types found
</td>
<tr v-if="visibleItems.length === 0">
<td colspan="4" style="text-align: center; color: var(--text-light);">No machine types found</td>
</tr>
</tbody>
</table>
</div>
<!-- Pagination -->
<PaginationBar
:page="page"
:totalPages="totalPages"
:perPage="perPage"
@update:page="goToPage"
@update:perPage="changePerPage"
/>
</template>
</div>
<!-- Add/Edit Modal -->
<div v-if="showModal" class="modal-overlay" @click.self="closeModal">
<div class="modal">
<div class="modal-header">
<h3>{{ editingType ? 'Edit Machine Type' : 'Add Machine Type' }}</h3>
</div>
<form @submit.prevent="saveType">
<div class="modal-header"><h3>{{ editing ? 'Edit' : 'Add' }} Machine Type</h3></div>
<form @submit.prevent="save">
<div class="modal-body">
<div class="form-group">
<label for="machinetype">Type Name *</label>
<input
id="machinetype"
v-model="form.machinetype"
type="text"
class="form-control"
required
/>
<label>Machine Type *</label>
<input v-model="form.machinetype" type="text" class="form-control" required />
</div>
<div class="form-group">
<label for="category">Category *</label>
<select
id="category"
v-model="form.category"
class="form-control"
required
>
<option value="">Select category...</option>
<option value="Equipment">Equipment</option>
<option value="PC">PC</option>
<option value="Network">Network</option>
<option value="Printer">Printer</option>
</select>
<label>Description</label>
<textarea v-model="form.description" class="form-control" rows="3"></textarea>
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea
id="description"
v-model="form.description"
class="form-control"
rows="3"
></textarea>
<label>Color <span class="hint">(map markers; blank = auto)</span></label>
<ColorSwatchPicker v-model="form.color" />
</div>
<div class="form-group">
<label class="checkbox-label"><input type="checkbox" v-model="form.isactive" /> Active</label>
</div>
<div v-if="error" class="error-message">{{ error }}</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" @click="closeModal">Cancel</button>
<button type="submit" class="btn btn-primary" :disabled="saving">
{{ saving ? 'Saving...' : 'Save' }}
</button>
<button type="submit" class="btn btn-primary" :disabled="saving">{{ saving ? 'Saving...' : 'Save' }}</button>
</div>
</form>
</div>
</div>
<!-- Delete Confirmation Modal -->
<div v-if="showDeleteModal" class="modal-overlay" @click.self="showDeleteModal = false">
<div class="modal">
<div class="modal-header">
<h3>Delete Machine Type</h3>
</div>
<div class="modal-body">
<p>Are you sure you want to delete <strong>{{ typeToDelete?.machinetype }}</strong>?</p>
<p style="color: var(--text-light); font-size: 0.875rem;">
This may affect machines using this type.
</p>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" @click="showDeleteModal = false">Cancel</button>
<button class="btn btn-danger" @click="deleteType">Delete</button>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { machinetypesApi } from '../../api'
import PaginationBar from '../../components/PaginationBar.vue'
import { ref, computed, onMounted } from 'vue'
import { machinesApi } from '../../api'
import ColorSwatchPicker from '@/components/ColorSwatchPicker.vue'
import { colorStyle } from '@/utils/colorStyle'
import { useToast } from '../../composables/toast'
import { apiError } from '../../utils/apiError'
const toast = useToast()
const machineTypes = ref([])
const items = ref([])
const showInactive = ref(false)
const visibleItems = computed(() => showInactive.value ? items.value : items.value.filter(x => x.isactive !== false))
const loading = ref(true)
const page = ref(1)
const totalPages = ref(1)
const perPage = ref(20)
const showModal = ref(false)
const editingType = ref(null)
const editing = ref(null)
const saving = ref(false)
const error = ref('')
const form = ref({ machinetype: '', description: '', color: '', isactive: true })
const showDeleteModal = ref(false)
const typeToDelete = ref(null)
onMounted(loadData)
const form = ref({
machinetype: '',
category: '',
description: ''
})
onMounted(() => {
loadTypes()
})
async function loadTypes() {
async function loadData() {
loading.value = true
try {
const params = {
page: page.value,
perpage: perPage.value
}
const response = await machinetypesApi.list(params)
machineTypes.value = response.data.data || []
totalPages.value = response.data.meta?.pagination?.totalpages || response.data.meta?.pagination?.total_pages || 1
const response = await machinesApi.types.list({ perpage: 200, active: false })
items.value = response.data.data || []
} catch (err) {
console.error('Error loading machine types:', err)
} finally {
@@ -191,87 +104,42 @@ async function loadTypes() {
}
}
function goToPage(p) {
page.value = p
loadTypes()
}
function changePerPage(newPerPage) {
perPage.value = newPerPage
page.value = 1
loadTypes()
}
function openModal(mt = null) {
editingType.value = mt
if (mt) {
form.value = {
machinetype: mt.machinetype || '',
category: mt.category || '',
description: mt.description || ''
}
} else {
form.value = {
machinetype: '',
category: '',
description: ''
}
}
function openModal(item = null) {
editing.value = item
form.value = item
? { machinetype: item.machinetype || '', description: item.description || '', color: item.color || '', isactive: item.isactive !== false }
: { machinetype: '', description: '', color: '', isactive: true }
error.value = ''
showModal.value = true
}
function closeModal() {
showModal.value = false
editingType.value = null
}
function closeModal() { showModal.value = false; editing.value = null }
async function saveType() {
async function save() {
error.value = ''
saving.value = true
try {
if (editingType.value) {
await machinetypesApi.update(editingType.value.machinetypeid, form.value)
if (editing.value) {
await machinesApi.types.update(editing.value.machinetypeid, form.value)
} else {
await machinetypesApi.create(form.value)
await machinesApi.types.create(form.value)
}
closeModal()
loadTypes()
loadData()
} catch (err) {
console.error('Error saving machine type:', err)
error.value = apiError(err, 'Failed to save machine type')
error.value = apiError(err, 'Failed to save')
} finally {
saving.value = false
}
}
function confirmDelete(mt) {
typeToDelete.value = mt
showDeleteModal.value = true
}
async function deleteType() {
async function deleteType(t) {
if (!confirm(`Delete machine type "${t.machinetype}"?`)) return
try {
await machinetypesApi.delete(typeToDelete.value.machinetypeid)
showDeleteModal.value = false
typeToDelete.value = null
loadTypes()
await machinesApi.types.remove(t.machinetypeid)
loadData()
} catch (err) {
console.error('Error deleting machine type:', err)
toast.error('Failed to delete machine type')
toast.error(apiError(err, 'Failed to delete'))
}
}
function getCategoryClass(category) {
if (!category) return 'badge-info'
const c = category.toLowerCase()
if (c === 'equipment') return 'badge-info'
if (c === 'pc') return 'badge-success'
if (c === 'network') return 'badge-warning'
if (c === 'printer') return 'badge-primary'
return 'badge-info'
}
</script>
<!-- Uses global styles from style.css -->

View File

@@ -0,0 +1,277 @@
<template>
<div>
<div class="page-header">
<h2>Model Types</h2>
<button class="btn btn-primary" @click="openModal()">+ Add Type</button>
</div>
<div class="card">
<div v-if="loading" class="loading">Loading...</div>
<template v-else>
<div class="table-container">
<table>
<thead>
<tr>
<th>Model Type</th>
<th>Category</th>
<th>Description</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr v-for="mt in modelTypes" :key="mt.modeltypeid">
<td>{{ mt.modeltype }}</td>
<td>
<span class="badge" :class="getCategoryClass(mt.category)">
{{ mt.category }}
</span>
</td>
<td class="cell-truncate" :title="mt.description">{{ mt.description || '-' }}</td>
<td class="actions">
<button
class="btn btn-secondary btn-sm"
@click="openModal(mt)"
>
Edit
</button>
<button
class="btn btn-danger btn-sm"
@click="confirmDelete(mt)"
>
Delete
</button>
</td>
</tr>
<tr v-if="modelTypes.length === 0">
<td colspan="4" style="text-align: center; color: var(--text-light);">
No model types found
</td>
</tr>
</tbody>
</table>
</div>
<!-- Pagination -->
<PaginationBar
:page="page"
:totalPages="totalPages"
:perPage="perPage"
@update:page="goToPage"
@update:perPage="changePerPage"
/>
</template>
</div>
<!-- Add/Edit Modal -->
<div v-if="showModal" class="modal-overlay" @click.self="closeModal">
<div class="modal">
<div class="modal-header">
<h3>{{ editingType ? 'Edit Model Type' : 'Add Model Type' }}</h3>
</div>
<form @submit.prevent="saveType">
<div class="modal-body">
<div class="form-group">
<label for="modeltype">Type Name *</label>
<input
id="modeltype"
v-model="form.modeltype"
type="text"
class="form-control"
required
/>
</div>
<div class="form-group">
<label for="category">Category *</label>
<select
id="category"
v-model="form.category"
class="form-control"
required
>
<option value="">Select category...</option>
<option value="Equipment">Equipment</option>
<option value="PC">PC</option>
<option value="Network">Network</option>
<option value="Printer">Printer</option>
</select>
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea
id="description"
v-model="form.description"
class="form-control"
rows="3"
></textarea>
</div>
<div v-if="error" class="error-message">{{ error }}</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" @click="closeModal">Cancel</button>
<button type="submit" class="btn btn-primary" :disabled="saving">
{{ saving ? 'Saving...' : 'Save' }}
</button>
</div>
</form>
</div>
</div>
<!-- Delete Confirmation Modal -->
<div v-if="showDeleteModal" class="modal-overlay" @click.self="showDeleteModal = false">
<div class="modal">
<div class="modal-header">
<h3>Delete Model Type</h3>
</div>
<div class="modal-body">
<p>Are you sure you want to delete <strong>{{ typeToDelete?.modeltype }}</strong>?</p>
<p style="color: var(--text-light); font-size: 0.875rem;">
This may affect models using this type.
</p>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" @click="showDeleteModal = false">Cancel</button>
<button class="btn btn-danger" @click="deleteType">Delete</button>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { modeltypesApi } from '../../api'
import PaginationBar from '../../components/PaginationBar.vue'
import { useToast } from '../../composables/toast'
import { apiError } from '../../utils/apiError'
const toast = useToast()
const modelTypes = ref([])
const loading = ref(true)
const page = ref(1)
const totalPages = ref(1)
const perPage = ref(20)
const showModal = ref(false)
const editingType = ref(null)
const saving = ref(false)
const error = ref('')
const showDeleteModal = ref(false)
const typeToDelete = ref(null)
const form = ref({
modeltype: '',
category: '',
description: ''
})
onMounted(() => {
loadTypes()
})
async function loadTypes() {
loading.value = true
try {
const params = {
page: page.value,
perpage: perPage.value
}
const response = await modeltypesApi.list(params)
modelTypes.value = response.data.data || []
totalPages.value = response.data.meta?.pagination?.totalpages || response.data.meta?.pagination?.total_pages || 1
} catch (err) {
console.error('Error loading model types:', err)
} finally {
loading.value = false
}
}
function goToPage(p) {
page.value = p
loadTypes()
}
function changePerPage(newPerPage) {
perPage.value = newPerPage
page.value = 1
loadTypes()
}
function openModal(mt = null) {
editingType.value = mt
if (mt) {
form.value = {
modeltype: mt.modeltype || '',
category: mt.category || '',
description: mt.description || ''
}
} else {
form.value = {
modeltype: '',
category: '',
description: ''
}
}
error.value = ''
showModal.value = true
}
function closeModal() {
showModal.value = false
editingType.value = null
}
async function saveType() {
error.value = ''
saving.value = true
try {
if (editingType.value) {
await modeltypesApi.update(editingType.value.modeltypeid, form.value)
} else {
await modeltypesApi.create(form.value)
}
closeModal()
loadTypes()
} catch (err) {
console.error('Error saving model type:', err)
error.value = apiError(err, 'Failed to save model type')
} finally {
saving.value = false
}
}
function confirmDelete(mt) {
typeToDelete.value = mt
showDeleteModal.value = true
}
async function deleteType() {
try {
await modeltypesApi.delete(typeToDelete.value.modeltypeid)
showDeleteModal.value = false
typeToDelete.value = null
loadTypes()
} catch (err) {
console.error('Error deleting model type:', err)
toast.error('Failed to delete model type')
}
}
function getCategoryClass(category) {
if (!category) return 'badge-info'
const c = category.toLowerCase()
if (c === 'equipment') return 'badge-info'
if (c === 'pc') return 'badge-success'
if (c === 'network') return 'badge-warning'
if (c === 'printer') return 'badge-primary'
return 'badge-info'
}
</script>
<!-- Uses global styles from style.css -->

View File

@@ -44,7 +44,7 @@
<small v-if="m.description" class="text-muted">{{ m.description }}</small>
</td>
<td>{{ m.vendor || '-' }}</td>
<td>{{ m.machinetype || '-' }}</td>
<td>{{ m.modeltype || '-' }}</td>
<td>
<a v-if="m.documentationurl" :href="m.documentationurl" target="_blank" class="btn btn-sm btn-link">
View Docs
@@ -108,11 +108,11 @@
<div class="form-row">
<div class="form-group">
<label for="machinetypeid">Machine Type</label>
<select id="machinetypeid" v-model="form.machinetypeid" class="form-control">
<label for="modeltypeid">Model Type</label>
<select id="modeltypeid" v-model="form.modeltypeid" class="form-control">
<option value="">Select type...</option>
<option v-for="mt in machineTypes" :key="mt.machinetypeid" :value="mt.machinetypeid">
{{ mt.machinetype }}
<option v-for="mt in modelTypes" :key="mt.modeltypeid" :value="mt.modeltypeid">
{{ mt.modeltype }}
</option>
</select>
</div>
@@ -181,7 +181,7 @@
<script setup>
import { ref, onMounted } from 'vue'
import { modelsApi, vendorsApi, machinetypesApi } from '../../api'
import { modelsApi, vendorsApi, modeltypesApi } from '../../api'
import PaginationBar from '../../components/PaginationBar.vue'
import { useToast } from '../../composables/toast'
import { apiError } from '../../utils/apiError'
@@ -189,7 +189,7 @@ const toast = useToast()
const models = ref([])
const vendors = ref([])
const machineTypes = ref([])
const modelTypes = ref([])
const loading = ref(true)
const search = ref('')
const vendorFilter = ref('')
@@ -208,7 +208,7 @@ const modelToDelete = ref(null)
const form = ref({
modelnumber: '',
vendorid: '',
machinetypeid: '',
modeltypeid: '',
description: '',
documentationurl: '',
imageurl: '',
@@ -221,7 +221,7 @@ onMounted(async () => {
await Promise.all([
loadModels(),
loadVendors(),
loadMachineTypes()
loadModelTypes()
])
})
@@ -251,12 +251,12 @@ async function loadVendors() {
}
}
async function loadMachineTypes() {
async function loadModelTypes() {
try {
const response = await machinetypesApi.list({ perpage: 100 })
machineTypes.value = response.data.data || []
const response = await modeltypesApi.list({ perpage: 100 })
modelTypes.value = response.data.data || []
} catch (err) {
console.error('Error loading machine types:', err)
console.error('Error loading model types:', err)
}
}
@@ -285,7 +285,7 @@ function openModal(m = null) {
form.value = {
modelnumber: m.modelnumber || '',
vendorid: m.vendorid || '',
machinetypeid: m.machinetypeid || '',
modeltypeid: m.modeltypeid || '',
description: m.description || '',
documentationurl: m.documentationurl || '',
imageurl: m.imageurl || '',
@@ -295,7 +295,7 @@ function openModal(m = null) {
form.value = {
modelnumber: '',
vendorid: '',
machinetypeid: '',
modeltypeid: '',
description: '',
documentationurl: '',
imageurl: '',
@@ -318,7 +318,7 @@ async function saveModel() {
try {
const data = { ...form.value }
if (!data.vendorid) data.vendorid = null
if (!data.machinetypeid) data.machinetypeid = null
if (!data.modeltypeid) data.modeltypeid = null
if (editingModel.value) {
await modelsApi.update(editingModel.value.modelnumberid, data)

View File

@@ -1037,9 +1037,9 @@ const brandingLogos = [
{ kind: 'qr', key: 'qr_logo', label: 'QR overlay logo', accept: 'image/*',
placeholder: '/ge-monogram.svg',
hint: 'Logo overlaid on printed QR codes. Leave blank for no overlay.' },
{ kind: 'badge', key: 'badge_logo', label: 'Equipment badge logo', accept: 'image/*',
{ kind: 'badge', key: 'badge_logo', label: 'Machine badge logo', accept: 'image/*',
placeholder: '/ge-aerospace-logo.svg',
hint: 'Logo printed on equipment badges. Upload an image or type a path/URL.' },
hint: 'Logo printed on machine badges. Upload an image or type a path/URL.' },
{ kind: 'favicon', key: 'site_favicon', label: 'Favicon', accept: 'image/*,.ico',
placeholder: '(blank = shipped /favicon.svg)',
hint: 'Browser-tab icon. Leave blank to use the shipped favicon.' },
@@ -1053,7 +1053,7 @@ const identifierRows = [
{ name: 'fqdn', label: 'FQDN / Hostname' }
]
const assetTypeCols = [
{ key: 'equipment', label: 'Equipment' },
{ key: 'machine', label: 'Machine' },
{ key: 'computer', label: 'PC' },
{ key: 'printer', label: 'Printer' },
{ key: 'network_device', label: 'Network' }
@@ -1075,7 +1075,7 @@ const searchDomains = [
{ key: 'application', label: 'Applications' },
{ key: 'knowledgebase', label: 'Knowledge Base' },
{ key: 'employee', label: 'Employees' },
{ key: 'equipment', label: 'Equipment' },
{ key: 'machine', label: 'Machines' },
{ key: 'computer', label: 'PCs' },
{ key: 'printer', label: 'Printers' },
{ key: 'network_device', label: 'Network Devices' },
@@ -1170,7 +1170,7 @@ async function loadSettings() {
for (const setting of data.data) {
if (setting.key in settings) {
settings[setting.key] = setting.value
} else if (/^identifier_.+_(equipment|computer|printer|network_device)_enabled$/.test(setting.key)) {
} else if (/^identifier_.+_(machine|computer|printer|network_device)_enabled$/.test(setting.key)) {
identifierMatrix[setting.key] = setting.value !== false
} else if (/^search_.+_enabled$/.test(setting.key)) {
searchMatrix[setting.key] = setting.value !== false

View File

@@ -17,6 +17,7 @@ export const settingsGroups = [
cards: [
{ to: '/settings/vendors', icon: Factory, title: 'Vendors', description: 'Manage equipment vendors and manufacturers' },
{ to: '/settings/models', icon: Package, title: 'Models', description: 'Manage equipment models by vendor' },
{ to: '/settings/modeltypes', icon: Monitor, title: 'Model Types', description: 'Manage model type categories' },
{ to: '/settings/statuses', icon: Tag, title: 'Statuses', description: 'Manage asset status types' },
{ to: '/settings/relationshiptypes', icon: Link, title: 'Relationship Types', description: 'Manage asset relationship types (Controls, Contains...) + colors' },
{ to: '/settings/assettypes', icon: Palette, title: 'Asset Type Colors', description: 'Map colors for the top-level asset categories' },
@@ -42,8 +43,7 @@ export const settingsGroups = [
{
title: 'Machines',
cards: [
{ to: '/settings/equipmenttypes', icon: Wrench, title: 'Equipment Types', description: 'Manage machine subtypes + map colors' },
{ to: '/settings/machinetypes', icon: Monitor, title: 'Machine Types', description: 'Manage machine type categories' },
{ to: '/settings/machinetypes', icon: Wrench, title: 'Machine Types', description: 'Manage machine subtypes + map colors' },
],
},
{

View File

@@ -208,7 +208,7 @@ function formatDate(d) { return new Date(d + 'T00:00:00').toLocaleDateString() }
// Route to the right detail page by asset type.
function assetLink(a) {
const map = { computer: '/pcs/', printer: '/printers/', network_device: '/network/', equipment: '/machines/' }
const map = { computer: '/pcs/', printer: '/printers/', network_device: '/network/', machine: '/machines/' }
const base = map[a.assettypename] || '/assets/'
return base + a.assetid
}