|
@@ -25,6 +25,10 @@
|
|
|
<input type="checkbox" v-model="onlineOnly" @change="loadDevices" />
|
|
<input type="checkbox" v-model="onlineOnly" @change="loadDevices" />
|
|
|
<span>{{ $t('devices.onlineOnly') }}</span>
|
|
<span>{{ $t('devices.onlineOnly') }}</span>
|
|
|
</label>
|
|
</label>
|
|
|
|
|
+
|
|
|
|
|
+ <button @click="showDefaultConfigModal" class="btn-primary btn-edit-default">
|
|
|
|
|
+ Edit Default Config
|
|
|
|
|
+ </button>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<div v-if="loading" class="loading">{{ $t('common.loading') }}</div>
|
|
<div v-if="loading" class="loading">{{ $t('common.loading') }}</div>
|
|
@@ -42,6 +46,8 @@
|
|
|
{{ $t('devices.macAddress') }}
|
|
{{ $t('devices.macAddress') }}
|
|
|
<span v-if="sortColumn === 'mac_address'">{{ sortDirection === 'asc' ? '↑' : '↓' }}</span>
|
|
<span v-if="sortColumn === 'mac_address'">{{ sortDirection === 'asc' ? '↑' : '↓' }}</span>
|
|
|
</th>
|
|
</th>
|
|
|
|
|
+ <th>BLE Enabled</th>
|
|
|
|
|
+ <th>WiFi Enabled</th>
|
|
|
<th @click="sortBy('status')">
|
|
<th @click="sortBy('status')">
|
|
|
{{ $t('common.status') }}
|
|
{{ $t('common.status') }}
|
|
|
<span v-if="sortColumn === 'status'">{{ sortDirection === 'asc' ? '↑' : '↓' }}</span>
|
|
<span v-if="sortColumn === 'status'">{{ sortDirection === 'asc' ? '↑' : '↓' }}</span>
|
|
@@ -57,8 +63,28 @@
|
|
|
<tr v-for="device in sortedDevices" :key="device.id">
|
|
<tr v-for="device in sortedDevices" :key="device.id">
|
|
|
<td><strong>#{{ device.simple_id }}</strong></td>
|
|
<td><strong>#{{ device.simple_id }}</strong></td>
|
|
|
<td><code>{{ device.mac_address }}</code></td>
|
|
<td><code>{{ device.mac_address }}</code></td>
|
|
|
|
|
+ <td class="text-center">
|
|
|
|
|
+ <label class="toggle-switch-inline">
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="checkbox"
|
|
|
|
|
+ :checked="device.config?.ble?.enabled ?? false"
|
|
|
|
|
+ @click="toggleBLE(device, $event)"
|
|
|
|
|
+ />
|
|
|
|
|
+ <span class="toggle-slider"></span>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </td>
|
|
|
|
|
+ <td class="text-center">
|
|
|
|
|
+ <label class="toggle-switch-inline">
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="checkbox"
|
|
|
|
|
+ :checked="device.config?.wifi?.monitor_enabled ?? false"
|
|
|
|
|
+ @click="toggleWiFi(device, $event)"
|
|
|
|
|
+ />
|
|
|
|
|
+ <span class="toggle-slider"></span>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </td>
|
|
|
<td><span class="badge" :class="`status-${device.status}`">{{ $t(`devices.${device.status}`) }}</span></td>
|
|
<td><span class="badge" :class="`status-${device.status}`">{{ $t(`devices.${device.status}`) }}</span></td>
|
|
|
- <td>{{ formatDate(device.last_seen_at) }}</td>
|
|
|
|
|
|
|
+ <td>{{ formatRelativeTime(device.last_seen_at) }}</td>
|
|
|
<td>
|
|
<td>
|
|
|
<button @click="showEditModal(device)" class="btn-icon" title="Edit">✏️</button>
|
|
<button @click="showEditModal(device)" class="btn-icon" title="Edit">✏️</button>
|
|
|
<button
|
|
<button
|
|
@@ -183,6 +209,11 @@
|
|
|
<!-- Other Settings -->
|
|
<!-- Other Settings -->
|
|
|
<div class="config-section">
|
|
<div class="config-section">
|
|
|
<h3>Other</h3>
|
|
<h3>Other</h3>
|
|
|
|
|
+ <div class="form-group">
|
|
|
|
|
+ <label>Config Polling Timeout (seconds)</label>
|
|
|
|
|
+ <input v-model.number="config.cfg_polling_timeout" type="number" min="5" max="300" step="5" />
|
|
|
|
|
+ <div class="form-hint">How often device fetches config from server (min: 5s, recommended: 30-300s)</div>
|
|
|
|
|
+ </div>
|
|
|
<div class="toggle-row">
|
|
<div class="toggle-row">
|
|
|
<span>{{ $t('devices.config.forceCloud') }}</span>
|
|
<span>{{ $t('devices.config.forceCloud') }}</span>
|
|
|
<label class="toggle-switch">
|
|
<label class="toggle-switch">
|
|
@@ -207,6 +238,10 @@
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
<div class="modal-footer">
|
|
<div class="modal-footer">
|
|
|
|
|
+ <button type="button" @click="deleteDevice" class="btn-danger btn-delete" :disabled="saving">
|
|
|
|
|
+ Delete Device
|
|
|
|
|
+ </button>
|
|
|
|
|
+ <div style="flex: 1"></div>
|
|
|
<button type="button" @click="closeModal" class="btn-secondary">{{ $t('common.cancel') }}</button>
|
|
<button type="button" @click="closeModal" class="btn-secondary">{{ $t('common.cancel') }}</button>
|
|
|
<button type="submit" :disabled="saving" class="btn-primary">
|
|
<button type="submit" :disabled="saving" class="btn-primary">
|
|
|
{{ saving ? $t('common.loading') : $t('common.save') }}
|
|
{{ saving ? $t('common.loading') : $t('common.save') }}
|
|
@@ -216,6 +251,184 @@
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
+ <!-- Edit Default Config Modal -->
|
|
|
|
|
+ <div v-if="defaultConfigModalVisible" class="modal-overlay" @click="closeDefaultConfigModal">
|
|
|
|
|
+ <div class="modal modal-wide" @click.stop>
|
|
|
|
|
+ <div class="modal-header">
|
|
|
|
|
+ <h2>Edit Default Device Configuration</h2>
|
|
|
|
|
+ <button @click="closeDefaultConfigModal" class="btn-close">×</button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- Tabs -->
|
|
|
|
|
+ <div class="modal-tabs">
|
|
|
|
|
+ <button
|
|
|
|
|
+ @click="defaultConfigTab = 'interactive'"
|
|
|
|
|
+ :class="['tab-button', { active: defaultConfigTab === 'interactive' }]"
|
|
|
|
|
+ >
|
|
|
|
|
+ Interactive
|
|
|
|
|
+ </button>
|
|
|
|
|
+ <button
|
|
|
|
|
+ @click="switchToJsonTab"
|
|
|
|
|
+ :class="['tab-button', { active: defaultConfigTab === 'json' }]"
|
|
|
|
|
+ >
|
|
|
|
|
+ JSON
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="modal-body">
|
|
|
|
|
+ <p style="margin-bottom: 16px; color: #718096; font-size: 14px;">
|
|
|
|
|
+ This configuration will be copied to all newly registered devices.
|
|
|
|
|
+ Changes do not affect existing devices.
|
|
|
|
|
+ </p>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- Interactive Tab -->
|
|
|
|
|
+ <div v-if="defaultConfigTab === 'interactive'">
|
|
|
|
|
+ <!-- WiFi Scanner Section -->
|
|
|
|
|
+ <div class="config-section">
|
|
|
|
|
+ <h3>WiFi Scanner</h3>
|
|
|
|
|
+ <div class="toggle-row">
|
|
|
|
|
+ <span>WiFi Scanner Enabled</span>
|
|
|
|
|
+ <label class="toggle-switch">
|
|
|
|
|
+ <input type="checkbox" v-model="defaultConfig.wifi.monitor_enabled" @change="onDefaultWifiMonitorChange" />
|
|
|
|
|
+ <span class="toggle-slider"></span>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div v-if="defaultConfig.wifi.monitor_enabled" class="toggle-content">
|
|
|
|
|
+ <div class="form-group">
|
|
|
|
|
+ <label>Batch Interval (ms)</label>
|
|
|
|
|
+ <input v-model.number="defaultConfig.wifi.batch_interval_ms" type="number" min="1000" step="1000" />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="form-group">
|
|
|
|
|
+ <label>Upload Endpoint (optional)</label>
|
|
|
|
|
+ <input v-model="defaultConfig.wifi.upload_endpoint" type="text" placeholder="http://custom.example.com:8080/wifi" />
|
|
|
|
|
+ <div class="form-hint">Custom upload endpoint URL (leave empty for default)</div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- BLE Section -->
|
|
|
|
|
+ <div class="config-section">
|
|
|
|
|
+ <h3>BLE Scanner</h3>
|
|
|
|
|
+ <div class="toggle-row">
|
|
|
|
|
+ <span>BLE Scanner Enabled</span>
|
|
|
|
|
+ <label class="toggle-switch">
|
|
|
|
|
+ <input type="checkbox" v-model="defaultConfig.ble.enabled" />
|
|
|
|
|
+ <span class="toggle-slider"></span>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div v-if="defaultConfig.ble.enabled" class="toggle-content">
|
|
|
|
|
+ <div class="form-group">
|
|
|
|
|
+ <label>Batch Interval (ms)</label>
|
|
|
|
|
+ <input v-model.number="defaultConfig.ble.batch_interval_ms" type="number" min="100" step="100" />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="form-group">
|
|
|
|
|
+ <label>UUID Filter</label>
|
|
|
|
|
+ <input v-model="defaultConfig.ble.uuid_filter_hex" type="text" placeholder="f7826da64fa24e988024bc5b71e0893e" maxlength="32" />
|
|
|
|
|
+ <div class="form-hint">Filter beacons by UUID (32 hex chars, optional)</div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="form-group">
|
|
|
|
|
+ <label>Upload Endpoint (optional)</label>
|
|
|
|
|
+ <input v-model="defaultConfig.ble.upload_endpoint" type="text" placeholder="http://custom.example.com:8080/ble" />
|
|
|
|
|
+ <div class="form-hint">Custom upload endpoint URL (leave empty for default)</div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- WiFi Client Section -->
|
|
|
|
|
+ <div class="config-section">
|
|
|
|
|
+ <h3>WiFi Client</h3>
|
|
|
|
|
+ <div class="toggle-row">
|
|
|
|
|
+ <span>WiFi Client Enabled</span>
|
|
|
|
|
+ <label class="toggle-switch">
|
|
|
|
|
+ <input type="checkbox" v-model="defaultConfig.wifi.client_enabled" @change="onDefaultWifiClientChange" />
|
|
|
|
|
+ <span class="toggle-slider"></span>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div v-if="defaultConfig.wifi.client_enabled" class="toggle-content">
|
|
|
|
|
+ <div class="form-row">
|
|
|
|
|
+ <div class="form-group">
|
|
|
|
|
+ <label>WiFi SSID</label>
|
|
|
|
|
+ <input v-model="defaultConfig.wifi.ssid" type="text" />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="form-group">
|
|
|
|
|
+ <label>WiFi Password</label>
|
|
|
|
|
+ <input v-model="defaultConfig.wifi.psk" type="password" />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- NTP Section -->
|
|
|
|
|
+ <div class="config-section">
|
|
|
|
|
+ <h3>NTP Servers</h3>
|
|
|
|
|
+ <div class="form-group">
|
|
|
|
|
+ <label>NTP Servers</label>
|
|
|
|
|
+ <input v-model="defaultNtpServersText" type="text" placeholder="pool.ntp.org, time.google.com" />
|
|
|
|
|
+ <div class="form-hint">Comma-separated list of NTP server addresses</div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- Other Settings -->
|
|
|
|
|
+ <div class="config-section">
|
|
|
|
|
+ <h3>Other</h3>
|
|
|
|
|
+ <div class="form-group">
|
|
|
|
|
+ <label>Config Polling Timeout (seconds)</label>
|
|
|
|
|
+ <input v-model.number="defaultConfig.cfg_polling_timeout" type="number" min="5" max="300" step="5" />
|
|
|
|
|
+ <div class="form-hint">How often device fetches config from server (min: 5s, recommended: 30-300s)</div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="toggle-row">
|
|
|
|
|
+ <span>Force Cloud Mode</span>
|
|
|
|
|
+ <label class="toggle-switch">
|
|
|
|
|
+ <input type="checkbox" v-model="defaultConfig.force_cloud" />
|
|
|
|
|
+ <span class="toggle-slider"></span>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="toggle-row">
|
|
|
|
|
+ <span>Debug Logging</span>
|
|
|
|
|
+ <label class="toggle-switch">
|
|
|
|
|
+ <input type="checkbox" v-model="defaultConfig.debug" />
|
|
|
|
|
+ <span class="toggle-slider"></span>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="toggle-row">
|
|
|
|
|
+ <span>Dashboard Enabled</span>
|
|
|
|
|
+ <label class="toggle-switch">
|
|
|
|
|
+ <input type="checkbox" v-model="defaultConfig.dashboard.enabled" />
|
|
|
|
|
+ <span class="toggle-slider"></span>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- JSON Tab -->
|
|
|
|
|
+ <div v-if="defaultConfigTab === 'json'">
|
|
|
|
|
+ <div class="form-group">
|
|
|
|
|
+ <label>Configuration (JSON)</label>
|
|
|
|
|
+ <textarea
|
|
|
|
|
+ v-model="defaultConfigJson"
|
|
|
|
|
+ rows="25"
|
|
|
|
|
+ class="config-editor"
|
|
|
|
|
+ @input="validateJson"
|
|
|
|
|
+ ></textarea>
|
|
|
|
|
+ <div v-if="jsonError" class="form-error">{{ jsonError }}</div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="modal-footer">
|
|
|
|
|
+ <button type="button" @click="closeDefaultConfigModal" class="btn-secondary">Cancel</button>
|
|
|
|
|
+ <button
|
|
|
|
|
+ type="button"
|
|
|
|
|
+ @click="saveDefaultConfig"
|
|
|
|
|
+ :disabled="savingDefaultConfig || (defaultConfigTab === 'json' && !!jsonError)"
|
|
|
|
|
+ class="btn-primary"
|
|
|
|
|
+ >
|
|
|
|
|
+ {{ savingDefaultConfig ? 'Saving...' : 'Save Default Config' }}
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
@@ -238,11 +451,61 @@ const sortColumn = ref('simple_id')
|
|
|
const sortDirection = ref('desc')
|
|
const sortDirection = ref('desc')
|
|
|
const ntpServersText = ref('')
|
|
const ntpServersText = ref('')
|
|
|
const tunnelLoading = ref({})
|
|
const tunnelLoading = ref({})
|
|
|
|
|
+const defaultConfigModalVisible = ref(false)
|
|
|
|
|
+const defaultConfigTab = ref('interactive')
|
|
|
|
|
+const defaultConfigJson = ref('')
|
|
|
|
|
+const savingDefaultConfig = ref(false)
|
|
|
|
|
+const jsonError = ref(null)
|
|
|
|
|
+const defaultNtpServersText = ref('')
|
|
|
|
|
+const defaultConfig = ref({
|
|
|
|
|
+ force_cloud: false,
|
|
|
|
|
+ cfg_polling_timeout: 30,
|
|
|
|
|
+ ble: {
|
|
|
|
|
+ enabled: true,
|
|
|
|
|
+ batch_interval_ms: 2500,
|
|
|
|
|
+ uuid_filter_hex: '',
|
|
|
|
|
+ upload_endpoint: ''
|
|
|
|
|
+ },
|
|
|
|
|
+ wifi: {
|
|
|
|
|
+ client_enabled: false,
|
|
|
|
|
+ ssid: '',
|
|
|
|
|
+ psk: '',
|
|
|
|
|
+ monitor_enabled: true,
|
|
|
|
|
+ batch_interval_ms: 10000,
|
|
|
|
|
+ upload_endpoint: ''
|
|
|
|
|
+ },
|
|
|
|
|
+ ssh_tunnel: {
|
|
|
|
|
+ enabled: false,
|
|
|
|
|
+ server: '192.168.5.4',
|
|
|
|
|
+ port: 22,
|
|
|
|
|
+ user: 'tunnel',
|
|
|
|
|
+ remote_port: 0,
|
|
|
|
|
+ keepalive_interval: 30
|
|
|
|
|
+ },
|
|
|
|
|
+ dashboard_tunnel: {
|
|
|
|
|
+ enabled: false,
|
|
|
|
|
+ server: '192.168.5.4',
|
|
|
|
|
+ port: 22,
|
|
|
|
|
+ user: 'tunnel',
|
|
|
|
|
+ remote_port: 0,
|
|
|
|
|
+ keepalive_interval: 30
|
|
|
|
|
+ },
|
|
|
|
|
+ dashboard: {
|
|
|
|
|
+ enabled: true
|
|
|
|
|
+ },
|
|
|
|
|
+ net: {
|
|
|
|
|
+ ntp: {
|
|
|
|
|
+ servers: ['pool.ntp.org', 'time.google.com']
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ debug: false
|
|
|
|
|
+})
|
|
|
let searchDebounceTimer = null
|
|
let searchDebounceTimer = null
|
|
|
let pollingInterval = null
|
|
let pollingInterval = null
|
|
|
|
|
|
|
|
const config = ref({
|
|
const config = ref({
|
|
|
force_cloud: false,
|
|
force_cloud: false,
|
|
|
|
|
+ cfg_polling_timeout: 30,
|
|
|
ble: {
|
|
ble: {
|
|
|
enabled: true,
|
|
enabled: true,
|
|
|
batch_interval_ms: 2500,
|
|
batch_interval_ms: 2500,
|
|
@@ -349,11 +612,35 @@ function formatDate(dateStr) {
|
|
|
return date.toLocaleString()
|
|
return date.toLocaleString()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function formatRelativeTime(dateStr) {
|
|
|
|
|
+ if (!dateStr) return 'Never'
|
|
|
|
|
+
|
|
|
|
|
+ const now = new Date()
|
|
|
|
|
+ const then = new Date(dateStr)
|
|
|
|
|
+ const diffMs = now - then
|
|
|
|
|
+ const diffMinutes = Math.floor(diffMs / 60000)
|
|
|
|
|
+
|
|
|
|
|
+ if (diffMinutes < 1) {
|
|
|
|
|
+ return 'Just now'
|
|
|
|
|
+ } else if (diffMinutes < 120) {
|
|
|
|
|
+ return `${diffMinutes} min ago`
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const diffHours = Math.floor(diffMinutes / 60)
|
|
|
|
|
+ if (diffHours < 24) {
|
|
|
|
|
+ return `${diffHours} hour${diffHours > 1 ? 's' : ''} ago`
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const diffDays = Math.floor(diffHours / 24)
|
|
|
|
|
+ return `${diffDays} day${diffDays > 1 ? 's' : ''} ago`
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function showEditModal(device) {
|
|
function showEditModal(device) {
|
|
|
editingDevice.value = device
|
|
editingDevice.value = device
|
|
|
// Deep copy device config with defaults
|
|
// Deep copy device config with defaults
|
|
|
config.value = {
|
|
config.value = {
|
|
|
force_cloud: device.config?.force_cloud ?? false,
|
|
force_cloud: device.config?.force_cloud ?? false,
|
|
|
|
|
+ cfg_polling_timeout: device.config?.cfg_polling_timeout ?? 30,
|
|
|
ble: {
|
|
ble: {
|
|
|
enabled: device.config?.ble?.enabled ?? true,
|
|
enabled: device.config?.ble?.enabled ?? true,
|
|
|
batch_interval_ms: device.config?.ble?.batch_interval_ms ?? 2500,
|
|
batch_interval_ms: device.config?.ble?.batch_interval_ms ?? 2500,
|
|
@@ -423,6 +710,31 @@ async function saveDevice() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+async function deleteDevice() {
|
|
|
|
|
+ const deviceName = `#${editingDevice.value.simple_id} (${editingDevice.value.mac_address})`
|
|
|
|
|
+
|
|
|
|
|
+ const confirmed = confirm(
|
|
|
|
|
+ `Are you sure you want to DELETE device ${deviceName}?\n\n` +
|
|
|
|
|
+ `This will permanently remove the device from the system.\n` +
|
|
|
|
|
+ `The device will need to re-register to be used again.\n\n` +
|
|
|
|
|
+ `This action CANNOT be undone!`
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ if (!confirmed) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ saving.value = true
|
|
|
|
|
+ try {
|
|
|
|
|
+ await devicesApi.deleteSuperadmin(editingDevice.value.id)
|
|
|
|
|
+ await loadDevices()
|
|
|
|
|
+ closeModal()
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ alert(err.response?.data?.detail || 'Failed to delete device')
|
|
|
|
|
+ saving.value = false
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
async function openTunnel(device, tunnelType) {
|
|
async function openTunnel(device, tunnelType) {
|
|
|
const loadingKey = `${device.id}:${tunnelType}`
|
|
const loadingKey = `${device.id}:${tunnelType}`
|
|
|
tunnelLoading.value[loadingKey] = true
|
|
tunnelLoading.value[loadingKey] = true
|
|
@@ -480,6 +792,192 @@ function openDashboard(device) {
|
|
|
openTunnel(device, 'dashboard')
|
|
openTunnel(device, 'dashboard')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+async function toggleBLE(device, event) {
|
|
|
|
|
+ event.preventDefault()
|
|
|
|
|
+
|
|
|
|
|
+ const newState = !(device.config?.ble?.enabled ?? false)
|
|
|
|
|
+ const action = newState ? 'enable' : 'disable'
|
|
|
|
|
+
|
|
|
|
|
+ if (!confirm(`Are you sure you want to ${action} BLE scanner for device #${device.simple_id}?`)) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const updatedConfig = {
|
|
|
|
|
+ ...device.config,
|
|
|
|
|
+ ble: {
|
|
|
|
|
+ ...(device.config?.ble || {}),
|
|
|
|
|
+ enabled: newState
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ await devicesApi.updateSuperadmin(device.id, { config: updatedConfig })
|
|
|
|
|
+ await loadDevices()
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ alert(err.response?.data?.detail || 'Failed to update BLE scanner')
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function toggleWiFi(device, event) {
|
|
|
|
|
+ event.preventDefault()
|
|
|
|
|
+
|
|
|
|
|
+ const newState = !(device.config?.wifi?.monitor_enabled ?? false)
|
|
|
|
|
+ const action = newState ? 'enable' : 'disable'
|
|
|
|
|
+
|
|
|
|
|
+ if (!confirm(`Are you sure you want to ${action} WiFi scanner for device #${device.simple_id}?`)) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const updatedConfig = {
|
|
|
|
|
+ ...device.config,
|
|
|
|
|
+ wifi: {
|
|
|
|
|
+ ...(device.config?.wifi || {}),
|
|
|
|
|
+ monitor_enabled: newState
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ await devicesApi.updateSuperadmin(device.id, { config: updatedConfig })
|
|
|
|
|
+ await loadDevices()
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ alert(err.response?.data?.detail || 'Failed to update WiFi scanner')
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function showDefaultConfigModal() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const configData = await devicesApi.getDefaultConfig()
|
|
|
|
|
+
|
|
|
|
|
+ // Load into interactive form
|
|
|
|
|
+ defaultConfig.value = {
|
|
|
|
|
+ force_cloud: configData.force_cloud ?? false,
|
|
|
|
|
+ cfg_polling_timeout: configData.cfg_polling_timeout ?? 30,
|
|
|
|
|
+ ble: {
|
|
|
|
|
+ enabled: configData.ble?.enabled ?? true,
|
|
|
|
|
+ batch_interval_ms: configData.ble?.batch_interval_ms ?? 2500,
|
|
|
|
|
+ uuid_filter_hex: configData.ble?.uuid_filter_hex ?? '',
|
|
|
|
|
+ upload_endpoint: configData.ble?.upload_endpoint ?? ''
|
|
|
|
|
+ },
|
|
|
|
|
+ wifi: {
|
|
|
|
|
+ client_enabled: configData.wifi?.client_enabled ?? false,
|
|
|
|
|
+ ssid: configData.wifi?.ssid ?? '',
|
|
|
|
|
+ psk: configData.wifi?.psk ?? '',
|
|
|
|
|
+ monitor_enabled: configData.wifi?.monitor_enabled ?? true,
|
|
|
|
|
+ batch_interval_ms: configData.wifi?.batch_interval_ms ?? 10000,
|
|
|
|
|
+ upload_endpoint: configData.wifi?.upload_endpoint ?? ''
|
|
|
|
|
+ },
|
|
|
|
|
+ ssh_tunnel: configData.ssh_tunnel || {
|
|
|
|
|
+ enabled: false,
|
|
|
|
|
+ server: '192.168.5.4',
|
|
|
|
|
+ port: 22,
|
|
|
|
|
+ user: 'tunnel',
|
|
|
|
|
+ remote_port: 0,
|
|
|
|
|
+ keepalive_interval: 30
|
|
|
|
|
+ },
|
|
|
|
|
+ dashboard_tunnel: configData.dashboard_tunnel || {
|
|
|
|
|
+ enabled: false,
|
|
|
|
|
+ server: '192.168.5.4',
|
|
|
|
|
+ port: 22,
|
|
|
|
|
+ user: 'tunnel',
|
|
|
|
|
+ remote_port: 0,
|
|
|
|
|
+ keepalive_interval: 30
|
|
|
|
|
+ },
|
|
|
|
|
+ dashboard: {
|
|
|
|
|
+ enabled: configData.dashboard?.enabled ?? true
|
|
|
|
|
+ },
|
|
|
|
|
+ net: {
|
|
|
|
|
+ ntp: {
|
|
|
|
|
+ servers: configData.net?.ntp?.servers ?? ['pool.ntp.org', 'time.google.com']
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ debug: configData.debug ?? false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Convert NTP servers to text
|
|
|
|
|
+ defaultNtpServersText.value = defaultConfig.value.net.ntp.servers.join(', ')
|
|
|
|
|
+
|
|
|
|
|
+ // Also load into JSON
|
|
|
|
|
+ defaultConfigJson.value = JSON.stringify(configData, null, 2)
|
|
|
|
|
+
|
|
|
|
|
+ jsonError.value = null
|
|
|
|
|
+ defaultConfigTab.value = 'interactive'
|
|
|
|
|
+ defaultConfigModalVisible.value = true
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ alert(err.response?.data?.detail || 'Failed to load default config')
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function closeDefaultConfigModal() {
|
|
|
|
|
+ defaultConfigModalVisible.value = false
|
|
|
|
|
+ defaultConfigTab.value = 'interactive'
|
|
|
|
|
+ defaultConfigJson.value = ''
|
|
|
|
|
+ jsonError.value = null
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function onDefaultWifiClientChange() {
|
|
|
|
|
+ if (defaultConfig.value.wifi.client_enabled) {
|
|
|
|
|
+ defaultConfig.value.wifi.monitor_enabled = false
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function onDefaultWifiMonitorChange() {
|
|
|
|
|
+ if (defaultConfig.value.wifi.monitor_enabled) {
|
|
|
|
|
+ defaultConfig.value.wifi.client_enabled = false
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function switchToJsonTab() {
|
|
|
|
|
+ // Convert interactive form to JSON before switching
|
|
|
|
|
+ defaultConfig.value.net.ntp.servers = defaultNtpServersText.value
|
|
|
|
|
+ .split(',')
|
|
|
|
|
+ .map(s => s.trim())
|
|
|
|
|
+ .filter(s => s.length > 0)
|
|
|
|
|
+
|
|
|
|
|
+ defaultConfigJson.value = JSON.stringify(defaultConfig.value, null, 2)
|
|
|
|
|
+ defaultConfigTab.value = 'json'
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function validateJson() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ JSON.parse(defaultConfigJson.value)
|
|
|
|
|
+ jsonError.value = null
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ jsonError.value = `Invalid JSON: ${e.message}`
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+async function saveDefaultConfig() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ let configToSave
|
|
|
|
|
+
|
|
|
|
|
+ if (defaultConfigTab.value === 'interactive') {
|
|
|
|
|
+ // Parse NTP servers from text
|
|
|
|
|
+ defaultConfig.value.net.ntp.servers = defaultNtpServersText.value
|
|
|
|
|
+ .split(',')
|
|
|
|
|
+ .map(s => s.trim())
|
|
|
|
|
+ .filter(s => s.length > 0)
|
|
|
|
|
+
|
|
|
|
|
+ configToSave = defaultConfig.value
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Validate and parse JSON
|
|
|
|
|
+ configToSave = JSON.parse(defaultConfigJson.value)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ savingDefaultConfig.value = true
|
|
|
|
|
+ await devicesApi.updateDefaultConfig(configToSave)
|
|
|
|
|
+ alert('Default configuration saved successfully!')
|
|
|
|
|
+ closeDefaultConfigModal()
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ if (err instanceof SyntaxError) {
|
|
|
|
|
+ jsonError.value = `Invalid JSON: ${err.message}`
|
|
|
|
|
+ } else {
|
|
|
|
|
+ alert(err.response?.data?.detail || 'Failed to save default config')
|
|
|
|
|
+ }
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ savingDefaultConfig.value = false
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
loadDevices()
|
|
loadDevices()
|
|
|
loadOrganizations()
|
|
loadOrganizations()
|
|
@@ -511,6 +1009,7 @@ onBeforeUnmount(() => {
|
|
|
|
|
|
|
|
/* Filters Row */
|
|
/* Filters Row */
|
|
|
.filters-row { display: flex; gap: 16px; align-items: center; margin-bottom: 20px; }
|
|
.filters-row { display: flex; gap: 16px; align-items: center; margin-bottom: 20px; }
|
|
|
|
|
+.btn-edit-default { margin-left: auto; }
|
|
|
.search-box { position: relative; flex: 1; max-width: 400px; }
|
|
.search-box { position: relative; flex: 1; max-width: 400px; }
|
|
|
.search-input { width: 100%; padding: 10px 40px 10px 14px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 14px; transition: border-color 0.2s; }
|
|
.search-input { width: 100%; padding: 10px 40px 10px 14px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 14px; transition: border-color 0.2s; }
|
|
|
.search-input:focus { outline: none; border-color: #667eea; }
|
|
.search-input:focus { outline: none; border-color: #667eea; }
|
|
@@ -553,14 +1052,22 @@ code { background: #f7fafc; padding: 4px 8px; border-radius: 4px; font-family: m
|
|
|
.modal-header h2 { font-size: 24px; font-weight: 700; color: #1a202c; }
|
|
.modal-header h2 { font-size: 24px; font-weight: 700; color: #1a202c; }
|
|
|
.btn-close { width: 32px; height: 32px; border: none; background: none; font-size: 32px; color: #718096; cursor: pointer; line-height: 1; }
|
|
.btn-close { width: 32px; height: 32px; border: none; background: none; font-size: 32px; color: #718096; cursor: pointer; line-height: 1; }
|
|
|
.btn-close:hover { color: #1a202c; }
|
|
.btn-close:hover { color: #1a202c; }
|
|
|
|
|
+.modal-tabs { display: flex; border-bottom: 2px solid #e2e8f0; padding: 0 24px; }
|
|
|
|
|
+.tab-button { padding: 12px 24px; background: none; border: none; border-bottom: 3px solid transparent; color: #718096; font-weight: 500; font-size: 14px; cursor: pointer; transition: all 0.2s; margin-bottom: -2px; }
|
|
|
|
|
+.tab-button:hover { color: #4a5568; background: #f7fafc; }
|
|
|
|
|
+.tab-button.active { color: #667eea; border-bottom-color: #667eea; }
|
|
|
.modal-body { padding: 16px; }
|
|
.modal-body { padding: 16px; }
|
|
|
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; padding: 16px; border-top: 1px solid #e2e8f0; }
|
|
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; padding: 16px; border-top: 1px solid #e2e8f0; }
|
|
|
|
|
+.btn-delete { margin-right: auto; }
|
|
|
.form-group { margin-bottom: 12px; }
|
|
.form-group { margin-bottom: 12px; }
|
|
|
.form-group label { display: block; margin-bottom: 4px; font-weight: 500; color: #4a5568; font-size: 13px; }
|
|
.form-group label { display: block; margin-bottom: 4px; font-weight: 500; color: #4a5568; font-size: 13px; }
|
|
|
.form-group input, .form-group select { width: 100%; padding: 8px 10px; border: 1px solid #e2e8f0; border-radius: 6px; font-size: 13px; transition: border-color 0.2s; }
|
|
.form-group input, .form-group select { width: 100%; padding: 8px 10px; border: 1px solid #e2e8f0; border-radius: 6px; font-size: 13px; transition: border-color 0.2s; }
|
|
|
.form-group input:focus, .form-group select:focus { outline: none; border-color: #667eea; }
|
|
.form-group input:focus, .form-group select:focus { outline: none; border-color: #667eea; }
|
|
|
.form-group input:disabled { background: #f7fafc; color: #718096; }
|
|
.form-group input:disabled { background: #f7fafc; color: #718096; }
|
|
|
.form-hint { margin-top: 4px; font-size: 11px; color: #718096; }
|
|
.form-hint { margin-top: 4px; font-size: 11px; color: #718096; }
|
|
|
|
|
+.config-editor { width: 100%; padding: 12px; border: 1px solid #e2e8f0; border-radius: 6px; font-family: 'Courier New', monospace; font-size: 13px; line-height: 1.5; resize: vertical; transition: border-color 0.2s; }
|
|
|
|
|
+.config-editor:focus { outline: none; border-color: #667eea; }
|
|
|
|
|
+.form-error { margin-top: 8px; padding: 8px 12px; background: #fed7d7; color: #742a2a; border-radius: 6px; font-size: 13px; }
|
|
|
|
|
|
|
|
/* Config sections */
|
|
/* Config sections */
|
|
|
.config-section { border: 1px solid #e2e8f0; border-radius: 6px; padding: 12px; margin-bottom: 12px; background: #fafafa; }
|
|
.config-section { border: 1px solid #e2e8f0; border-radius: 6px; padding: 12px; margin-bottom: 12px; background: #fafafa; }
|
|
@@ -581,6 +1088,16 @@ code { background: #f7fafc; padding: 4px 8px; border-radius: 4px; font-family: m
|
|
|
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(22px); }
|
|
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(22px); }
|
|
|
.toggle-switch input:disabled + .toggle-slider { opacity: 0.5; cursor: not-allowed; }
|
|
.toggle-switch input:disabled + .toggle-slider { opacity: 0.5; cursor: not-allowed; }
|
|
|
|
|
|
|
|
|
|
+/* Toggle switch inline (for table cells) */
|
|
|
|
|
+.toggle-switch-inline { position: relative; display: inline-block; width: 38px; height: 20px; }
|
|
|
|
|
+.toggle-switch-inline input { opacity: 0; width: 0; height: 0; }
|
|
|
|
|
+.toggle-switch-inline .toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e0; border-radius: 20px; transition: 0.3s; }
|
|
|
|
|
+.toggle-switch-inline .toggle-slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: white; border-radius: 50%; transition: 0.3s; }
|
|
|
|
|
+.toggle-switch-inline input:checked + .toggle-slider { background-color: #667eea; }
|
|
|
|
|
+.toggle-switch-inline input:checked + .toggle-slider:before { transform: translateX(18px); }
|
|
|
|
|
+.toggle-switch-inline input:disabled + .toggle-slider { opacity: 0.5; cursor: not-allowed; }
|
|
|
|
|
+.text-center { text-align: center; }
|
|
|
|
|
+
|
|
|
/* Toggle content (expanded section) */
|
|
/* Toggle content (expanded section) */
|
|
|
.toggle-content { padding-left: 0; margin-top: 8px; border-top: 1px solid #e2e8f0; padding-top: 12px; }
|
|
.toggle-content { padding-left: 0; margin-top: 8px; border-top: 1px solid #e2e8f0; padding-top: 12px; }
|
|
|
.toggle-content .form-group:last-child { margin-bottom: 0; }
|
|
.toggle-content .form-group:last-child { margin-bottom: 0; }
|