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

sync to sensor partly done. Auth not working yet

parent 1e1a8c38
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,7 @@ A cross plattform project for android and ios to log events offline everywhere a
- Events added on the addevent.dart page have to be stored locally persistently. They can be displayed in the view
events widget. Each event has a flag which shows if the event is already exported to sensor.
Shall exported events be displayed here? Slide switch to also show exported events?
- Functionality to export events locally for backup in the field!
- Functionality to export events locally for backup in the field!
## Configuration Page
......@@ -53,6 +53,6 @@ The fields lat, long, elevation are updated automatically if checkbox is checked
a-z , A-Z , _ , 0-9 , ,(Comma) , ( , ) , + , - , . , :
-90 => Latitude <= +90
-180 => Latitude <= +180
-180 => Longitude <= +180
Elevation: any numer
......@@ -465,10 +465,13 @@ class _AddEventPageState extends State<AddEvent> {
if (_validateInput()) {
_storeCurrentEvent();
HapticFeedback.vibrate();
//Update time for next event
var date = DateTime.now().toUtc();
eventsStore.currentEvent.startDate = '$date';
eventsStore.currentEvent.endDate = '$date';
}
else {
setState(() {});
}
setState(() {});
},
tooltip: 'Add Event',
child: const Icon(Icons.check),
......
......@@ -253,7 +253,7 @@ class _MyHomePageState extends State<Configuration> {
icon: const Icon(Icons.cancel),
label: const Text('Reset all'),
onPressed: () {
events.reset();
//events.reset(); //TODO: remove before release!
configuration.reset();
},
),
......
......@@ -87,6 +87,23 @@ class Event{
);
}
Map<String, dynamic> toSensorJson() => {
'itemID':id,
'inheritToAllChildren':'false',
'inheritToChildren':[],
'event':{
'startDate':startDate,
'endDate':endDate,
'label':label,
'description':description,
'eventType':type,
'latitude':latitude,
'longitude':longitude,
'elevationInMeter':elevation,
'id':0
}
};
@override
String toString(){
return '{ ${this.id}, '
......@@ -94,6 +111,8 @@ class Event{
'${this.label}, '
'${this.type}, '
'${this.description}, '
'${this.startDate}, '
'${this.endDate}, '
'${this.latitude},'
'${this.longitude},'
'${this.elevation},'
......
......@@ -39,6 +39,7 @@ void main() {
//Add some dummy events to event store. Just development purpose. TODO: Remove after development.
/*
events.events.add(Event.fromJson({
'id': 8311,
'urn': 'station:neumayer_iii:awi_snow_sampler_1',
......@@ -79,6 +80,8 @@ void main() {
'startDate': '2022-03-08T05:29:26Z',
'endDate': '2022-03-08T06:29:26Z'
}));
*/
//Add some dummy eventtypes.
// TODO: loard from shared preferences.
......
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'datamodel.dart';
import 'package:http/http.dart' as http;
Future<bool> syncEvents() async {
final EventStoreInstance events = EventStoreInstance();
String base_url = 'https://sandbox.sensor.awi.de/rest/sensors/events/putEvent/';
String url = '';
debugPrint('Number of Events: ' + events.events.length.toString());
debugPrint('Pending Events:');
var index = 0;
for (var event in events.events){
if (event.status == 'PENDING') {
debugPrint('Idx: ' + index.toString() + ' ' + event.toSensorJson().toString());
index++;
url = base_url + event.id.toString() + '?createVersion=false';
debugPrint('XXX ' + Uri.parse(url).toString());
final response = await http.put(Uri.parse(url),
headers: { "Accept" : "application/json"},
body: event.toSensorJson().toString(),
encoding: Encoding.getByName("utf-8"),
);
if (response.statusCode == 200) {
debugPrint('put success');
debugPrint(response.body.toString());
debugPrint(response.headers.toString());
debugPrint(response.headers['set-cookie']);
} else {
debugPrint('Header: ' + response.headers.toString());
debugPrint('Body: ' + response.body.toString());
debugPrint('StatusCode: ' + response.statusCode.toString());
throw Exception('Failed to login');
}
}
}
return true;
}
class ViewEvents extends StatelessWidget {
const ViewEvents({Key? key}) : super(key: key);
......@@ -164,7 +227,12 @@ class ViewEvents extends StatelessWidget {
icon: null,
label: const Text('Sync'),
onPressed: () {
//showDialog(
// context: context,
// builder: (BuildContext context) => _buildPopupDialog(context),
//);
syncEvents();
},
),
],
......@@ -173,4 +241,25 @@ class ViewEvents extends StatelessWidget {
}
}
Widget _buildPopupDialog(BuildContext context) {
return AlertDialog(
title: const Text('Popup example'),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: const <Widget>[
Text("Hello"),
],
),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
textColor: Theme.of(context).primaryColor,
child: const Text('Close'),
),
],
);
}
//TODO: allow editing fields here. Check validation of input value!
\ 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