Add USB, Notifications, Network plugins and reusable EmployeeSearch component

New Plugins:
- USB plugin: Device checkout/checkin with employee lookup, checkout history
- Notifications plugin: Announcements with types, scheduling, shopfloor display
- Network plugin: Network device management with subnets and VLANs
- Equipment and Computers plugins: Asset type separation

Frontend:
- EmployeeSearch component: Reusable employee lookup with autocomplete
- USB views: List, detail, checkout/checkin modals
- Notifications views: List, form with recognition mode
- Network views: Device list, detail, form
- Calendar view with FullCalendar integration
- Shopfloor and TV dashboard views
- Reports index page
- Map editor for asset positioning
- Light/dark mode fixes for map tooltips

Backend:
- Employee search API with external lookup service
- Collector API for PowerShell data collection
- Reports API endpoints
- Slides API for TV dashboard
- Fixed AppVersion model (removed BaseModel inheritance)
- Added checkout_name column to usbcheckouts table

Styling:
- Unified detail page styles
- Improved pagination (page numbers instead of prev/next)
- Dark/light mode theme improvements

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-01-21 16:37:49 -05:00
parent 7e729c8fdc
commit c8b325d2e7
108 changed files with 17693 additions and 600 deletions

View File

@@ -0,0 +1,348 @@
<template>
<div class="detail-page" v-if="device">
<div class="hero-card">
<div class="hero-image">
<div class="device-icon">
<span class="icon">{{ getDeviceIcon() }}</span>
</div>
</div>
<div class="hero-content">
<div class="hero-title-row">
<h1 class="hero-title">{{ device.network_device?.hostname || device.name || device.assetnumber }}</h1>
<router-link
v-if="authStore.isAuthenticated"
:to="`/network/${deviceId}/edit`"
class="btn btn-secondary"
>
Edit
</router-link>
</div>
<div class="hero-meta">
<span class="badge" :class="getStatusClass(device.status_name)">
{{ device.status_name || 'Unknown' }}
</span>
<span v-if="device.network_device?.networkdevicetype_name" class="meta-item">
{{ device.network_device.networkdevicetype_name }}
</span>
<span v-if="device.network_device?.vendor_name" class="meta-item">
{{ device.network_device.vendor_name }}
</span>
</div>
<div class="hero-details">
<div class="detail-item" v-if="device.assetnumber">
<span class="label">Asset #</span>
<span class="value">{{ device.assetnumber }}</span>
</div>
<div class="detail-item" v-if="device.serialnumber">
<span class="label">Serial</span>
<span class="value mono">{{ device.serialnumber }}</span>
</div>
<div class="detail-item" v-if="device.location_name">
<span class="label">Location</span>
<span class="value">{{ device.location_name }}</span>
</div>
<div class="detail-item" v-if="device.businessunit_name">
<span class="label">Business Unit</span>
<span class="value">{{ device.businessunit_name }}</span>
</div>
</div>
<div class="hero-features" v-if="device.network_device">
<span v-if="device.network_device.ispoe" class="feature-badge poe">PoE</span>
<span v-if="device.network_device.ismanaged" class="feature-badge managed">Managed</span>
<span v-if="device.network_device.portcount" class="feature-badge ports">{{ device.network_device.portcount }} Ports</span>
</div>
</div>
</div>
<div class="content-grid">
<div class="content-column">
<!-- Network Info -->
<div class="section-card">
<h3 class="section-title">Network Information</h3>
<div class="info-list">
<div class="info-row">
<span class="info-label">Hostname</span>
<span class="info-value mono">{{ device.network_device?.hostname || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">Firmware Version</span>
<span class="info-value">{{ device.network_device?.firmwareversion || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">Port Count</span>
<span class="info-value">{{ device.network_device?.portcount || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">Rack Unit</span>
<span class="info-value">{{ device.network_device?.rackunit || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">PoE Capable</span>
<span class="info-value">{{ device.network_device?.ispoe ? 'Yes' : 'No' }}</span>
</div>
<div class="info-row">
<span class="info-label">Managed Device</span>
<span class="info-value">{{ device.network_device?.ismanaged ? 'Yes' : 'No' }}</span>
</div>
</div>
</div>
<!-- Notes -->
<div class="section-card" v-if="device.notes">
<h3 class="section-title">Notes</h3>
<div class="notes-content">{{ device.notes }}</div>
</div>
</div>
<div class="content-column">
<!-- Asset Info -->
<div class="section-card">
<h3 class="section-title">Asset Information</h3>
<div class="info-list">
<div class="info-row">
<span class="info-label">Asset Number</span>
<span class="info-value">{{ device.assetnumber }}</span>
</div>
<div class="info-row">
<span class="info-label">Name</span>
<span class="info-value">{{ device.name || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">Serial Number</span>
<span class="info-value mono">{{ device.serialnumber || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">Vendor</span>
<span class="info-value">{{ device.network_device?.vendor_name || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">Device Type</span>
<span class="info-value">{{ device.network_device?.networkdevicetype_name || '-' }}</span>
</div>
<div class="info-row">
<span class="info-label">Status</span>
<span class="info-value">
<span class="badge" :class="getStatusClass(device.status_name)">
{{ device.status_name || 'Unknown' }}
</span>
</span>
</div>
</div>
</div>
<!-- Relationships -->
<AssetRelationships
v-if="device.assetid"
:assetId="device.assetid"
/>
<!-- Audit Info -->
<div class="section-card audit-card">
<h3 class="section-title">Record Info</h3>
<div class="info-list">
<div class="info-row" v-if="device.datecreated">
<span class="info-label">Created</span>
<span class="info-value">{{ formatDate(device.datecreated) }}</span>
</div>
<div class="info-row" v-if="device.datemodified">
<span class="info-label">Last Modified</span>
<span class="info-value">{{ formatDate(device.datemodified) }}</span>
</div>
</div>
</div>
</div>
</div>
<!-- Actions -->
<div class="action-bar" v-if="authStore.isAuthenticated">
<router-link :to="`/network/${deviceId}/edit`" class="btn btn-primary">
Edit Device
</router-link>
<button @click="confirmDelete" class="btn btn-danger">
Delete Device
</button>
</div>
</div>
<div v-else-if="loading" class="loading-container">
<div class="loading">Loading device...</div>
</div>
<div v-else class="error-container">
<p>Device not found</p>
<router-link to="/network" class="btn btn-secondary">Back to Network Devices</router-link>
</div>
</template>
<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useAuthStore } from '../../stores/auth'
import { networkApi } from '../../api'
import AssetRelationships from '../../components/AssetRelationships.vue'
const route = useRoute()
const router = useRouter()
const authStore = useAuthStore()
const deviceId = route.params.id
const device = ref(null)
const loading = ref(true)
onMounted(async () => {
await loadDevice()
})
async function loadDevice() {
loading.value = true
try {
const response = await networkApi.get(deviceId)
device.value = response.data.data
} catch (error) {
console.error('Error loading device:', error)
device.value = null
} finally {
loading.value = false
}
}
function getDeviceIcon() {
const type = device.value?.network_device?.networkdevicetype_name?.toLowerCase() || ''
if (type.includes('switch')) return '⏛'
if (type.includes('router')) return '⇌'
if (type.includes('firewall')) return '🛡'
if (type.includes('access point') || type.includes('ap')) return '📶'
if (type.includes('camera')) return '📷'
if (type.includes('server')) return '🖥'
if (type.includes('idf') || type.includes('closet')) return '🗄'
return '🌐'
}
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 === 'maintenance') return 'badge-warning'
if (s === 'retired' || s === 'decommissioned') return 'badge-danger'
return 'badge-info'
}
function formatDate(dateStr) {
if (!dateStr) return '-'
const date = new Date(dateStr)
return date.toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
})
}
async function confirmDelete() {
if (confirm(`Are you sure you want to delete ${device.value.network_device?.hostname || device.value.assetnumber}?`)) {
try {
await networkApi.delete(deviceId)
router.push('/network')
} catch (error) {
console.error('Error deleting device:', error)
alert('Failed to delete device')
}
}
}
</script>
<style scoped>
.hero-title-row {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 1rem;
margin-bottom: 0.5rem;
}
.hero-title {
margin: 0;
}
.device-icon {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
border-radius: 8px;
}
.device-icon .icon {
font-size: 4rem;
}
.hero-features {
display: flex;
gap: 0.5rem;
margin-top: 1rem;
flex-wrap: wrap;
}
.feature-badge {
display: inline-block;
padding: 0.35rem 0.75rem;
font-size: 0.875rem;
border-radius: 5px;
font-weight: 500;
}
.feature-badge.poe {
background: #d4edda;
color: #155724;
}
.feature-badge.managed {
background: #e3f2fd;
color: #1565c0;
}
.feature-badge.ports {
background: var(--bg);
color: var(--text-light);
}
.mono {
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}
.notes-content {
white-space: pre-wrap;
color: var(--text);
line-height: 1.6;
}
.action-bar {
display: flex;
gap: 1rem;
margin-top: 2rem;
padding-top: 1.5rem;
border-top: 1px solid var(--border);
}
.loading-container,
.error-container {
text-align: center;
padding: 3rem;
color: var(--text-light);
}
@media (prefers-color-scheme: dark) {
.feature-badge.poe {
background: #1e3a29;
color: #4ade80;
}
.feature-badge.managed {
background: #1e3a5f;
color: #60a5fa;
}
}
</style>

View File

@@ -0,0 +1,497 @@
<template>
<div>
<div class="page-header">
<h2>{{ isEdit ? 'Edit Network Device' : 'Add Network Device' }}</h2>
</div>
<div class="card form-card">
<form @submit.prevent="submitForm">
<!-- Asset Information -->
<fieldset>
<legend>Asset Information</legend>
<div class="form-row">
<div class="form-group">
<label for="assetnumber">Asset Number *</label>
<input
id="assetnumber"
v-model="form.assetnumber"
type="text"
class="form-control"
required
:disabled="isEdit"
/>
</div>
<div class="form-group">
<label for="name">Name</label>
<input
id="name"
v-model="form.name"
type="text"
class="form-control"
/>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="serialnumber">Serial Number</label>
<input
id="serialnumber"
v-model="form.serialnumber"
type="text"
class="form-control"
/>
</div>
<div class="form-group">
<label for="statusid">Status</label>
<select id="statusid" v-model="form.statusid" class="form-control">
<option value="">Select Status</option>
<option v-for="s in statuses" :key="s.statusid" :value="s.statusid">
{{ s.status }}
</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="locationid">Location</label>
<select id="locationid" v-model="form.locationid" class="form-control">
<option value="">Select Location</option>
<option v-for="loc in locations" :key="loc.locationid" :value="loc.locationid">
{{ loc.location }}
</option>
</select>
</div>
<div class="form-group">
<label for="businessunitid">Business Unit</label>
<select id="businessunitid" v-model="form.businessunitid" class="form-control">
<option value="">Select Business Unit</option>
<option v-for="bu in businessUnits" :key="bu.businessunitid" :value="bu.businessunitid">
{{ bu.businessunit }}
</option>
</select>
</div>
</div>
</fieldset>
<!-- Network Device Information -->
<fieldset>
<legend>Network Device Details</legend>
<div class="form-row">
<div class="form-group">
<label for="hostname">Hostname</label>
<input
id="hostname"
v-model="form.hostname"
type="text"
class="form-control"
placeholder="e.g., sw-bldg1-floor2"
/>
</div>
<div class="form-group">
<label for="networkdevicetypeid">Device Type</label>
<select id="networkdevicetypeid" v-model="form.networkdevicetypeid" class="form-control">
<option value="">Select Type</option>
<option v-for="t in deviceTypes" :key="t.networkdevicetypeid" :value="t.networkdevicetypeid">
{{ t.networkdevicetype }}
</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="vendorid">Vendor</label>
<select id="vendorid" v-model="form.vendorid" class="form-control">
<option value="">Select Vendor</option>
<option v-for="v in vendors" :key="v.vendorid" :value="v.vendorid">
{{ v.vendor }}
</option>
</select>
</div>
<div class="form-group">
<label for="firmwareversion">Firmware Version</label>
<input
id="firmwareversion"
v-model="form.firmwareversion"
type="text"
class="form-control"
/>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="portcount">Port Count</label>
<input
id="portcount"
v-model.number="form.portcount"
type="number"
class="form-control"
min="0"
/>
</div>
<div class="form-group">
<label for="rackunit">Rack Unit</label>
<input
id="rackunit"
v-model="form.rackunit"
type="text"
class="form-control"
placeholder="e.g., U1, U5-U8"
/>
</div>
</div>
<div class="form-row checkboxes">
<div class="form-group checkbox-group">
<label>
<input type="checkbox" v-model="form.ispoe" />
<span>PoE Capable</span>
</label>
<small>Device supports Power over Ethernet</small>
</div>
<div class="form-group checkbox-group">
<label>
<input type="checkbox" v-model="form.ismanaged" />
<span>Managed Device</span>
</label>
<small>Device has SNMP, web interface, or CLI management</small>
</div>
</div>
</fieldset>
<!-- Map Position (optional) -->
<fieldset>
<legend>Map Position (Optional)</legend>
<div class="form-row">
<div class="form-group">
<label for="mapleft">Map X Position</label>
<input
id="mapleft"
v-model.number="form.mapleft"
type="number"
class="form-control"
min="0"
/>
</div>
<div class="form-group">
<label for="maptop">Map Y Position</label>
<input
id="maptop"
v-model.number="form.maptop"
type="number"
class="form-control"
min="0"
/>
</div>
</div>
</fieldset>
<!-- Notes -->
<fieldset>
<legend>Notes</legend>
<div class="form-group">
<textarea
id="notes"
v-model="form.notes"
class="form-control"
rows="4"
placeholder="Additional notes about this device..."
></textarea>
</div>
</fieldset>
<!-- Form Actions -->
<div class="form-actions">
<button type="button" class="btn btn-secondary" @click="cancel">Cancel</button>
<button type="submit" class="btn btn-primary" :disabled="saving">
{{ saving ? 'Saving...' : (isEdit ? 'Save Changes' : 'Create Device') }}
</button>
</div>
<div v-if="error" class="error-message">{{ error }}</div>
</form>
</div>
</div>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import {
networkApi,
vendorsApi,
locationsApi,
statusesApi,
businessunitsApi
} from '../../api'
const route = useRoute()
const router = useRouter()
const deviceId = route.params.id
const isEdit = computed(() => !!deviceId)
const form = ref({
assetnumber: '',
name: '',
serialnumber: '',
statusid: '',
locationid: '',
businessunitid: '',
hostname: '',
networkdevicetypeid: '',
vendorid: '',
firmwareversion: '',
portcount: null,
rackunit: '',
ispoe: false,
ismanaged: false,
mapleft: null,
maptop: null,
notes: ''
})
const deviceTypes = ref([])
const vendors = ref([])
const locations = ref([])
const statuses = ref([])
const businessUnits = ref([])
const saving = ref(false)
const error = ref('')
onMounted(async () => {
await Promise.all([
loadDeviceTypes(),
loadVendors(),
loadLocations(),
loadStatuses(),
loadBusinessUnits()
])
if (isEdit.value) {
await loadDevice()
}
})
async function loadDeviceTypes() {
try {
const response = await networkApi.types.list({ per_page: 100 })
deviceTypes.value = response.data.data || []
} catch (err) {
console.error('Error loading device types:', err)
}
}
async function loadVendors() {
try {
const response = await vendorsApi.list({ per_page: 100 })
vendors.value = response.data.data || []
} catch (err) {
console.error('Error loading vendors:', err)
}
}
async function loadLocations() {
try {
const response = await locationsApi.list({ per_page: 100 })
locations.value = response.data.data || []
} catch (err) {
console.error('Error loading locations:', err)
}
}
async function loadStatuses() {
try {
const response = await statusesApi.list({ per_page: 100 })
statuses.value = response.data.data || []
} catch (err) {
console.error('Error loading statuses:', err)
}
}
async function loadBusinessUnits() {
try {
const response = await businessunitsApi.list({ per_page: 100 })
businessUnits.value = response.data.data || []
} catch (err) {
console.error('Error loading business units:', err)
}
}
async function loadDevice() {
try {
const response = await networkApi.get(deviceId)
const data = response.data.data
// Populate form with existing data
form.value.assetnumber = data.assetnumber || ''
form.value.name = data.name || ''
form.value.serialnumber = data.serialnumber || ''
form.value.statusid = data.statusid || ''
form.value.locationid = data.locationid || ''
form.value.businessunitid = data.businessunitid || ''
form.value.mapleft = data.mapleft
form.value.maptop = data.maptop
form.value.notes = data.notes || ''
// Network device specific
if (data.network_device) {
form.value.hostname = data.network_device.hostname || ''
form.value.networkdevicetypeid = data.network_device.networkdevicetypeid || ''
form.value.vendorid = data.network_device.vendorid || ''
form.value.firmwareversion = data.network_device.firmwareversion || ''
form.value.portcount = data.network_device.portcount
form.value.rackunit = data.network_device.rackunit || ''
form.value.ispoe = data.network_device.ispoe || false
form.value.ismanaged = data.network_device.ismanaged || false
}
} catch (err) {
console.error('Error loading device:', err)
error.value = 'Failed to load device'
}
}
async function submitForm() {
saving.value = true
error.value = ''
try {
const payload = {
assetnumber: form.value.assetnumber,
name: form.value.name || null,
serialnumber: form.value.serialnumber || null,
statusid: form.value.statusid || null,
locationid: form.value.locationid || null,
businessunitid: form.value.businessunitid || null,
hostname: form.value.hostname || null,
networkdevicetypeid: form.value.networkdevicetypeid || null,
vendorid: form.value.vendorid || null,
firmwareversion: form.value.firmwareversion || null,
portcount: form.value.portcount || null,
rackunit: form.value.rackunit || null,
ispoe: form.value.ispoe,
ismanaged: form.value.ismanaged,
mapleft: form.value.mapleft,
maptop: form.value.maptop,
notes: form.value.notes || null
}
if (isEdit.value) {
await networkApi.update(deviceId, payload)
router.push(`/network/${deviceId}`)
} else {
const response = await networkApi.create(payload)
const newId = response.data.data?.network_device?.networkdeviceid
router.push(newId ? `/network/${newId}` : '/network')
}
} catch (err) {
console.error('Error saving device:', err)
error.value = err.response?.data?.message || 'Failed to save device'
} finally {
saving.value = false
}
}
function cancel() {
if (isEdit.value) {
router.push(`/network/${deviceId}`)
} else {
router.push('/network')
}
}
</script>
<style scoped>
.form-card {
max-width: 800px;
}
fieldset {
border: 1px solid var(--border);
border-radius: 8px;
padding: 1.5rem;
margin-bottom: 1.5rem;
}
legend {
font-weight: 600;
padding: 0 0.5rem;
color: var(--text);
}
.form-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1rem;
margin-bottom: 1rem;
}
.form-row:last-child {
margin-bottom: 0;
}
.form-group {
display: flex;
flex-direction: column;
}
.form-group label {
margin-bottom: 0.375rem;
font-weight: 500;
color: var(--text);
}
.form-group small {
margin-top: 0.25rem;
color: var(--text-light);
font-size: 0.8rem;
}
.checkboxes {
margin-top: 1rem;
}
.checkbox-group label {
display: flex;
align-items: center;
gap: 0.5rem;
cursor: pointer;
}
.checkbox-group input[type="checkbox"] {
width: 1.125rem;
height: 1.125rem;
}
.checkbox-group span {
font-weight: 500;
}
.form-actions {
display: flex;
gap: 1rem;
justify-content: flex-end;
margin-top: 1.5rem;
padding-top: 1.5rem;
border-top: 1px solid var(--border);
}
.error-message {
margin-top: 1rem;
padding: 0.75rem 1rem;
background: var(--danger);
color: white;
border-radius: 6px;
}
@media (max-width: 600px) {
.form-row {
grid-template-columns: 1fr;
}
}
</style>

View File

@@ -0,0 +1,360 @@
<template>
<div>
<div class="page-header">
<h2>Network Devices</h2>
<router-link to="/network/new" class="btn btn-primary">Add Device</router-link>
</div>
<!-- Type Tabs -->
<div class="type-tabs">
<button
:class="{ active: selectedType === null }"
@click="selectType(null)"
>
All ({{ totalCount }})
</button>
<button
v-for="t in deviceTypes"
:key="t.networkdevicetypeid"
:class="{ active: selectedType === t.networkdevicetypeid }"
@click="selectType(t.networkdevicetypeid)"
>
{{ t.networkdevicetype }} ({{ t.count || 0 }})
</button>
</div>
<!-- Filters -->
<div class="filters">
<input
v-model="search"
type="text"
class="form-control"
placeholder="Search by hostname, asset #, serial..."
@input="debouncedSearch"
/>
<select v-model="vendorFilter" class="form-control" @change="loadDevices">
<option value="">All Vendors</option>
<option v-for="v in vendors" :key="v.vendorid" :value="v.vendorid">
{{ v.vendor }}
</option>
</select>
<select v-model="locationFilter" class="form-control" @change="loadDevices">
<option value="">All Locations</option>
<option v-for="loc in locations" :key="loc.locationid" :value="loc.locationid">
{{ loc.location }}
</option>
</select>
</div>
<div class="card">
<div v-if="loading" class="loading">Loading...</div>
<template v-else>
<div class="table-container">
<table>
<thead>
<tr>
<th>Hostname</th>
<th>Asset #</th>
<th>Type</th>
<th>Vendor</th>
<th>Features</th>
<th>Location</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr v-for="device in devices" :key="device.network_device?.networkdeviceid || device.assetid">
<td class="mono">{{ device.network_device?.hostname || '-' }}</td>
<td>{{ device.assetnumber }}</td>
<td>{{ device.network_device?.networkdevicetype_name || '-' }}</td>
<td>{{ device.network_device?.vendor_name || '-' }}</td>
<td class="features">
<span v-if="device.network_device?.ispoe" class="feature-tag poe">PoE</span>
<span v-if="device.network_device?.ismanaged" class="feature-tag managed">Managed</span>
<span v-if="device.network_device?.portcount" class="feature-tag ports">{{ device.network_device.portcount }} ports</span>
<span v-if="!device.network_device?.ispoe && !device.network_device?.ismanaged && !device.network_device?.portcount">-</span>
</td>
<td>{{ device.location_name || '-' }}</td>
<td>
<span class="badge" :class="getStatusClass(device.status_name)">
{{ device.status_name || 'Unknown' }}
</span>
</td>
<td class="actions">
<router-link
:to="`/network/${device.network_device?.networkdeviceid}`"
class="btn btn-secondary btn-sm"
>
View
</router-link>
</td>
</tr>
<tr v-if="devices.length === 0">
<td colspan="8" style="text-align: center; color: var(--text-light);">
No network devices found
</td>
</tr>
</tbody>
</table>
</div>
<!-- Pagination -->
<div class="pagination" v-if="totalPages > 1">
<button
:disabled="page === 1"
@click="goToPage(page - 1)"
>
Prev
</button>
<button
v-for="p in visiblePages"
:key="p"
:class="{ active: p === page }"
@click="goToPage(p)"
>
{{ p }}
</button>
<button
:disabled="page === totalPages"
@click="goToPage(page + 1)"
>
Next
</button>
</div>
</template>
</div>
</div>
</template>
<script setup>
import { ref, computed, onMounted } from 'vue'
import { networkApi, vendorsApi, locationsApi } from '../../api'
const devices = ref([])
const deviceTypes = ref([])
const vendors = ref([])
const locations = ref([])
const loading = ref(true)
const search = ref('')
const selectedType = ref(null)
const vendorFilter = ref('')
const locationFilter = ref('')
const page = ref(1)
const totalPages = ref(1)
const totalCount = ref(0)
let searchTimeout = null
const visiblePages = computed(() => {
const pages = []
const start = Math.max(1, page.value - 2)
const end = Math.min(totalPages.value, page.value + 2)
for (let i = start; i <= end; i++) {
pages.push(i)
}
return pages
})
onMounted(async () => {
await Promise.all([
loadDeviceTypes(),
loadVendors(),
loadLocations()
])
await loadDevices()
})
async function loadDeviceTypes() {
try {
const response = await networkApi.types.list({ per_page: 100 })
deviceTypes.value = response.data.data || []
// Get counts for each type
await updateTypeCounts()
} catch (error) {
console.error('Error loading device types:', error)
}
}
async function updateTypeCounts() {
// Get summary for type counts
try {
const response = await networkApi.dashboardSummary()
const byType = response.data.data?.by_type || []
totalCount.value = response.data.data?.total || 0
// Map counts to types
deviceTypes.value = deviceTypes.value.map(t => {
const found = byType.find(bt => bt.type === t.networkdevicetype)
return { ...t, count: found?.count || 0 }
})
} catch (error) {
console.error('Error loading type counts:', error)
}
}
async function loadVendors() {
try {
const response = await vendorsApi.list({ per_page: 100 })
vendors.value = response.data.data || []
} catch (error) {
console.error('Error loading vendors:', error)
}
}
async function loadLocations() {
try {
const response = await locationsApi.list({ per_page: 100 })
locations.value = response.data.data || []
} catch (error) {
console.error('Error loading locations:', error)
}
}
async function loadDevices() {
loading.value = true
try {
const params = {
page: page.value,
per_page: 25
}
if (search.value) params.search = search.value
if (selectedType.value) params.type_id = selectedType.value
if (vendorFilter.value) params.vendor_id = vendorFilter.value
if (locationFilter.value) params.location_id = locationFilter.value
const response = await networkApi.list(params)
devices.value = response.data.data || []
totalPages.value = response.data.meta?.pagination?.total_pages || 1
} catch (error) {
console.error('Error loading network devices:', error)
} finally {
loading.value = false
}
}
function selectType(typeId) {
selectedType.value = typeId
page.value = 1
loadDevices()
}
function debouncedSearch() {
clearTimeout(searchTimeout)
searchTimeout = setTimeout(() => {
page.value = 1
loadDevices()
}, 300)
}
function goToPage(p) {
if (p >= 1 && p <= totalPages.value) {
page.value = p
loadDevices()
}
}
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 === 'maintenance') return 'badge-warning'
if (s === 'retired' || s === 'decommissioned') return 'badge-danger'
return 'badge-info'
}
</script>
<style scoped>
.type-tabs {
display: flex;
gap: 0.5rem;
margin-bottom: 1rem;
flex-wrap: wrap;
}
.type-tabs button {
padding: 0.5rem 1rem;
border: 1px solid var(--border);
background: var(--bg-card);
color: var(--text);
border-radius: 6px;
cursor: pointer;
transition: all 0.2s;
}
.type-tabs button:hover {
background: var(--bg);
border-color: var(--primary);
}
.type-tabs button.active {
background: var(--primary);
color: white;
border-color: var(--primary);
}
.filters {
display: flex;
gap: 0.75rem;
margin-bottom: 1rem;
flex-wrap: wrap;
}
.filters .form-control {
flex: 1;
min-width: 150px;
}
.filters select.form-control {
flex: 0 0 auto;
width: auto;
min-width: 150px;
}
.mono {
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}
.features {
display: flex;
gap: 0.375rem;
flex-wrap: wrap;
}
.feature-tag {
display: inline-block;
padding: 0.2rem 0.5rem;
font-size: 0.75rem;
border-radius: 4px;
background: var(--bg);
color: var(--text-light);
}
.feature-tag.poe {
background: #d4edda;
color: #155724;
}
.feature-tag.managed {
background: #e3f2fd;
color: #1565c0;
}
.feature-tag.ports {
background: var(--bg);
color: var(--text-light);
}
@media (prefers-color-scheme: dark) {
.feature-tag.poe {
background: #1e3a29;
color: #4ade80;
}
.feature-tag.managed {
background: #1e3a5f;
color: #60a5fa;
}
}
</style>