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
3067ca4d
Commit
3067ca4d
authored
3 years ago
by
Maximilian Betz
Browse files
Options
Downloads
Patches
Plain Diff
removed sensor logic from configuration
parent
cbb1b7a2
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
+45
-142
45 additions, 142 deletions
lib/configuration.dart
lib/sensorconnector.dart
+1
-1
1 addition, 1 deletion
lib/sensorconnector.dart
with
46 additions
and
143 deletions
lib/configuration.dart
+
45
−
142
View file @
3067ca4d
...
...
@@ -6,140 +6,6 @@ import 'dart:convert';
import
'datamodel.dart'
;
import
'sensorconnector.dart'
;
Future
<
int
>
login
()
async
{
// Get Access to local configuration store. Token must be stored there!
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
String
url
=
'https://sandbox.sensor.awi.de/rest/sensors/contacts/login'
;
debugPrint
(
"Start login to : "
+
url
);
Map
<
String
,
dynamic
>
body
=
{
'username'
:
configuration
.
loginInformation
.
mail
,
'authPassword'
:
configuration
.
loginInformation
.
password
};
String
encodedBody
=
body
.
keys
.
map
((
key
)
=
>
"
$key
=
${body[key]}
"
)
.
join
(
"&"
);
debugPrint
(
encodedBody
);
final
response
=
await
http
.
post
(
Uri
.
parse
(
url
),
body:
encodedBody
,
headers:
{
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/x-www-form-urlencoded'
},
encoding:
Encoding
.
getByName
(
"utf-8"
)
);
if
(
response
.
statusCode
==
200
)
{
debugPrint
(
'Login success'
);
//TODO: display feedback to user that credentials are correct
debugPrint
(
response
.
headers
[
'set-cookie'
]
?.
split
(
';'
)[
0
]
.
toString
());
debugPrint
(
response
.
body
.
toString
());
debugPrint
(
response
.
headers
.
toString
());
debugPrint
(
response
.
headers
[
'set-cookie'
]);
}
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
;
}
Future
<
List
<
Device
>>
updateDevices
(
int
collectionId
)
async
{
debugPrint
(
"Start HTTP GET Collection Devices. Collection Id: "
+
collectionId
.
toString
());
String
url
=
'https://sandbox.sensor.awi.de/rest/sensors/collections/getItemsOfCollection/'
+
collectionId
.
toString
();
// Get Access to local device and current event store.
EventStoreInstance
events
=
EventStoreInstance
();
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
List
<
Device
>
collectionDevices
=
[];
final
response
=
await
http
.
get
(
Uri
.
parse
(
url
));
if
(
response
.
statusCode
==
200
)
{
List
<
dynamic
>
data
=
json
.
decode
(
response
.
body
);
for
(
var
entry
in
data
)
{
collectionDevices
.
add
(
Device
.
fromJson
(
entry
));
}
debugPrint
(
"Got the following devices: "
);
for
(
var
device
in
collectionDevices
){
debugPrint
(
device
.
toString
());
}
/*Update to local device store*/
configuration
.
devices
=
collectionDevices
;
//Update id and urn for the add event widget
events
.
currentEvent
.
id
=
collectionDevices
[
0
]
.
id
;
events
.
currentEvent
.
urn
=
collectionDevices
[
0
]
.
urn
;
events
.
currentEvent
.
description
=
''
;
events
.
currentEvent
.
label
=
''
;
events
.
currentEvent
.
type
=
configuration
.
eventTypes
[
0
]
.
name
;
var
date
=
DateTime
.
now
()
.
toUtc
();
events
.
currentEvent
.
startDate
=
'
$date
'
;
events
.
currentEvent
.
endDate
=
'
$date
'
;
configuration
.
initialized
=
true
;
return
collectionDevices
;
}
else
{
throw
Exception
(
'Failed to load Collection'
);
}
}
Future
<
List
<
Collection
>>
fetchCollections
()
async
{
debugPrint
(
"Fetching Collections..."
);
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
List
<
Collection
>
collectionList
=
[];
final
response
=
await
http
.
get
(
Uri
.
parse
(
'https://sandbox.sensor.awi.de/rest/sensors/collections/getAllCollections?pointInTime=2018-07-03T12%3A30%3A55.389Z'
));
if
(
response
.
statusCode
==
200
)
{
return
(
json
.
decode
(
response
.
body
)
as
List
)
.
map
((
i
)
=
>
Collection
.
fromJson
(
i
))
.
toList
();
}
else
{
debugPrint
(
'Failed to load Collection'
);
return
collectionList
;
}
}
Future
<
List
<
EventType
>>
fetchEventTypes
()
async
{
debugPrint
(
"Fetching Event Types..."
);
List
<
EventType
>
eventTypeList
=
[];
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
final
response
=
await
http
.
get
(
Uri
.
parse
(
'https://sandbox.sensor.awi.de/rest/sensors/events/getAllEventTypes'
));
if
(
response
.
statusCode
==
200
)
{
debugPrint
(
response
.
body
);
eventTypeList
=
(
json
.
decode
(
response
.
body
)
as
List
)
.
map
((
i
)
=
>
EventType
.
fromJson
(
i
))
.
toList
();
configuration
.
eventTypes
=
eventTypeList
;
return
eventTypeList
;
}
else
{
debugPrint
(
'Failed to load Collection'
);
return
eventTypeList
;
}
return
eventTypeList
;
}
class
Configuration
extends
StatefulWidget
{
const
Configuration
({
Key
?
key
})
:
super
(
key:
key
);
...
...
@@ -149,22 +15,27 @@ class Configuration extends StatefulWidget {
}
class
_MyHomePageState
extends
State
<
Configuration
>
{
late
Future
<
Collection
>
futureCollection
;
late
Future
<
List
<
Collection
>>
futureCollections
;
late
Future
<
List
<
EventType
>>
futureEventTypes
;
late
Future
<
List
<
Device
>>
futureDevices
;
late
Future
<
String
>
futureAuthToken
;
SensorConnector
connector
=
SensorConnector
();
final
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
@override
void
initState
()
{
super
.
initState
();
//Start fetching all possible sensor data as soon as possible:
futureCollections
=
connector
.
fetchCollections
();
futureEventTypes
=
connector
.
fetchEventTypes
();
fetchEventTypes
();
futureDevices
=
connector
.
fetchCollectionDevices
(
configuration
.
currentCollection
.
id
);
futureAuthToken
=
connector
.
getAuthToken
(
configuration
.
loginInformation
.
mail
,
configuration
.
loginInformation
.
password
);
}
late
Future
<
String
>
eventTypes
;
@override
Widget
build
(
BuildContext
context
)
{
...
...
@@ -195,6 +66,9 @@ class _MyHomePageState extends State<Configuration> {
onChanged:
(
value
)
{
configuration
.
loginInformation
.
mail
=
value
;
},
onFieldSubmitted:
(
value
)
{
futureAuthToken
=
connector
.
getAuthToken
(
configuration
.
loginInformation
.
mail
,
configuration
.
loginInformation
.
password
);
},
),
TextFormField
(
autofocus:
false
,
...
...
@@ -206,6 +80,9 @@ class _MyHomePageState extends State<Configuration> {
onChanged:
(
value
){
configuration
.
loginInformation
.
password
=
value
;
},
onFieldSubmitted:
(
value
)
{
futureAuthToken
=
connector
.
getAuthToken
(
configuration
.
loginInformation
.
mail
,
configuration
.
loginInformation
.
password
);
},
),
const
SizedBox
(
height:
50
),
FutureBuilder
<
List
<
Collection
>>(
...
...
@@ -238,6 +115,8 @@ class _MyHomePageState extends State<Configuration> {
})
.
toList
(),
onChanged:
(
value
)
{
configuration
.
currentCollection
=
configuration
.
getCollectionFromName
(
value
.
toString
());
//Fetch new selected collection devices
futureDevices
=
connector
.
fetchCollectionDevices
(
configuration
.
currentCollection
.
id
);
}
);
}
...
...
@@ -259,7 +138,7 @@ class _MyHomePageState extends State<Configuration> {
label:
const
Text
(
'Reset all'
),
onPressed:
()
{
//events.reset(); //TODO: remove before release!
configuration
.
reset
();
configuration
.
reset
();
//TODO: remove before release this is not a real use case!
},
),
FloatingActionButton
.
extended
(
...
...
@@ -269,10 +148,34 @@ class _MyHomePageState extends State<Configuration> {
icon:
const
Icon
(
Icons
.
save
),
label:
const
Text
(
'Store'
),
onPressed:
()
{
login
();
fetchEventTypes
();
updateDevices
(
configuration
.
currentCollection
.
id
);
HapticFeedback
.
vibrate
();
futureAuthToken
.
whenComplete
((){
futureDevices
.
whenComplete
(()
{
//Update configuration with newly fetched data
futureDevices
.
then
((
value
)
=
>
configuration
.
devices
=
value
);
futureEventTypes
.
then
((
value
)
=
>
configuration
.
eventTypes
=
value
);
//Update id and urn for the add event widget with some initial data
events
.
currentEvent
.
id
=
configuration
.
devices
[
0
]
.
id
;
events
.
currentEvent
.
urn
=
configuration
.
devices
[
0
]
.
urn
;
events
.
currentEvent
.
description
=
''
;
events
.
currentEvent
.
label
=
''
;
events
.
currentEvent
.
type
=
configuration
.
eventTypes
[
0
]
.
name
;
var
date
=
DateTime
.
now
()
.
toUtc
();
var
isodata
=
date
.
toIso8601String
();
events
.
currentEvent
.
startDate
=
isodata
;
events
.
currentEvent
.
endDate
=
isodata
;
configuration
.
initialized
=
true
;
HapticFeedback
.
vibrate
();
});
});
//login();
//fetchEventTypes();
//updateDevices(configuration.currentCollection.id);
//HapticFeedback.vibrate();
},
),
],
...
...
This diff is collapsed.
Click to expand it.
lib/sensorconnector.dart
+
1
−
1
View file @
3067ca4d
...
...
@@ -80,7 +80,7 @@ class SensorConnector {
return
eventTypeList
;
}
Future
<
List
<
Device
>>
update
Devices
(
int
collectionId
)
async
{
Future
<
List
<
Device
>>
fetchCollection
Devices
(
int
collectionId
)
async
{
String
url
=
baseUrl
+
collectionItemsUrl
+
collectionId
.
toString
();
List
<
Device
>
collectionDevices
=
[];
...
...
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