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

minor changes

parent 53074cde
No related branches found
No related tags found
No related merge requests found
import 'dart:convert';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
...@@ -147,36 +149,51 @@ class _MyHomePageState extends State<Configuration> { ...@@ -147,36 +149,51 @@ class _MyHomePageState extends State<Configuration> {
icon: const Icon(Icons.save), icon: const Icon(Icons.save),
label: const Text('Store'), label: const Text('Store'),
onPressed: () { onPressed: () {
futureAuthToken.whenComplete((){ futureAuthToken.then((value){ //NOTE: Counterintuitive async callback function
futureDevices.whenComplete(() { debugPrint("Login credentials correct! Auth Token: " + value);
//Update configuration with newly fetched data
futureDevices.then((value) => configuration.devices = value); futureDevices.then((value) {
futureEventTypes.then((value) => configuration.eventTypes = value); debugPrint("Device List complete");
print("Devices: " + configuration.devices.toString()); //Still empty on first execution Why? configuration.devices = value;
// TODO: Move fetchCollectionDevices to an own future and set configuration inside on finish!
try { futureEventTypes.then((value) {
//Update id and urn for the add event widget with some initial data debugPrint("Event Types List complete");
events.currentEvent.id = configuration.devices[0].id; //TODO: fix if devices are an empty list. configuration.eventTypes = value;
events.currentEvent.urn = configuration.devices[0].urn;
events.currentEvent.description = ''; debugPrint("EventType Json: " + jsonEncode(
events.currentEvent.label = ''; configuration.eventTypes[0]));
events.currentEvent.type = configuration.eventTypes[0].name; debugPrint("Device Json: " + jsonEncode(
configuration.devices[0]));
var date = DateTime.now().toUtc(); debugPrint("Current Collection Json: " + jsonEncode(
var isodata = date.toIso8601String(); configuration.currentCollection));
events.currentEvent.startDate = isodata; debugPrint("Sensor Login Json: " + jsonEncode(
events.currentEvent.endDate = isodata; configuration.loginInformation));
configuration.initialized = true;
try {
HapticFeedback.vibrate(); //Update id and urn for the add event widget with some initial data
//TODO: display success events.currentEvent.id = configuration.devices[0]
} catch(e){ .id; //TODO: fix if devices are an empty list.
throw Exception('Something went wrong try again'); events.currentEvent.urn = configuration.devices[0].urn;
} events.currentEvent.description = '';
events.currentEvent.label = '';
events.currentEvent.type = configuration.eventTypes[0]
.name;
var date = DateTime.now().toUtc();
var isoDate = date.toIso8601String();
events.currentEvent.startDate = isoDate;
events.currentEvent.endDate = isoDate;
configuration.initialized = true;
HapticFeedback.vibrate();
//TODO: display success user feedback
} catch (e) {
throw Exception('Something went wrong try again');
}
});
}); });
}); });
//TODO: display failed as user feedback somehow
//TODO: display failed here somehow
}, },
), ),
], ],
......
...@@ -49,7 +49,7 @@ class Device{ ...@@ -49,7 +49,7 @@ class Device{
@override @override
String toString(){ String toString(){
return '{ ${this.id}, ${this.urn} }'; return urn;
} }
} }
...@@ -155,14 +155,14 @@ class EventType{ ...@@ -155,14 +155,14 @@ class EventType{
int id; int id;
String name; String name;
EventType( EventType({
this.id, required this.id,
this.name required this.name
); });
factory EventType.fromSensorJson(Map<String, dynamic> parsedJson){ EventType.fromSensorJson(Map<String, dynamic> json)
return EventType(parsedJson['id'] as int, parsedJson['generalName'] as String); : id = json['id'],
} name = json['generalName'];
EventType.fromJson(Map<String, dynamic> json) EventType.fromJson(Map<String, dynamic> json)
: id = json['id'], : id = json['id'],
...@@ -172,6 +172,11 @@ class EventType{ ...@@ -172,6 +172,11 @@ class EventType{
'id': id, 'id': id,
'name': name, 'name': name,
}; };
@override
String toString(){
return name;
}
} }
...@@ -184,14 +189,14 @@ class SensorLogin{ ...@@ -184,14 +189,14 @@ class SensorLogin{
this.password, this.password,
); );
String toJsonString() {
return '{ "username": $mail, "authPassword": $password }';
}
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
"username": mail, "mail": mail,
"authPassword": password "password": password
}; };
SensorLogin.fromJson(Map<String, dynamic> json)
: mail = json['mail'],
password = json['password'];
} }
......
...@@ -37,12 +37,16 @@ void main() { ...@@ -37,12 +37,16 @@ void main() {
events.reset(); // TODO: load configuration and events from shared preferences. events.reset(); // TODO: load configuration and events from shared preferences.
configuration.reset(); configuration.reset();
configuration.loginInformation.mail = 'admin'; // Sandbox.sensor.de admin account configuration.loginInformation = SensorLogin.fromJson({"mail":"admin","password":"adminadmin"}); //TODO: replace for productive version.
configuration.loginInformation.password ='adminadmin'; //TODO: replace for productive version.
//Load data from storage:
//events.currentEvent = Event.fromJson({"id":102,"urn":"mooring:f9-12","label":"gg","type":"Calibration","typeId":15,"description":"gvg","status":"EXPORTED","startDate":"2022-03-25T09:24:48.856120Z","endDate":"2022-03-25T09:24:48.856120Z","latitude":"53.54388522","longitude":"8.58144825","elevation":"1.9925537109375"});
//events.events.add(Event.fromJson({"id":102,"urn":"mooring:f9-12","label":"gg","type":"Calibration","typeId":15,"description":"gvg","status":"EXPORTED","startDate":"2022-03-25T09:24:48.856120Z","endDate":"2022-03-25T09:24:48.856120Z","latitude":"53.54388522","longitude":"8.58144825","elevation":"1.9925537109375"}));
//configuration.devices.add(Device.fromJson({"id":102,"urn":"mooring:f9-12"}));
//configuration.eventTypes.add(EventType.fromJson({"id":15,"name":"Calibration"}));
//configuration.currentCollection = Collection.fromJson({"id":1,"description":"","collectionName":"FRAM"});
//configuration.initialized = true;
//events.events.add(Event.fromJson({id: 102, urn: mooring:f9-12, label: gg, type: Calibration, typeId: 15, description: ggg, status: EXPORTED, startDate: 2022-03-25T09:10:46.932955Z, endDate: 2022-03-25T09:10:46.932955Z, latitude: 53.54409252, longitude: 8.58022428, elevation: 52.7396240234375}
//));
runApp(MaterialApp( runApp(MaterialApp(
title: 'Mobile Event Log', title: 'Mobile Event Log',
......
...@@ -69,9 +69,14 @@ class SensorConnector { ...@@ -69,9 +69,14 @@ class SensorConnector {
final response = await http.get(Uri.parse(url)); final response = await http.get(Uri.parse(url));
if (response.statusCode == 200) { if (response.statusCode == 200) {
eventTypeList = (json.decode(response.body) as List) //eventTypeList = (json.decode(response.body) as List)
.map((i) => EventType.fromSensorJson(i)) // .map((i) => EventType.fromSensorJson(i))
.toList(); // .toList();
List<dynamic> data = json.decode(response.body);
for (var entry in data) {
eventTypeList.add(EventType.fromSensorJson(entry));
}
debugPrint("Fetching Event Types Success: " + eventTypeList.toString()); debugPrint("Fetching Event Types Success: " + eventTypeList.toString());
} else{ } else{
throw Exception('Failed to fetch event types. ' throw Exception('Failed to fetch event types. '
......
...@@ -239,7 +239,7 @@ class _ViewEvents extends State<ViewEvents> { ...@@ -239,7 +239,7 @@ class _ViewEvents extends State<ViewEvents> {
label: const Text('Sync'), label: const Text('Sync'),
onPressed: () { onPressed: () {
for (var event in _events.events){ for (var event in _events.events){
debugPrint("Event: " + event.toJson().toString()); debugPrint("Event: " + jsonEncode(event));
} }
syncEvents(); syncEvents();
......
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