Files
bookhoard/templates/devices.templ
T
john-okeefe a075a5061f feat(ui): refresh auth, entry, admin, and secondary pages
Apply the new design-system primitives across the remaining pages so the
whole app shares one visual language:

- Auth/entry: redesigned index, login, register (centered card layout,
  SVG icons, semantic tokens)
- Admin: sidebar nav with icons, cohesive admin dashboard/users/library/
  processing-issues/settings (tables use border-line + hover states;
  scan/websocket attributes preserved)
- Secondary: analytics (stat cards), devices, progress, conflicts, queue,
  profile + form/modal all migrated to .card/.btn/.input primitives and
  SVG action icons
- Docs + API explorer + setup wizard + collection/rules/modals +
  unlinked books + book-detail modals: consistent chrome, modal scrims
  use --surface-overlay, close buttons use icon-btn
- reader.templ and error.templ intentionally left unchanged
2026-08-05 16:01:22 -04:00

486 lines
19 KiB
Templ

package templates
import "bookhoard/internal/handlers"
templ Devices(user User, devices []handlers.DeviceInfo, pendingRegistrations []PendingRegistrationData, errorMessage string, baseURL string) {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Device Management - Bookhoard</title>
<script src="/static/htmx.min.js"></script>
<link href="/static/style.css" rel="stylesheet"/>
</head>
<body class="theme-{ user.Theme }" x-data="devices" x-init="setupEventDelegation()">
@Header(user, "/devices")
<div class="w-full px-4 sm:px-6 lg:px-8 py-8">
<!-- Header Section -->
<div class="mb-8">
<div class="flex justify-between items-center">
<div>
<h1 class="text-2xl font-bold tracking-tight text-content">Device Management</h1>
<p class="text-content-muted">Manage your reading devices and sync settings</p>
</div>
<button @click="showAddDeviceModal()" class="btn btn-primary">
@Icon("plus", "h-4 w-4")
Add New Device
</button>
</div>
</div>
<!-- Devices Grid -->
<div id="devices-container" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<!-- Empty state -->
if len(devices) == 0 {
<div id="empty-state" class="text-center py-16 col-span-full text-content-muted">
<div class="mx-auto mb-4 flex h-14 w-14 items-center justify-center rounded-full bg-brand/15 text-brand">
@Icon("device", "h-7 w-7")
</div>
<h3 class="text-xl font-semibold mb-2 text-content">No Devices Yet</h3>
<p class="mb-4">Add your reading devices to enable cross-device sync</p>
<button @click="showAddDeviceModal()" class="btn btn-primary">
Add Your First Device
</button>
</div>
}
<!-- Devices Grid -->
if len(devices) > 0 {
<div id="devices-grid" class="grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
for _, device := range devices {
<div class="card p-6">
<div class="flex items-start justify-between mb-4">
<div class="text-4xl">
if device.DeviceType == "koreader" {
📖
} else if device.DeviceType == "kobo" {
📚
} else if device.DeviceType == "web" {
🌐
} else {
📱
}
</div>
<div class="flex space-x-2">
<button @click={ "showShelfMappings('" + device.ID.String() + "')" } class="icon-btn" aria-label="Shelf mappings">
@Icon("library", "h-4 w-4")
</button>
<button @click={ "showDeviceSettings('" + device.ID.String() + "')" } class="icon-btn" aria-label="Device settings">
@Icon("settings", "h-4 w-4")
</button>
</div>
</div>
<h3 class="text-lg font-semibold mb-1 text-content">{ device.DeviceName }</h3>
<p class="text-sm mb-4 text-content-muted">{ device.DeviceType }</p>
<div class="space-y-2 text-sm mb-4">
<div class="flex justify-between">
<span class="text-content-muted">Sync Status</span>
if device.SyncEnabled {
<span class="inline-flex items-center gap-1 text-brand">
@Icon("check", "h-3.5 w-3.5")
Enabled
</span>
} else {
<span class="inline-flex items-center gap-1 text-content-muted">
@Icon("close", "h-3.5 w-3.5")
Disabled
</span>
}
</div>
<div class="flex justify-between">
<span class="text-content-muted">Last Sync</span>
if device.LastSync != nil {
<span class="text-content">{ FormatInTimezone(*device.LastSync, user.Timezone) }</span>
} else {
<span class="text-content">Never</span>
}
</div>
<div class="flex justify-between">
<span class="text-content-muted">Last Seen</span>
if device.LastSeen != nil {
<span class="text-content">{ FormatInTimezone(*device.LastSeen, user.Timezone) }</span>
} else {
<span class="text-content">Never</span>
}
</div>
</div>
<!-- NEW: Sync URL & Token Management -->
<div class="border-t border-line pt-4">
<p class="text-xs font-semibold mb-2 text-content-muted">DEVICE SYNC CONFIGURATION</p>
if device.DeviceType == "kobo" {
<!-- Kobo: Copy Full Sync URL -->
<div class="mb-3">
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wide text-content-muted">Kobo Sync URL</label>
<div class="flex space-x-2">
<input
type="text"
id="sync-url-{ device.ID }"
readonly
value={ baseURL + "/api/sync/kobo/" + device.AuthToken }
class="input flex-1 text-xs"
/>
<button
@click="copyToClipboard(document.getElementById('sync-url-{ device.ID }').value, 'Kobo sync URL')"
class="btn btn-primary text-xs"
>
@Icon("copy", "h-3.5 w-3.5")
Copy
</button>
</div>
<p class="text-xs mt-1 text-content-muted">Paste this URL into Kobo's <code class="px-1 py-0.5 rounded bg-surface">api_endpoint</code> setting</p>
</div>
}
if device.DeviceType == "koreader" {
<!-- KOReader: Copy Auth Token -->
<div class="mb-3">
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wide text-content-muted">Auth Token (for plugin)</label>
<div class="flex space-x-2">
<input
type="text"
id="auth-token-{ device.ID }"
readonly
value={ device.AuthToken }
class="input flex-1 text-xs font-mono"
/>
<button
@click="copyToClipboard(document.getElementById('auth-token-{ device.ID }').value, 'Auth token')"
class="btn btn-primary text-xs"
>
@Icon("copy", "h-3.5 w-3.5")
Copy
</button>
</div>
<p class="text-xs mt-1 text-content-muted">Enter this token in the KOReader plugin settings</p>
</div>
}
<!-- Regenerate Token Button -->
<button
hx-put={ "/api/devices/" + device.ID.String() + "/regenerate-token" }
hx-confirm="⚠️ Old token will immediately stop working. Regenerate anyway?"
class="btn btn-secondary w-full text-xs"
>
@Icon("refresh", "h-3.5 w-3.5")
Regenerate Token
</button>
<p class="text-xs mt-1 inline-flex items-center gap-1 text-content-muted">
@Icon("alert", "h-3 w-3")
Old token will immediately stop working
</p>
</div>
</div>
}
</div>
}
</div>
<!-- Pending Registrations -->
if len(pendingRegistrations) > 0 {
<div id="pending-section" class="mt-12">
<h2 class="text-2xl font-bold tracking-tight mb-4 text-content">Pending Device Registrations</h2>
<div class="space-y-4">
for _, reg := range pendingRegistrations {
<div class="card p-4 flex items-center justify-between">
<div>
<h3 class="font-semibold text-content">{ reg.DeviceName }</h3>
<p class="text-sm text-content-muted">
{ reg.DeviceType } - Expires in { reg.ExpiresAt }
</p>
</div>
<div class="flex space-x-2">
<button @click={ "approveDevice('" + reg.RegistrationID + "')" } class="btn btn-primary text-sm">
Approve
</button>
<button @click={ "rejectDevice('" + reg.RegistrationID + "')" } class="btn btn-danger text-sm">
Reject
</button>
</div>
</div>
}
</div>
</div>
}
<!-- Sync Queue Section -->
<div id="sync-queue-section" class="mt-12 hidden">
<div class="flex justify-between items-center mb-4">
<h2 class="text-2xl font-bold tracking-tight text-content">Sync Queue</h2>
<button @click="clearSyncQueue()" class="btn btn-secondary">
Clear Queue
</button>
</div>
<div id="sync-queue" class="space-y-3"></div>
</div>
</div>
<!-- Add Device Modal -->
<div id="add-device-modal" class="hidden fixed inset-0 z-50 flex items-center justify-center" style="background-color: var(--surface-overlay);">
<div class="card p-6 w-full max-w-md mx-4">
<div class="flex justify-between items-center mb-6">
<h2 class="text-xl font-bold text-content">Add New Device</h2>
<button @click="hideAddDeviceModal()" class="icon-btn" aria-label="Close">
@Icon("close", "h-5 w-5")
</button>
</div>
<form id="add-device-form" @submit="handleAddDevice($event)">
<div class="mb-4">
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wide text-content-muted">Device Name</label>
<input
type="text"
id="device-name"
required
class="input"
placeholder="My Kindle Paperwhite"
/>
</div>
<div class="mb-4">
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wide text-content-muted">Device Type</label>
<select
id="device-type"
required
class="input"
>
<option value="">Select device type...</option>
<option value="koreader">KOReader (Kindle, Kobo, PocketBook)</option>
<option value="kobo">Kobo E-Reader</option>
<option value="web">Web Browser</option>
<option value="mobile">Mobile App</option>
</select>
</div>
<div class="mb-6">
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wide text-content-muted">Device Identifier</label>
<input
type="text"
id="device-identifier"
required
class="input"
placeholder="Hardware ID or Serial Number"
/>
<p class="text-xs mt-1 text-content-muted">Enter your device's unique identifier</p>
</div>
<div class="flex justify-end space-x-3">
<button type="button" @click="hideAddDeviceModal()" class="btn btn-secondary">
Cancel
</button>
<button type="submit" class="btn btn-primary">
Register Device
</button>
</div>
</form>
</div>
</div>
<!-- Device Settings Modal -->
<div id="device-settings-modal" class="hidden fixed inset-0 z-50 flex items-center justify-center" style="background-color: var(--surface-overlay);">
<div class="card p-6 w-full max-w-md mx-4">
<div class="flex justify-between items-center mb-6">
<h2 class="text-xl font-bold text-content">Device Settings</h2>
<button @click="hideDeviceSettingsModal()" class="icon-btn" aria-label="Close">
@Icon("close", "h-5 w-5")
</button>
</div>
<form id="device-settings-form" @submit="handleSaveDeviceSettings($event)">
<input type="hidden" id="settings-device-id"/>
<input type="hidden" id="settings-device-type"/>
<div class="mb-4">
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wide text-content-muted">Device Name</label>
<input
type="text"
id="settings-device-name"
required
class="input"
/>
</div>
<div class="mb-4">
<label class="flex items-center space-x-3 cursor-pointer">
<input
type="checkbox"
id="settings-sync-enabled"
checked
class="w-5 h-5 rounded"
/>
<span class="text-content">Enable Sync</span>
</label>
<p class="text-xs mt-1 ml-8 text-content-muted">Allow this device to sync reading progress</p>
</div>
<div class="mb-4">
<label class="flex items-center space-x-3 cursor-pointer">
<input
type="checkbox"
id="settings-auto-sync"
checked
class="w-5 h-5 rounded"
/>
<span class="text-content">Auto Sync</span>
</label>
<p class="text-xs mt-1 ml-8 text-content-muted">Automatically sync changes</p>
</div>
<div class="mb-6">
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wide text-content-muted">Sync Frequency</label>
<select
id="settings-sync-frequency"
class="input"
>
<option value="1">Every 1 minute</option>
<option value="5" selected>Every 5 minutes</option>
<option value="15">Every 15 minutes</option>
<option value="30">Every 30 minutes</option>
<option value="60">Every hour</option>
</select>
</div>
<div class="border-t border-line pt-6 mb-6">
<h3 class="text-lg font-semibold mb-4 text-content">Collection View Settings</h3>
<p class="text-sm mb-4 text-content-muted">Configure how collections are displayed on this device</p>
<div class="mb-4">
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wide text-content-muted">Default View Mode</label>
<select
id="settings-view-mode"
class="input"
>
<option value="grid">Grid View</option>
<option value="list">List View</option>
<option value="compact">Compact View</option>
</select>
</div>
<div class="mb-4">
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wide text-content-muted">Sort Collections By</label>
<select
id="settings-sort-order"
class="input"
>
<option value="name">Collection Name</option>
<option value="created">Date Created</option>
<option value="book_count">Book Count</option>
<option value="recent">Recently Added</option>
</select>
</div>
<div class="mb-4">
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wide text-content-muted">Items Per Page</label>
<select
id="settings-items-per-page"
class="input"
>
<option value="12">12 items</option>
<option value="24" selected>24 items</option>
<option value="48">48 items</option>
<option value="96">96 items</option>
</select>
</div>
<div class="mb-4">
<label class="flex items-center space-x-3 cursor-pointer">
<input
type="checkbox"
id="settings-show-covers"
checked
class="w-5 h-5 rounded"
/>
<span class="text-content">Show Cover Images</span>
</label>
<p class="text-xs mt-1 ml-8 text-content-muted">Display book covers in collection views</p>
</div>
<div class="mb-4">
<label class="flex items-center space-x-3 cursor-pointer">
<input
type="checkbox"
id="settings-show-progress"
class="w-5 h-5 rounded"
/>
<span class="text-content">Show Reading Progress</span>
</label>
<p class="text-xs mt-1 ml-8 text-content-muted">Display progress indicators for books</p>
</div>
</div>
<div class="flex justify-end space-x-3">
<button type="button" @click="hideDeviceSettingsModal()" class="btn btn-secondary">
Cancel
</button>
<button type="button" @click="handleRevokeDevice()" class="btn btn-danger">
Revoke Device
</button>
<button type="submit" class="btn btn-primary">
Save Settings
</button>
</div>
</form>
</div>
</div>
<!-- Device Shelf Mappings Modal -->
<div id="shelf-mappings-modal" class="hidden fixed inset-0 z-50 flex items-center justify-center" style="background-color: var(--surface-overlay);">
<div class="card p-6 w-full max-w-2xl mx-4 max-h-[90vh] overflow-y-auto">
<div class="flex justify-between items-center mb-6">
<h2 class="text-xl font-bold text-content">Collection to Shelf Mappings</h2>
<button @click="hideShelfMappingsModal()" class="icon-btn" aria-label="Close">
@Icon("close", "h-5 w-5")
</button>
</div>
<input type="hidden" id="mappings-device-id"/>
<div id="shelf-mappings-container" class="space-y-4 mb-6">
<p class="text-content-muted">Loading mappings...</p>
</div>
<div class="flex justify-end space-x-3">
<button type="button" @click="hideShelfMappingsModal()" class="btn btn-secondary">
Close
</button>
<button type="button" @click="showAddMappingModal()" class="btn btn-primary">
@Icon("plus", "h-4 w-4")
Add Mapping
</button>
</div>
</div>
</div>
<!-- Add/Edit Shelf Mapping Modal -->
<div id="add-mapping-modal" class="hidden fixed inset-0 z-50 flex items-center justify-center" style="background-color: var(--surface-overlay);">
<div class="card p-6 w-full max-w-md mx-4">
<div class="flex justify-between items-center mb-6">
<h2 class="text-xl font-bold text-content">Add Collection Mapping</h2>
<button @click="hideAddMappingModal()" class="icon-btn" aria-label="Close">
@Icon("close", "h-5 w-5")
</button>
</div>
<form id="mapping-form" @submit="handleSaveMapping($event)">
<input type="hidden" id="mapping-device-id"/>
<input type="hidden" id="mapping-id"/>
<div class="mb-4">
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wide text-content-muted">Collection</label>
<select
id="mapping-collection"
required
class="input"
>
<option value="">Select collection...</option>
</select>
</div>
<div class="mb-4">
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wide text-content-muted">Device Shelf Name</label>
<input
type="text"
id="mapping-shelf-name"
required
class="input"
placeholder="e.g., Sci-Fi"
/>
<p class="text-xs mt-1 text-content-muted">Name of the shelf on this device</p>
</div>
<div class="mb-6">
<label class="mb-1.5 block text-xs font-semibold uppercase tracking-wide text-content-muted">Sync Direction</label>
<select
id="mapping-sync-direction"
required
class="input"
>
<option value="bidirectional">Bidirectional (sync both ways)</option>
<option value="book_to_device">Bookhoard Device</option>
<option value="device_to_book">Device Bookhoard</option>
<option value="none">No sync</option>
</select>
</div>
<div class="flex justify-end space-x-3">
<button type="button" @click="hideAddMappingModal()" class="btn btn-secondary">
Cancel
</button>
<button type="submit" class="btn btn-primary">
Save Mapping
</button>
</div>
</form>
</div>
</div>
@ErrorToast(errorMessage)
</body>
</html>
}