Vervollstaendigt Doku 3.5/3.6/7.1/7.3/7.5: ein Vollbild-Verwaltungsmenue fuer Missionen und Drohnenprofile (per Tabs umschaltbar, wie im HTML- Demonstrator #missionsPanel gemeinsam mit der Profilliste), Autosave der aktuell bearbeiteten Mission, Drift-Persistenz statt der bisherigen In-Memory-only currentMissionProvider, sowie Anzeige/Zugang ueber neue Chips in der Fusszeile (HTML-Demonstrator: #missionNameBtn/#droneNameBtn). Datenbank (services/database/): Missions-Tabelle um updatedAt ergaenzt, neue DroneProfiles- und AppSettingsTable-Tabellen (schemaVersion 2 mit onUpgrade-Migration). Drei Repositories kapseln Drift-Zugriff + JSON-(De-)Serialisierung der Wegpunktliste: MissionRepository, DroneProfileRepository, AppSettingsRepository - je mit Unit-Tests gegen eine In-Memory-Datenbank (NativeDatabase.memory()). Provider: CurrentMissionMetaNotifier haelt Name/id der aktuellen Mission und autosaved sie 800ms-debounced (identisch zum HTML-Demonstrator: scheduleAutosave()/flushPendingAutosave()) - inklusive Wiederherstellung des zuletzt bearbeiteten Autosave-Drafts beim App-Start (Doku 7.5). ActiveDroneProfileNotifier haelt das aktive Profil, seedet beim ersten Start automatisch T1 Ranger und merkt sich die Auswahl ueber AppSettingsTable neustart-fest. UI: MissionsDronesPanel (Missions-Tab: Liste mit Umbenennen/Loeschen/ Laden; Drones-Tab: Liste mit Bearbeiten/Loeschen/Auswaehlen, faellt beim Loeschen des aktiven Profils auf das naechste zurueck). DroneProfileEditor als Formular (bewusste Vereinfachung gegenueber den Swipe-Gesten-Chips des HTML-Demonstrators - bei elf Feldern ist ein normales Formular auf einem Mobilgeraet zugaenglicher). Rename per AlertDialog+TextField statt Browser-prompt(). Aktives Drohnenprofil ist jetzt tatsaechlich wirksam statt nur eine feste Anzeige: Speed-/Alt-Drehrad-Grenzen, Fangradius neuer Wegpunkte und die Flugpfad-Machbarkeitspruefung (Kurvenradius, Steig-/Sinkrate) in PlanScreen und WaypointListPanel lesen jetzt activeDroneProfileProvider statt der bisherigen statischen DefaultDroneProfile-Konstanten (die als T1-Ranger-Seed-Werte weiterleben). Beim Verifizieren zwei echte Bugs in BottomStatsBar gefunden und gefixt: ein Stack+Align-ohne-Factor blaehte sich auf unbegrenzte Groesse auf und verschob die Details-Pille aus ihrer sichtbaren Position (durch zwei gleich grosse Expanded-Bereiche ersetzt); zwei ConstrainedBox-Chips nebeneinander verursachten auf schmaleren Breiten einen RenderFlex- Overflow (durch Flexible ersetzt). Widget-Tests: AppShell/PlanScreen initialisieren beim Start jetzt die echte Datenbank - alle Tests, die AppShell pumpen, ueberschreiben appDatabaseProvider testweise mit einer In-Memory-Instanz. Ausserdem mussten mehrere Tests den neuen 800ms-Autosave-Timer abwarten (wie zuvor schon beim WaypointChip-Flash-Timer etabliert), damit nach Testende kein Timer mehr aussteht. Verifiziert: flutter analyze (0 issues), flutter test (59/59, davon 14 neue Repository-Tests), manuell auf Pixel_10a-Emulator - Wegpunkte werden automatisch als "New mission" gespeichert und erscheinen in der Liste, Umbenennen/Laden/Loeschen funktionieren, neues Drohnenprofil mit abweichender Max-Speed wird angelegt+aktiviert+in der Fusszeile angezeigt, Loeschen des aktiven Profils faellt auf das verbleibende zurueck. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
150 lines
4.7 KiB
Dart
150 lines
4.7 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:drift/drift.dart';
|
|
|
|
import '../../domain/waypoint/flat_waypoint_list.dart';
|
|
import 'app_database.dart';
|
|
|
|
/// Kopfzeilen-taugliche Zusammenfassung einer gespeicherten Mission, ohne
|
|
/// die komplette Wegpunktliste zu materialisieren (fuer die Missionsliste
|
|
/// im Verwaltungsmenue, Doku 3.6/7.1).
|
|
class MissionSummary {
|
|
const MissionSummary({
|
|
required this.id,
|
|
required this.name,
|
|
required this.placeName,
|
|
required this.waypointCount,
|
|
required this.updatedAt,
|
|
});
|
|
|
|
final int id;
|
|
final String name;
|
|
final String? placeName;
|
|
final int waypointCount;
|
|
final DateTime updatedAt;
|
|
}
|
|
|
|
class LoadedMission {
|
|
const LoadedMission({
|
|
required this.name,
|
|
required this.placeName,
|
|
required this.waypoints,
|
|
});
|
|
|
|
final String name;
|
|
final String? placeName;
|
|
final List<Waypoint> waypoints;
|
|
}
|
|
|
|
/// Persistenz-Zugriff fuer Missionen (Doku 4.15): kapselt die Drift-Tabelle
|
|
/// und die JSON-(De-)Serialisierung der Wegpunktliste - die Domain-Schicht
|
|
/// (Waypoint) kennt bewusst kein JSON, siehe flat_waypoint_list.dart.
|
|
class MissionRepository {
|
|
MissionRepository(this._db);
|
|
|
|
final AppDatabase _db;
|
|
|
|
Stream<List<MissionSummary>> watchSummaries() {
|
|
return _db.select(_db.missions).watch().map((rows) {
|
|
final summaries = [
|
|
for (final row in rows)
|
|
MissionSummary(
|
|
id: row.id,
|
|
name: row.name,
|
|
placeName: row.location,
|
|
waypointCount:
|
|
(jsonDecode(row.waypointsJson) as List).length,
|
|
updatedAt: row.updatedAt,
|
|
),
|
|
];
|
|
return summaries;
|
|
});
|
|
}
|
|
|
|
Future<LoadedMission?> load(int id) async {
|
|
final row = await (_db.select(_db.missions)
|
|
..where((m) => m.id.equals(id)))
|
|
.getSingleOrNull();
|
|
if (row == null) return null;
|
|
final decoded = jsonDecode(row.waypointsJson) as List;
|
|
return LoadedMission(
|
|
name: row.name,
|
|
placeName: row.location,
|
|
waypoints: [
|
|
for (final entry in decoded) _waypointFromJson(entry as Map<String, dynamic>),
|
|
],
|
|
);
|
|
}
|
|
|
|
/// Legt eine neue Mission an oder ueberschreibt die bestehende mit [id] -
|
|
/// analog saveCurrentMission()/Mission.toRecord() im HTML-Demonstrator
|
|
/// (find-or-insert nach id). Gibt die (ggf. neu vergebene) id zurueck.
|
|
Future<int> upsert({
|
|
int? id,
|
|
required String name,
|
|
String? placeName,
|
|
required List<Waypoint> waypoints,
|
|
}) async {
|
|
final waypointsJson = jsonEncode([for (final w in waypoints) _waypointToJson(w)]);
|
|
final companion = MissionsCompanion(
|
|
name: Value(name),
|
|
location: Value(placeName),
|
|
updatedAt: Value(DateTime.now()),
|
|
waypointsJson: Value(waypointsJson),
|
|
);
|
|
if (id == null) {
|
|
return _db.into(_db.missions).insert(companion);
|
|
}
|
|
final existing = await (_db.select(_db.missions)
|
|
..where((m) => m.id.equals(id)))
|
|
.getSingleOrNull();
|
|
if (existing == null) {
|
|
return _db.into(_db.missions).insert(companion.copyWith(id: Value(id)));
|
|
}
|
|
await (_db.update(_db.missions)..where((m) => m.id.equals(id)))
|
|
.write(companion);
|
|
return id;
|
|
}
|
|
|
|
Future<void> rename(int id, String name) async {
|
|
await (_db.update(_db.missions)..where((m) => m.id.equals(id))).write(
|
|
MissionsCompanion(name: Value(name), updatedAt: Value(DateTime.now())),
|
|
);
|
|
}
|
|
|
|
Future<void> delete(int id) async {
|
|
await (_db.delete(_db.missions)..where((m) => m.id.equals(id))).go();
|
|
}
|
|
|
|
Map<String, dynamic> _waypointToJson(Waypoint w) => {
|
|
'lat': w.lat,
|
|
'lon': w.lon,
|
|
'altitudeM': w.altitudeM,
|
|
'speedMs': w.speedMs,
|
|
'catchRadiusM': w.catchRadiusM,
|
|
'action': w.action.name,
|
|
'jumpTargetIndex': w.jumpTargetIndex,
|
|
'jumpRepeatCount': w.jumpRepeatCount,
|
|
'windSpeedMs': w.windSpeedMs,
|
|
'windDirFromDeg': w.windDirFromDeg,
|
|
'windElevationM': w.windElevationM,
|
|
};
|
|
|
|
Waypoint _waypointFromJson(Map<String, dynamic> json) => Waypoint(
|
|
lat: (json['lat'] as num).toDouble(),
|
|
lon: (json['lon'] as num).toDouble(),
|
|
altitudeM: (json['altitudeM'] as num).toDouble(),
|
|
speedMs: (json['speedMs'] as num).toDouble(),
|
|
catchRadiusM: (json['catchRadiusM'] as num).toDouble(),
|
|
action: WaypointAction.values.firstWhere(
|
|
(a) => a.name == json['action'],
|
|
orElse: () => WaypointAction.none,
|
|
),
|
|
jumpTargetIndex: json['jumpTargetIndex'] as int?,
|
|
jumpRepeatCount: json['jumpRepeatCount'] as int?,
|
|
windSpeedMs: (json['windSpeedMs'] as num?)?.toDouble(),
|
|
windDirFromDeg: (json['windDirFromDeg'] as num?)?.toDouble(),
|
|
windElevationM: (json['windElevationM'] as num?)?.toDouble(),
|
|
);
|
|
}
|