add filter by network for legs, add full export for traction
All checks were successful
Release / meta (push) Successful in 1m45s
Release / linux-build (push) Successful in 1m48s
Release / web-build (push) Successful in 1m56s
Release / android-build (push) Successful in 7m33s
Release / release-dev (push) Successful in 30s
Release / release-master (push) Successful in 5s
All checks were successful
Release / meta (push) Successful in 1m45s
Release / linux-build (push) Successful in 1m48s
Release / web-build (push) Successful in 1m56s
Release / android-build (push) Successful in 7m33s
Release / release-dev (push) Successful in 30s
Release / release-master (push) Successful in 5s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
part of 'traction.dart';
|
||||
|
||||
enum _TractionMoreAction {
|
||||
exportResults,
|
||||
classStats,
|
||||
classLeaderboard,
|
||||
adminPending,
|
||||
@@ -68,14 +69,14 @@ class _TractionPageState extends State<TractionPage> {
|
||||
_ClassLeaderboardScope _classLeaderboardScope = _ClassLeaderboardScope.global;
|
||||
|
||||
final Map<String, TextEditingController> _dynamicControllers = {};
|
||||
final Map<String, String?> _enumSelections = {};
|
||||
final Map<String, dynamic> _enumSelections = {};
|
||||
bool _restoredFromPrefs = false;
|
||||
static const int _pageSize = 100;
|
||||
int _lastTractionOffset = 0;
|
||||
String? _lastQuerySignature;
|
||||
String? _transferFromLabel;
|
||||
bool _isSearching = false;
|
||||
bool _classExporting = false;
|
||||
bool _exporting = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -169,12 +170,7 @@ class _TractionPageState extends State<TractionPage> {
|
||||
].join(';');
|
||||
}
|
||||
|
||||
Future<void> _refreshTraction({
|
||||
bool append = false,
|
||||
bool preservePosition = true,
|
||||
}) async {
|
||||
_setState(() => _isSearching = true);
|
||||
final data = context.read<DataService>();
|
||||
Map<String, dynamic> _buildTractionFilters() {
|
||||
final filters = <String, dynamic>{};
|
||||
final name = _nameController.text.trim();
|
||||
if (name.isNotEmpty) filters['name'] = name;
|
||||
@@ -187,6 +183,16 @@ class _TractionPageState extends State<TractionPage> {
|
||||
filters[key] = value;
|
||||
}
|
||||
});
|
||||
return filters;
|
||||
}
|
||||
|
||||
Future<void> _refreshTraction({
|
||||
bool append = false,
|
||||
bool preservePosition = true,
|
||||
}) async {
|
||||
_setState(() => _isSearching = true);
|
||||
final data = context.read<DataService>();
|
||||
final filters = _buildTractionFilters();
|
||||
final hadOnly = !_hasFilters;
|
||||
final signature = _tractionQuerySignature(filters, hadOnly);
|
||||
final queryChanged =
|
||||
@@ -673,23 +679,6 @@ class _TractionPageState extends State<TractionPage> {
|
||||
);
|
||||
|
||||
final hasClassActions = _hasClassQuery;
|
||||
final classLabel = _currentClassLabel;
|
||||
|
||||
final exportClassButton = !hasClassActions
|
||||
? null
|
||||
: FilledButton.tonalIcon(
|
||||
onPressed: _classExporting ? null : _exportSelectedClass,
|
||||
icon: _classExporting
|
||||
? const SizedBox(
|
||||
height: 16,
|
||||
width: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.download),
|
||||
label: Text(
|
||||
_classExporting ? 'Exporting...' : 'Export $classLabel',
|
||||
),
|
||||
);
|
||||
|
||||
final newTractionButton = FilledButton.icon(
|
||||
onPressed: () async {
|
||||
@@ -710,7 +699,7 @@ class _TractionPageState extends State<TractionPage> {
|
||||
);
|
||||
|
||||
final hasAdminActions = isElevated;
|
||||
final hasMoreMenu = hasClassActions || hasAdminActions;
|
||||
final hasMoreMenu = true;
|
||||
|
||||
final moreButton = !hasMoreMenu
|
||||
? null
|
||||
@@ -718,6 +707,9 @@ class _TractionPageState extends State<TractionPage> {
|
||||
tooltip: 'More options',
|
||||
onSelected: (action) async {
|
||||
switch (action) {
|
||||
case _TractionMoreAction.exportResults:
|
||||
await _exportTractionResults();
|
||||
break;
|
||||
case _TractionMoreAction.classStats:
|
||||
_toggleClassStatsPanel();
|
||||
break;
|
||||
@@ -759,6 +751,25 @@ class _TractionPageState extends State<TractionPage> {
|
||||
},
|
||||
itemBuilder: (context) {
|
||||
final items = <PopupMenuEntry<_TractionMoreAction>>[];
|
||||
items.add(
|
||||
PopupMenuItem(
|
||||
value: _TractionMoreAction.exportResults,
|
||||
child: Row(
|
||||
children: [
|
||||
if (_exporting)
|
||||
const SizedBox(
|
||||
height: 16,
|
||||
width: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
else
|
||||
const Icon(Icons.download, size: 18),
|
||||
const SizedBox(width: 8),
|
||||
Text(_exporting ? 'Exporting...' : 'Export'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
if (hasClassActions) {
|
||||
items.add(
|
||||
PopupMenuItem(
|
||||
@@ -847,14 +858,12 @@ class _TractionPageState extends State<TractionPage> {
|
||||
|
||||
final desktopActions = [
|
||||
refreshButton,
|
||||
if (exportClassButton != null) exportClassButton,
|
||||
newTractionButton,
|
||||
if (moreButton != null) moreButton,
|
||||
];
|
||||
|
||||
final mobileActions = [
|
||||
if (moreButton != null) moreButton,
|
||||
if (exportClassButton != null) exportClassButton,
|
||||
newTractionButton,
|
||||
refreshButton,
|
||||
];
|
||||
@@ -882,23 +891,36 @@ class _TractionPageState extends State<TractionPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _exportSelectedClass() async {
|
||||
if (_classExporting) return;
|
||||
final classLabel = _currentClassLabel;
|
||||
if (classLabel.isEmpty) return;
|
||||
setState(() => _classExporting = true);
|
||||
Future<void> _exportTractionResults() async {
|
||||
if (_exporting) return;
|
||||
setState(() => _exporting = true);
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
try {
|
||||
final data = context.read<DataService>();
|
||||
final encodedClass = Uri.encodeComponent(classLabel);
|
||||
final response = await data.api.getBytes(
|
||||
'/loco/class/export/$encodedClass',
|
||||
final filters = _buildTractionFilters();
|
||||
final hadOnly = !_hasFilters;
|
||||
final limit = data.traction.length;
|
||||
final params = StringBuffer('?limit=$limit&offset=0');
|
||||
if (hadOnly) params.write('&had_only=true');
|
||||
if (!_mileageFirst) params.write('&mileage_first=false');
|
||||
|
||||
final payload = <String, dynamic>{};
|
||||
final classLabel = (_selectedClass ?? _classController.text).trim();
|
||||
if (classLabel.isNotEmpty) payload['class'] = classLabel;
|
||||
final numberLabel = _numberController.text.trim();
|
||||
if (numberLabel.isNotEmpty) payload['number'] = numberLabel;
|
||||
filters.forEach((key, value) {
|
||||
if (value == null) return;
|
||||
if (value is String && value.trim().isEmpty) return;
|
||||
payload[key] = value;
|
||||
});
|
||||
|
||||
final response = await data.api.postBytes(
|
||||
'/locos/search/v2/export${params.toString()}',
|
||||
payload.isEmpty ? null : payload,
|
||||
headers: const {'accept': '*/*'},
|
||||
);
|
||||
final safeClassName =
|
||||
classLabel.replaceAll(RegExp(r'[^a-zA-Z0-9-_]+'), '_');
|
||||
final fallbackName = 'traction-${safeClassName.isEmpty ? 'class' : safeClassName}.xlsx';
|
||||
final filename = response.filename ?? fallbackName;
|
||||
final filename = response.filename ?? 'traction-export.xlsx';
|
||||
final saveResult = await saveBytes(
|
||||
Uint8List.fromList(response.bytes),
|
||||
filename,
|
||||
@@ -932,7 +954,7 @@ class _TractionPageState extends State<TractionPage> {
|
||||
SnackBar(content: Text('Export failed: $e')),
|
||||
);
|
||||
} finally {
|
||||
if (mounted) setState(() => _classExporting = false);
|
||||
if (mounted) setState(() => _exporting = false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1847,13 +1869,44 @@ class _TractionPageState extends State<TractionPage> {
|
||||
bool isMobile,
|
||||
) {
|
||||
final width = isMobile ? double.infinity : 220.0;
|
||||
final type = field.type?.toLowerCase() ?? '';
|
||||
final isBooleanField =
|
||||
type == 'bool' || type == 'boolean' || type.contains('bool');
|
||||
if (isBooleanField) {
|
||||
final currentValue = _enumSelections[field.name];
|
||||
final safeValue = currentValue is bool ? currentValue : null;
|
||||
return SizedBox(
|
||||
width: width,
|
||||
child: DropdownButtonFormField<bool?>(
|
||||
value: safeValue,
|
||||
decoration: InputDecoration(
|
||||
labelText: field.display,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
items: const [
|
||||
DropdownMenuItem(value: null, child: Text('Any')),
|
||||
DropdownMenuItem(value: true, child: Text('Yes')),
|
||||
DropdownMenuItem(value: false, child: Text('No')),
|
||||
],
|
||||
onChanged: (val) {
|
||||
setState(() {
|
||||
_enumSelections[field.name] = val;
|
||||
});
|
||||
_refreshTraction();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
if (field.enumValues != null && field.enumValues!.isNotEmpty) {
|
||||
final options = field.enumValues!
|
||||
.map((e) => e.toString())
|
||||
.toSet()
|
||||
.toList();
|
||||
final currentValue = _enumSelections[field.name];
|
||||
final safeValue = options.contains(currentValue) ? currentValue : null;
|
||||
final safeValue =
|
||||
currentValue is String && options.contains(currentValue)
|
||||
? currentValue
|
||||
: null;
|
||||
return SizedBox(
|
||||
width: width,
|
||||
child: DropdownButtonFormField<String?>(
|
||||
@@ -1883,7 +1936,6 @@ class _TractionPageState extends State<TractionPage> {
|
||||
_dynamicControllers[field.name] = controller;
|
||||
TextInputType? inputType;
|
||||
if (field.type != null) {
|
||||
final type = field.type!.toLowerCase();
|
||||
if (type.contains('int') ||
|
||||
type.contains('num') ||
|
||||
type.contains('double')) {
|
||||
|
||||
Reference in New Issue
Block a user