diff --git a/lib/components/traction/traction_card.dart b/lib/components/traction/traction_card.dart index cf16f51..c3c8996 100644 --- a/lib/components/traction/traction_card.dart +++ b/lib/components/traction/traction_card.dart @@ -744,57 +744,92 @@ Future showTractionDetails( ); }, ), - if (auth.isElevated || canDeleteAsOwner) ...[ - const SizedBox(height: 16), - FilledButton.tonal( - style: FilledButton.styleFrom( - backgroundColor: - Theme.of(context).colorScheme.errorContainer, - foregroundColor: - Theme.of(context).colorScheme.onErrorContainer, - ), - onPressed: () async { - final confirmed = await showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: const Text('Delete loco?'), - content: const Text( - 'This will permanently delete this loco. Are you sure?', - ), - actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(false), - child: const Text('Cancel'), - ), - FilledButton( - onPressed: () => Navigator.of(context).pop(true), - style: FilledButton.styleFrom( - backgroundColor: - Theme.of(context).colorScheme.error, - ), - child: const Text('Delete'), - ), - ], - ); + const SizedBox(height: 16), + FilledButton.icon( + onPressed: () { + Navigator.of(ctx).pop(); + navContext.push( + Uri( + path: '/traction', + queryParameters: { + 'selection': 'single', + 'transferFromLocoId': loco.id.toString(), }, - ); - if (confirmed != true) return; - try { - await data.adminDeleteLoco(locoId: loco.id); - messenger.showSnackBar( - const SnackBar(content: Text('Loco deleted')), - ); - await onActionComplete?.call(); - if (!context.mounted) return; - Navigator.of(ctx).pop(); - } catch (e) { - messenger.showSnackBar( - SnackBar(content: Text('Failed to delete loco: $e')), - ); - } - }, - child: const Text('Delete loco'), + ).toString(), + extra: { + 'selection': 'single', + 'transferFromLocoId': loco.id, + }, + ); + }, + icon: const Icon(Icons.swap_horiz), + label: const Text('Transfer allocations'), + ), + if (auth.isElevated || canDeleteAsOwner) ...[ + const SizedBox(height: 8), + ExpansionTile( + tilePadding: EdgeInsets.zero, + childrenPadding: EdgeInsets.zero, + title: Text( + 'More', + style: Theme.of(context).textTheme.titleSmall, + ), + children: [ + FilledButton.tonal( + style: FilledButton.styleFrom( + backgroundColor: + Theme.of(context).colorScheme.errorContainer, + foregroundColor: + Theme.of(context).colorScheme.onErrorContainer, + ), + onPressed: () async { + final confirmed = await showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: const Text('Delete loco?'), + content: const Text( + 'This will permanently delete this loco. Are you sure?', + ), + actions: [ + TextButton( + onPressed: () => + Navigator.of(context).pop(false), + child: const Text('Cancel'), + ), + FilledButton( + onPressed: () => + Navigator.of(context).pop(true), + style: FilledButton.styleFrom( + backgroundColor: + Theme.of(context).colorScheme.error, + ), + child: const Text('Delete'), + ), + ], + ); + }, + ); + if (confirmed != true) return; + try { + await data.adminDeleteLoco(locoId: loco.id); + messenger.showSnackBar( + const SnackBar(content: Text('Loco deleted')), + ); + await onActionComplete?.call(); + if (!context.mounted) return; + Navigator.of(ctx).pop(); + } catch (e) { + messenger.showSnackBar( + SnackBar( + content: Text('Failed to delete loco: $e')), + ); + } + }, + child: const Text('Delete loco'), + ), + const SizedBox(height: 8), + ], ), ], ], diff --git a/lib/services/data_service/data_service_traction.dart b/lib/services/data_service/data_service_traction.dart index b80c0f8..78ef0ed 100644 --- a/lib/services/data_service/data_service_traction.dart +++ b/lib/services/data_service/data_service_traction.dart @@ -472,7 +472,7 @@ extension DataServiceTraction on DataService { }) async { try { await api.post('/loco/alloc/transfer', { - 'loco_id': fromLocoId, + 'from_loco_id': fromLocoId, 'to_loco_id': toLocoId, }); } catch (e) {