fixed delete in view_app. Also some other things but i forgot everything
This commit is contained in:
@@ -43,16 +43,16 @@ class PlaceDBHelper implements IDb{
|
||||
@override
|
||||
Future<int> addMainEntry(Map<String, String> place) async {
|
||||
var placeDBClient = await dB;
|
||||
final existingID = await placeDBClient.query(
|
||||
'place',
|
||||
where: 'ID = ?',
|
||||
whereArgs: [place['ID']],
|
||||
);
|
||||
|
||||
if (existingID.isNotEmpty) {
|
||||
updateMainEntry(place);
|
||||
return existingID.first['ID'] as int; // Return existing ID
|
||||
}
|
||||
// final existingID = await placeDBClient.query(
|
||||
// 'place',
|
||||
// where: 'ID = ?',
|
||||
// whereArgs: [place['ID']],
|
||||
// );
|
||||
//
|
||||
// if (existingID.isNotEmpty) {
|
||||
// updateMainEntry(place);
|
||||
// return existingID.first['ID'] as int; // Return existing ID
|
||||
// }
|
||||
|
||||
int id = await placeDBClient.insert(
|
||||
'place',
|
||||
|
||||
@@ -23,7 +23,6 @@ import 'widgets/status.dart';
|
||||
|
||||
class AddCamMain extends StatefulWidget {
|
||||
final bool isTemplate;
|
||||
final bool isFinished;
|
||||
final bool isSent;
|
||||
final Map<String, dynamic>? existingData;
|
||||
|
||||
@@ -31,7 +30,6 @@ class AddCamMain extends StatefulWidget {
|
||||
super.key,
|
||||
this.isTemplate = false,
|
||||
this.existingData,
|
||||
this.isFinished = false,
|
||||
this.isSent = false,
|
||||
});
|
||||
|
||||
@@ -148,6 +146,8 @@ class _AddCamMainState extends State<AddCamMain> {
|
||||
// select initial werte
|
||||
rmap["MEZ"]!["controller"]!.text = selectedMEZ;
|
||||
rmap["Status"]!["controller"]!.text = selectedStatus;
|
||||
rmap["DECLAT"]!["controller"]!.text = currentPosition.latitude.toString();
|
||||
rmap["DECLNG"]!["controller"]!.text = currentPosition.longitude.toString();
|
||||
|
||||
// If a template is edited this fills in the existing values
|
||||
if (widget.existingData?.isNotEmpty ?? false) {
|
||||
@@ -286,8 +286,8 @@ class _AddCamMainState extends State<AddCamMain> {
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Text(currentPosition.latitude.toString()),
|
||||
Text(currentPosition.longitude.toString()),
|
||||
Text(rmap["DECLAT"]!["controller"]!.text),
|
||||
Text(rmap["DECLNG"]!["controller"]!.text),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
|
||||
@@ -4,6 +4,19 @@ import 'package:fforte/methods/excursion_db_helper.dart';
|
||||
import 'package:fforte/methods/place_db_helper.dart';
|
||||
|
||||
class DeleteTemplates {
|
||||
|
||||
static void deleteSingle(DatabasesEnum dbType, String id) {
|
||||
IDb? db;
|
||||
|
||||
if (dbType == DatabasesEnum.place) {
|
||||
db = PlaceDBHelper();
|
||||
} else if (dbType == DatabasesEnum.excursion) {
|
||||
db = ExcursionDBHelper();
|
||||
}
|
||||
|
||||
db!.deleteTemplateById(id);
|
||||
}
|
||||
|
||||
static void deleteAll(DatabasesEnum dbType) {
|
||||
IDb? db;
|
||||
|
||||
|
||||
@@ -19,10 +19,10 @@ class SaveMainEntryMethod {
|
||||
placeDB = ExcursionDBHelper();
|
||||
}
|
||||
|
||||
int entryId;
|
||||
if (isTemplate) placeDB!.deleteTemplateById(entryData["ID"]!);
|
||||
|
||||
// Get the ID of the newly added or updated place
|
||||
if (entryData["ID"] == "") {
|
||||
int entryId;
|
||||
if (isTemplate || entryData["ID"] == "") {
|
||||
entryData.remove("ID");
|
||||
entryId = await placeDB!.addMainEntry(entryData);
|
||||
} else {
|
||||
|
||||
@@ -14,6 +14,9 @@ void saveTemplate(Map<String, String> templateData, DatabasesEnum dbType,
|
||||
return;
|
||||
}
|
||||
|
||||
templateData.remove("Sent");
|
||||
templateData.remove("ID");
|
||||
|
||||
if (update) {
|
||||
await dbHelper.updateTemplate(templateData);
|
||||
} else {
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:fforte/screens/addCam/add_cam_main.dart';
|
||||
import 'package:fforte/methods/place_db_helper.dart';
|
||||
import 'package:fforte/screens/helper/view_entries_dialog_helper.dart';
|
||||
import 'package:fforte/screens/sharedMethods/delete_main_entries.dart';
|
||||
import 'package:fforte/screens/sharedMethods/delete_templates.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fforte/l10n/app_localizations.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
@@ -25,11 +26,11 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
late Future<List<Map<String, dynamic>>> mainEntries;
|
||||
late Future<List<Map<String, dynamic>>> templates;
|
||||
late List<Marker> markers;
|
||||
IDb? db;
|
||||
|
||||
// loads the entries
|
||||
@override
|
||||
void initState() {
|
||||
IDb? db;
|
||||
super.initState();
|
||||
if (widget.dbType == DatabasesEnum.place) {
|
||||
db = PlaceDBHelper();
|
||||
@@ -37,8 +38,12 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
db = ExcursionDBHelper();
|
||||
}
|
||||
|
||||
reloadAllEntries();
|
||||
}
|
||||
|
||||
Future<void> reloadAllEntries() async {
|
||||
mainEntries = db!.getAllMainEntries();
|
||||
templates = db.getAllTemplates();
|
||||
templates = db!.getAllTemplates();
|
||||
}
|
||||
|
||||
// The widet tree with taps to differentiate between templates and finished entries
|
||||
@@ -89,24 +94,24 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
style: const TextStyle(
|
||||
decoration: TextDecoration.underline),
|
||||
AppLocalizations.of(context)!.placedata),
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
AppLocalizations.of(context)!.placedata,
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
style: const TextStyle(
|
||||
decoration: TextDecoration.underline),
|
||||
AppLocalizations.of(context)!.sent),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
AppLocalizations.of(context)!.sent,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -128,6 +133,9 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
widget.dbType,
|
||||
place['ID'.toString()],
|
||||
);
|
||||
setState(() {
|
||||
reloadAllEntries();
|
||||
});
|
||||
},
|
||||
backgroundColor: Colors.red,
|
||||
foregroundColor: Colors.white,
|
||||
@@ -158,7 +166,6 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
place['Sent'] == 1
|
||||
? true
|
||||
: false,
|
||||
isFinished: true,
|
||||
existingData: place,
|
||||
),
|
||||
),
|
||||
@@ -203,7 +210,31 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
itemBuilder: (context, index) {
|
||||
Map<String, dynamic> templates =
|
||||
snapshot.data![index];
|
||||
return ListTile(
|
||||
return Slidable(
|
||||
startActionPane: ActionPane(
|
||||
motion: const ScrollMotion(),
|
||||
children: [
|
||||
SlidableAction(
|
||||
onPressed: (context) {
|
||||
DeleteTemplates.deleteSingle(
|
||||
widget.dbType,
|
||||
templates['ID'].toString(),
|
||||
);
|
||||
setState(() {
|
||||
reloadAllEntries();
|
||||
});
|
||||
},
|
||||
backgroundColor: Colors.red,
|
||||
foregroundColor: Colors.white,
|
||||
icon: Icons.delete,
|
||||
label:
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
)!.justdelete,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ListTile(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
@@ -211,7 +242,6 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
builder:
|
||||
(context) => AddCamMain(
|
||||
isTemplate: true,
|
||||
isFinished: false,
|
||||
existingData: templates,
|
||||
),
|
||||
),
|
||||
@@ -221,6 +251,7 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
subtitle: Text(
|
||||
'ID: ${templates['CID']} DATUM: ${templates['Datum']} RUDEL: ${templates['Rudel']} STATUS: ${templates['Status']}',
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -241,6 +272,7 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
} else if (snapshot.hasError) {
|
||||
return Text("Error ${snapshot.error}");
|
||||
} else {
|
||||
if (snapshot.data != null) {
|
||||
markers =
|
||||
snapshot.data!.map((e) {
|
||||
return Marker(
|
||||
@@ -264,6 +296,7 @@ class _ViewCamsState extends State<ViewCams> {
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
return FlutterMap(
|
||||
options: MapOptions(
|
||||
initialCenter:
|
||||
|
||||
Reference in New Issue
Block a user