From 0ab81a8c9ce7bd525ae1e5e7d4110cdc3898554a Mon Sep 17 00:00:00 2001 From: Carlos Tello Date: Wed, 14 Oct 2026 20:53:16 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20soporte=20multi-carril=20con=20pesta?= =?UTF-8?q?=C3=B1as=20de=20entrada=20y=20salida=20y=20selector=20multi-pue?= =?UTF-8?q?sto?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/styles/base.css | 186 +++++ frontend/src/views/ControlPostView.tsx | 901 ++++++++++++++++++++++--- 2 files changed, 992 insertions(+), 95 deletions(-) diff --git a/frontend/src/styles/base.css b/frontend/src/styles/base.css index e09bf50..fede6f1 100644 --- a/frontend/src/styles/base.css +++ b/frontend/src/styles/base.css @@ -185,6 +185,71 @@ button:disabled, .btn:disabled, .touch-button:disabled { border-color: var(--border); } +/* ============================================================================== + PESTAÑAS DE CARRILES / PUESTOS DE CONTROL (PARIDAD QTabWidget DESKTOP) + ============================================================================== */ +.lane-tabs-nav { + display: flex; + align-items: center; + justify-content: space-between; + background-color: var(--bg-surface); + border-bottom: 1px solid var(--border); + padding: 0 1rem; + overflow-x: auto; + scrollbar-width: none; + min-height: 48px; +} +.lane-tabs-nav::-webkit-scrollbar { + display: none; +} +.lane-tabs-list { + display: flex; + align-items: center; + gap: 0.35rem; +} +.lane-tab-button { + background: transparent; + border: none; + border-bottom: 3px solid transparent; + border-radius: 6px 6px 0 0; + padding: 0.6rem 0.95rem; + font-size: 0.88rem; + font-weight: 700; + color: var(--text-secondary); + cursor: pointer; + display: inline-flex; + align-items: center; + gap: 0.5rem; + white-space: nowrap; + transition: all 0.15s ease; + min-height: 48px; +} +.lane-tab-button:hover { + background-color: var(--hover-bg); + color: var(--text-primary); +} +.lane-tab-button.active { + background-color: var(--hover-bg); + color: var(--text-primary); +} +.lane-tab-dot { + width: 9px; + height: 9px; + border-radius: 50%; + display: inline-block; + box-shadow: 0 0 5px rgba(0, 0, 0, 0.4); +} + +.lane-header-banner { + padding: 0.85rem 1.25rem; + border-bottom: 1px solid var(--border); + display: flex; + align-items: center; + justify-content: space-between; + flex-wrap: wrap; + gap: 0.75rem; +} + /* ============================================================================== PESTAÑAS ESTILO ONEVER ============================================================================== */ @@ -352,3 +417,124 @@ button:disabled, .btn:disabled, .touch-button:disabled { } } +/* ============================================================================== + ESTILOS DE PESTAÑAS MULTI-CARRIL Y MULTI-PUESTO (PARIDAD ESCRITORIO PCT_VIEW_ADMIN) + ============================================================================== */ +.lane-tabs-nav { + display: flex; + align-items: center; + justify-content: space-between; + background-color: var(--bg-surface); + border-bottom: 1px solid var(--border-subtle); + padding: 0 1rem; + overflow-x: auto; + -webkit-overflow-scrolling: touch; + gap: 0.75rem; + min-height: 50px; +} + +.lane-tabs-list { + display: flex; + align-items: center; + gap: 0.35rem; + flex: 1; + min-width: 0; + overflow-x: auto; +} + +.lane-tab-button { + padding: 0.7rem 1.15rem; + min-height: 48px; + border: none; + border-bottom: 3px solid transparent; + background: transparent; + color: var(--text-secondary); + font-size: 0.92rem; + font-weight: 600; + cursor: pointer; + display: flex; + align-items: center; + gap: 0.55rem; + transition: all 0.2s ease; + border-radius: 8px 8px 0 0; + white-space: nowrap; + user-select: none; +} + +.lane-tab-button:hover { + background-color: var(--hover-bg); + color: var(--text-primary); +} + +.lane-tab-button.active { + color: var(--text-primary); + background-color: var(--bg-card); + font-weight: 700; +} + +.lane-tab-button.active.tab-entry { + border-bottom-color: #10B981; +} + +.lane-tab-button.active.tab-exit { + border-bottom-color: #EF4444; +} + +.lane-tab-button.active.tab-overview { + border-bottom-color: var(--brand-primary); +} + +.lane-tab-dot { + width: 11px; + height: 11px; + border-radius: 50%; + display: inline-block; + flex-shrink: 0; +} + +.lane-tab-dot.entry { + background-color: #10B981; + box-shadow: 0 0 7px rgba(16, 185, 129, 0.7); +} + +.lane-tab-dot.exit { + background-color: #EF4444; + box-shadow: 0 0 7px rgba(239, 68, 68, 0.7); +} + +.lane-tab-dot.overview { + background-color: var(--brand-primary); + box-shadow: 0 0 7px rgba(0, 102, 204, 0.5); +} + +.lane-header-banner { + display: flex; + align-items: center; + justify-content: space-between; + padding: 0.75rem 1.25rem; + border-bottom: 1px solid var(--border-subtle); + background: var(--bg-surface); + flex-wrap: wrap; + gap: 0.75rem; +} + +.wks-switcher-btn { + display: flex; + align-items: center; + gap: 0.45rem; + padding: 0.45rem 0.85rem; + border-radius: 8px; + border: 1px solid var(--border); + background-color: var(--bg-card); + color: var(--text-primary); + font-weight: 600; + font-size: 0.85rem; + cursor: pointer; + transition: all 0.2s ease; + white-space: nowrap; +} + +.wks-switcher-btn:hover { + background-color: var(--hover-bg); + border-color: var(--accent); +} diff --git a/frontend/src/views/ControlPostView.tsx b/frontend/src/views/ControlPostView.tsx index abd279b..f1626d2 100644 --- a/frontend/src/views/ControlPostView.tsx +++ b/frontend/src/views/ControlPostView.tsx @@ -4,7 +4,7 @@ // ============================================================================== import React, { useState, useEffect, useCallback, useMemo } from 'react'; import { useAuth } from '../context/AuthContext'; -import { workstationApi } from '../api/workstationApi'; +import { workstationApi, WorkstationListItem } from '../api/workstationApi'; import { accessApi } from '../api/accessApi'; import { hardwareApi } from '../api/hardwareApi'; import { useWebSocket } from '../hooks/useWebSocket'; @@ -23,9 +23,18 @@ import { LotPermission, } from '../types'; +export interface LaneTab { + key: string; + moduleId: number; + direction: 'ENTRY' | 'EXIT' | 'ALL'; + name: string; + address: number; + tipo_acceso_nombre?: string; + es_acceso_peatonal?: boolean; +} export const ControlPostView: React.FC = () => { - const { user, workstation, logout } = useAuth(); + const { user, workstation, setWorkstation, logout } = useAuth(); const { theme, toggleTheme } = useTheme(); // Configuración de Estación y Módulos @@ -33,6 +42,14 @@ export const ControlPostView: React.FC = () => { const [selectedEntryModuleId, setSelectedEntryModuleId] = useState(0); const [selectedExitModuleId, setSelectedExitModuleId] = useState(0); + // Soporte Multi-Carril (Pestañas de Entrada y Salida) y Multi-Puesto + const [activeLaneTabKey, setActiveLaneTabKey] = useState(''); + const [availableWorkstations, setAvailableWorkstations] = useState([]); + const [isWksModalOpen, setIsWksModalOpen] = useState(false); + const [quickExitInput, setQuickExitInput] = useState(''); + const [quickExitMessage, setQuickExitMessage] = useState<{ text: string; type: 'success' | 'warn' | 'error' } | null>(null); + const [scannerMode, setScannerMode] = useState<'entry' | 'exit'>('entry'); + // Tickets activos y movimientos registrados en BD const [activeTickets, setActiveTickets] = useState([]); const [recentMovements, setRecentMovements] = useState([]); @@ -163,10 +180,95 @@ export const ControlPostView: React.FC = () => { } }, []); + // Carga de puestos de trabajo disponibles en la red + const loadAvailableWorkstations = useCallback(async () => { + try { + const list = await workstationApi.getAvailableWorkstations(); + setAvailableWorkstations(list); + } catch (err) { + console.warn('Error cargando puestos disponibles:', err); + } + }, []); + useEffect(() => { loadConfig(); loadActiveTickets(); - }, [loadConfig, loadActiveTickets]); + loadAvailableWorkstations(); + }, [loadConfig, loadActiveTickets, loadAvailableWorkstations]); + + // Lista de carriles/pestañas del puesto actual (Paridad escritorio FormularioPuestoControlHost) + const laneTabs = useMemo(() => { + const tabs: LaneTab[] = []; + if (config?.entry_modules) { + config.entry_modules.forEach((m) => { + tabs.push({ + key: `entry-${m.id}`, + moduleId: m.id, + direction: 'ENTRY', + name: m.name, + address: m.address, + tipo_acceso_nombre: m.tipo_acceso_nombre, + es_acceso_peatonal: m.es_acceso_peatonal, + }); + }); + } + if (config?.exit_modules) { + config.exit_modules.forEach((m) => { + tabs.push({ + key: `exit-${m.id}`, + moduleId: m.id, + direction: 'EXIT', + name: m.name, + address: m.address, + tipo_acceso_nombre: m.tipo_acceso_nombre, + es_acceso_peatonal: m.es_acceso_peatonal, + }); + }); + } + tabs.push({ + key: 'overview', + moduleId: 0, + direction: 'ALL', + name: 'Predio y Movimientos', + address: 0, + }); + return tabs; + }, [config]); + + // Sincronizar carril activo al cargar o cambiar de puesto + useEffect(() => { + if (laneTabs.length > 0) { + const exists = laneTabs.some((t) => t.key === activeLaneTabKey); + if (!exists) { + const first = laneTabs[0]; + setActiveLaneTabKey(first.key); + if (first.direction === 'ENTRY') { + setSelectedEntryModuleId(first.moduleId); + setForm((prev) => ({ ...prev, modulo_ingreso_id: first.moduleId })); + setScannerMode('entry'); + } else if (first.direction === 'EXIT') { + setSelectedExitModuleId(first.moduleId); + setScannerMode('exit'); + } + } + } + }, [laneTabs, activeLaneTabKey]); + + const currentLaneTab = useMemo(() => { + return laneTabs.find((t) => t.key === activeLaneTabKey) || laneTabs[0]; + }, [laneTabs, activeLaneTabKey]); + + const handleSelectLaneTab = (tab: LaneTab) => { + setActiveLaneTabKey(tab.key); + if (tab.direction === 'ENTRY') { + setSelectedEntryModuleId(tab.moduleId); + setForm((prev) => ({ ...prev, modulo_ingreso_id: tab.moduleId })); + setScannerMode('entry'); + } else if (tab.direction === 'EXIT') { + setSelectedExitModuleId(tab.moduleId); + setScannerMode('exit'); + } + }; // WebSockets para recepción de eventos en tiempo real const handleWsEvent = useCallback( @@ -311,18 +413,55 @@ export const ControlPostView: React.FC = () => { setForm((prev) => ({ ...prev, [field]: `${yyyy}-${mm}-${dd}` })); }; - // Callback al escanear DNI con cámara + // Búsqueda y salida rápida por DNI o Patente (Paridad pct_view.py:3313 txt_doc / cmb_patente) + const handleQuickExitSearch = (query: string) => { + const q = query.trim().toUpperCase(); + if (!q) return; + + const cleanDni = q.replace(/[^0-9]/g, ''); + const matched = activeTickets.find((t) => { + const matchDoc = cleanDni && cleanDni.length >= 4 && t.documento && t.documento.replace(/[^0-9]/g, '').includes(cleanDni); + const matchPat = t.patente && t.patente.toUpperCase().replace(/\s/g, '').includes(q.replace(/\s/g, '')); + const matchName = `${t.apellido} ${t.nombre}`.toUpperCase().includes(q); + return matchDoc || matchPat || matchName; + }); + + if (matched) { + setQuickExitMessage({ + text: `Vehículo / Persona localizada: ${matched.patente || 'Peatón'} - ${matched.apellido}, ${matched.nombre}`, + type: 'success', + }); + if (currentLaneTab && currentLaneTab.direction === 'EXIT') { + setSelectedExitModuleId(currentLaneTab.moduleId); + } + setTicketForExit(matched); + setExitModalOpen(true); + setQuickExitInput(''); + } else { + setQuickExitMessage({ + text: `No se encontró ningún ticket activo en el predio con "${query}".`, + type: 'warn', + }); + setTimeout(() => setQuickExitMessage(null), 5000); + } + }; + + // Callback al escanear DNI con cámara (soporta Entrada y Salida) const handleDniScanned = (data: DNIParsedResult) => { - setForm((prev) => ({ - ...prev, - documento: data.documento, - apellido: data.apellido, - nombre: data.nombre, - sexo: data.sexo || 'M', - })); - lookupPerson(data.documento); - setActionSuccess(`DNI escaneado exitosamente: ${data.apellido}, ${data.nombre} (${data.documento})`); - setTimeout(() => setActionSuccess(null), 4000); + if (scannerMode === 'exit') { + handleQuickExitSearch(data.documento); + } else { + setForm((prev) => ({ + ...prev, + documento: data.documento, + apellido: data.apellido, + nombre: data.nombre, + sexo: data.sexo || 'M', + })); + lookupPerson(data.documento); + setActionSuccess(`DNI escaneado exitosamente: ${data.apellido}, ${data.nombre} (${data.documento})`); + setTimeout(() => setActionSuccess(null), 4000); + } }; // Envío del formulario de Ingreso con Validación Estricta @@ -706,97 +845,542 @@ export const ControlPostView: React.FC = () => { )} - {/* Barra de pestañas responsive para tablets en modo vertical y móviles */} -
- - -
- {/* ========================================================================= - Cuerpo Principal de Garita (Layout Cockpit con soporte Multiorientación) + Barra de Pestañas Multi-Carril y Multi-Puesto (Paridad Desktop FormularioPuestoControlHost) ========================================================================= */} -
- {/* ======================================================================= - COLUMNA 1: FORMULARIO DE INGRESO RÁPIDO - ======================================================================= */} -
+
+ {laneTabs.map((tab) => { + const isActive = tab.key === activeLaneTabKey; + const tabClass = + tab.direction === 'ENTRY' + ? 'tab-entry' + : tab.direction === 'EXIT' + ? 'tab-exit' + : 'tab-overview'; + const dotClass = + tab.direction === 'ENTRY' + ? 'entry' + : tab.direction === 'EXIT' + ? 'exit' + : 'overview'; + + return ( + + ); + })} +
+ +
+ +
+ + + {/* Banner de Estado del Carril Activo */} + {currentLaneTab && currentLaneTab.direction === 'ENTRY' && ( +
+
+ +
+
+ + CARRIL DE ENTRADA: {currentLaneTab.name.toUpperCase()} + + + (Módulo #{currentLaneTab.moduleId} • Addr {currentLaneTab.address}) + +
+ + Habilitación: {currentLaneTab.tipo_acceso_nombre || (currentLaneTab.es_acceso_peatonal ? 'Molinete / Puerta Peatonal' : 'Barrera Vehicular')} + +
+
+
+ +
+
+ )} + + {currentLaneTab && currentLaneTab.direction === 'EXIT' && ( +
+
+ +
+
+ + CARRIL DE SALIDA: {currentLaneTab.name.toUpperCase()} + + + (Módulo #{currentLaneTab.moduleId} • Addr {currentLaneTab.address}) + +
+ + Habilitación: {currentLaneTab.tipo_acceso_nombre || (currentLaneTab.es_acceso_peatonal ? 'Molinete / Puerta Peatonal' : 'Barrera Vehicular')} + +
+
+
+ +
+
+ )} + + {/* Si el carril activo es SALIDA, renderizamos el Cockpit de Salida dedicado (Paridad pct_view.py _set_modo_salida) */} + {currentLaneTab && currentLaneTab.direction === 'EXIT' ? ( +
- {/* Botón Gigante de Escaneo con Cámara */} - + +
{ + e.preventDefault(); + handleQuickExitSearch(quickExitInput); + }} + style={{ flex: 1, display: 'flex', gap: '0.6rem', minWidth: '280px' }} + > + setQuickExitInput(e.target.value)} + style={{ + flex: 1, + minHeight: '52px', + fontSize: '1.05rem', + border: '2px solid #EF4444', + borderRadius: '8px', + padding: '0 1rem', + }} + /> + +
+
+ + {quickExitMessage && ( +
+ {quickExitMessage.text} +
+ )} +
+ + {/* Grilla Principal de Salida */} +
+ {/* Lista de Vehículos y Visitas en Predio */} +
+
+
+

+ 🚗 Visitas y Vehículos en Predio ({activeTickets.length}) +

+ + {filteredTickets.length} mostrados + +
+ setFilterQuery(e.target.value)} + style={{ maxWidth: '280px', minHeight: '40px', fontSize: '0.9rem' }} + /> +
+ +
+ {filteredTickets.length === 0 ? ( +
+ No hay vehículos ni visitas activas en el predio para dar salida. +
+ ) : ( + filteredTickets.map((t) => ( +
+
+
+ {t.patente || 'PEATÓN'} +
+ +
+
+ {t.apellido}, {t.nombre}{' '} + + (DNI: {t.documento}) + +
+
+ Destino: Lote {t.lote_codigo || 'S/D'} • Ingreso: {t.fecha_ingreso} + {t.ocupantes > 1 && ( + + 👥 {t.ocupantes} personas + + )} + {t.cacheo_salida && ( + + 🔍 CACHEO OBLIGATORIO + + )} +
+
+
+ + +
+ )) + )} +
+
+ + {/* Columna Derecha: Movimientos recientes */} +
+
+

+ 📋 Últimos Movimientos +

+ +
+ +
+ {recentMovements.slice(0, 12).map((m: any, idx: number) => ( +
+
+ {m.patente || 'Peatón'} + {m.sentido} +
+
+ {m.apellido}, {m.nombre} (Lote {m.lote_codigo || '-'}) +
+
{m.fecha_hora}
+
+ ))} +
+
+
+ + ) : ( + /* Caso ENTRADA o PREDIO GENERAL: Layout Cockpit con soporte Multiorientación */ + <> + {/* Barra de pestañas responsive para tablets en modo vertical y móviles */} +
+ + +
+ +
+ {/* ======================================================================= + COLUMNA 1: FORMULARIO DE INGRESO RÁPIDO (Oculto en tab Predio General) + ======================================================================= */} + {currentLaneTab?.direction !== 'ALL' && ( +
+ {/* Botón Gigante de Escaneo con Cámara */} +
+ )} {/* ======================================================================= COLUMNA 2: TICKETS ACTIVOS Y EGRESOS DEL PREDIO @@ -2060,6 +2645,8 @@ export const ControlPostView: React.FC = () => {
+ + )} {/* Modal de Escaneo con Cámara */} { onSelectLot={selectLot} selectedLotId={form.lote_id} /> + + {/* Modal de Selección de Puesto de Trabajo (Multi-Puesto) */} + {isWksModalOpen && ( +
setIsWksModalOpen(false)} + style={{ + position: 'fixed', + top: 0, + left: 0, + right: 0, + bottom: 0, + backgroundColor: 'rgba(0, 0, 0, 0.7)', + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + zIndex: 1000, + padding: '1rem', + }} + > +
e.stopPropagation()} + > +
+
+ 🏢 +

+ Seleccionar Puesto de Control +

+
+ +
+ +

+ Seleccione la estación o garita que desea operar. Se cargarán sus carriles virtuales, barreras de entrada/salida y lectores asociados. +

+ +
+ {availableWorkstations.length === 0 ? ( +
+ Cargando estaciones de trabajo registradas... +
+ ) : ( + availableWorkstations.map((wks) => { + const isCurrent = wks.name.toUpperCase() === workstation.toUpperCase(); + return ( + + ); + }) + )} +
+ +
+ +
+
+
+ )} ); };