feat: conectar alarmas, mensajes y accesos a BD real
- MonitoreoAlarmaPage: alarmas activas/resueltas desde AlarmasDao, alarma más crítica en tiempo real, log completo con zona y estado, pull-to-refresh, estado vacío - MensajeriaPage: mensajes desde MensajesDao, envío guarda en BD, botones pánico y soporte también persisten en BD, estado vacío - ControlAccesoPage: accesos desde AccesosDao con JOIN a usuarios y puertas, método de acceso, autorizado/denegado, pull-to-refresh, estado vacío - AlarmasDao: contarResueltasUltimas24h, getActivasConZona, getAllConZona - AccesosDao: getRecientesConDetalle (JOIN usuarios + puertas) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
49302dfd23
commit
f566139e0a
@@ -2,6 +2,7 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme.dart';
|
||||
import '../db/dao/accesos_dao.dart';
|
||||
|
||||
class ControlAccesoPage extends StatefulWidget {
|
||||
const ControlAccesoPage({Key? key}) : super(key: key);
|
||||
@@ -15,22 +16,62 @@ class _ControlAccesoPageState extends State<ControlAccesoPage> {
|
||||
bool _muelleBloqueado = false;
|
||||
bool _serverBloqueado = true;
|
||||
|
||||
final _dao = AccesosDao();
|
||||
List<Map<String, dynamic>> _accesos = [];
|
||||
bool _cargando = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cargar();
|
||||
}
|
||||
|
||||
Future<void> _cargar() async {
|
||||
setState(() => _cargando = true);
|
||||
try {
|
||||
final lista = await _dao.getRecientesConDetalle(limit: 20);
|
||||
if (!mounted) return;
|
||||
setState(() => _accesos = lista);
|
||||
} catch (_) {}
|
||||
if (mounted) setState(() => _cargando = false);
|
||||
}
|
||||
|
||||
String _horaCorta(String iso) {
|
||||
try {
|
||||
final dt = DateTime.parse(iso).toLocal();
|
||||
return '${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}';
|
||||
} catch (_) { return '—'; }
|
||||
}
|
||||
|
||||
String _metodoLabel(String metodo) {
|
||||
switch (metodo) {
|
||||
case 'remoto': return 'Apertura Remota';
|
||||
case 'biometrico':return 'Biométrico';
|
||||
default: return 'PIN';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
primary: false,
|
||||
padding: const EdgeInsets.fromLTRB(24, 24, 24, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_encabezado(),
|
||||
const SizedBox(height: 32),
|
||||
_gridEntradas(),
|
||||
const SizedBox(height: 40),
|
||||
_registroAcceso(),
|
||||
const SizedBox(height: 24),
|
||||
_snapshotCamara(),
|
||||
],
|
||||
return RefreshIndicator(
|
||||
onRefresh: _cargar,
|
||||
color: AppColors.primary,
|
||||
child: SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
primary: false,
|
||||
padding: const EdgeInsets.fromLTRB(24, 24, 24, 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_encabezado(),
|
||||
const SizedBox(height: 32),
|
||||
_gridEntradas(),
|
||||
const SizedBox(height: 40),
|
||||
_registroAcceso(),
|
||||
const SizedBox(height: 24),
|
||||
_snapshotCamara(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -252,58 +293,69 @@ class _ControlAccesoPageState extends State<ControlAccesoPage> {
|
||||
|
||||
// ── Registro de acceso ──────────────────────────────────────────────────────
|
||||
Widget _registroAcceso() => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
|
||||
Text('Registro de Acceso',
|
||||
style: appHeadline(size: 20, weight: FontWeight.bold)),
|
||||
GestureDetector(
|
||||
onTap: () {},
|
||||
child: Row(children: [
|
||||
const Icon(Icons.filter_list,
|
||||
color: AppColors.primary, size: 20),
|
||||
const SizedBox(width: 6),
|
||||
Text('FILTRAR',
|
||||
style: appLabel(
|
||||
size: 10,
|
||||
weight: FontWeight.bold,
|
||||
color: AppColors.primary,
|
||||
spacing: 2.0)),
|
||||
Text('Registro de Acceso',
|
||||
style: appHeadline(size: 20, weight: FontWeight.bold)),
|
||||
const SizedBox(height: 16),
|
||||
if (_cargando)
|
||||
const Center(child: Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 24),
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2, color: AppColors.primary),
|
||||
))
|
||||
else if (_accesos.isEmpty)
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(24),
|
||||
decoration: BoxDecoration(color: AppColors.surfaceLow,
|
||||
borderRadius: BorderRadius.circular(12)),
|
||||
child: Column(children: [
|
||||
const Icon(Icons.no_accounts_outlined,
|
||||
color: AppColors.outlineVariant, size: 32),
|
||||
const SizedBox(height: 8),
|
||||
Text('Sin registros de acceso',
|
||||
style: appLabel(size: 13, color: AppColors.outlineVariant)),
|
||||
Text('Carga datos de demo o sincroniza',
|
||||
style: appLabel(size: 11, color: AppColors.outlineVariant)),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
const SizedBox(height: 24),
|
||||
_entradaLog(
|
||||
iniciales: 'MV',
|
||||
colorAvatar: AppColors.primary,
|
||||
nombre: 'Marcus Vance',
|
||||
hora: '14:22:04',
|
||||
descripcion: 'Lobby Principal • Entrada Autorizada',
|
||||
descColor: AppColors.onSurfaceVariant,
|
||||
estadoOk: true,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
_entradaLog(
|
||||
iniciales: 'ER',
|
||||
colorAvatar: AppColors.tertiary,
|
||||
nombre: 'Elena Rodríguez',
|
||||
hora: '13:45:12',
|
||||
descripcion: 'Centro de Datos • Acceso Denegado (Falla de Auth)',
|
||||
descColor: AppColors.tertiary,
|
||||
estadoOk: false,
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
_entradaLog(
|
||||
iniciales: 'ST',
|
||||
colorAvatar: AppColors.primary,
|
||||
nombre: 'Equipo de Seguridad (R0)',
|
||||
hora: '12:30:00',
|
||||
descripcion: 'Muelle de Carga • Apertura Remota',
|
||||
descColor: AppColors.onSurfaceVariant,
|
||||
estadoOk: true,
|
||||
),
|
||||
)
|
||||
else
|
||||
..._accesos.asMap().entries.map((e) {
|
||||
final a = e.value;
|
||||
final autorizado = (a['autorizado'] as int) == 1;
|
||||
final nombre = a['usuario_nombre'] as String? ?? 'Usuario';
|
||||
final iniciales = a['usuario_iniciales'] as String? ?? _iniciales(nombre);
|
||||
final puerta = a['puerta_nombre'] as String? ?? '—';
|
||||
final metodo = _metodoLabel(a['metodo'] as String? ?? 'pin');
|
||||
final hora = _horaCorta(a['timestamp'] as String? ?? '');
|
||||
final desc = '$puerta · ${autorizado ? metodo : 'Acceso Denegado'}';
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 20),
|
||||
child: _entradaLog(
|
||||
iniciales: iniciales,
|
||||
colorAvatar: autorizado ? AppColors.primary : AppColors.error,
|
||||
nombre: nombre,
|
||||
hora: hora,
|
||||
descripcion: desc,
|
||||
descColor: autorizado
|
||||
? AppColors.onSurfaceVariant
|
||||
: AppColors.error,
|
||||
estadoOk: autorizado,
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
],
|
||||
);
|
||||
|
||||
String _iniciales(String nombre) {
|
||||
final partes = nombre.trim().split(' ');
|
||||
if (partes.length >= 2) {
|
||||
return '${partes.first[0]}${partes.last[0]}'.toUpperCase();
|
||||
}
|
||||
return nombre.isNotEmpty ? nombre[0].toUpperCase() : '?';
|
||||
}
|
||||
|
||||
Widget _entradaLog({
|
||||
required String iniciales,
|
||||
required Color colorAvatar,
|
||||
|
||||
Reference in New Issue
Block a user