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
c8807576
Commit
c8807576
authored
3 years ago
by
Maximilian Betz
Browse files
Options
Downloads
Patches
Plain Diff
fetching eventtypes from sensor added
parent
9ec2d5f2
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/configuration.dart
+99
-5
99 additions, 5 deletions
lib/configuration.dart
lib/datamodel.dart
+1
-1
1 addition, 1 deletion
lib/datamodel.dart
lib/viewevents.dart
+2
-12
2 additions, 12 deletions
lib/viewevents.dart
with
102 additions
and
18 deletions
lib/configuration.dart
+
99
−
5
View file @
c8807576
...
...
@@ -5,6 +5,46 @@ import 'package:http/http.dart' as http;
import
'dart:convert'
;
import
'datamodel.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'
);
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'
);
}
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
();
...
...
@@ -34,7 +74,6 @@ Future<List<Device>> updateDevices(int collectionId) async {
//Update id and urn for the add event widget
eventsStore
.
currentEvent
.
id
=
collectionDevices
[
0
]
.
id
;
eventsStore
.
currentEvent
.
urn
=
collectionDevices
[
0
]
.
urn
;
return
collectionDevices
;
}
else
{
throw
Exception
(
'Failed to load Collection'
);
...
...
@@ -43,6 +82,8 @@ Future<List<Device>> updateDevices(int collectionId) async {
Future
<
List
<
Collection
>>
fetchCollections
()
async
{
debugPrint
(
"Fetching Collections..."
);
ConfigurationStoreInstance
configuration
=
ConfigurationStoreInstance
();
List
<
Collection
>
collectionList
=
[];
final
response
=
await
http
...
...
@@ -59,6 +100,35 @@ Future<List<Collection>> fetchCollections() async {
}
}
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
);
...
...
@@ -76,6 +146,7 @@ class _MyHomePageState extends State<Configuration> {
void
initState
()
{
super
.
initState
();
futureCollections
=
fetchCollections
();
fetchEventTypes
();
}
late
Future
<
String
>
eventTypes
;
...
...
@@ -98,6 +169,30 @@ class _MyHomePageState extends State<Configuration> {
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'
,
),
onChanged:
(
value
)
{
configuration
.
loginInformation
.
mail
=
value
;
},
),
TextFormField
(
autofocus:
false
,
initialValue:
configuration
.
loginInformation
.
password
,
decoration:
const
InputDecoration
(
labelText:
'Sensor Password'
,
hintText:
'Password for writing events'
,
),
onChanged:
(
value
){
configuration
.
loginInformation
.
password
=
value
;
},
),
const
SizedBox
(
height:
50
),
FutureBuilder
<
List
<
Collection
>>(
future:
futureCollections
,
builder:
(
context
,
snapshot
){
...
...
@@ -114,9 +209,6 @@ class _MyHomePageState extends State<Configuration> {
configuration
.
currentCollection
=
configuration
.
collections
[
0
];
}
//print(activeCollection.store);
//print(collections.store);
return
DropdownButtonFormField
(
value:
configuration
.
currentCollection
.
collectionName
,
decoration:
const
InputDecoration
(
...
...
@@ -149,9 +241,11 @@ class _MyHomePageState extends State<Configuration> {
heroTag:
null
,
tooltip:
'Select Collection and download corresponding devices'
,
icon:
const
Icon
(
Icons
.
save
),
label:
const
Text
(
'S
elect
'
),
label:
const
Text
(
'S
tore
'
),
onPressed:
()
{
updateDevices
(
configuration
.
currentCollection
.
id
);
login
();
fetchEventTypes
();
HapticFeedback
.
vibrate
();
},
),
...
...
This diff is collapsed.
Click to expand it.
lib/datamodel.dart
+
1
−
1
View file @
c8807576
...
...
@@ -111,7 +111,7 @@ class EventType{
);
factory
EventType
.
fromJson
(
Map
<
String
,
dynamic
>
parsedJson
){
return
EventType
(
parsedJson
[
'id'
]
as
int
,
parsedJson
[
'
n
ame'
]
as
String
);
return
EventType
(
parsedJson
[
'id'
]
as
int
,
parsedJson
[
'
generalN
ame'
]
as
String
);
}
}
...
...
This diff is collapsed.
Click to expand it.
lib/viewevents.dart
+
2
−
12
View file @
c8807576
...
...
@@ -156,23 +156,13 @@ class ViewEvents extends StatelessWidget {
),
),
bottomNavigationBar:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
start
,
mainAxisAlignment:
MainAxisAlignment
.
end
,
children:
[
FloatingActionButton
.
extended
(
heroTag:
null
,
tooltip:
'Login to Sensor'
,
icon:
null
,
label:
const
Text
(
'Login'
),
onPressed:
()
{
// Provide
Navigator
.
pushNamed
(
context
,
'/fifth'
);
},
),
FloatingActionButton
.
extended
(
heroTag:
null
,
tooltip:
'Upload Events'
,
icon:
null
,
label:
const
Text
(
'
Upload
'
),
label:
const
Text
(
'
Sync
'
),
onPressed:
()
{
},
...
...
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