Add dashboard defaults (visitor-IP -> business-unit) for kiosk displays
Classic feature gap: a shopfloor/lobby kiosk auto-selects which business unit to show based on the display PC's IP (classic dashboarddefaults table + apivisitorlocation.asp). For the main admin dashboard this does nothing - it is kiosk/visitor-display infra. - Model: DashboardDefault (dashboarddefaults: ipaddress unique, businessunitid FK, description). Migration 7d01_dashboarddefaults (head). - API (core, /api/dashboarddefaults): CRUD + GET /visitor-location that resolves the calling display's business unit from its IP (X-Forwarded-For/remote_addr, or explicit ?ipaddress=); unmapped IP returns a null businessunitid, not an error. Unauthenticated resolve (kiosks); writes are admin. - Frontend: ShopfloorDashboard auto-selects its business unit via visitor-location on load when none is chosen; Settings > Dashboard Defaults CRUD page + dashboardDefaultsApi client. Tests: create + resolve by IP -> BU; unmapped IP -> null; duplicate IP 409. 191 tests pass, naming green, app boots, endpoint + admin page verified live. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -129,7 +129,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||
import { notificationsApi, businessUnitsApi } from '@/api'
|
||||
import { notificationsApi, businessUnitsApi, dashboardDefaultsApi } from '@/api'
|
||||
|
||||
const loading = ref(true)
|
||||
const businessUnit = ref('')
|
||||
@@ -176,6 +176,19 @@ onMounted(async () => {
|
||||
console.error('Error loading business units:', err)
|
||||
}
|
||||
|
||||
// Auto-select this kiosk's business unit from its IP (visitor location),
|
||||
// unless one was already chosen. Falls back to "all" when the IP is unmapped.
|
||||
if (!businessUnit.value) {
|
||||
try {
|
||||
const response = await dashboardDefaultsApi.visitorLocation()
|
||||
if (response.data.data?.businessunitid) {
|
||||
businessUnit.value = response.data.data.businessunitid
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error resolving visitor location:', err)
|
||||
}
|
||||
}
|
||||
|
||||
await loadData()
|
||||
|
||||
// Auto-refresh every 30 seconds
|
||||
|
||||
Reference in New Issue
Block a user