initial commit
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../core/models/models.dart';
|
||||
import '../../core/network/api_exception.dart';
|
||||
import '../../core/theme/theme_x.dart';
|
||||
import '../../core/widgets/error_banner.dart';
|
||||
import '../../data/repositories/nodes_repository.dart';
|
||||
import 'widgets/fleet_card_grid.dart';
|
||||
import 'widgets/fleet_table.dart';
|
||||
import 'widgets/node_form_dialog.dart';
|
||||
|
||||
class FleetScreen extends ConsumerWidget {
|
||||
const FleetScreen({super.key});
|
||||
|
||||
Future<void> _delete(BuildContext context, WidgetRef ref, RemoteNode node) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Remove node?'),
|
||||
content: Text('This removes "${node.name}" from the registry. It does not affect that host.'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.of(context).pop(false), child: const Text('Cancel')),
|
||||
FilledButton(
|
||||
style: FilledButton.styleFrom(backgroundColor: context.status.critical),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('Remove'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmed != true) return;
|
||||
|
||||
final repo = ref.read(nodesRepositoryProvider);
|
||||
if (repo == null) return;
|
||||
try {
|
||||
await repo.delete(node.id);
|
||||
ref.invalidate(remoteNodesListProvider);
|
||||
ref.invalidate(aggregatedNodesProvider);
|
||||
} catch (e) {
|
||||
final message = e is ApiException ? e.userMessage : e.toString();
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final nodesAsync = ref.watch(remoteNodesListProvider);
|
||||
final aggregatedAsync = ref.watch(aggregatedNodesProvider);
|
||||
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('REGISTERED NODES', style: context.text.titleSmall),
|
||||
FilledButton.icon(
|
||||
onPressed: () => showNodeFormDialog(context),
|
||||
icon: const Icon(Icons.add, size: 17),
|
||||
label: const Text('Register node'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
nodesAsync.when(
|
||||
loading: () => const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 40),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
error: (error, stackTrace) => ErrorBanner(
|
||||
message: error is ApiException ? error.userMessage : error.toString(),
|
||||
onRetry: () => ref.invalidate(remoteNodesListProvider),
|
||||
),
|
||||
data: (nodes) => FleetTable(
|
||||
nodes: nodes,
|
||||
aggregated: aggregatedAsync.value,
|
||||
onEdit: (node) => showNodeFormDialog(context, existing: node),
|
||||
onDelete: (node) => _delete(context, ref, node),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 22),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('AGGREGATED SERVICES', style: context.text.titleSmall),
|
||||
Text(
|
||||
'live fan-out via /nodes/aggregated',
|
||||
style: context.dataStyles.dataMonoSmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
aggregatedAsync.when(
|
||||
loading: () => const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 40),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
error: (error, stackTrace) => ErrorBanner(
|
||||
message: error is ApiException ? error.userMessage : error.toString(),
|
||||
onRetry: () => ref.invalidate(aggregatedNodesProvider),
|
||||
),
|
||||
data: (entries) => FleetCardGrid(entries: entries),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user