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

some simple sync feedback implemented

parent 5cc95545
No related branches found
No related tags found
No related merge requests found
......@@ -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
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