mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Redesign Home screen with device summary and scanner status
Adds a responsive Home screen combining the notification list with a device summary panel and ARP scanner status, visible side-by-side on wide screens and stacked on narrow ones. Backend: - New GET /api/devices/summary endpoint returning registered device counts and "seen in last 24h / 7 days" breakdowns by registration status - Migration 07 adds indexes on (is_registered) and (last_seen, is_registered) so summary queries use index range scans instead of full table scans Frontend: - HomeScreen replaces NotificationList, embedding notifications, device summary card, and ArpScannerCard in a LayoutBuilder-driven two-column (≥700 px) or single-column layout - ArpScannerCard extracted to a shared public widget reused by both HomeScreen and StatusScreen - Nav rail entry renamed to "Home" with home icon Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
dc8f47e66d
commit
251d8a479e
@@ -3,6 +3,7 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:frontend/model/arp_scanner_status.dart';
|
||||
import 'package:frontend/utils/oott_api.dart';
|
||||
import 'package:frontend/widgets/arp_scanner_card.dart';
|
||||
|
||||
class StatusScreen extends StatefulWidget {
|
||||
const StatusScreen({super.key});
|
||||
@@ -29,7 +30,9 @@ class _StatusScreenState extends State<StatusScreen> {
|
||||
);
|
||||
_tickTimer = Timer.periodic(
|
||||
const Duration(seconds: 1),
|
||||
(_) { if (mounted) setState(() {}); },
|
||||
(_) {
|
||||
if (mounted) setState(() {});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -66,100 +69,13 @@ class _StatusScreenState extends State<StatusScreen> {
|
||||
children: [
|
||||
Text('Status', style: Theme.of(context).textTheme.headlineMedium),
|
||||
const SizedBox(height: 20),
|
||||
if (_isLoading)
|
||||
const Center(child: CircularProgressIndicator())
|
||||
else
|
||||
_ArpScannerCard(
|
||||
status: _status,
|
||||
statusReceivedAt: _statusReceivedAt,
|
||||
error: _error,
|
||||
),
|
||||
ArpScannerCard(
|
||||
status: _status,
|
||||
statusReceivedAt: _statusReceivedAt,
|
||||
error: _error,
|
||||
isLoading: _isLoading,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ArpScannerCard extends StatelessWidget {
|
||||
final ArpScannerStatus? status;
|
||||
final DateTime? statusReceivedAt;
|
||||
final String? error;
|
||||
|
||||
const _ArpScannerCard({this.status, this.statusReceivedAt, this.error});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final (color, label, sublabel) = _resolveState(context);
|
||||
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.circle, color: color, size: 14),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'ARP Scanner',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(label, style: Theme.of(context).textTheme.bodyMedium),
|
||||
if (sublabel != null) ...[
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
sublabel,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
(Color, String, String?) _resolveState(BuildContext context) {
|
||||
if (error != null || status == null) {
|
||||
return (
|
||||
Colors.red,
|
||||
'Error',
|
||||
'Unable to reach the server or a server-side error occurred. Check the logs for details.',
|
||||
);
|
||||
}
|
||||
|
||||
final elapsed = statusReceivedAt != null
|
||||
? DateTime.now().difference(statusReceivedAt!).inSeconds.toDouble()
|
||||
: 0.0;
|
||||
|
||||
if (status!.isRunning) {
|
||||
final sub = status!.runningForSeconds != null
|
||||
? 'Running for ${_formatSeconds(status!.runningForSeconds! + elapsed)}'
|
||||
: null;
|
||||
return (Colors.green, 'Running', sub);
|
||||
}
|
||||
if (status!.nextRunInSeconds != null) {
|
||||
final remaining = (status!.nextRunInSeconds! - elapsed).clamp(0.0, double.infinity);
|
||||
return (
|
||||
Colors.amber,
|
||||
'Waiting for next run',
|
||||
'Next run in ${_formatSeconds(remaining)}',
|
||||
);
|
||||
}
|
||||
return (Colors.grey, 'Not yet started', null);
|
||||
}
|
||||
}
|
||||
|
||||
String _formatSeconds(double seconds) {
|
||||
final total = seconds.round().clamp(0, double.maxFinite.toInt());
|
||||
if (total < 60) return '${total}s';
|
||||
final m = total ~/ 60;
|
||||
final s = total % 60;
|
||||
return '${m}m ${s}s';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user