Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MobileEventLog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Data-Logistics-Support
MobileEventLog
Commits
aff8e325
Commit
aff8e325
authored
2 years ago
by
Maximilian Betz
Browse files
Options
Downloads
Patches
Plain Diff
configuration widget status feedback partly done.
parent
7a150f31
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/configuration.dart
+164
-146
164 additions, 146 deletions
lib/configuration.dart
lib/main.dart
+0
-1
0 additions, 1 deletion
lib/main.dart
with
164 additions
and
147 deletions
lib/configuration.dart
+
164
−
146
View file @
aff8e325
...
...
@@ -24,7 +24,7 @@ class _MyHomePageState extends State<Configuration> {
var
database
=
DatabaseInstance
();
SensorConnector
connector
=
SensorConnector
();
final
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
String
_status
=
''
;
Future
<
void
>
dumpToFile
()
async
{
var
date
=
DateTime
.
now
()
.
toUtc
();
...
...
@@ -54,78 +54,79 @@ class _MyHomePageState extends State<Configuration> {
Future
<
void
>
updateConfiguration
()
async
{
final
EventStoreInstance
event
=
EventStoreInstance
();
String
token
=
''
;
List
<
Device
>
devices
=
[];
try
{
token
=
await
connector
.
getAuthToken
(
configuration
.
loginInformation
.
mail
,
configuration
.
loginInformation
.
password
);
devices
=
await
connector
.
fetchCollectionDevices
(
configuration
.
currentCollection
.
id
);
event
.
currentEvent
.
id
=
0
;
event
.
currentEvent
.
urnId
=
configuration
.
devices
[
0
]
.
id
;
//TODO: fix if devices are an empty list.
event
.
currentEvent
.
urn
=
configuration
.
devices
[
0
]
.
urn
;
event
.
currentEvent
.
description
=
''
;
event
.
currentEvent
.
label
=
''
;
event
.
currentEvent
.
type
=
configuration
.
eventTypes
[
0
]
.
name
;
var
date
=
DateTime
.
now
()
.
toUtc
();
var
isoDate
=
date
.
toIso8601String
();
event
.
currentEvent
.
startDate
=
isoDate
;
event
.
currentEvent
.
endDate
=
isoDate
;
configuration
.
initialized
=
true
;
HapticFeedback
.
vibrate
();
//TODO: display success user feedback
//TODO: store complete "configuration"
await
event
.
storeToSharedPrefs
();
await
configuration
.
storeToSharedPrefs
();
debugPrint
(
'Configuration stored!'
);
futureAuthToken
.
then
((
value
){
//NOTE: Counterintuitive async callback function
debugPrint
(
"Login credentials correct! Auth Token: "
+
value
);
futureDevices
.
then
((
value
)
{
debugPrint
(
"Device List complete"
);
configuration
.
devices
=
value
;
futureEventTypes
.
then
((
value
)
async
{
debugPrint
(
"Event Types List complete"
);
configuration
.
eventTypes
=
value
;
debugPrint
(
"EventType Json: "
+
jsonEncode
(
configuration
.
eventTypes
[
0
]));
debugPrint
(
"Device Json: "
+
jsonEncode
(
configuration
.
devices
[
0
]));
debugPrint
(
"Current Collection Json: "
+
jsonEncode
(
configuration
.
currentCollection
));
debugPrint
(
"Sensor Login Json: "
+
jsonEncode
(
configuration
.
loginInformation
));
try
{
//Update id and urn for the add event widget with some initial data
event
.
currentEvent
.
id
=
0
;
event
.
currentEvent
.
urnId
=
configuration
.
devices
[
0
]
.
id
;
//TODO: fix if devices are an empty list.
event
.
currentEvent
.
urn
=
configuration
.
devices
[
0
]
.
urn
;
event
.
currentEvent
.
description
=
''
;
event
.
currentEvent
.
label
=
''
;
event
.
currentEvent
.
type
=
configuration
.
eventTypes
[
0
]
.
name
;
var
date
=
DateTime
.
now
()
.
toUtc
();
var
isoDate
=
date
.
toIso8601String
();
event
.
currentEvent
.
startDate
=
isoDate
;
event
.
currentEvent
.
endDate
=
isoDate
;
configuration
.
initialized
=
true
;
HapticFeedback
.
vibrate
();
//TODO: display success user feedback
//TODO: store complete "configuration"
}
catch
(
e
)
{
throw
Exception
(
'Something went wrong try again'
);
}
await
event
.
storeToSharedPrefs
();
await
configuration
.
storeToSharedPrefs
();
debugPrint
(
'Configuration stored!'
);
});
});
});
//TODO: display failed as user feedback somehow
}
on
SocketException
catch
(
e
)
{
debugPrint
(
'Exception:
$e
'
);
_status
=
'No connection'
;
setState
(()
{});
}
catch
(
e
)
{
debugPrint
(
'Exception:
$e
'
);
_status
=
'
$e
'
;
setState
(()
{});
}
_status
=
'Success. Login valid, configuration stored'
;
setState
(()
{});
return
;
}
Future
<
void
>
fetchInitData
()
async
{
@override
void
initState
()
{
super
.
initState
();
try
{
//Start fetching all possible sensor data as soon as possible:
futureCollections
=
connector
.
fetchCollections
();
futureEventTypes
=
connector
.
fetchEventTypes
();
if
(
configuration
.
currentCollection
.
id
!=
-
1
)
{
futureDevices
=
connector
.
fetchCollectionDevices
(
configuration
.
currentCollection
.
id
);
}
//Start fetching all possible sensor data as soon as possible:
futureCollections
=
connector
.
fetchCollections
()
;
futureEventTypes
=
connector
.
fetchEventTypes
()
;
if
(
configuration
.
currentCollection
.
id
!=
-
1
)
{
futureDevices
=
connector
.
fetchCollectionDevices
(
configuration
.
currentCollection
.
id
);
await
futureCollections
;
await
futureEventTypes
;
await
futureDevices
;
}
catch
(
e
)
{
debugPrint
(
e
.
toString
()
);
}
futureAuthToken
=
connector
.
getAuthToken
(
configuration
.
loginInformation
.
mail
,
configuration
.
loginInformation
.
password
);
}
@override
void
initState
()
{
super
.
initState
();
fetchInitData
();
}
late
Future
<
String
>
eventTypes
;
@override
Widget
build
(
BuildContext
context
)
{
final
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
final
EventStoreInstance
events
=
EventStoreInstance
();
...
...
@@ -134,95 +135,109 @@ class _MyHomePageState extends State<Configuration> {
title:
const
Text
(
'Configuration'
),
),
body:
SingleChildScrollView
(
child:
Container
(
margin:
const
EdgeInsets
.
symmetric
(
horizontal:
5.0
),
child:
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
const
SizedBox
(
height:
50
),
const
Text
(
'You must be online to do something here!'
,
style:
TextStyle
(
fontSize:
14
)
),
const
SizedBox
(
height:
50
),
TextFormField
(
keyboardType:
TextInputType
.
emailAddress
,
autofocus:
false
,
initialValue:
configuration
.
loginInformation
.
mail
,
decoration:
const
InputDecoration
(
labelText:
'Sensor E-Mail'
,
hintText:
'User for writing events'
,
child:
Container
(
margin:
const
EdgeInsets
.
symmetric
(
horizontal:
5.0
),
child:
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
const
SizedBox
(
height:
50
),
const
Text
(
'You must be online to do something here!'
,
style:
TextStyle
(
fontSize:
14
)
),
const
SizedBox
(
height:
50
),
TextFormField
(
keyboardType:
TextInputType
.
emailAddress
,
autofocus:
false
,
initialValue:
configuration
.
loginInformation
.
mail
,
decoration:
const
InputDecoration
(
border:
OutlineInputBorder
(),
labelText:
'Sensor E-Mail'
,
hintText:
'User for writing events'
,
),
onChanged:
(
value
)
{
configuration
.
loginInformation
.
mail
=
value
;
},
onFieldSubmitted:
(
value
)
{
//futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password);
},
),
onChanged:
(
value
)
{
configuration
.
loginInformation
.
mail
=
value
;
},
onFieldSubmitted:
(
value
)
{
futureAuthToken
=
connector
.
getAuthToken
(
configuration
.
loginInformation
.
mail
,
configuration
.
loginInformation
.
password
);
},
),
TextFormField
(
autofocus:
false
,
initialValue:
configuration
.
loginInformation
.
password
,
decoration:
const
InputDecoration
(
labelText:
'Sensor Password'
,
hintText:
'Password for writing events'
,
const
SizedBox
(
height:
15.0
),
TextFormField
(
autofocus:
false
,
initialValue:
configuration
.
loginInformation
.
password
,
decoration:
const
InputDecoration
(
border:
OutlineInputBorder
(),
labelText:
'Sensor Password'
,
hintText:
'Password for writing events'
,
),
onChanged:
(
value
){
configuration
.
loginInformation
.
password
=
value
;
},
onFieldSubmitted:
(
value
)
{
//futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password);
},
),
onChanged:
(
value
){
configuration
.
loginInformation
.
password
=
value
;
},
onFieldSubmitted:
(
value
)
{
futureAuthToken
=
connector
.
getAuthToken
(
configuration
.
loginInformation
.
mail
,
configuration
.
loginInformation
.
password
);
},
),
const
SizedBox
(
height:
50
),
FutureBuilder
<
List
<
Collection
>>(
future:
futureCollections
,
builder:
(
context
,
snapshot
){
if
(
snapshot
.
hasData
)
{
configuration
.
collections
=
[];
snapshot
.
data
?.
forEach
((
element
)
{
configuration
.
collections
.
add
(
element
);
});
/*Initialize active collection with first received
const
SizedBox
(
height:
50
),
FutureBuilder
<
List
<
Collection
>>(
future:
futureCollections
,
builder:
(
context
,
snapshot
){
if
(
snapshot
.
hasData
)
{
configuration
.
collections
=
[];
snapshot
.
data
?.
forEach
((
element
)
{
configuration
.
collections
.
add
(
element
);
});
/*Initialize active collection with first received
collection if not initialized yet*/
if
(
configuration
.
currentCollection
.
id
==
-
1
){
configuration
.
currentCollection
=
configuration
.
collections
[
0
];
futureDevices
=
connector
.
fetchCollectionDevices
(
configuration
.
currentCollection
.
id
);
}
if
(
configuration
.
currentCollection
.
id
==
-
1
){
configuration
.
currentCollection
=
configuration
.
collections
[
0
];
futureDevices
=
connector
.
fetchCollectionDevices
(
configuration
.
currentCollection
.
id
);
}
return
DropdownButtonFormField
(
value:
configuration
.
currentCollection
.
collectionName
,
decoration:
const
InputDecoration
(
labelText:
'Chose Collection'
,
),
items:
configuration
.
collections
.
map
((
Collection
collection
)
{
return
DropdownMenuItem
(
value:
collection
.
collectionName
,
child:
Text
(
collection
.
collectionName
),
);
})
.
toList
(),
onChanged:
(
value
)
{
configuration
.
currentCollection
=
configuration
.
getCollectionFromName
(
value
.
toString
());
//Fetch new selected collection devices
futureDevices
=
connector
.
fetchCollectionDevices
(
configuration
.
currentCollection
.
id
);
}
);
}
else
{
return
const
CircularProgressIndicator
();
return
DropdownButtonFormField
(
value:
configuration
.
currentCollection
.
collectionName
,
decoration:
const
InputDecoration
(
labelText:
'Chose Collection'
,
border:
OutlineInputBorder
(),
),
items:
configuration
.
collections
.
map
((
Collection
collection
)
{
return
DropdownMenuItem
(
value:
collection
.
collectionName
,
child:
Text
(
collection
.
collectionName
),
);
})
.
toList
(),
onChanged:
(
value
)
{
configuration
.
currentCollection
=
configuration
.
getCollectionFromName
(
value
.
toString
());
//Fetch new selected collection devices
futureDevices
=
connector
.
fetchCollectionDevices
(
configuration
.
currentCollection
.
id
);
}
);
}
else
{
return
const
CircularProgressIndicator
();
}
}
}
),
],
),
const
SizedBox
(
height:
50.0
),
TextFormField
(
readOnly:
true
,
autofocus:
false
,
enabled:
false
,
controller:
TextEditingController
(
text:
_status
),
),
const
SizedBox
(
height:
15.0
),
],
),
),
),
),
),
bottomNavigationBar:
Container
(
margin:
const
EdgeInsets
.
symmetric
(
vertical:
10.0
),
child:
Row
(
...
...
@@ -233,7 +248,7 @@ class _MyHomePageState extends State<Configuration> {
heroTag:
null
,
tooltip:
'Export events to local .json file'
,
icon:
const
Icon
(
Icons
.
download
),
label:
const
Text
(
'
Export
Events'
),
label:
const
Text
(
'
Dump
Events'
),
onPressed:
()
{
dumpToFile
();
...
...
@@ -248,7 +263,7 @@ class _MyHomePageState extends State<Configuration> {
heroTag:
null
,
tooltip:
'Download corresponding devices and store locally'
,
icon:
const
Icon
(
Icons
.
save
),
label:
const
Text
(
'
Updat
e'
),
label:
const
Text
(
'
Stor
e'
),
onPressed:
()
{
updateConfiguration
();
//TODO: display failed as user feedback somehow
...
...
@@ -262,4 +277,7 @@ class _MyHomePageState extends State<Configuration> {
}
}
//TODO: write configuration on app dispose!
\ No newline at end of file
//TODO: write configuration on app dispose!
//TODO: grey out update button if nothing has changed. ?
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib/main.dart
+
0
−
1
View file @
aff8e325
...
...
@@ -28,7 +28,6 @@ Future<void> loadConfiguration() async {
void
main
()
{
loadConfiguration
();
//configuration.loginInformation = SensorLogin.fromJson({"mail":"admin","password":"adminadmin"}); //TODO: replace for productive version.
runApp
(
MaterialApp
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment