- InicioPage conectada a BD: eventos reales, métricas suscripción y nodos - Eventos del log cargan desde EventosDao (getRecientes limit 6) - Métricas: estado suscripción (PROTEGIDO/POR VENCER/SUSPENDIDO/VENCIDO) - NodosDao: nuevo método contarActivos() - InicioPageState pública + método recargar() vía GlobalKey - MainPage: llama recargar() al volver al tab INICIO - DemoDataService: singleton que carga eventos, alarmas, mensajes, accesos y sesiones de prueba - Settings: botón "Datos de demostración" con diálogo de confirmación Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
53 lines
1.5 KiB
Dart
53 lines
1.5 KiB
Dart
import '../database_helper.dart';
|
|
import '../../models/nodo.dart';
|
|
|
|
class NodosDao {
|
|
final _db = DatabaseHelper.instance;
|
|
|
|
Future<List<Nodo>> getAll() async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('nodos', orderBy: 'nombre ASC');
|
|
return rows.map(Nodo.fromMap).toList();
|
|
}
|
|
|
|
Future<List<Nodo>> getByZona(int zonaId) async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('nodos', where: 'zona_id = ?', whereArgs: [zonaId]);
|
|
return rows.map(Nodo.fromMap).toList();
|
|
}
|
|
|
|
Future<Nodo?> getById(int id) async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('nodos', where: 'id = ?', whereArgs: [id]);
|
|
return rows.isEmpty ? null : Nodo.fromMap(rows.first);
|
|
}
|
|
|
|
Future<int> insert(Nodo n) async {
|
|
final db = await _db.db;
|
|
return db.insert('nodos', n.toMap());
|
|
}
|
|
|
|
Future<int> update(Nodo n) async {
|
|
final db = await _db.db;
|
|
return db.update('nodos', n.toMap(), where: 'id = ?', whereArgs: [n.id]);
|
|
}
|
|
|
|
Future<int> delete(int id) async {
|
|
final db = await _db.db;
|
|
return db.delete('nodos', where: 'id = ?', whereArgs: [id]);
|
|
}
|
|
|
|
Future<int> contarActivos() async {
|
|
final db = await _db.db;
|
|
final result = await db.rawQuery(
|
|
'SELECT COUNT(*) as total FROM nodos WHERE activo = 1');
|
|
return result.first['total'] as int? ?? 0;
|
|
}
|
|
|
|
Future<List<Nodo>> getPendientes() async {
|
|
final db = await _db.db;
|
|
final rows = await db.query('nodos', where: 'sincronizado = 0');
|
|
return rows.map(Nodo.fromMap).toList();
|
|
}
|
|
}
|