initial commit
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
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/node_repository.dart';
|
||||
|
||||
/// Edit dialog for the node-level [BackupConfig]'s source path. Target
|
||||
/// management (add/edit/remove/run/schedule) lives in the dedicated
|
||||
/// [BackupTargetsList] on the Backups screen, not in this dialog.
|
||||
Future<void> showBackupConfigFormDialog(BuildContext context, {required BackupConfig existing}) {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => _BackupConfigFormDialog(existing: existing),
|
||||
);
|
||||
}
|
||||
|
||||
class _BackupConfigFormDialog extends ConsumerStatefulWidget {
|
||||
const _BackupConfigFormDialog({required this.existing});
|
||||
|
||||
final BackupConfig existing;
|
||||
|
||||
@override
|
||||
ConsumerState<_BackupConfigFormDialog> createState() => _BackupConfigFormDialogState();
|
||||
}
|
||||
|
||||
class _BackupConfigFormDialogState extends ConsumerState<_BackupConfigFormDialog> {
|
||||
late final _sourcePathController = TextEditingController(text: widget.existing.sourcePath);
|
||||
bool _saving = false;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_sourcePathController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
setState(() {
|
||||
_saving = true;
|
||||
_error = null;
|
||||
});
|
||||
|
||||
final repo = ref.read(nodeRepositoryProvider);
|
||||
if (repo == null) {
|
||||
setState(() {
|
||||
_saving = false;
|
||||
_error = 'No active connection.';
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
final draft = widget.existing.copyWith(sourcePath: _sourcePathController.text.trim());
|
||||
|
||||
try {
|
||||
await repo.updateBackup(draft);
|
||||
ref.invalidate(backupConfigProvider);
|
||||
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: const Text('Edit backup configuration'),
|
||||
content: SizedBox(
|
||||
width: 420,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: _sourcePathController,
|
||||
decoration: const InputDecoration(labelText: 'Source path', hintText: '/opt'),
|
||||
),
|
||||
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'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../core/models/models.dart';
|
||||
import '../../../core/models/severity_mapping.dart';
|
||||
import '../../../core/theme/theme_x.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 BackupHistoryTable extends StatelessWidget {
|
||||
const BackupHistoryTable({super.key, required this.history, required this.targets});
|
||||
|
||||
final List<BackupExecution> history;
|
||||
final List<BackupTarget> targets;
|
||||
|
||||
String _targetName(String? targetId) {
|
||||
if (targetId == null) return '—';
|
||||
for (final t in targets) {
|
||||
if (t.id == targetId) return t.name;
|
||||
}
|
||||
return targetId;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sorted = [...history]..sort((a, b) => b.timestamp.compareTo(a.timestamp));
|
||||
final timeFormat = DateFormat('yyyy-MM-dd HH:mm');
|
||||
|
||||
return DataTableScaffold(
|
||||
empty: const EmptyState(
|
||||
icon: Icons.cloud_outlined,
|
||||
title: 'No backup history yet',
|
||||
message: 'Run a backup to see execution results here.',
|
||||
),
|
||||
columns: const [
|
||||
DataColumn(label: Text('Timestamp')),
|
||||
DataColumn(label: Text('Target')),
|
||||
DataColumn(label: Text('Result')),
|
||||
DataColumn(label: Text('Duration')),
|
||||
DataColumn(label: Text('Message')),
|
||||
],
|
||||
rows: [
|
||||
for (final execution in sorted)
|
||||
DataRow(
|
||||
cells: [
|
||||
DataCell(MonoText(timeFormat.format(execution.timestamp.toLocal()))),
|
||||
DataCell(Text(_targetName(execution.targetId))),
|
||||
DataCell(
|
||||
StatusPill(
|
||||
label: execution.success ? 'success' : 'failed',
|
||||
severity: severityForSuccess(execution.success),
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
Text(
|
||||
'${execution.durationSeconds}s',
|
||||
style: context.dataStyles.numericTabular,
|
||||
),
|
||||
),
|
||||
DataCell(
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 340),
|
||||
child: MonoText(execution.message, small: true, maxLines: 1),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user