Handle device default dashboard
This commit is contained in:
@@ -19,6 +19,7 @@ abstract class EntityQueryApi {
|
||||
static final defaultDeviceFields = <EntityKey>[
|
||||
EntityKey(type: EntityKeyType.ENTITY_FIELD, key: 'name'),
|
||||
EntityKey(type: EntityKeyType.ENTITY_FIELD, key: 'type'),
|
||||
EntityKey(type: EntityKeyType.ENTITY_FIELD, key: 'label'),
|
||||
EntityKey(type: EntityKeyType.ENTITY_FIELD, key: 'createdTime')
|
||||
];
|
||||
|
||||
@@ -29,7 +30,7 @@ abstract class EntityQueryApi {
|
||||
static Future<int> countDevices(ThingsboardClient tbClient, {String? deviceType, bool? active}) {
|
||||
EntityFilter deviceFilter;
|
||||
if (deviceType != null) {
|
||||
deviceFilter = DeviceTypeFilter(deviceType: deviceType);
|
||||
deviceFilter = DeviceTypeFilter(deviceType: deviceType, deviceNameFilter: '');
|
||||
} else {
|
||||
deviceFilter = EntityTypeFilter(entityType: EntityType.DEVICE);
|
||||
}
|
||||
@@ -40,11 +41,11 @@ abstract class EntityQueryApi {
|
||||
return tbClient.getEntityQueryService().countEntitiesByQuery(deviceCountQuery);
|
||||
}
|
||||
|
||||
static EntityDataQuery createDefaultDeviceQuery({int pageSize = 10, String? searchText, String? deviceType, bool? active}) {
|
||||
static EntityDataQuery createDefaultDeviceQuery({int pageSize = 20, String? searchText, String? deviceType, bool? active}) {
|
||||
EntityFilter deviceFilter;
|
||||
List<KeyFilter>? keyFilters;
|
||||
if (deviceType != null) {
|
||||
deviceFilter = DeviceTypeFilter(deviceType: deviceType);
|
||||
deviceFilter = DeviceTypeFilter(deviceType: deviceType, deviceNameFilter: '');
|
||||
} else {
|
||||
deviceFilter = EntityTypeFilter(entityType: EntityType.DEVICE);
|
||||
}
|
||||
|
||||
30
lib/utils/utils.dart
Normal file
30
lib/utils/utils.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:thingsboard_client/thingsboard_client.dart';
|
||||
|
||||
abstract class Utils {
|
||||
|
||||
static String createDashboardEntityState(EntityId entityId, {String? entityName, String? entityLabel}) {
|
||||
var stateObj = [<String, dynamic>{
|
||||
'params': <String, dynamic>{
|
||||
'entityId': entityId.toJson()
|
||||
}
|
||||
}];
|
||||
if (entityName != null) {
|
||||
stateObj[0]['params']['entityName'] = entityName;
|
||||
}
|
||||
if (entityLabel != null) {
|
||||
stateObj[0]['params']['entityLabel'] = entityLabel;
|
||||
}
|
||||
var stateJson = json.encode(stateObj);
|
||||
var encodedUri = Uri.encodeComponent(stateJson);
|
||||
encodedUri = encodedUri.replaceAllMapped(RegExp(r'%([0-9A-F]{2})'), (match) {
|
||||
var p1 = match.group(1)!;
|
||||
return String.fromCharCode(int.parse(p1, radix: 16));
|
||||
});
|
||||
return Uri.encodeComponent(
|
||||
base64.encode(utf8.encode(encodedUri))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user