initial commit
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/models/models.dart';
|
||||
import '../../../core/models/severity_mapping.dart';
|
||||
import '../../../core/theme/theme_x.dart';
|
||||
import '../../../core/widgets/empty_state.dart';
|
||||
import '../../../core/widgets/status_pill.dart';
|
||||
|
||||
/// One card per registered node showing its live services (via
|
||||
/// `/nodes/aggregated`), or an inline error card if this particular node
|
||||
/// was unreachable — a per-entry condition the local API itself reports,
|
||||
/// distinct from the aggregated fetch as a whole failing.
|
||||
class FleetCardGrid extends StatelessWidget {
|
||||
const FleetCardGrid({super.key, required this.entries});
|
||||
|
||||
final List<AggregatedNodeStatus> entries;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (entries.isEmpty) {
|
||||
return const EmptyState(
|
||||
icon: Icons.hub_outlined,
|
||||
title: 'Nothing to show yet',
|
||||
message: 'Register a node to see its live services here.',
|
||||
);
|
||||
}
|
||||
|
||||
return GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
maxCrossAxisExtent: 320,
|
||||
mainAxisExtent: 180,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
),
|
||||
itemCount: entries.length,
|
||||
itemBuilder: (context, index) => _NodeCard(entry: entries[index]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NodeCard extends StatelessWidget {
|
||||
const _NodeCard({required this.entry});
|
||||
|
||||
final AggregatedNodeStatus entry;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final hasError = entry.error != null;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: context.colors.surface,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: hasError ? context.status.critical.withValues(alpha: 0.4) : context.colors.outlineVariant,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(entry.node.name, style: context.text.labelLarge),
|
||||
const SizedBox(height: 10),
|
||||
Expanded(
|
||||
child: hasError
|
||||
? _ErrorCallout(message: entry.error!)
|
||||
: entry.services.isEmpty
|
||||
? Text('No services reported.', style: context.text.bodySmall)
|
||||
: ListView(
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
for (final service in entry.services)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 3.5),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
service.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: context.text.bodyMedium,
|
||||
),
|
||||
),
|
||||
StatusPill(
|
||||
label: service.status,
|
||||
severity: severityForServiceStatus(service.status),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ErrorCallout extends StatelessWidget {
|
||||
const _ErrorCallout({required this.message});
|
||||
|
||||
final String message;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Color.alphaBlend(context.status.critical.withValues(alpha: 0.08), context.colors.surface),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: context.status.critical.withValues(alpha: 0.35)),
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(Icons.error_outline, size: 15, color: context.status.critical),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
message,
|
||||
style: context.dataStyles.dataMonoSmall,
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/models/models.dart';
|
||||
import '../../../core/theme/status_colors.dart';
|
||||
import '../../../core/theme/theme_x.dart';
|
||||
import '../../../core/utils/relative_time.dart';
|
||||
import '../../../core/widgets/data_table_scaffold.dart';
|
||||
import '../../../core/widgets/empty_state.dart';
|
||||
import '../../../core/widgets/mono_text.dart';
|
||||
import '../../../core/widgets/status_pill.dart';
|
||||
|
||||
class FleetTable extends StatelessWidget {
|
||||
const FleetTable({
|
||||
super.key,
|
||||
required this.nodes,
|
||||
required this.aggregated,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
});
|
||||
|
||||
final List<RemoteNode> nodes;
|
||||
|
||||
/// Null while the aggregated fetch is still loading/erroring — reachability
|
||||
/// then shows as "unknown" rather than guessing.
|
||||
final List<AggregatedNodeStatus>? aggregated;
|
||||
final void Function(RemoteNode node) onEdit;
|
||||
final void Function(RemoteNode node) onDelete;
|
||||
|
||||
({String label, Severity severity}) _reachability(RemoteNode node) {
|
||||
final entry = aggregated?.where((a) => a.node.id == node.id).firstOrNull;
|
||||
if (entry == null) return (label: 'unknown', severity: Severity.neutral);
|
||||
return entry.error == null
|
||||
? (label: 'online', severity: Severity.good)
|
||||
: (label: 'unreachable', severity: Severity.critical);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DataTableScaffold(
|
||||
empty: const EmptyState(
|
||||
icon: Icons.hub_outlined,
|
||||
title: 'No nodes registered',
|
||||
message: 'Register a sibling NodeMaster host to see it here.',
|
||||
),
|
||||
columns: const [
|
||||
DataColumn(label: Text('Node')),
|
||||
DataColumn(label: Text('URL')),
|
||||
DataColumn(label: Text('Tags')),
|
||||
DataColumn(label: Text('Status')),
|
||||
DataColumn(label: Text('Last seen')),
|
||||
DataColumn(label: Text('')),
|
||||
],
|
||||
rows: [
|
||||
for (final node in nodes)
|
||||
DataRow(
|
||||
cells: [
|
||||
DataCell(
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(node.name, style: context.text.labelLarge),
|
||||
if (node.description?.isNotEmpty == true)
|
||||
Text(node.description!, style: context.text.bodySmall),
|
||||
],
|
||||
),
|
||||
),
|
||||
DataCell(MonoText(node.url)),
|
||||
DataCell(
|
||||
Wrap(
|
||||
spacing: 4,
|
||||
children: [
|
||||
for (final tag in node.tags)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: context.colors.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(tag, style: context.dataStyles.dataMonoSmall),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
DataCell(Builder(
|
||||
builder: (context) {
|
||||
final r = _reachability(node);
|
||||
return StatusPill(label: r.label, severity: r.severity);
|
||||
},
|
||||
)),
|
||||
DataCell(
|
||||
Text(
|
||||
node.lastSeen == null ? '—' : formatRelative(node.lastSeen!.toLocal()),
|
||||
style: context.text.bodySmall,
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
tooltip: 'Edit',
|
||||
icon: const Icon(Icons.edit_outlined, size: 18),
|
||||
onPressed: () => onEdit(node),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: 'Remove',
|
||||
icon: const Icon(Icons.delete_outline, size: 18),
|
||||
onPressed: () => onDelete(node),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/models/models.dart';
|
||||
import '../../../core/network/api_exception.dart';
|
||||
import '../../../data/repositories/nodes_repository.dart';
|
||||
|
||||
/// Add/edit dialog for a registered [RemoteNode]. This only edits the
|
||||
/// registry entry (name/url/description/tags) — reachability is never
|
||||
/// user-editable, it's always computed live via `/nodes/aggregated`.
|
||||
Future<void> showNodeFormDialog(BuildContext context, {RemoteNode? existing}) {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => _NodeFormDialog(existing: existing),
|
||||
);
|
||||
}
|
||||
|
||||
class _NodeFormDialog extends ConsumerStatefulWidget {
|
||||
const _NodeFormDialog({this.existing});
|
||||
|
||||
final RemoteNode? existing;
|
||||
|
||||
@override
|
||||
ConsumerState<_NodeFormDialog> createState() => _NodeFormDialogState();
|
||||
}
|
||||
|
||||
class _NodeFormDialogState extends ConsumerState<_NodeFormDialog> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
late final _nameController = TextEditingController(text: widget.existing?.name);
|
||||
late final _urlController = TextEditingController(text: widget.existing?.url);
|
||||
late final _descriptionController = TextEditingController(text: widget.existing?.description);
|
||||
late final _tagsController = TextEditingController(text: widget.existing?.tags.join(', '));
|
||||
bool _saving = false;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nameController.dispose();
|
||||
_urlController.dispose();
|
||||
_descriptionController.dispose();
|
||||
_tagsController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String? _validateUrl(String? value) {
|
||||
final trimmed = value?.trim() ?? '';
|
||||
if (trimmed.isEmpty) return 'Required.';
|
||||
final uri = Uri.tryParse(trimmed);
|
||||
if (uri == null || !uri.hasScheme || !uri.hasAuthority) {
|
||||
return 'Enter a full URL, e.g. https://edge-02.local:8080';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
if (!(_formKey.currentState?.validate() ?? false)) return;
|
||||
setState(() {
|
||||
_saving = true;
|
||||
_error = null;
|
||||
});
|
||||
|
||||
final repo = ref.read(nodesRepositoryProvider);
|
||||
if (repo == null) {
|
||||
setState(() {
|
||||
_saving = false;
|
||||
_error = 'No active connection.';
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
var url = _urlController.text.trim();
|
||||
if (url.endsWith('/')) url = url.substring(0, url.length - 1);
|
||||
final tags = _tagsController.text
|
||||
.split(',')
|
||||
.map((t) => t.trim())
|
||||
.where((t) => t.isNotEmpty)
|
||||
.toList();
|
||||
final description = _descriptionController.text.trim();
|
||||
|
||||
final draft = (widget.existing ?? const RemoteNode(name: '', url: '')).copyWith(
|
||||
name: _nameController.text.trim(),
|
||||
url: url,
|
||||
description: description.isEmpty ? null : description,
|
||||
tags: tags,
|
||||
);
|
||||
|
||||
try {
|
||||
if (widget.existing == null) {
|
||||
await repo.add(draft);
|
||||
} else {
|
||||
await repo.update(widget.existing!.id, draft);
|
||||
}
|
||||
ref.invalidate(remoteNodesListProvider);
|
||||
if (mounted) Navigator.of(context).pop();
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_saving = false;
|
||||
_error = e is ApiException ? e.userMessage : e.toString();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(widget.existing == null ? 'Register node' : 'Edit node'),
|
||||
content: Form(
|
||||
key: _formKey,
|
||||
child: SizedBox(
|
||||
width: 420,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _nameController,
|
||||
decoration: const InputDecoration(labelText: 'Name'),
|
||||
validator: (v) => (v == null || v.trim().isEmpty) ? 'Required.' : null,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
TextFormField(
|
||||
controller: _urlController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Base URL',
|
||||
hintText: 'https://edge-02.local:8080',
|
||||
),
|
||||
validator: _validateUrl,
|
||||
keyboardType: TextInputType.url,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
TextFormField(
|
||||
controller: _descriptionController,
|
||||
decoration: const InputDecoration(labelText: 'Description (optional)'),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
TextFormField(
|
||||
controller: _tagsController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Tags (optional, comma-separated)',
|
||||
hintText: 'prod, db',
|
||||
),
|
||||
),
|
||||
if (_error != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Text(_error!, style: TextStyle(color: Theme.of(context).colorScheme.error)),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: _saving ? null : () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _saving ? null : _save,
|
||||
child: _saving
|
||||
? const SizedBox(width: 16, height: 16, child: CircularProgressIndicator(strokeWidth: 2))
|
||||
: const Text('Save'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user