feat: commit inicial — Central Monitoreo v1.0.0
- OperadorLoginPage con auth WebControl 2 pasos (empresas → login) - ShellPage: sidebar 220px + IndexedStack + header con estado API - DashboardPage: stat cards, feed alarmas, clientes, incidentes (timer 30s) - ApiAuthService: flujo real con email + paswd + dba → token + apiKey - DB SQLite v1: 7 tablas + 7 DAOs completos - theme.dart: AppColors, appHeadline (Manrope), appLabel (Inter) - Logo app: escudo radar neón (SVG + PNG 512px) en lib/recursos/ - desplegar.sh: build release Linux + upload a siax-system.net - agents.md: estado completo + objetivos futuros documentados Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import '../database_helper.dart';
|
||||
|
||||
class CacheAlarmasDao {
|
||||
final _db = DatabaseHelper.instance;
|
||||
|
||||
Future<List<Map<String, dynamic>>> getActivas({int? clienteId}) async {
|
||||
final db = await _db.db;
|
||||
if (clienteId != null) {
|
||||
return db.query(
|
||||
'cache_alarmas',
|
||||
where: "estado = 'activa' AND cliente_id = ?",
|
||||
whereArgs: [clienteId],
|
||||
orderBy: 'severidad DESC, timestamp DESC',
|
||||
);
|
||||
}
|
||||
return db.query(
|
||||
'cache_alarmas',
|
||||
where: "estado = 'activa'",
|
||||
orderBy: 'severidad DESC, timestamp DESC',
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getTodas({int limit = 100}) async {
|
||||
final db = await _db.db;
|
||||
return db.query('cache_alarmas', orderBy: 'severidad DESC, timestamp DESC', limit: limit);
|
||||
}
|
||||
|
||||
Future<int> contarActivas() async {
|
||||
final db = await _db.db;
|
||||
final result = await db.rawQuery("SELECT COUNT(*) as c FROM cache_alarmas WHERE estado = 'activa'");
|
||||
return result.first['c'] as int;
|
||||
}
|
||||
|
||||
Future<int> contarCriticas() async {
|
||||
final db = await _db.db;
|
||||
final result = await db.rawQuery("SELECT COUNT(*) as c FROM cache_alarmas WHERE estado = 'activa' AND severidad >= 4");
|
||||
return result.first['c'] as int;
|
||||
}
|
||||
|
||||
Future<void> reemplazarTodas(List<Map<String, dynamic>> alarmas) async {
|
||||
final db = await _db.db;
|
||||
await db.delete('cache_alarmas');
|
||||
for (final a in alarmas) {
|
||||
await db.insert('cache_alarmas', a, conflictAlgorithm: ConflictAlgorithm.replace);
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> actualizarEstado(int id, String nuevoEstado) async {
|
||||
final db = await _db.db;
|
||||
return db.update(
|
||||
'cache_alarmas',
|
||||
{'estado': nuevoEstado},
|
||||
where: 'id = ?',
|
||||
whereArgs: [id],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> limpiar() async {
|
||||
final db = await _db.db;
|
||||
await db.delete('cache_alarmas');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import '../database_helper.dart';
|
||||
|
||||
class CacheClientesDao {
|
||||
final _db = DatabaseHelper.instance;
|
||||
|
||||
Future<List<Map<String, dynamic>>> getTodos() async {
|
||||
final db = await _db.db;
|
||||
return db.query('cache_clientes', orderBy: 'alarmas_criticas DESC, nombre ASC');
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>?> getById(int id) async {
|
||||
final db = await _db.db;
|
||||
final rows = await db.query('cache_clientes', where: 'id = ?', whereArgs: [id]);
|
||||
return rows.isEmpty ? null : rows.first;
|
||||
}
|
||||
|
||||
Future<int> contarActivos() async {
|
||||
final db = await _db.db;
|
||||
final result = await db.rawQuery('SELECT COUNT(*) as c FROM cache_clientes');
|
||||
return result.first['c'] as int;
|
||||
}
|
||||
|
||||
Future<void> reemplazarTodos(List<Map<String, dynamic>> clientes) async {
|
||||
final db = await _db.db;
|
||||
await db.delete('cache_clientes');
|
||||
for (final c in clientes) {
|
||||
await db.insert('cache_clientes', c, conflictAlgorithm: ConflictAlgorithm.replace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import '../database_helper.dart';
|
||||
|
||||
class ConfiguracionDao {
|
||||
final _db = DatabaseHelper.instance;
|
||||
|
||||
Future<String?> get(String clave) async {
|
||||
final db = await _db.db;
|
||||
final rows = await db.query('configuracion', where: 'clave = ?', whereArgs: [clave]);
|
||||
return rows.isEmpty ? null : rows.first['valor'] as String?;
|
||||
}
|
||||
|
||||
Future<void> set(String clave, String valor) async {
|
||||
final db = await _db.db;
|
||||
await db.insert(
|
||||
'configuracion',
|
||||
{'clave': clave, 'valor': valor},
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import '../database_helper.dart';
|
||||
|
||||
class IncidentesDao {
|
||||
final _db = DatabaseHelper.instance;
|
||||
|
||||
Future<int> registrar({
|
||||
int? alarmaId,
|
||||
int? clienteId,
|
||||
String? clienteNombre,
|
||||
required String tipo,
|
||||
required String operador,
|
||||
String? notas,
|
||||
}) async {
|
||||
final db = await _db.db;
|
||||
return db.insert('incidentes', {
|
||||
'alarma_id': alarmaId,
|
||||
'cliente_id': clienteId,
|
||||
'cliente_nombre': clienteNombre,
|
||||
'tipo': tipo,
|
||||
'operador': operador,
|
||||
'notas': notas,
|
||||
'timestamp': DateTime.now().toIso8601String(),
|
||||
'resuelto': 0,
|
||||
'sincronizado': 0,
|
||||
});
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getRecientes({int limit = 50}) async {
|
||||
final db = await _db.db;
|
||||
return db.query('incidentes', orderBy: 'timestamp DESC', limit: limit);
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getPendientes() async {
|
||||
final db = await _db.db;
|
||||
return db.query('incidentes', where: 'sincronizado = 0');
|
||||
}
|
||||
|
||||
Future<int> marcarResuelto(int id, String notas) async {
|
||||
final db = await _db.db;
|
||||
return db.update(
|
||||
'incidentes',
|
||||
{'resuelto': 1, 'notas': notas, 'sincronizado': 0},
|
||||
where: 'id = ?',
|
||||
whereArgs: [id],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import '../database_helper.dart';
|
||||
|
||||
class OperadoresDao {
|
||||
final _db = DatabaseHelper.instance;
|
||||
|
||||
Future<List<Map<String, dynamic>>> getTodos() async {
|
||||
final db = await _db.db;
|
||||
return db.query('operadores', where: 'activo = 1', orderBy: 'nombre ASC');
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getEnTurno() async {
|
||||
final db = await _db.db;
|
||||
return db.query('operadores', where: 'activo = 1 AND en_turno = 1');
|
||||
}
|
||||
|
||||
Future<int> insertar(String nombre, int nivel) async {
|
||||
final db = await _db.db;
|
||||
final iniciales = _calcularIniciales(nombre);
|
||||
return db.insert('operadores', {
|
||||
'nombre': nombre,
|
||||
'iniciales': iniciales,
|
||||
'nivel': nivel,
|
||||
'activo': 1,
|
||||
'en_turno': 0,
|
||||
});
|
||||
}
|
||||
|
||||
Future<int> setEnTurno(int id, bool valor) async {
|
||||
final db = await _db.db;
|
||||
return db.update(
|
||||
'operadores',
|
||||
{'en_turno': valor ? 1 : 0},
|
||||
where: 'id = ?',
|
||||
whereArgs: [id],
|
||||
);
|
||||
}
|
||||
|
||||
Future<int> desactivar(int id) async {
|
||||
final db = await _db.db;
|
||||
return db.update('operadores', {'activo': 0}, where: 'id = ?', whereArgs: [id]);
|
||||
}
|
||||
|
||||
String _calcularIniciales(String nombre) {
|
||||
final p = nombre.trim().split(RegExp(r'\s+'));
|
||||
if (p.length >= 2) return '${p.first[0]}${p.last[0]}'.toUpperCase();
|
||||
return nombre.isNotEmpty ? nombre[0].toUpperCase() : '?';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import '../database_helper.dart';
|
||||
|
||||
class SesionesDao {
|
||||
final _db = DatabaseHelper.instance;
|
||||
|
||||
Future<int> iniciarSesion(String nombre, String usuario) async {
|
||||
final db = await _db.db;
|
||||
await db.update('sesiones_operador', {'activa': 0});
|
||||
return db.insert('sesiones_operador', {
|
||||
'nombre': nombre,
|
||||
'usuario': usuario,
|
||||
'inicio': DateTime.now().toIso8601String(),
|
||||
'activa': 1,
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> cerrarSesion() async {
|
||||
final db = await _db.db;
|
||||
await db.update(
|
||||
'sesiones_operador',
|
||||
{'fin': DateTime.now().toIso8601String(), 'activa': 0},
|
||||
where: 'activa = 1',
|
||||
);
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>?> getSesionActiva() async {
|
||||
final db = await _db.db;
|
||||
final rows = await db.query('sesiones_operador', where: 'activa = 1', limit: 1);
|
||||
return rows.isEmpty ? null : rows.first;
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getRecientes({int limit = 10}) async {
|
||||
final db = await _db.db;
|
||||
return db.query('sesiones_operador', orderBy: 'inicio DESC', limit: limit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import '../database_helper.dart';
|
||||
|
||||
class SyncLogDao {
|
||||
final _db = DatabaseHelper.instance;
|
||||
|
||||
Future<void> registrar({
|
||||
required String tipo,
|
||||
required String estado,
|
||||
String? detalle,
|
||||
}) async {
|
||||
final db = await _db.db;
|
||||
await db.insert('sync_log', {
|
||||
'tipo': tipo,
|
||||
'estado': estado,
|
||||
'detalle': detalle,
|
||||
'timestamp': DateTime.now().toIso8601String(),
|
||||
});
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> getRecientes({int limit = 20}) async {
|
||||
final db = await _db.db;
|
||||
return db.query('sync_log', orderBy: 'timestamp DESC', limit: limit);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user