feat: ApiAuthService + Sincronizador reescritos para WebControl/Centinel
- ApiAuthService: login WebControl → guarda jwt + apiKey + db_tenant - Sincronizador: pull alarmas/zonas/usuarios/mensajes/banners + push pendientes - DAOs: métodos adicionales en alarmas, eventos, usuarios - Páginas actualizadas: ConectarProveedorPage, ControlAccesoPage, MensajeríaPage, MonitoreoAlarmaPage Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
4724f84b04
commit
efa4a792f4
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme.dart';
|
||||
import '../db/dao/mensajes_dao.dart';
|
||||
import '../db/dao/eventos_dao.dart';
|
||||
import '../models/mensaje.dart';
|
||||
import 'llamada_page.dart';
|
||||
|
||||
@@ -16,6 +17,7 @@ class _MensajeriaPageState extends State<MensajeriaPage> {
|
||||
final _inputController = TextEditingController();
|
||||
final _scrollController = ScrollController();
|
||||
final _dao = MensajesDao();
|
||||
final _eventosDao = EventosDao();
|
||||
|
||||
List<Mensaje> _mensajes = [];
|
||||
|
||||
@@ -159,16 +161,7 @@ class _MensajeriaPageState extends State<MensajeriaPage> {
|
||||
icon: Icons.warning_rounded,
|
||||
label: 'PÁNICO',
|
||||
labelBoton: 'ACTIVAR',
|
||||
onTap: () async {
|
||||
final m = Mensaje(
|
||||
texto: 'ALERTA DE PÁNICO ACTIVADA. Requiero asistencia inmediata.',
|
||||
esMio: true,
|
||||
hora: _horaActual(),
|
||||
timestamp: DateTime.now().toIso8601String(),
|
||||
);
|
||||
await _dao.insert(m);
|
||||
await _cargar();
|
||||
},
|
||||
onTap: _activarPanico,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
@@ -179,16 +172,7 @@ class _MensajeriaPageState extends State<MensajeriaPage> {
|
||||
icon: Icons.headset_mic_rounded,
|
||||
label: 'SOPORTE',
|
||||
labelBoton: 'CONTACTAR',
|
||||
onTap: () async {
|
||||
final m = Mensaje(
|
||||
texto: 'Hola, necesito asistencia técnica.',
|
||||
esMio: true,
|
||||
hora: _horaActual(),
|
||||
timestamp: DateTime.now().toIso8601String(),
|
||||
);
|
||||
await _dao.insert(m);
|
||||
await _cargar();
|
||||
},
|
||||
onTap: _solicitarSoporte,
|
||||
),
|
||||
),
|
||||
]),
|
||||
@@ -236,9 +220,70 @@ class _MensajeriaPageState extends State<MensajeriaPage> {
|
||||
]),
|
||||
);
|
||||
|
||||
Future<void> _activarPanico() async {
|
||||
final confirmar = await showDialog<bool>(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => AlertDialog(
|
||||
backgroundColor: AppColors.surfaceHigh,
|
||||
title: Text('Confirmar Alerta de Pánico',
|
||||
style: appHeadline(
|
||||
size: 16, weight: FontWeight.w700, color: AppColors.error)),
|
||||
content: Text(
|
||||
'Se registrará una alerta de pánico de severidad máxima y se notificará a la central cuando el sistema se sincronice.',
|
||||
style: appLabel(size: 13, color: AppColors.onSurface),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: Text('Cancelar',
|
||||
style: appLabel(color: AppColors.onSurfaceVariant)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: Text('ACTIVAR',
|
||||
style: appLabel(
|
||||
weight: FontWeight.bold, color: AppColors.error)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmar != true) return;
|
||||
await _eventosDao.registrar(
|
||||
tipo: 'alerta',
|
||||
titulo: 'ALERTA DE PANICO — Severidad maxima',
|
||||
descripcion:
|
||||
'Operador activó alarma de pánico. Requiere atención inmediata de la central.',
|
||||
);
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: AppColors.error,
|
||||
content: Text('Alerta de pánico registrada',
|
||||
style: appLabel(color: Colors.white, weight: FontWeight.bold)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _solicitarSoporte() async {
|
||||
await _eventosDao.registrar(
|
||||
tipo: 'notificacion',
|
||||
titulo: 'Solicitud de soporte tecnico',
|
||||
descripcion: 'Operador solicitó asistencia técnica a la central.',
|
||||
);
|
||||
if (!mounted) return;
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (_) => const LlamadaPage(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _horaActual() {
|
||||
final t = TimeOfDay.now();
|
||||
return '${t.hour.toString().padLeft(2, '0')}:${t.minute.toString().padLeft(2, '0')}';
|
||||
final now = DateTime.now();
|
||||
return '${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
// ── Lista de mensajes ──────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user