Fix transfer functoin, add display for numer of pending locos
All checks were successful
Release / meta (push) Successful in 12s
Release / linux-build (push) Successful in 1m10s
Release / web-build (push) Successful in 1m19s
Release / android-build (push) Successful in 9m2s
Release / release-master (push) Successful in 17s
Release / release-dev (push) Successful in 19s
All checks were successful
Release / meta (push) Successful in 12s
Release / linux-build (push) Successful in 1m10s
Release / web-build (push) Successful in 1m19s
Release / android-build (push) Successful in 9m2s
Release / release-master (push) Successful in 17s
Release / release-dev (push) Successful in 19s
This commit is contained in:
@@ -12,6 +12,7 @@ class TractionPage extends StatefulWidget {
|
||||
this.selectionMode = false,
|
||||
this.selectionSingle = false,
|
||||
this.replacementPendingLocoId,
|
||||
this.transferFromLabel,
|
||||
this.transferFromLocoId,
|
||||
this.onSelect,
|
||||
this.selectedKeys = const {},
|
||||
@@ -20,6 +21,7 @@ class TractionPage extends StatefulWidget {
|
||||
final bool selectionMode;
|
||||
final bool selectionSingle;
|
||||
final int? replacementPendingLocoId;
|
||||
final String? transferFromLabel;
|
||||
final int? transferFromLocoId;
|
||||
final ValueChanged<LocoSummary>? onSelect;
|
||||
final Set<String> selectedKeys;
|
||||
@@ -61,6 +63,8 @@ class _TractionPageState extends State<TractionPage> {
|
||||
static const int _pageSize = 100;
|
||||
int _lastTractionOffset = 0;
|
||||
String? _lastQuerySignature;
|
||||
String? _transferFromLabel;
|
||||
bool _isSearching = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -74,6 +78,7 @@ class _TractionPageState extends State<TractionPage> {
|
||||
if (!_initialised) {
|
||||
_initialised = true;
|
||||
_selectedKeys = {...widget.selectedKeys};
|
||||
_transferFromLabel = widget.transferFromLabel;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_initialLoad();
|
||||
});
|
||||
@@ -82,12 +87,16 @@ class _TractionPageState extends State<TractionPage> {
|
||||
|
||||
Future<void> _initialLoad() async {
|
||||
final data = context.read<DataService>();
|
||||
final auth = context.read<AuthService>();
|
||||
await _restoreSearchState();
|
||||
if (_lastTractionOffset == 0 && data.traction.length > _pageSize) {
|
||||
_lastTractionOffset = data.traction.length - _pageSize;
|
||||
}
|
||||
data.fetchClassList();
|
||||
data.fetchEventFields();
|
||||
if (auth.isElevated) {
|
||||
unawaited(data.fetchPendingLocoCount());
|
||||
}
|
||||
await _refreshTraction();
|
||||
}
|
||||
|
||||
@@ -153,6 +162,7 @@ class _TractionPageState extends State<TractionPage> {
|
||||
bool append = false,
|
||||
bool preservePosition = true,
|
||||
}) async {
|
||||
_setState(() => _isSearching = true);
|
||||
final data = context.read<DataService>();
|
||||
final filters = <String, dynamic>{};
|
||||
final name = _nameController.text.trim();
|
||||
@@ -211,6 +221,7 @@ class _TractionPageState extends State<TractionPage> {
|
||||
}
|
||||
|
||||
await _persistSearchState();
|
||||
_setState(() => _isSearching = false);
|
||||
}
|
||||
|
||||
void _clearFilters() {
|
||||
@@ -309,6 +320,7 @@ class _TractionPageState extends State<TractionPage> {
|
||||
final isMobile = MediaQuery.of(context).size.width < 700;
|
||||
_syncControllersForFields(data.eventFields);
|
||||
final extraFields = _activeEventFields(data.eventFields);
|
||||
final transferBanner = _buildTransferBanner(data);
|
||||
|
||||
final slivers = <Widget>[
|
||||
SliverPadding(
|
||||
@@ -338,6 +350,10 @@ class _TractionPageState extends State<TractionPage> {
|
||||
_buildHeaderActions(context, isMobile),
|
||||
],
|
||||
),
|
||||
if (transferBanner != null) ...[
|
||||
const SizedBox(height: 8),
|
||||
transferBanner,
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
Card(
|
||||
child: Padding(
|
||||
@@ -487,8 +503,25 @@ class _TractionPageState extends State<TractionPage> {
|
||||
),
|
||||
ElevatedButton.icon(
|
||||
onPressed: _refreshTraction,
|
||||
icon: const Icon(Icons.search),
|
||||
label: const Text('Search'),
|
||||
icon: (_isSearching || data.isTractionLoading)
|
||||
? SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimary,
|
||||
),
|
||||
),
|
||||
)
|
||||
: const Icon(Icons.search),
|
||||
label: Text(
|
||||
(_isSearching || data.isTractionLoading)
|
||||
? 'Searching...'
|
||||
: 'Search',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -613,6 +646,12 @@ class _TractionPageState extends State<TractionPage> {
|
||||
|
||||
Widget _buildHeaderActions(BuildContext context, bool isMobile) {
|
||||
final isElevated = context.read<AuthService>().isElevated;
|
||||
final data = context.watch<DataService>();
|
||||
final pendingCount = data.pendingLocoCount;
|
||||
String? pendingLabel;
|
||||
if (pendingCount > 0) {
|
||||
pendingLabel = pendingCount > 999 ? '999+' : pendingCount.toString();
|
||||
}
|
||||
final refreshButton = IconButton(
|
||||
tooltip: 'Refresh',
|
||||
onPressed: _refreshTraction,
|
||||
@@ -659,6 +698,7 @@ class _TractionPageState extends State<TractionPage> {
|
||||
try {
|
||||
await context.push('/traction/pending');
|
||||
if (!mounted) return;
|
||||
await data.fetchPendingLocoCount();
|
||||
} catch (_) {
|
||||
if (!mounted) return;
|
||||
messenger.showSnackBar(
|
||||
@@ -693,9 +733,16 @@ class _TractionPageState extends State<TractionPage> {
|
||||
}
|
||||
if (hasAdminActions) {
|
||||
items.add(
|
||||
const PopupMenuItem(
|
||||
PopupMenuItem(
|
||||
value: _TractionMoreAction.adminPending,
|
||||
child: Text('Pending locos'),
|
||||
child: Row(
|
||||
children: [
|
||||
const Text('Pending locos'),
|
||||
const Spacer(),
|
||||
if (pendingLabel != null)
|
||||
_countChip(context, pendingLabel),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -705,7 +752,16 @@ class _TractionPageState extends State<TractionPage> {
|
||||
child: FilledButton.tonalIcon(
|
||||
onPressed: () {},
|
||||
icon: const Icon(Icons.more_horiz),
|
||||
label: const Text('More'),
|
||||
label: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('More'),
|
||||
if (pendingLabel != null) ...[
|
||||
const SizedBox(width: 6),
|
||||
_countChip(context, pendingLabel),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -1208,13 +1264,35 @@ class _TractionPageState extends State<TractionPage> {
|
||||
if (fromId == null) return;
|
||||
final navContext = context;
|
||||
final messenger = ScaffoldMessenger.of(navContext);
|
||||
final data = navContext.read<DataService>();
|
||||
final fromLoco = data.traction.firstWhere(
|
||||
(l) => l.id == fromId,
|
||||
orElse: () => target,
|
||||
);
|
||||
final fromLabel = '${fromLoco.locoClass} ${fromLoco.number}'.trim();
|
||||
final toLabel = '${target.locoClass} ${target.number}'.trim();
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: navContext,
|
||||
builder: (dialogContext) {
|
||||
return AlertDialog(
|
||||
title: const Text('Transfer allocations?'),
|
||||
content: Text(
|
||||
'Transfer all allocations from this loco to ${target.locoClass} ${target.number}?',
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Transfer all allocations from $fromLabel to $toLabel?',
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'From: $fromLabel',
|
||||
style: Theme.of(dialogContext)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(fontWeight: FontWeight.w700),
|
||||
),
|
||||
Text('To: $toLabel'),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -1273,6 +1351,69 @@ class _TractionPageState extends State<TractionPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget? _buildTransferBanner(DataService data) {
|
||||
final fromId = _transferFromLocoId;
|
||||
if (fromId == null) return null;
|
||||
if (_transferFromLabel == null || _transferFromLabel!.trim().isEmpty) {
|
||||
final from = data.traction.firstWhere(
|
||||
(loco) => loco.id == fromId,
|
||||
orElse: () => LocoSummary(
|
||||
locoId: fromId,
|
||||
locoType: '',
|
||||
locoNumber: '',
|
||||
locoName: '',
|
||||
locoClass: '',
|
||||
locoOperator: '',
|
||||
),
|
||||
);
|
||||
final fallbackLabel = '${from.locoClass} ${from.number}'.trim().isEmpty
|
||||
? 'Loco $fromId'
|
||||
: '${from.locoClass} ${from.number}'.trim();
|
||||
_transferFromLabel = fallbackLabel;
|
||||
}
|
||||
final label = _transferFromLabel ?? 'Loco $fromId';
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.orange.withValues(alpha: 0.4)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.swap_horiz, color: Colors.orange),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Transferring allocations from $label. Select a loco to transfer to.',
|
||||
style: const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _countChip(BuildContext context, String label) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.primary,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
color: scheme.onPrimary,
|
||||
fontWeight: FontWeight.w700,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFilterInput(
|
||||
BuildContext context,
|
||||
EventField field,
|
||||
@@ -1395,12 +1536,16 @@ class _TractionPageState extends State<TractionPage> {
|
||||
onOpenLegs: () => _openLegs(loco),
|
||||
onActionComplete: _refreshTraction,
|
||||
onToggleSelect: widget.selectionMode &&
|
||||
widget.replacementPendingLocoId == null
|
||||
widget.replacementPendingLocoId == null &&
|
||||
(widget.transferFromLocoId == null ||
|
||||
widget.transferFromLocoId != loco.id)
|
||||
? () => _toggleSelection(loco)
|
||||
: null,
|
||||
onReplacePending: widget.selectionMode &&
|
||||
widget.selectionSingle &&
|
||||
widget.replacementPendingLocoId != null
|
||||
widget.replacementPendingLocoId != null &&
|
||||
(widget.transferFromLocoId == null ||
|
||||
widget.transferFromLocoId != loco.id)
|
||||
? () => _confirmReplacePending(loco)
|
||||
: null,
|
||||
onTransferAllocations: widget.selectionMode &&
|
||||
|
||||
Reference in New Issue
Block a user