118 lines
3.6 KiB
Dart
118 lines
3.6 KiB
Dart
import 'package:flutter/material.dart';
|
||
import '../log/screen_logspage.dart';
|
||
import '../log/class_sitecheck.dart';
|
||
import '../log/class_sitelog.dart';
|
||
import 'dialog_addsite.dart';
|
||
|
||
class HomePage extends StatelessWidget {
|
||
final List<SiteCheck> sites;
|
||
final List<SiteLog> logs;
|
||
final Function(String) addSite;
|
||
final Function(int) removeSite;
|
||
final VoidCallback forceCheck;
|
||
final bool isChecking;
|
||
|
||
const HomePage({
|
||
super.key,
|
||
required this.sites,
|
||
required this.logs,
|
||
required this.addSite,
|
||
required this.removeSite,
|
||
required this.forceCheck,
|
||
required this.isChecking,
|
||
});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
appBar: AppBar(
|
||
title: Text('🌐 Surveillance de sites'),
|
||
actions: [
|
||
IconButton(
|
||
icon: Icon(Icons.list_alt),
|
||
tooltip: 'Voir tous les logs',
|
||
onPressed: () {
|
||
Navigator.push(
|
||
context,
|
||
MaterialPageRoute(builder: (_) => LogsPage(logs: logs)),
|
||
);
|
||
},
|
||
),
|
||
IconButton(
|
||
icon:
|
||
isChecking
|
||
? SizedBox(
|
||
width: 24,
|
||
height: 24,
|
||
child: CircularProgressIndicator(
|
||
color: Colors.white,
|
||
strokeWidth: 3,
|
||
),
|
||
)
|
||
: Icon(Icons.refresh),
|
||
tooltip:
|
||
isChecking ? 'Vérification en cours...' : 'Forcer les tests',
|
||
onPressed: isChecking ? null : forceCheck,
|
||
),
|
||
],
|
||
),
|
||
body: ListView.builder(
|
||
itemCount: sites.length,
|
||
itemBuilder: (context, index) {
|
||
final site = sites[index];
|
||
final lastLog = logs.lastWhere(
|
||
(l) => l.url == site.url,
|
||
orElse: () => SiteLog(DateTime.now(), site.url, 0),
|
||
);
|
||
final isOk = lastLog.statusCode == 200;
|
||
return Card(
|
||
child: ListTile(
|
||
leading: Text(isOk ? '✅' : '❌', style: TextStyle(fontSize: 24)),
|
||
title: Text(site.url),
|
||
subtitle:
|
||
lastLog.statusCode == 0
|
||
? Text('Aucune vérification')
|
||
: Text(
|
||
isOk ? 'OK' : 'Erreur: ${lastLog.statusCode}',
|
||
style: TextStyle(
|
||
color: isOk ? Colors.black : Colors.red.withAlpha(10),
|
||
fontWeight:
|
||
isOk ? FontWeight.normal : FontWeight.bold,
|
||
),
|
||
),
|
||
tileColor: isOk ? null : Colors.red.withAlpha(10),
|
||
onTap: () {
|
||
Navigator.push(
|
||
context,
|
||
MaterialPageRoute(
|
||
builder:
|
||
(_) => LogsPage(
|
||
logs: logs.where((l) => l.url == site.url).toList(),
|
||
),
|
||
),
|
||
);
|
||
},
|
||
trailing: IconButton(
|
||
icon: Icon(Icons.delete, color: Colors.grey),
|
||
onPressed: () => removeSite(index),
|
||
),
|
||
),
|
||
);
|
||
},
|
||
),
|
||
floatingActionButton: FloatingActionButton(
|
||
child: Text('➕', style: TextStyle(fontSize: 24)),
|
||
onPressed: () async {
|
||
final url = await showDialog<String>(
|
||
context: context,
|
||
builder: (context) => AddSiteDialog(),
|
||
);
|
||
if (url != null && url.isNotEmpty) {
|
||
addSite(url);
|
||
}
|
||
},
|
||
),
|
||
);
|
||
}
|
||
}
|