diff --git a/lib/addevent.dart b/lib/addevent.dart index f3e0a5020deec9105e89af805034ecd88a5a2dd2..32e44f63223a3faa884078a1688146e5d3ff1afd 100644 --- a/lib/addevent.dart +++ b/lib/addevent.dart @@ -95,20 +95,19 @@ class _AddEventPageState extends State<AddEvent> { } void _storeCurrentEvent() { - final EventStoreInstance storedEvents = EventStoreInstance(); - final EventCurrentInstance currentEvent = EventCurrentInstance(); - currentEvent.store.status = "PENDING"; - storedEvents.store.add( + final EventStoreInstance eventsStore = EventStoreInstance(); + eventsStore.currentEvent.status = "PENDING"; + eventsStore.events.add( Event( - currentEvent.store.id, - currentEvent.store.urn, - currentEvent.store.label, - currentEvent.store.type, - currentEvent.store.description, - currentEvent.store.status, - currentEvent.store.latitude, - currentEvent.store.longitude, - currentEvent.store.elevation + eventsStore.currentEvent.id, + eventsStore.currentEvent.urn, + eventsStore.currentEvent.label, + eventsStore.currentEvent.type, + eventsStore.currentEvent.description, + eventsStore.currentEvent.status, + eventsStore.currentEvent.latitude, + eventsStore.currentEvent.longitude, + eventsStore.currentEvent.elevation //TODO: add timestamp! Begin & End )); } @@ -118,10 +117,8 @@ class _AddEventPageState extends State<AddEvent> { @override Widget build(BuildContext context) { /* Get singletons to access relevant data here.*/ - final EventTypeStoreInstance eventTypes = EventTypeStoreInstance(); - final DeviceStoreInstance availableDevice = DeviceStoreInstance(); - final EventStoreInstance storedEvents = EventStoreInstance(); - final EventCurrentInstance currentEvent = EventCurrentInstance(); + final EventStoreInstance eventsStore = EventStoreInstance(); + final ConfigurationStoreInstance configuration = ConfigurationStoreInstance(); String gnssStatusText = ""; final formKey = GlobalKey<FormState>(); //key for form @@ -129,9 +126,9 @@ class _AddEventPageState extends State<AddEvent> { if (true == syncGNSSData){ // Update current event coordinates from GNSS stream - currentEvent.store.latitude = lat; - currentEvent.store.longitude = long; - currentEvent.store.elevation = alt; + eventsStore.currentEvent.latitude = lat; + eventsStore.currentEvent.longitude = long; + eventsStore.currentEvent.elevation = alt; if(accuracy == 0.0){ gnssStatusText = "No-Fix"; @@ -151,102 +148,102 @@ class _AddEventPageState extends State<AddEvent> { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ TextFormField( - initialValue: currentEvent.store.label, + initialValue: eventsStore.currentEvent.label, autovalidateMode: AutovalidateMode.onUserInteraction, decoration: const InputDecoration( labelText: 'Label', errorText: 'Only: a-z , A-Z , _ , 0-9 , ,(Comma) , ( , ) , + , - , . , :' ), onChanged: (value) { - currentEvent.store.label = value; + eventsStore.currentEvent.label = value; }, validator: (value){ if(!RegExp(r'^[a-z A-Z . \- 0-9 , ( ) + - _ :]+$').hasMatch(value!)){ return "Only: a-z , A-Z , _ , 0-9 , ,(Comma) , ( , ) , + , - , . , :"; }else{ - currentEvent.store.label = value; + eventsStore.currentEvent.label = value; return ''; // Entered Text is valid } }, ), DropdownButtonFormField( - value: currentEvent.store.type, + value: eventsStore.currentEvent.type, decoration: const InputDecoration( labelText: 'Event Type', ), items: - eventTypes.store.map((EventType event) { + configuration.eventTypes.map((EventType event) { return DropdownMenuItem( value: event.name, child: Text(event.name), ); }).toList(), onChanged: (value) { - currentEvent.store.type = value.toString(); + eventsStore.currentEvent.type = value.toString(); } ), DropdownButtonFormField( - value: currentEvent.store.urn, + value: eventsStore.currentEvent.urn, decoration: const InputDecoration( labelText: 'URN', ), items: - availableDevice.store.map((Device device) { + configuration.devices.map((Device device) { return DropdownMenuItem( value: device.urn, child: Text(device.urn), ); }).toList(), onChanged: (value) { - currentEvent.store.urn = value.toString(); - currentEvent.store.id = availableDevice.getDeviceIdFromUrn(value.toString()); + eventsStore.currentEvent.urn = value.toString(); + eventsStore.currentEvent.id = configuration.getDeviceIdFromUrn(value.toString()); } ), TextFormField( - initialValue: currentEvent.store.description, + initialValue: eventsStore.currentEvent.description, decoration: const InputDecoration( labelText: 'Description' ), onChanged: (value) { - currentEvent.store.description = value; + eventsStore.currentEvent.description = value; }, ), TextFormField( readOnly: false, enabled: !syncGNSSData, - controller: TextEditingController(text: currentEvent.store.latitude.toString()), + controller: TextEditingController(text: eventsStore.currentEvent.latitude.toString()), decoration: const InputDecoration( labelText: 'Latitude', border: OutlineInputBorder(), ), onChanged: (value) { - currentEvent.store.latitude = value; + eventsStore.currentEvent.latitude = value; } ), TextFormField( readOnly: false, enabled: !syncGNSSData, - controller: TextEditingController(text: currentEvent.store.longitude.toString()), + controller: TextEditingController(text: eventsStore.currentEvent.longitude.toString()), decoration: const InputDecoration( labelText: 'Longitude', border: OutlineInputBorder(), ), onChanged: (value) { - currentEvent.store.longitude = value; + eventsStore.currentEvent.longitude = value; } ), TextFormField( readOnly: false, enabled: !syncGNSSData, - controller: TextEditingController(text: currentEvent.store.elevation.toString()), + controller: TextEditingController(text: eventsStore.currentEvent.elevation.toString()), decoration: const InputDecoration( labelText: 'Elevation', border: OutlineInputBorder(), ), onChanged: (value) { - currentEvent.store.elevation = value; + eventsStore.currentEvent.elevation = value; } ), ]), diff --git a/lib/configuration.dart b/lib/configuration.dart index fad1d0b59785b208308e2e60ec4d0ee1f9dbbd7c..8007b44a9f42c242ab122607a067170463a9d3bb 100644 --- a/lib/configuration.dart +++ b/lib/configuration.dart @@ -10,8 +10,9 @@ Future<List<Device>> updateDevices(int collectionId) async { String url = 'https://sensor.awi.de/rest/sensors/collections/getItemsOfCollection/' + collectionId.toString(); // Get Access to local device and current event store. - DeviceStoreInstance availableDevices = DeviceStoreInstance(); - EventCurrentInstance currentEvent = EventCurrentInstance(); + EventStoreInstance eventsStore = EventStoreInstance(); + ConfigurationStoreInstance configuration = ConfigurationStoreInstance(); + List<Device> collectionDevices = []; final response = await http @@ -29,10 +30,10 @@ Future<List<Device>> updateDevices(int collectionId) async { } /*Update to local device store*/ - availableDevices.store = collectionDevices; + configuration.devices = collectionDevices; //Update id and urn for the add event widget - currentEvent.store.id = collectionDevices[0].id; - currentEvent.store.urn = collectionDevices[0].urn; + eventsStore.currentEvent.id = collectionDevices[0].id; + eventsStore.currentEvent.urn = collectionDevices[0].urn; return collectionDevices; } else { @@ -43,7 +44,6 @@ Future<List<Device>> updateDevices(int collectionId) async { Future<List<Collection>> fetchCollections() async { debugPrint("Fetching Collections..."); List<Collection> collectionList = []; - CollectionStoreInstance collections = CollectionStoreInstance(); final response = await http .get(Uri.parse('https://sensor.awi.de/rest/sensors/collections/getAllCollections?pointInTime=2018-07-03T12%3A30%3A55.389Z')); @@ -82,8 +82,10 @@ class _MyHomePageState extends State<Configuration> { @override Widget build(BuildContext context) { - final CollectionStoreInstance collections = CollectionStoreInstance(); - final CollectionCurrentInstance activeCollection = CollectionCurrentInstance(); + + final ConfigurationStoreInstance configuration = ConfigurationStoreInstance(); + //final CollectionStoreInstance collections = CollectionStoreInstance(); + //final CollectionCurrentInstance activeCollection = CollectionCurrentInstance(); return Scaffold( appBar: AppBar( @@ -103,34 +105,34 @@ class _MyHomePageState extends State<Configuration> { builder: (context, snapshot){ if (snapshot.hasData) { - collections.store = []; + configuration.collections = []; snapshot.data?.forEach((element) { - collections.store.add(element); + configuration.collections.add(element); }); /*Initialize active collection with first received collection if not initialized yet*/ - if(activeCollection.store.id == -1){ - activeCollection.store = collections.store[0]; + if(configuration.currentCollection.id == -1){ + configuration.currentCollection = configuration.collections[0]; } - print(activeCollection.store); - print(collections.store); + //print(activeCollection.store); + //print(collections.store); return DropdownButtonFormField( - value: activeCollection.store.collectionName, + value: configuration.currentCollection.collectionName, decoration: const InputDecoration( labelText: 'Chose Collection', ), items: - collections.store.map((Collection collection) { + configuration.collections.map((Collection collection) { return DropdownMenuItem( value: collection.collectionName, child: Text(collection.collectionName), ); }).toList(), onChanged: (value) { - activeCollection.store = collections.getCollectionFromName(value.toString()); + configuration.currentCollection = configuration.getCollectionFromName(value.toString()); } ); } @@ -151,7 +153,7 @@ class _MyHomePageState extends State<Configuration> { icon: const Icon(Icons.save), label: const Text('Select'), onPressed: () { - updateDevices(activeCollection.store.id); + updateDevices(configuration.currentCollection.id); HapticFeedback.vibrate(); }, ), diff --git a/lib/datamodel.dart b/lib/datamodel.dart index dc5b634da4a527db9f0ab241087e7380f51fb9be..7c8aa4d2c08585142325b12f7a83dae3c2c29378 100644 --- a/lib/datamodel.dart +++ b/lib/datamodel.dart @@ -107,11 +107,18 @@ class EventType{ } } -abstract class CollectionStoreBase { - List<Collection> store = []; +// Storage classes +// ConfigurationStoreBase for Collection, devices, event types, login information +// EventStoreBase for created event information. +abstract class ConfigurationStoreBase { + List<Collection> collections = []; + Collection currentCollection = Collection(id: -1, description: '', collectionName: ''); + + List<Device> devices = []; + List<EventType> eventTypes = []; Collection getCollectionFromName(String name) { - for (var collection in store) { + for (var collection in collections) { if (collection.collectionName == name) { return collection; } @@ -119,32 +126,8 @@ abstract class CollectionStoreBase { throw Exception('Event with name :' + name + ' was not found.'); } -} - -class CollectionStoreInstance extends CollectionStoreBase { - static final CollectionStoreInstance _instance = CollectionStoreInstance - ._internal(); - - factory CollectionStoreInstance() { - return _instance; - } - - CollectionStoreInstance._internal() { - store = []; - } - - void reset() { - store = []; - } -} - - - -abstract class DeviceStoreBase { - List<Device> store = []; - int getDeviceIdFromUrn(String urn) { - for (var device in store) { + for (var device in devices) { if (device.urn == urn) { return device.id; } @@ -152,111 +135,58 @@ abstract class DeviceStoreBase { throw Exception('Device with urn:' + urn + ' was not found.'); } - void reset(){ - store = []; - } -} - -abstract class EventStoreBase{ - List<Event> store = []; - -} - -abstract class EventCurrentBase{ - Event store = Event(0, 'urn0', '', '', '', 'PENDING'); -} - -abstract class CollectionCurrentBase{ - Collection store = Collection(id: -1, description: '', collectionName: ''); -} - -abstract class EventTypeStoreBase{ - List<EventType> store = []; - int getEventIdFromName(String name) { - for (var eventType in store) { + for (var eventType in eventTypes) { if (eventType.name == name) { return eventType.id; } } throw Exception('Event with name :' + name + ' was not found.'); } -} - -class EventStoreInstance extends EventStoreBase { - static final EventStoreInstance _instance = EventStoreInstance._internal(); - - factory EventStoreInstance() { - return _instance; - } - - EventStoreInstance._internal() { - store = []; - } void reset(){ - store = []; + collections = []; + devices = []; + eventTypes = []; + currentCollection = Collection(id: -1, description: '', collectionName: ''); } } -class EventCurrentInstance extends EventCurrentBase { - static final EventCurrentInstance _instance = EventCurrentInstance._internal(); +class ConfigurationStoreInstance extends ConfigurationStoreBase { + static final ConfigurationStoreInstance _instance = ConfigurationStoreInstance + ._internal(); - factory EventCurrentInstance(){ + factory ConfigurationStoreInstance() { return _instance; } - EventCurrentInstance._internal(){ - store = Event(-1, 'urn0', '', '', '', 'PENDING'); - } - - void reset(){ - store = Event(-1, 'urn0', '', '', '', 'PENDING'); + ConfigurationStoreInstance._internal() { + collections = []; + devices = []; + eventTypes = []; } } -class CollectionCurrentInstance extends CollectionCurrentBase { - static final CollectionCurrentInstance _instance = CollectionCurrentInstance._internal(); - - factory CollectionCurrentInstance(){ - return _instance; - } - - CollectionCurrentInstance._internal(){ - store = Collection(collectionName: 'name', description: 'description', id: -1); - } - void reset(){ - store = Collection(collectionName: 'name', description: 'description', id: -1); - } +abstract class EventStoreBase{ + List<Event> events = []; + Event currentEvent = Event(0, 'urn0', '', '', '', 'PENDING'); } -class EventTypeStoreInstance extends EventTypeStoreBase{ - static final EventTypeStoreInstance _instance = EventTypeStoreInstance._internal(); +class EventStoreInstance extends EventStoreBase { + static final EventStoreInstance _instance = EventStoreInstance._internal(); - factory EventTypeStoreInstance(){ + factory EventStoreInstance() { return _instance; } - EventTypeStoreInstance._internal(){ - store = []; + EventStoreInstance._internal() { + events = []; + currentEvent = Event(0, 'urn0', '', '', '', 'PENDING'); } - void reset(){ - store = []; + events = []; + currentEvent = Event(0, 'urn0', '', '', '', 'PENDING'); } } - - -class DeviceStoreInstance extends DeviceStoreBase{ - static final DeviceStoreInstance _instance = DeviceStoreInstance._internal(); - - factory DeviceStoreInstance(){ - return _instance; - } - - DeviceStoreInstance._internal(){ - store = []; - } -} \ No newline at end of file diff --git a/lib/login.dart b/lib/login.dart index 4628bee0e1db3e4d764829af4f8651a8e0246457..c3c9588f4d86c6ca505f0f16fbba44fd938b44d7 100644 --- a/lib/login.dart +++ b/lib/login.dart @@ -25,7 +25,7 @@ class _LoginPageState extends State<LoginPage> { final email = TextFormField( keyboardType: TextInputType.emailAddress, autofocus: false, - initialValue: 'initialValue@aa.com', + initialValue: '', decoration: InputDecoration( hintText: 'sensor e-mail address', contentPadding: const EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0), @@ -37,7 +37,7 @@ class _LoginPageState extends State<LoginPage> { final password = TextFormField( autofocus: false, - initialValue: 'your password', + initialValue: '', decoration: InputDecoration( hintText: 'sensor password', contentPadding: const EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0), diff --git a/lib/main.dart b/lib/main.dart index c907cf4df6b867d45977224142cc34621d3ca556..48eacfebc5489d2e1a093d524123fcb657939143 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,34 +11,31 @@ import 'login.dart'; void main() { EventStoreInstance events = EventStoreInstance(); - EventTypeStoreInstance eventTypes = EventTypeStoreInstance(); - EventCurrentInstance currentEvent = EventCurrentInstance(); - DeviceStoreInstance availableDevices = DeviceStoreInstance(); + final ConfigurationStoreInstance configuration = ConfigurationStoreInstance(); //Reset old data events.reset(); - eventTypes.reset(); - currentEvent.reset(); - availableDevices.reset(); + configuration.reset(); + // Add some dummy devices // TODO: load from shared preferences. // TODO: this shall be requested from sensor.awi.de after selecting a collection in configuration. - availableDevices.store.add(Device.fromJson({'id': 8311, 'urn':'station:neumayer_iii:awi_snow_sampler_1'})); - availableDevices.store.add(Device.fromJson({'id': 4086, 'urn':'acoustic_backscatter_sensor:test'})); - availableDevices.store.add(Device.fromJson({'id': 1393, 'urn':'vessel:polarstern:hydrosweep_ds3'})); + configuration.devices.add(Device.fromJson({'id': 8311, 'urn':'station:neumayer_iii:awi_snow_sampler_1'})); + configuration.devices.add(Device.fromJson({'id': 4086, 'urn':'acoustic_backscatter_sensor:test'})); + configuration.devices.add(Device.fromJson({'id': 1393, 'urn':'vessel:polarstern:hydrosweep_ds3'})); // Fill the textboxes in addevent with some usefull data. // TODO: store this in shared preferences so that last entered data reappears when restarting the app. - currentEvent.store.urn = 'acoustic_backscatter_sensor:test'; - currentEvent.store.id = 4086; - currentEvent.store.description = 'blabla'; - currentEvent.store.label = 'PS129_ABC'; - currentEvent.store.type = 'Deployment'; + events.currentEvent.urn = 'acoustic_backscatter_sensor:test'; + events.currentEvent.id = 4086; + events.currentEvent.description = 'blabla'; + events.currentEvent.label = 'PS129_ABC'; + events.currentEvent.type = 'Deployment'; //Add some dummy events to event store. Just development purpose. TODO: Remove after development. - events.store.add(Event.fromJson({ + events.events.add(Event.fromJson({ 'id': 8311, 'urn': 'station:neumayer_iii:awi_snow_sampler_1', 'label': 'SML_KO21_SC01', @@ -46,7 +43,7 @@ void main() { 'description': 'Remi tool Tag1 1 Traverse', 'status': 'PENDING' })); - events.store.add(Event.fromJson({ + events.events.add(Event.fromJson({ 'id': 8311, 'urn': 'station:neumayer_iii:awi_snow_sampler_1', 'label': 'SML_KO21_SC01', @@ -54,7 +51,7 @@ void main() { 'description': 'Remi tool Tag1 1 Traverse', 'status': 'PENDING' })); - events.store.add(Event.fromJson({ + events.events.add(Event.fromJson({ 'id': 8311, 'urn': 'station:neumayer_iii:awi_snow_sampler_1', 'label': 'SML_KO21_SC01', @@ -62,7 +59,7 @@ void main() { 'description': 'Remi tool Tag1 1 Traverse', 'status': 'PENDING' })); - events.store.add(Event.fromJson({ + events.events.add(Event.fromJson({ 'id': 8311, 'urn': 'station:neumayer_iii:awi_snow_sampler_1', 'label': 'SML_KO21_SC01', @@ -74,11 +71,11 @@ void main() { //Add some dummy eventtypes. // TODO: loard from shared preferences. // TODO: request from https://sensor.awi.de/rest/sensors/events/getAllEventTypes in configuration widget. - eventTypes.store.add(EventType.fromJson({'id': 317, 'name':'Configuration'})); - eventTypes.store.add(EventType.fromJson({'id': 216, 'name':'Decommissioned'})); - eventTypes.store.add(EventType.fromJson({'id': 187, 'name':'Deployment'})); - eventTypes.store.add(EventType.fromJson({'id': 50, 'name':'Information'})); - eventTypes.store.add(EventType.fromJson({'id': 16, 'name':'Maintenance'})); + configuration.eventTypes.add(EventType.fromJson({'id': 317, 'name':'Configuration'})); + configuration.eventTypes.add(EventType.fromJson({'id': 216, 'name':'Decommissioned'})); + configuration.eventTypes.add(EventType.fromJson({'id': 187, 'name':'Deployment'})); + configuration.eventTypes.add(EventType.fromJson({'id': 50, 'name':'Information'})); + configuration.eventTypes.add(EventType.fromJson({'id': 16, 'name':'Maintenance'})); runApp(MaterialApp( title: 'Mobile Event Log', diff --git a/lib/viewevents.dart b/lib/viewevents.dart index 0c8009bcbad80840a9dfcf51672ab9beaecce297..b9435c9ef49e0feb7b452020e8e3117ad8bd6a7c 100644 --- a/lib/viewevents.dart +++ b/lib/viewevents.dart @@ -75,7 +75,7 @@ class ViewEvents extends StatelessWidget { ), ], rows: <DataRow>[ - for (var event in events.store) + for (var event in events.events) DataRow( cells: <DataCell>[ DataCell(Text(event.id.toString())), @@ -142,7 +142,7 @@ class ViewEvents extends StatelessWidget { ), ), bottomNavigationBar: Row( - mainAxisAlignment: MainAxisAlignment.end, + mainAxisAlignment: MainAxisAlignment.start, children: [ FloatingActionButton.extended( heroTag: null, @@ -154,6 +154,15 @@ class ViewEvents extends StatelessWidget { Navigator.pushNamed(context, '/fifth'); }, ), + FloatingActionButton.extended( + heroTag: null, + tooltip: 'Upload Events', + icon: null, + label: const Text('Upload'), + onPressed: () { + // Provide + }, + ), ], ), );