initial commit
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../core/models/models.dart';
|
||||
import '../../core/models/severity_mapping.dart';
|
||||
import '../../core/network/api_exception.dart';
|
||||
import '../../core/theme/status_colors.dart';
|
||||
import '../../core/theme/theme_x.dart';
|
||||
import '../../core/utils/relative_time.dart';
|
||||
import '../../core/widgets/error_banner.dart';
|
||||
import '../../core/widgets/stat_tile.dart';
|
||||
import '../../data/repositories/nodes_repository.dart';
|
||||
import 'providers/dashboard_summary.dart';
|
||||
import 'providers/dashboard_summary_provider.dart';
|
||||
import 'widgets/activity_feed.dart';
|
||||
import 'widgets/quick_actions_row.dart';
|
||||
|
||||
class DashboardScreen extends ConsumerWidget {
|
||||
const DashboardScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final summaryAsync = ref.watch(dashboardSummaryProvider);
|
||||
final fleetAsync = ref.watch(aggregatedNodesProvider);
|
||||
|
||||
return summaryAsync.when(
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (error, stackTrace) => Center(
|
||||
child: ErrorBanner(
|
||||
message: error is ApiException ? error.userMessage : error.toString(),
|
||||
onRetry: () => ref.invalidate(dashboardSummaryProvider),
|
||||
),
|
||||
),
|
||||
data: (summary) => ListView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
children: [
|
||||
_StatRow(summary: summary, fleetAsync: fleetAsync),
|
||||
const SizedBox(height: 22),
|
||||
Text('QUICK ACTIONS', style: context.text.titleSmall),
|
||||
const SizedBox(height: 10),
|
||||
const QuickActionsRow(),
|
||||
const SizedBox(height: 22),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('RECENT ACTIVITY', style: context.text.titleSmall),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Card(child: ActivityFeed(node: summary.node)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StatRow extends StatelessWidget {
|
||||
const _StatRow({required this.summary, required this.fleetAsync});
|
||||
|
||||
final DashboardSummary summary;
|
||||
final AsyncValue<List<AggregatedNodeStatus>> fleetAsync;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final services = summary.services;
|
||||
final up = services.where((s) => s.status == 'up').length;
|
||||
final down = services.where((s) => s.status == 'down').length;
|
||||
final unknown = services.length - up - down;
|
||||
|
||||
final servicesSeverity = down > 0
|
||||
? Severity.critical
|
||||
: unknown > 0
|
||||
? Severity.warning
|
||||
: Severity.good;
|
||||
final servicesCaption = services.isEmpty
|
||||
? 'No services discovered yet'
|
||||
: [
|
||||
if (down > 0) '$down down',
|
||||
if (unknown > 0) '$unknown unknown',
|
||||
].isEmpty
|
||||
? 'All running'
|
||||
: [if (down > 0) '$down down', if (unknown > 0) '$unknown unknown'].join(' · ');
|
||||
|
||||
final history = [...summary.node.backup.history]
|
||||
..sort((a, b) => b.timestamp.compareTo(a.timestamp));
|
||||
final lastBackup = history.isEmpty ? null : history.first;
|
||||
|
||||
final updates = [...summary.node.updateHistory]..sort((a, b) => b.timestamp.compareTo(a.timestamp));
|
||||
final lastUpdate = updates.isEmpty ? null : updates.first;
|
||||
|
||||
return Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 12,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 260,
|
||||
child: StatTile(
|
||||
label: 'Services',
|
||||
value: '$up',
|
||||
valueQualifier: '/ ${services.length} up',
|
||||
caption: servicesCaption,
|
||||
severity: services.isEmpty ? Severity.neutral : servicesSeverity,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 260,
|
||||
child: StatTile(
|
||||
label: 'Last backup',
|
||||
value: lastBackup == null ? 'Never' : formatRelative(lastBackup.timestamp),
|
||||
caption: lastBackup == null
|
||||
? 'No backups run yet'
|
||||
: (lastBackup.success ? '${lastBackup.durationSeconds}s' : lastBackup.message),
|
||||
severity: lastBackup == null ? Severity.neutral : severityForSuccess(lastBackup.success),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 260,
|
||||
child: StatTile(
|
||||
label: 'Last system update',
|
||||
value: lastUpdate == null ? 'Never' : formatRelative(lastUpdate.timestamp),
|
||||
caption: lastUpdate == null
|
||||
? 'No updates recorded yet'
|
||||
: '${lastUpdate.packages.length} package(s)',
|
||||
severity: lastUpdate == null ? Severity.neutral : severityForSuccess(lastUpdate.success),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 260, child: _FleetTile(fleetAsync: fleetAsync)),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FleetTile extends StatelessWidget {
|
||||
const _FleetTile({required this.fleetAsync});
|
||||
|
||||
final AsyncValue<List<AggregatedNodeStatus>> fleetAsync;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return fleetAsync.when(
|
||||
loading: () => const StatTile(
|
||||
label: 'Fleet',
|
||||
value: '…',
|
||||
severity: Severity.neutral,
|
||||
),
|
||||
error: (error, stackTrace) => StatTile(
|
||||
label: 'Fleet',
|
||||
value: '—',
|
||||
caption: error is ApiException ? error.userMessage : error.toString(),
|
||||
severity: Severity.critical,
|
||||
),
|
||||
data: (nodes) {
|
||||
if (nodes.isEmpty) {
|
||||
return const StatTile(
|
||||
label: 'Fleet',
|
||||
value: '0',
|
||||
caption: 'No nodes registered',
|
||||
severity: Severity.neutral,
|
||||
);
|
||||
}
|
||||
final online = nodes.where((n) => n.error == null).length;
|
||||
final unreachable = nodes.where((n) => n.error != null).toList();
|
||||
return StatTile(
|
||||
label: 'Fleet',
|
||||
value: '$online',
|
||||
valueQualifier: '/ ${nodes.length} online',
|
||||
caption: unreachable.isEmpty
|
||||
? 'All nodes reachable'
|
||||
: 'unreachable: ${unreachable.map((n) => n.node.name).join(', ')}',
|
||||
severity: unreachable.isEmpty ? Severity.good : Severity.critical,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import '../../../core/models/models.dart';
|
||||
|
||||
part 'dashboard_summary.freezed.dart';
|
||||
|
||||
/// Client-side composition of the two data sources the Dashboard needs —
|
||||
/// no server endpoint returns this shape directly. Not JSON-serializable
|
||||
/// (nothing here is ever sent/stored as JSON), so no `fromJson`/`toJson`.
|
||||
@freezed
|
||||
sealed class DashboardSummary with _$DashboardSummary {
|
||||
const factory DashboardSummary({required List<Service> services, required NodeInfo node}) =
|
||||
_DashboardSummary;
|
||||
}
|
||||
@@ -0,0 +1,292 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// coverage:ignore-file
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
|
||||
|
||||
part of 'dashboard_summary.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$DashboardSummary {
|
||||
|
||||
List<Service> get services; NodeInfo get node;
|
||||
/// Create a copy of DashboardSummary
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$DashboardSummaryCopyWith<DashboardSummary> get copyWith => _$DashboardSummaryCopyWithImpl<DashboardSummary>(this as DashboardSummary, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is DashboardSummary&&const DeepCollectionEquality().equals(other.services, services)&&(identical(other.node, node) || other.node == node));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(services),node);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'DashboardSummary(services: $services, node: $node)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $DashboardSummaryCopyWith<$Res> {
|
||||
factory $DashboardSummaryCopyWith(DashboardSummary value, $Res Function(DashboardSummary) _then) = _$DashboardSummaryCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
List<Service> services, NodeInfo node
|
||||
});
|
||||
|
||||
|
||||
$NodeInfoCopyWith<$Res> get node;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$DashboardSummaryCopyWithImpl<$Res>
|
||||
implements $DashboardSummaryCopyWith<$Res> {
|
||||
_$DashboardSummaryCopyWithImpl(this._self, this._then);
|
||||
|
||||
final DashboardSummary _self;
|
||||
final $Res Function(DashboardSummary) _then;
|
||||
|
||||
/// Create a copy of DashboardSummary
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? services = null,Object? node = null,}) {
|
||||
return _then(_self.copyWith(
|
||||
services: null == services ? _self.services : services // ignore: cast_nullable_to_non_nullable
|
||||
as List<Service>,node: null == node ? _self.node : node // ignore: cast_nullable_to_non_nullable
|
||||
as NodeInfo,
|
||||
));
|
||||
}
|
||||
/// Create a copy of DashboardSummary
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$NodeInfoCopyWith<$Res> get node {
|
||||
|
||||
return $NodeInfoCopyWith<$Res>(_self.node, (value) {
|
||||
return _then(_self.copyWith(node: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [DashboardSummary].
|
||||
extension DashboardSummaryPatterns on DashboardSummary {
|
||||
/// A variant of `map` that fallback to returning `orElse`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _DashboardSummary value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _DashboardSummary() when $default != null:
|
||||
return $default(_that);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// Callbacks receives the raw object, upcasted.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case final Subclass2 value:
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _DashboardSummary value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _DashboardSummary():
|
||||
return $default(_that);}
|
||||
}
|
||||
/// A variant of `map` that fallback to returning `null`.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case final Subclass value:
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _DashboardSummary value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _DashboardSummary() when $default != null:
|
||||
return $default(_that);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
/// A variant of `when` that fallback to an `orElse` callback.
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return orElse();
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<Service> services, NodeInfo node)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _DashboardSummary() when $default != null:
|
||||
return $default(_that.services,_that.node);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
}
|
||||
/// A `switch`-like method, using callbacks.
|
||||
///
|
||||
/// As opposed to `map`, this offers destructuring.
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case Subclass2(:final field2):
|
||||
/// return ...;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<Service> services, NodeInfo node) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _DashboardSummary():
|
||||
return $default(_that.services,_that.node);}
|
||||
}
|
||||
/// A variant of `when` that fallback to returning `null`
|
||||
///
|
||||
/// It is equivalent to doing:
|
||||
/// ```dart
|
||||
/// switch (sealedClass) {
|
||||
/// case Subclass(:final field):
|
||||
/// return ...;
|
||||
/// case _:
|
||||
/// return null;
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<Service> services, NodeInfo node)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _DashboardSummary() when $default != null:
|
||||
return $default(_that.services,_that.node);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
|
||||
class _DashboardSummary implements DashboardSummary {
|
||||
const _DashboardSummary({required final List<Service> services, required this.node}): _services = services;
|
||||
|
||||
|
||||
final List<Service> _services;
|
||||
@override List<Service> get services {
|
||||
if (_services is EqualUnmodifiableListView) return _services;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_services);
|
||||
}
|
||||
|
||||
@override final NodeInfo node;
|
||||
|
||||
/// Create a copy of DashboardSummary
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$DashboardSummaryCopyWith<_DashboardSummary> get copyWith => __$DashboardSummaryCopyWithImpl<_DashboardSummary>(this, _$identity);
|
||||
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _DashboardSummary&&const DeepCollectionEquality().equals(other._services, _services)&&(identical(other.node, node) || other.node == node));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_services),node);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'DashboardSummary(services: $services, node: $node)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$DashboardSummaryCopyWith<$Res> implements $DashboardSummaryCopyWith<$Res> {
|
||||
factory _$DashboardSummaryCopyWith(_DashboardSummary value, $Res Function(_DashboardSummary) _then) = __$DashboardSummaryCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
List<Service> services, NodeInfo node
|
||||
});
|
||||
|
||||
|
||||
@override $NodeInfoCopyWith<$Res> get node;
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$DashboardSummaryCopyWithImpl<$Res>
|
||||
implements _$DashboardSummaryCopyWith<$Res> {
|
||||
__$DashboardSummaryCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _DashboardSummary _self;
|
||||
final $Res Function(_DashboardSummary) _then;
|
||||
|
||||
/// Create a copy of DashboardSummary
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? services = null,Object? node = null,}) {
|
||||
return _then(_DashboardSummary(
|
||||
services: null == services ? _self._services : services // ignore: cast_nullable_to_non_nullable
|
||||
as List<Service>,node: null == node ? _self.node : node // ignore: cast_nullable_to_non_nullable
|
||||
as NodeInfo,
|
||||
));
|
||||
}
|
||||
|
||||
/// Create a copy of DashboardSummary
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$NodeInfoCopyWith<$Res> get node {
|
||||
|
||||
return $NodeInfoCopyWith<$Res>(_self.node, (value) {
|
||||
return _then(_self.copyWith(node: value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// dart format on
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../../core/network/api_exception.dart';
|
||||
import '../../../core/polling/polling_async_notifier.dart';
|
||||
import '../../../data/repositories/node_repository.dart';
|
||||
import '../../../data/repositories/services_repository.dart';
|
||||
import 'dashboard_summary.dart';
|
||||
|
||||
part 'dashboard_summary_provider.g.dart';
|
||||
|
||||
/// Polled every 20s while the Dashboard is mounted — deliberately its own
|
||||
/// notifier rather than watching `servicesListProvider`/`currentNodeProvider`
|
||||
/// directly, so Dashboard auto-refreshes independent of whether the
|
||||
/// Services screen (manual-refresh only) happens to be open too.
|
||||
@riverpod
|
||||
class DashboardSummaryNotifier extends _$DashboardSummaryNotifier
|
||||
with PollingMixin<DashboardSummary> {
|
||||
@override
|
||||
Duration get interval => const Duration(seconds: 20);
|
||||
|
||||
@override
|
||||
Future<DashboardSummary> fetch() async {
|
||||
final servicesRepo = ref.watch(servicesRepositoryProvider);
|
||||
final nodeRepo = ref.watch(nodeRepositoryProvider);
|
||||
if (servicesRepo == null || nodeRepo == null) {
|
||||
// The router redirects to Settings whenever there's no active
|
||||
// connection, so reaching this in the UI would mean that redirect
|
||||
// hasn't fired yet — an ApiException here (vs. a raw StateError)
|
||||
// keeps error handling on the same path as every other screen.
|
||||
throw const ApiException.unknown('No active connection.');
|
||||
}
|
||||
final services = await servicesRepo.getAll();
|
||||
final node = await nodeRepo.getNode();
|
||||
return DashboardSummary(services: services, node: node);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DashboardSummary> build() => startPolling();
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'dashboard_summary_provider.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RiverpodGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
// ignore_for_file: type=lint, type=warning
|
||||
/// Polled every 20s while the Dashboard is mounted — deliberately its own
|
||||
/// notifier rather than watching `servicesListProvider`/`currentNodeProvider`
|
||||
/// directly, so Dashboard auto-refreshes independent of whether the
|
||||
/// Services screen (manual-refresh only) happens to be open too.
|
||||
|
||||
@ProviderFor(DashboardSummaryNotifier)
|
||||
const dashboardSummaryProvider = DashboardSummaryNotifierProvider._();
|
||||
|
||||
/// Polled every 20s while the Dashboard is mounted — deliberately its own
|
||||
/// notifier rather than watching `servicesListProvider`/`currentNodeProvider`
|
||||
/// directly, so Dashboard auto-refreshes independent of whether the
|
||||
/// Services screen (manual-refresh only) happens to be open too.
|
||||
final class DashboardSummaryNotifierProvider
|
||||
extends $AsyncNotifierProvider<DashboardSummaryNotifier, DashboardSummary> {
|
||||
/// Polled every 20s while the Dashboard is mounted — deliberately its own
|
||||
/// notifier rather than watching `servicesListProvider`/`currentNodeProvider`
|
||||
/// directly, so Dashboard auto-refreshes independent of whether the
|
||||
/// Services screen (manual-refresh only) happens to be open too.
|
||||
const DashboardSummaryNotifierProvider._()
|
||||
: super(
|
||||
from: null,
|
||||
argument: null,
|
||||
retry: null,
|
||||
name: r'dashboardSummaryProvider',
|
||||
isAutoDispose: true,
|
||||
dependencies: null,
|
||||
$allTransitiveDependencies: null,
|
||||
);
|
||||
|
||||
@override
|
||||
String debugGetCreateSourceHash() => _$dashboardSummaryNotifierHash();
|
||||
|
||||
@$internal
|
||||
@override
|
||||
DashboardSummaryNotifier create() => DashboardSummaryNotifier();
|
||||
}
|
||||
|
||||
String _$dashboardSummaryNotifierHash() =>
|
||||
r'807d0df3c8b7ce9652ae56fdba542b108aa99456';
|
||||
|
||||
/// Polled every 20s while the Dashboard is mounted — deliberately its own
|
||||
/// notifier rather than watching `servicesListProvider`/`currentNodeProvider`
|
||||
/// directly, so Dashboard auto-refreshes independent of whether the
|
||||
/// Services screen (manual-refresh only) happens to be open too.
|
||||
|
||||
abstract class _$DashboardSummaryNotifier
|
||||
extends $AsyncNotifier<DashboardSummary> {
|
||||
FutureOr<DashboardSummary> build();
|
||||
@$mustCallSuper
|
||||
@override
|
||||
void runBuild() {
|
||||
final created = build();
|
||||
final ref =
|
||||
this.ref as $Ref<AsyncValue<DashboardSummary>, DashboardSummary>;
|
||||
final element =
|
||||
ref.element
|
||||
as $ClassProviderElement<
|
||||
AnyNotifier<AsyncValue<DashboardSummary>, DashboardSummary>,
|
||||
AsyncValue<DashboardSummary>,
|
||||
Object?,
|
||||
Object?
|
||||
>;
|
||||
element.handleValue(ref, created);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/models/models.dart';
|
||||
import '../../../core/models/severity_mapping.dart';
|
||||
import '../../../core/theme/status_colors.dart';
|
||||
import '../../../core/theme/theme_x.dart';
|
||||
import '../../../core/utils/relative_time.dart';
|
||||
import '../../../core/widgets/empty_state.dart';
|
||||
|
||||
class _FeedEntry {
|
||||
const _FeedEntry({
|
||||
required this.timestamp,
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
required this.severity,
|
||||
required this.icon,
|
||||
});
|
||||
|
||||
final DateTime timestamp;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
final Severity severity;
|
||||
final IconData icon;
|
||||
}
|
||||
|
||||
/// Merges backup executions and OS update records from [NodeInfo] into one
|
||||
/// reverse-chronological feed. There's no persisted scan-result log on the
|
||||
/// server to fold in here — only these two histories actually exist.
|
||||
class ActivityFeed extends StatelessWidget {
|
||||
const ActivityFeed({super.key, required this.node, this.maxEntries = 6});
|
||||
|
||||
final NodeInfo node;
|
||||
final int maxEntries;
|
||||
|
||||
List<_FeedEntry> _buildEntries() {
|
||||
final entries = <_FeedEntry>[
|
||||
for (final execution in node.backup.history)
|
||||
_FeedEntry(
|
||||
timestamp: execution.timestamp,
|
||||
title: execution.success ? 'Backup completed' : 'Backup failed',
|
||||
subtitle: execution.message.isEmpty
|
||||
? '${execution.durationSeconds}s'
|
||||
: execution.message,
|
||||
severity: severityForSuccess(execution.success),
|
||||
icon: Icons.cloud_outlined,
|
||||
),
|
||||
for (final update in node.updateHistory)
|
||||
_FeedEntry(
|
||||
timestamp: update.timestamp,
|
||||
title: update.success ? 'System update applied' : 'System update failed',
|
||||
subtitle: update.packages.isEmpty
|
||||
? update.message
|
||||
: '${update.packages.length} package(s)${update.message.isEmpty ? '' : ' · ${update.message}'}',
|
||||
severity: severityForSuccess(update.success),
|
||||
icon: Icons.history_rounded,
|
||||
),
|
||||
]..sort((a, b) => b.timestamp.compareTo(a.timestamp));
|
||||
|
||||
return entries.take(maxEntries).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final entries = _buildEntries();
|
||||
|
||||
if (entries.isEmpty) {
|
||||
return const EmptyState(
|
||||
icon: Icons.history_rounded,
|
||||
title: 'No activity yet',
|
||||
message: 'Backup runs and system updates will show up here.',
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
for (var i = 0; i < entries.length; i++) ...[
|
||||
if (i > 0) const Divider(height: 1),
|
||||
_FeedRow(entry: entries[i]),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FeedRow extends StatelessWidget {
|
||||
const _FeedRow({required this.entry});
|
||||
|
||||
final _FeedEntry entry;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final color = entry.severity.resolve(context.status, muted: context.colors.outline);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 11),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
width: 26,
|
||||
height: 26,
|
||||
decoration: BoxDecoration(
|
||||
color: Color.alphaBlend(color.withValues(alpha: 0.14), context.colors.surface),
|
||||
borderRadius: BorderRadius.circular(7),
|
||||
),
|
||||
child: Icon(entry.icon, size: 14, color: color),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(entry.title, style: context.text.labelLarge),
|
||||
Text(
|
||||
entry.subtitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: context.text.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
formatRelative(entry.timestamp),
|
||||
style: context.dataStyles.numericTabular.copyWith(fontSize: 12, color: context.colors.outline),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../../core/network/api_exception.dart';
|
||||
import '../../../data/repositories/node_repository.dart';
|
||||
import '../../../data/repositories/nodes_repository.dart';
|
||||
import '../providers/dashboard_summary_provider.dart';
|
||||
|
||||
class QuickActionsRow extends ConsumerStatefulWidget {
|
||||
const QuickActionsRow({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<QuickActionsRow> createState() => _QuickActionsRowState();
|
||||
}
|
||||
|
||||
class _QuickActionsRowState extends ConsumerState<QuickActionsRow> {
|
||||
bool _busy = false;
|
||||
|
||||
Future<void> _guarded(Future<String> Function() action) async {
|
||||
setState(() => _busy = true);
|
||||
try {
|
||||
final message = await action();
|
||||
if (mounted) ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
} catch (e) {
|
||||
final message = e is ApiException ? e.userMessage : e.toString();
|
||||
if (mounted) ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
} finally {
|
||||
if (mounted) setState(() => _busy = false);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _scan() => _guarded(() async {
|
||||
final repo = ref.read(nodeRepositoryProvider);
|
||||
if (repo == null) throw StateError('No active connection.');
|
||||
final result = await repo.scan();
|
||||
await ref.read(dashboardSummaryProvider.notifier).refresh();
|
||||
final changed = result.created.length + result.updated.length;
|
||||
return changed == 0
|
||||
? 'Scan complete — no changes (${result.found} compose file(s) found)'
|
||||
: 'Scan complete — ${result.created.length} new, ${result.updated.length} updated';
|
||||
});
|
||||
|
||||
Future<void> _runBackup() => _guarded(() async {
|
||||
final repo = ref.read(nodeRepositoryProvider);
|
||||
if (repo == null) throw StateError('No active connection.');
|
||||
await repo.runBackup();
|
||||
await ref.read(dashboardSummaryProvider.notifier).refresh();
|
||||
return 'Backup started';
|
||||
});
|
||||
|
||||
Future<void> _recheckFleet() => _guarded(() async {
|
||||
await ref.read(aggregatedNodesProvider.notifier).refresh();
|
||||
return 'Fleet status refreshed';
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children: [
|
||||
FilledButton.icon(
|
||||
onPressed: _busy ? null : _scan,
|
||||
icon: const Icon(Icons.search_rounded, size: 17),
|
||||
label: const Text('Scan for services'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: _busy ? null : _runBackup,
|
||||
icon: const Icon(Icons.cloud_outlined, size: 17),
|
||||
label: const Text('Run backup now'),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: _busy ? null : _recheckFleet,
|
||||
icon: const Icon(Icons.refresh_rounded, size: 17),
|
||||
label: const Text('Re-check fleet'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user