Enhance schedule management; implement recurring schedules retrieval, update TimetableViewer to display summary, and improve schedule loading logic

This commit is contained in:
Sven laptop
2026-05-13 18:15:08 +02:00
parent 1e41c05214
commit 6e62a9cac1
4 changed files with 184 additions and 8 deletions
@@ -24,10 +24,7 @@ class _RecurringSchedulesScreenState extends State<RecurringSchedulesScreen> {
}
void _loadRecurringSchedules() {
// Load schedules from a reference date, then filter for recurring ones
_schedulesFuture = _scheduleService.getSchedules(DateTime.now()).then((schedules) {
return schedules.where((s) => s.isRecurring).toList();
});
_schedulesFuture = _scheduleService.getRecurringSchedules();
}
String _formatWeekdays(List<int> weekdays) {
@@ -38,6 +38,31 @@ class ScheduleService {
}
}
/// Get all recurring schedule templates, independent of a specific date.
Future<List<ServiceSchedule>> getRecurringSchedules({int? lineId}) async {
try {
final queryParameters = <String, String>{};
if (lineId != null) {
queryParameters['lineId'] = lineId.toString();
}
final uri = Uri.parse('$_apiBaseUrl/schedules/recurring').replace(queryParameters: queryParameters);
final response = await http.get(uri);
if (response.statusCode == 200) {
final data = jsonDecode(response.body) as Map<String, dynamic>;
return (data['schedules'] as List? ?? [])
.map((schedule) => schedule as Map<String, dynamic>)
.map(ServiceSchedule.fromJson)
.toList();
}
throw Exception('Failed to load recurring schedules: ${response.statusCode}');
} catch (e) {
throw Exception('Recurring schedule error: $e');
}
}
/// Get stop list for a specific schedule.
Future<List<ScheduleStop>> getScheduleStops(int scheduleId) async {
try {