added device option panel and implement search function
This commit is contained in:
parent
b31dee4799
commit
259985f8cc
|
@ -23,7 +23,7 @@ class CloudServiceAPI {
|
|||
static String _password = "";
|
||||
static late Map<String, String> _headers;
|
||||
static bool _initState = false;
|
||||
static List<dynamic> devices = List<dynamic>.empty(growable: true);
|
||||
static List<DeviceModel> devices = List<DeviceModel>.empty(growable: true);
|
||||
|
||||
CloudServiceAPI() {
|
||||
if (!_initState) {
|
||||
|
@ -72,14 +72,16 @@ class CloudServiceAPI {
|
|||
DeviceInfoModel deviceInfoModel = DeviceInfoModel.fromJson(jsonObject);
|
||||
return deviceInfoModel;
|
||||
}
|
||||
Future<List<DeviceInfoModel>> getDevicesInfo() async {
|
||||
updateDeviceList();
|
||||
List<DeviceInfoModel> deviceInfoModelList = List<DeviceInfoModel>.empty(growable: true);
|
||||
for(DeviceModel tmp in devices){
|
||||
deviceInfoModelList.add(await getDeviceInfo(tmp.id));
|
||||
}
|
||||
return deviceInfoModelList;
|
||||
}
|
||||
Future updateDeviceList() async {
|
||||
devices = await getDevices();
|
||||
debugPrint("devices: ${devices.elementAt(0)}");
|
||||
}
|
||||
Future<Map<String, dynamic>> getDeviceInfo(deviceID) async {
|
||||
Uri url = Uri.https(address, '/api/devices/$deviceID');
|
||||
Response r = await get(url, headers: headers);
|
||||
return json.decode(r.body) as Map<String, dynamic>;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> getInformation() async {
|
||||
|
@ -87,6 +89,14 @@ class CloudServiceAPI {
|
|||
Response response = await get(url, headers: _headers);
|
||||
return json.decode(response.body) as Map<String, dynamic>;
|
||||
}
|
||||
Future<bool> deleteDevice(String clientId) async {
|
||||
Uri url = Uri.https(_address, '/api/devices/$clientId');
|
||||
Response response = await delete(url, headers: _headers);
|
||||
if(response.statusCode == 204){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<bool> createDevice(String id, String primaryThumbprint, String secondaryThumbprint) async {
|
||||
Uri url = Uri.https(_address, '/api/devices');
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../objects/cloud_service_api.dart';
|
||||
import '../objects/create_material_color.dart';
|
||||
import '../widgets/sidebar.dart';
|
||||
|
||||
|
@ -33,6 +34,7 @@ class HomeScreen extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _HomeScreen extends State<HomeScreen> {
|
||||
final CloudServiceAPI _cloudServiceAPI = CloudServiceAPI();
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
@ -63,6 +64,21 @@ class _RegisteredDevicesScreen extends State<RegisteredDevicesScreen> {
|
|||
super.initState();
|
||||
}
|
||||
|
||||
Future searchDevice(String clientId) async {
|
||||
List<DeviceInfoModel> searchResult = List<DeviceInfoModel>.empty(growable: true);
|
||||
for(DeviceInfoModel tmp in _registeredInfoDevices!){
|
||||
if(clientId == ""){
|
||||
// _fetchRegisteredDevices();
|
||||
// break;
|
||||
// missing implementation
|
||||
}
|
||||
if(tmp.id.contains(clientId)){
|
||||
searchResult.add(tmp);
|
||||
}
|
||||
}
|
||||
_registeredInfoDevices = searchResult;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -99,13 +115,13 @@ class _RegisteredDevicesScreen extends State<RegisteredDevicesScreen> {
|
|||
obscureText: false,
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
hintText: 'Enter the server password',
|
||||
hintText: 'Search for Devices',
|
||||
labelText: "Search",
|
||||
suffixIcon: IconButton(
|
||||
icon: const Icon(Icons.search),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
// TODO Suchfunktion
|
||||
searchDevice(_searchText);
|
||||
});
|
||||
},
|
||||
),
|
||||
|
@ -130,8 +146,39 @@ class _RegisteredDevicesScreen extends State<RegisteredDevicesScreen> {
|
|||
DeviceInfoModel entry = _registeredInfoDevices![index];
|
||||
//DeviceInfoModel entryInfo = await _cloudServiceAPI.getDeviceInfo(entry.id);
|
||||
return CustomListTile(
|
||||
title: "${entry.id} \nentrypoint: ${entry.endpoint} \nstatus: ${entry.status} \nconnection: ${entry.connectionState} \nlast activity: ${entry.lastActivityTime}",
|
||||
title: entry.id,
|
||||
icon: Icons.devices,
|
||||
onTap: () => showDialog<String>(
|
||||
context: context,
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: const Text('Device Info'),
|
||||
content: Text("${entry.id} "
|
||||
"\nentrypoint: ${entry.endpoint} "
|
||||
"\nstatus: ${entry.status} "
|
||||
"\nconnection: ${entry.connectionState} "
|
||||
"\nlast activity: ${entry.lastActivityTime}"
|
||||
"\nprimaryThumbprint: ${entry.primaryThumbprint}"),
|
||||
backgroundColor: Colors.white70,
|
||||
actions: <Widget>[
|
||||
TextButton(onPressed: () => Navigator.pop(context, 'Cancel'),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
_cloudServiceAPI.deleteDevice(entry.id);
|
||||
Navigator.pop(context, 'delete device');
|
||||
},
|
||||
child: const Text('Delete Device'),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
/*
|
||||
Navigator.push(context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => DeviceOptions(deviceInfoModel: entry)));
|
||||
*/
|
||||
|
||||
);
|
||||
},
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue