diff --git a/lib/addevent.dart b/lib/addevent.dart index 72be5acb6708ea4dfb2fa3d13edaf697ea19bdf4..918c7d7f5bdd4aca3492dd4e30ff2445c0c40009 100644 --- a/lib/addevent.dart +++ b/lib/addevent.dart @@ -178,7 +178,6 @@ class _AddEventPageState extends State<AddEvent> { )); } - //TODO: add field validators for freetext fields. Check allowed characters in sensor.awi.de @override Widget build(BuildContext context) { /* Get singletons to access relevant data here.*/ diff --git a/lib/configuration.dart b/lib/configuration.dart index 56e37661de316e3189ddb9b38265feb2fb68a34f..245a4fbf378d61c5c3107c816f5c2ec231650209 100644 --- a/lib/configuration.dart +++ b/lib/configuration.dart @@ -27,19 +27,19 @@ Future<int> login() async { if (response.statusCode == 200) { debugPrint('Login success'); + //TODO: display feedback to user that credentials are correct debugPrint(response.body.toString()); debugPrint(response.headers.toString()); debugPrint(response.headers['set-cookie']); - - //TODO store token - } else { debugPrint('Header: ' + response.headers.toString()); debugPrint('Body: ' + response.body.toString()); debugPrint('StatusCode: ' + response.statusCode.toString()); throw Exception('Failed to login'); + + //TODO: display feedback to user. Only allow export in view events if user is valid. } return 0; diff --git a/lib/datamodel.dart b/lib/datamodel.dart index 3ad31f16aa1cdb14f80983e417371f96fe7607af..178ba4d5af497571dff1c2342c6e2845ca359e98 100644 --- a/lib/datamodel.dart +++ b/lib/datamodel.dart @@ -159,12 +159,10 @@ class EventType{ class SensorLogin{ String mail; String password; - String token; SensorLogin( this.mail, this.password, - this.token //REST API access Token ); String toJsonString() { @@ -186,7 +184,7 @@ abstract class ConfigurationStoreBase { Collection currentCollection = Collection(id: -1, description: '', collectionName: ''); List<Device> devices = []; List<EventType> eventTypes = []; - SensorLogin loginInformation = SensorLogin('', '', ''); + SensorLogin loginInformation = SensorLogin('', ''); bool initialized = false; Collection getCollectionFromName(String name) { @@ -221,7 +219,7 @@ abstract class ConfigurationStoreBase { devices = []; eventTypes = []; currentCollection = Collection(id: -1, description: '', collectionName: ''); - loginInformation = SensorLogin('admin', 'adminadmin', ''); + loginInformation = SensorLogin('admin', 'adminadmin'); initialized = false; } } diff --git a/lib/login.dart b/lib/login.dart index 16a3884b331a84ec4637eef2f959874f7df57158..0f52d951431493e6df35668de8928ce14fe61b67 100644 --- a/lib/login.dart +++ b/lib/login.dart @@ -31,9 +31,6 @@ Future<int> login() async { debugPrint(response.headers.toString()); debugPrint(response.headers['set-cookie']); - - //TODO store token - } else { debugPrint('Header: ' + response.headers.toString()); debugPrint('Body: ' + response.body.toString()); diff --git a/lib/main.dart b/lib/main.dart index 9ba93c6a996efad7860101fd4b7b2625eb97505f..14701a675fef52c5d5758120a98140ac629139f9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,79 +18,9 @@ void main() { configuration.reset(); configuration.loginInformation.mail = 'admin'; // Sandbox.sensor.de admin account - configuration.loginInformation.password ='adminadmin'; + configuration.loginInformation.password ='adminadmin'; //TODO: replace for productive version. - // Add some dummy devices - // TODO: load from shared preferences. - // TODO: this shall be requested from sensor.awi.de after selecting a collection in configuration. - //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. - //events.currentEvent.urn = 'vessel:polarstern:hydrosweep_ds3'; - //events.currentEvent.id = -1; - //events.currentEvent.description = ''; - //events.currentEvent.label = ''; - //events.currentEvent.type = 'Configuration'; - //events.currentEvent.startDate = '2022-03-09 15:06:00.000Z'; - //events.currentEvent.endDate = '2022-03-09 15:08:00.000Z'; - - - //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', - 'label': 'SML_KO21_SC01', - 'type': 'Deployment', - 'description': 'Remi tool Tag1 1 Traverse', - 'status': 'PENDING', - 'startDate': '2022-03-08T05:29:26Z', - 'endDate': '2022-03-08T06:29:26Z' - })); - events.events.add(Event.fromJson({ - 'id': 8311, - 'urn': 'station:neumayer_iii:awi_snow_sampler_1', - 'label': 'SML_KO21_SC01', - 'type': 'Deployment', - 'description': 'Remi tool Tag1 1 Traverse', - 'status': 'PENDING', - 'startDate': '2022-03-08T05:29:26Z', - 'endDate': '2022-03-08T06:29:26Z' - })); - events.events.add(Event.fromJson({ - 'id': 8311, - 'urn': 'station:neumayer_iii:awi_snow_sampler_1', - 'label': 'SML_KO21_SC01', - 'type': 'Deployment', - 'description': 'Remi tool Tag1 1 Traverse', - 'status': 'PENDING', - 'startDate': '2022-03-08T05:29:26Z', - 'endDate': '2022-03-08T06:29:26Z' - })); - events.events.add(Event.fromJson({ - 'id': 8311, - 'urn': 'station:neumayer_iii:awi_snow_sampler_1', - 'label': 'SML_KO21_SC01', - 'type': 'Deployment', - 'description': 'Remi tool Tag1 1 Traverse', - 'status': 'PENDING', - 'startDate': '2022-03-08T05:29:26Z', - 'endDate': '2022-03-08T06:29:26Z' - })); - */ - - - //Add some dummy eventtypes. - // TODO: loard from shared preferences. - // TODO: request from https://sensor.awi.de/rest/sensors/events/getAllEventTypes in configuration widget. - //configuration.eventTypes.add(EventType.fromJson({'id': 317, 'generalName':'Configuration'})); - //configuration.eventTypes.add(EventType.fromJson({'id': 216, 'generalName':'Decommissioned'})); - //configuration.eventTypes.add(EventType.fromJson({'id': 187, 'generalName':'Deployment'})); - //configuration.eventTypes.add(EventType.fromJson({'id': 50, 'generalName':'Information'})); - //configuration.eventTypes.add(EventType.fromJson({'id': 16, 'generalName':'Maintenance'})); + // TODO: load configuration and events from shared preferences. runApp(MaterialApp( title: 'Mobile Event Log', diff --git a/lib/viewevents.dart b/lib/viewevents.dart index 5e25506431cfdefe1667de4d08fa0dda6b5233dc..a6d61044ea754a68a701887edd80d8e9d969a471 100644 --- a/lib/viewevents.dart +++ b/lib/viewevents.dart @@ -7,10 +7,13 @@ import 'package:http/http.dart' as http; Future<bool> syncEvents() async { final EventStoreInstance events = EventStoreInstance(); + final ConfigurationStoreInstance configuration = ConfigurationStoreInstance(); - String base_url = 'https://sandbox.sensor.awi.de/rest/sensors/events/putEvent/'; + String baseUrl = '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; @@ -19,11 +22,10 @@ Future<bool> syncEvents() async { debugPrint('Idx: ' + index.toString() + ' ' + event.toSensorJson().toString()); index++; - url = base_url + event.id.toString() + '?createVersion=false'; + url = baseUrl + event.id.toString() + '?createVersion=false'; debugPrint('XXX ' + Uri.parse(url).toString()); final response = await http.put(Uri.parse(url), - headers: { "Content-Type": "application/json", "Cookie": "x-auth-token=72d9d4d20a33f87edca7e1ba01ce8db8" @@ -32,14 +34,14 @@ Future<bool> syncEvents() async { encoding: Encoding.getByName("utf-8"), ); - if (response.statusCode == 200) { + if (response.statusCode == 201) { debugPrint('put success'); + event.status = 'EXPORTED'; //Update event status so that it is only exported once. debugPrint(response.body.toString()); debugPrint(response.headers.toString()); debugPrint(response.headers['set-cookie']); - } else { debugPrint('Header: ' + response.headers.toString()); debugPrint('Body: ' + response.body.toString()); @@ -54,17 +56,6 @@ Future<bool> syncEvents() async { - - - - - - - - - - - class ViewEvents extends StatelessWidget { const ViewEvents({Key? key}) : super(key: key);