From 6596ab644b4dfe2f8736b3e9c7d2a5d010752302 Mon Sep 17 00:00:00 2001 From: Maximilian Betz <Maximilian.Betz@awi.de> Date: Mon, 21 Mar 2022 13:19:42 +0100 Subject: [PATCH] some simple sync feedback implemented --- lib/viewevents.dart | 62 +++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 45 deletions(-) diff --git a/lib/viewevents.dart b/lib/viewevents.dart index b470729..10fec9e 100644 --- a/lib/viewevents.dart +++ b/lib/viewevents.dart @@ -13,9 +13,16 @@ class ViewEvents extends StatefulWidget { class _ViewEvents extends State<ViewEvents> { // Get singleton to access locally stored events: - EventStoreInstance events = EventStoreInstance(); + EventStoreInstance _events = EventStoreInstance(); + String _sync_status = ''; //TODO: add exception handling and display exceptions to user. + @override + void initState() { + _sync_status = _events.getPendingEventCount().toString() + ' event(s) pending'; + super.initState(); + } + Future<bool> syncEvents() async { //final EventStoreInstance events = EventStoreInstance(); final ConfigurationStoreInstance configuration = ConfigurationStoreInstance(); @@ -26,11 +33,11 @@ class _ViewEvents extends State<ViewEvents> { configuration.loginInformation.password); if (token != null) { - _synccounter = events.getPendingEventCount(); - debugPrint('Number of Events: ' + events.events.length.toString()); + _synccounter = _events.getPendingEventCount(); + debugPrint('Number of Events: ' + _events.events.length.toString()); debugPrint('Number of Pending Events: ' + _synccounter.toString()); var index = 0; - for (var event in events.events) { + for (var event in _events.events) { if (event.status == 'PENDING') { debugPrint('Idx: ' + index.toString() + ' ' + event.toSensorJson().toString()); @@ -41,9 +48,12 @@ class _ViewEvents extends State<ViewEvents> { debugPrint('put success, remaining events: ' + _synccounter.toString()); event.status = 'EXPORTED'; //Update event status so that it is only exported once. setState(() {}); + }else{ + _sync_status = 'export failed: ' + event.urn; } } } + _sync_status = 'export success'; return true; } return false; @@ -134,7 +144,7 @@ class _ViewEvents extends State<ViewEvents> { ), ], rows: <DataRow>[ - for (var event in events.events) + for (var event in _events.events) DataRow( cells: <DataCell>[ DataCell(Text(event.id.toString())), @@ -208,58 +218,20 @@ class _ViewEvents extends State<ViewEvents> { bottomNavigationBar: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text('Remaining events to sync: ' + events.getPendingEventCount().toString()), + const SizedBox(width: 10), + Text(_sync_status), FloatingActionButton.extended( heroTag: null, tooltip: 'Upload Events', icon: null, label: const Text('Sync'), onPressed: () { - syncEvents(); - //showDialog( - // barrierDismissible: false, - // context: context, - // builder: (BuildContext context) => _buildPopupDialog(context), - //); }, ), ], ), ); } - - Widget _buildPopupDialog(BuildContext context) { - - return AlertDialog( - title: const Text('Uploading Events'), - - content: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.center, - children: <Widget>[ - //Text("Progress"), - const CircularProgressIndicator(), - const SizedBox(height: 10), - Text('Remaining events to sync'), - ], - ), - actions: <Widget>[ - TextButton( - onPressed: () { - //syncEvents(); - - setState(() { - - }); - //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 -- GitLab