Skip to content
Snippets Groups Projects
Commit 30973c57 authored by Maximilian Betz's avatar Maximilian Betz
Browse files

moved json event file export to configuration widget

parent 5bd68ac0
No related branches found
No related tags found
No related merge requests found
......@@ -143,7 +143,7 @@ class _AddEventPageState extends State<AddEvent> {
if (RegExp(r'^[a-z A-Z . \- 0-9 , ( ) + - _ :]+$').hasMatch(
eventStore.currentEvent.label)) {
if (RegExp(r'^[a-z A-Z . \- 0-9 , ( ) + - _ :]+$').hasMatch(
eventStore.currentEvent.description)) {
eventStore.currentEvent.description) || eventStore.currentEvent.description == '') {
if(_validateLatitude(eventStore.currentEvent.latitude)){
if(_validateLongitude(eventStore.currentEvent.longitude)){
if(_validateElevation(eventStore.currentEvent.elevation)){
......@@ -282,9 +282,11 @@ class _AddEventPageState extends State<AddEvent> {
validator: (value) {
if (!RegExp(r'^[a-z A-Z . \- 0-9 , ( ) + - _ :]+$').hasMatch(
value!)) {
if(value == ''){
return null; //An empty description is also allowed.
}
return "Only: a-z , A-Z , _ , 0-9 , ,(Comma) , ( , ) , + , - , . , :";
} else {
//eventStore.currentEvent.label = value;
return null; // Entered Text is valid
}
},
......@@ -486,7 +488,7 @@ class _AddEventPageState extends State<AddEvent> {
//child: const Icon(Icons.check),
)
),
const SizedBox(width: 10.0),
const SizedBox(width: 5.0),
],
),
);
......
import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'datamodel.dart';
import 'sensorconnector.dart';
import 'databaseconnector.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
class Configuration extends StatefulWidget {
const Configuration({Key? key}) : super(key: key);
......@@ -19,10 +22,37 @@ class _MyHomePageState extends State<Configuration> {
late Future<List<EventType>> futureEventTypes;
late Future<List<Device>> futureDevices;
late Future<String> futureAuthToken;
var database = DatabaseInstance();
SensorConnector connector = SensorConnector();
final ConfigurationStoreInstance configuration = ConfigurationStoreInstance();
Future<void> dumpToFile() async{
var date = DateTime.now().toUtc();
var isoDate = date.toIso8601String();
String filename =
date.year.toString().padLeft(4, '0') +
date.month.toString().padLeft(2, '0') +
date.day.toString().padLeft(2, '0') +
date.hour.toString().padLeft(2, '0') +
date.minute.toString().padLeft(2, '0') +
date.second.toString().padLeft(2, '0') +
'_events.json';
String eventsJson = await database.eventDump();
final Directory? directory = await getExternalStorageDirectory();
if(directory != null) {
String filepath = join(directory.path, filename);
final File file = File(filepath);
await file.writeAsString(eventsJson);
debugPrint('Stored file at: ' + filepath);
}
}
Future<void> updateConfiguration() async {
final EventStoreInstance event = EventStoreInstance();
......@@ -197,18 +227,19 @@ class _MyHomePageState extends State<Configuration> {
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
const SizedBox(width: 10.0),
//const SizedBox(width: 10.0),
FloatingActionButton.extended(
heroTag: null,
tooltip: 'Reset all data',
icon: const Icon(Icons.cancel),
label: const Text('Reset all'),
tooltip: 'Export events to local .json file',
icon: const Icon(Icons.download),
label: const Text('Export Events'),
onPressed: () {
//events.reset(); //TODO: remove before release!
var db = DatabaseInstance();
db.delete();
dumpToFile();
configuration.reset(); //TODO: remove before release this is not a real use case!
//events.reset(); //TODO: remove before release this is not a real use case!
//var db = DatabaseInstance();
//db.delete();
//configuration.reset();
},
),
const SizedBox(width: 50),
......@@ -222,7 +253,7 @@ class _MyHomePageState extends State<Configuration> {
//TODO: display failed as user feedback somehow
},
),
const SizedBox(width: 10.0),
const SizedBox(width: 5.0),
],
),
)
......
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
import 'datamodel.dart';
import 'sensorconnector.dart';
import 'databaseconnector.dart';
import 'package:path/path.dart';
class ViewEvents extends StatefulWidget {
const ViewEvents({Key? key}) : super(key: key);
......@@ -34,24 +32,6 @@ class _ViewEvents extends State<ViewEvents> {
setState(() {}); //Got events from database, so update UI
}
Future<void> dumpToFile() async{
//localEvents = await database.getEvents();
var date = DateTime.now().toUtc();
var isoDate = date.toIso8601String();
String eventsJson = await database.eventDump();
final Directory? directory = await getExternalStorageDirectory();
if(directory != null) {
String filename = 'time_event_dump.json';
String filepath = join(directory.path, filename);
final File file = File(filepath);
await file.writeAsString(eventsJson);
debugPrint('Stored file at: ' + filepath);
}
}
@override
void initState() {
_syncStatus = '';
......@@ -279,8 +259,6 @@ class _ViewEvents extends State<ViewEvents> {
label: const Text('Sync'),
onPressed: () {
syncEvents();
dumpToFile(); //TODO. Move to right button.
},
),
),
......@@ -291,4 +269,3 @@ class _ViewEvents extends State<ViewEvents> {
}
}
//TODO: allow editing fields here. Check validation of input value!
//TODO: dump events to json for local backups in the field. "dumpToFile"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment