Appearance
Device Management Documentation
File: src/pages/private/admin/devices/index.svelte
Overview
This component provides a comprehensive interface for managing Headset devices within a tenant environment. It supports viewing, adding, editing, and deleting devices, with additional functionality for bulk operations and device status monitoring.
Module Script (API Operations)
Interfaces
ts
export interface ITenantDevice {
id: number;
deviceId: string;
name: string;
deviceType: string;
tenant: {
id: number;
name: string;
};
notes: string;
}
interface QueryResult {
registeredDevices: {
nodes: ITenantDevice[];
};
myDevices: {
data: any;
};
}
interface ApiResponse {
success: boolean;
message: string;
data: ITenantDevice[];
online?: any[];
}Core Functions
ts
// Fetch all tenant devices with online status
export async function getTenantDeviceIds(): Promise<ApiResponse> {
// GraphQL query implementation
}
// Generate QR code for new device registration
export async function generateDeviceQrCode(name: string, notes: string) {
// Mutation implementation
}Component Script
State Management
ts
let busy = true; // Loading state for initial data fetch
let devicesData: ITenantDevice[] = []; // List of devices
let onlineDevices = {}; // Map of online device IDs
let showAddModal = false; // Controls add device modal visibility
let qrCodeUrl = ""; // Generated QR code URL
let regRef = ""; // Registration reference code
let loading = false; // Loading state for operations
let setEdit = false; // Edit mode flag
let showDeleteModal = false; // Delete confirmation modal
let showBulkAddModal = false; // Bulk add modal
let activeDeviceData: ITenantDevice | undefined; // Currently active deviceCore Methods
ts
// Initialize edit mode for a device
function initEdit(role: ITenantDevice) { ... }
// Initialize delete confirmation
function initDelete(role: ITenantDevice) { ... }
// Handle device addition/editing
async function handleDeviceAddition(event: CustomEvent) { ... }
// Delete a device
async function doDelete() { ... }
// Refresh device list
async function refresh() { ... }
// Handle successful device registration
async function handleDeviceAdded(event: CustomEvent) { ... }UI Structure
Main Layout
svelte
<div class="min-w-full px-4 sm:px-6 lg:px-8">
<!-- Header with action buttons -->
<div class="mb-2 sm:flex sm:items-center">
<!-- Title and action buttons -->
</div>
<!-- Device table -->
<div class="pt-4 flex flex-col sm:border-t sm:border-gray-200">
{#if busy}
<!-- Loading spinner -->
{:else if !devicesData.length}
<!-- Empty state -->
{:else}
<!-- Device table -->
<table class="min-w-full divide-y divide-gray-300">
<!-- Table headers and rows -->
</table>
{/if}
</div>
</div>Modal Components
Add/Edit Device Modal:
svelte<NewModal size={setEdit ? "md" : "lg"} ...> <Form ... /> </NewModal>Bulk Add Modal:
svelte<NewModal size="lg" ...> <BulkDevice ... /> </NewModal>Delete Confirmation Modal:
svelte<Alert ...> <p>Are you sure you want to delete this device?</p> </Alert>
Key Features
Device Management:
- View all registered devices with online/offline status
- Add new devices (single or bulk)
- Edit existing device details
- Delete devices
Device Registration:
- QR code generation for new devices
- Registration reference tracking
- Automatic refresh after successful registration
User Experience:
- Loading states for all operations
- Empty state handling
- Responsive table layout
- Confirmation dialogs for destructive actions
Security:
- Admin-only access (redirects non-admins)
- Protected operations with error handling
Usage Patterns
Initialization
ts
onMount(async () => {
if (!$userInfo?.isAdmin) {
$goto("/private/dashboard");
return;
}
await refresh();
});Adding a Device
- Click "Add Single Device" or "Add Bulk Device"
- Fill in device details
- Submit form to generate QR code
- Device appears in list after registration
Editing a Device
- Click edit icon on device row
- Modify details in modal
- Submit to save changes
Deleting a Device
- Click delete icon on device row
- Confirm deletion in modal
- Device is removed from list
Dependencies
svelte-loading-spinnersfor loading animation@steeze-uiicons- Custom form components (
Form,BulkDevice) - Custom modal components (
NewModal,Alert) - GraphQL query utilities
- Keycloak integration for auth
Error Handling
- Catches and displays API errors
- Shows error states for failed operations
- Provides retry mechanisms
- Validates inputs before submission
Accessibility Features
- Semantic HTML structure
- Clear visual hierarchy
- Loading states for async operations
- Keyboard-navigable interface
- ARIA-compliant modals