Add mission/drone profile management with autosave and persistence
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>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
3dd9c38fb1
commit
aaec7f0f72
@@ -17,17 +17,64 @@ class Missions extends Table {
|
||||
TextColumn get location => text().nullable()();
|
||||
DateTimeColumn get createdAt =>
|
||||
dateTime().withDefault(currentDateAndTime)();
|
||||
DateTimeColumn get updatedAt =>
|
||||
dateTime().withDefault(currentDateAndTime)();
|
||||
TextColumn get waypointsJson => text()();
|
||||
BoolColumn get isDirty => boolean().withDefault(const Constant(true))();
|
||||
TextColumn get serverId => text().nullable()();
|
||||
}
|
||||
|
||||
@DriftDatabase(tables: [Missions])
|
||||
/// Drohnen-Profile (Doku 3.5/7.3) - FC-Typ bewusst nicht Teil des Schemas,
|
||||
/// siehe DroneProfile-Domainklasse.
|
||||
class DroneProfiles extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
TextColumn get name => text()();
|
||||
RealColumn get minSpeed => real()();
|
||||
RealColumn get cruiseSpeed => real()();
|
||||
RealColumn get maxSpeed => real()();
|
||||
RealColumn get minTurnRadius => real()();
|
||||
RealColumn get loiterRadius => real()();
|
||||
RealColumn get catchRadius => real()();
|
||||
RealColumn get maxClimbRate => real()();
|
||||
RealColumn get maxDescentRate => real()();
|
||||
RealColumn get maxRangeM => real()();
|
||||
RealColumn get maxEnduranceMin => real()();
|
||||
RealColumn get maxAltitudeM => real()();
|
||||
}
|
||||
|
||||
/// Einzeilige Einstellungstabelle (id fest 0) fuer app-weite Auswahl, die
|
||||
/// einen Neustart ueberleben soll: zuletzt aktives Drohnenprofil und die
|
||||
/// zuletzt bearbeitete (autosaved) Mission, um sie beim naechsten Start
|
||||
/// fortzusetzen (Doku 7.5: Autosave/Mission-Drafts).
|
||||
class AppSettingsTable extends Table {
|
||||
IntColumn get id => integer()();
|
||||
IntColumn get activeDroneProfileId => integer().nullable()();
|
||||
IntColumn get currentMissionId => integer().nullable()();
|
||||
|
||||
@override
|
||||
Set<Column> get primaryKey => {id};
|
||||
}
|
||||
|
||||
@DriftDatabase(tables: [Missions, DroneProfiles, AppSettingsTable])
|
||||
class AppDatabase extends _$AppDatabase {
|
||||
AppDatabase() : super(_openConnection());
|
||||
|
||||
AppDatabase.forTesting(super.executor);
|
||||
|
||||
@override
|
||||
int get schemaVersion => 1;
|
||||
int get schemaVersion => 2;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration => MigrationStrategy(
|
||||
onCreate: (m) => m.createAll(),
|
||||
onUpgrade: (m, from, to) async {
|
||||
if (from < 2) {
|
||||
await m.addColumn(missions, missions.updatedAt);
|
||||
await m.createTable(droneProfiles);
|
||||
await m.createTable(appSettingsTable);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
static LazyDatabase _openConnection() {
|
||||
return LazyDatabase(() async {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,42 @@
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
import 'app_database.dart';
|
||||
|
||||
/// Zugriff auf die Einzeilen-Einstellungstabelle (Doku 7.5): welches
|
||||
/// Drohnenprofil zuletzt aktiv war und welche Mission zuletzt bearbeitet
|
||||
/// wurde, um beide nach einem Neustart wiederherzustellen.
|
||||
class AppSettingsRepository {
|
||||
AppSettingsRepository(this._db);
|
||||
|
||||
final AppDatabase _db;
|
||||
|
||||
static const _rowId = 0;
|
||||
|
||||
Future<({int? activeDroneProfileId, int? currentMissionId})> load() async {
|
||||
final row = await (_db.select(_db.appSettingsTable)
|
||||
..where((s) => s.id.equals(_rowId)))
|
||||
.getSingleOrNull();
|
||||
return (
|
||||
activeDroneProfileId: row?.activeDroneProfileId,
|
||||
currentMissionId: row?.currentMissionId,
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> setActiveDroneProfileId(int? id) async {
|
||||
await _upsert(AppSettingsTableCompanion(
|
||||
id: const Value(_rowId),
|
||||
activeDroneProfileId: Value(id),
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> setCurrentMissionId(int? id) async {
|
||||
await _upsert(AppSettingsTableCompanion(
|
||||
id: const Value(_rowId),
|
||||
currentMissionId: Value(id),
|
||||
));
|
||||
}
|
||||
|
||||
Future<void> _upsert(AppSettingsTableCompanion companion) async {
|
||||
await _db.into(_db.appSettingsTable).insertOnConflictUpdate(companion);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import 'package:drift/drift.dart';
|
||||
|
||||
import '../../domain/mission/drone_profile.dart' as domain;
|
||||
import 'app_database.dart';
|
||||
|
||||
/// Persistenz-Zugriff fuer Drohnenprofile (Doku 3.5/7.3).
|
||||
///
|
||||
/// `domain.DroneProfile` (das reine Datenmodell) und `DroneProfile` (die von
|
||||
/// Drift aus der `DroneProfiles`-Tabelle generierte Zeilenklasse) heissen
|
||||
/// gleich - hier daher qualifiziert importiert, um beide zu unterscheiden.
|
||||
class DroneProfileRepository {
|
||||
DroneProfileRepository(this._db);
|
||||
|
||||
final AppDatabase _db;
|
||||
|
||||
Stream<List<domain.DroneProfile>> watchAll() {
|
||||
return _db.select(_db.droneProfiles).watch().map(
|
||||
(rows) => [for (final row in rows) _fromRow(row)],
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<domain.DroneProfile>> loadAll() async {
|
||||
final rows = await _db.select(_db.droneProfiles).get();
|
||||
return [for (final row in rows) _fromRow(row)];
|
||||
}
|
||||
|
||||
/// Legt beim allerersten Start ein T1-Ranger-Standardprofil an, falls
|
||||
/// noch keines existiert (analog `if (!drones) drones=[DEFAULT_DRONE]`
|
||||
/// im HTML-Demonstrator). Gibt dessen id zurueck.
|
||||
Future<int> ensureSeeded() async {
|
||||
final existing = await loadAll();
|
||||
if (existing.isNotEmpty) return existing.first.id!;
|
||||
return insert(domain.DroneProfile.t1Ranger());
|
||||
}
|
||||
|
||||
Future<int> insert(domain.DroneProfile profile) {
|
||||
return _db.into(_db.droneProfiles).insert(_toCompanion(profile));
|
||||
}
|
||||
|
||||
Future<void> update(domain.DroneProfile profile) async {
|
||||
await (_db.update(_db.droneProfiles)..where((d) => d.id.equals(profile.id!)))
|
||||
.write(_toCompanion(profile));
|
||||
}
|
||||
|
||||
Future<void> delete(int id) async {
|
||||
await (_db.delete(_db.droneProfiles)..where((d) => d.id.equals(id))).go();
|
||||
}
|
||||
|
||||
domain.DroneProfile _fromRow(DroneProfile row) => domain.DroneProfile(
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
minSpeed: row.minSpeed,
|
||||
cruiseSpeed: row.cruiseSpeed,
|
||||
maxSpeed: row.maxSpeed,
|
||||
minTurnRadius: row.minTurnRadius,
|
||||
loiterRadius: row.loiterRadius,
|
||||
catchRadius: row.catchRadius,
|
||||
maxClimbRate: row.maxClimbRate,
|
||||
maxDescentRate: row.maxDescentRate,
|
||||
maxRangeM: row.maxRangeM,
|
||||
maxEnduranceMin: row.maxEnduranceMin,
|
||||
maxAltitudeM: row.maxAltitudeM,
|
||||
);
|
||||
|
||||
DroneProfilesCompanion _toCompanion(domain.DroneProfile profile) =>
|
||||
DroneProfilesCompanion(
|
||||
name: Value(profile.name),
|
||||
minSpeed: Value(profile.minSpeed),
|
||||
cruiseSpeed: Value(profile.cruiseSpeed),
|
||||
maxSpeed: Value(profile.maxSpeed),
|
||||
minTurnRadius: Value(profile.minTurnRadius),
|
||||
loiterRadius: Value(profile.loiterRadius),
|
||||
catchRadius: Value(profile.catchRadius),
|
||||
maxClimbRate: Value(profile.maxClimbRate),
|
||||
maxDescentRate: Value(profile.maxDescentRate),
|
||||
maxRangeM: Value(profile.maxRangeM),
|
||||
maxEnduranceMin: Value(profile.maxEnduranceMin),
|
||||
maxAltitudeM: Value(profile.maxAltitudeM),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
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(),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user