mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-26 20:44:54 +00:00
push search, space color selection, global user access fixes
This commit is contained in:
@ -134,11 +134,27 @@ class DeviceManagementBloc
|
||||
|
||||
void _onSearchDevices(
|
||||
SearchDevices event, Emitter<DeviceManagementState> emit) {
|
||||
if (_devices.isNotEmpty) {
|
||||
_selectedDevices.clear();
|
||||
_selectedIndex = 0;
|
||||
// If the search fields are all empty, restore the last filtered devices
|
||||
if ((event.community == null || event.community!.isEmpty) &&
|
||||
(event.unitName == null || event.unitName!.isEmpty) &&
|
||||
(event.productName == null || event.productName!.isEmpty)) {
|
||||
// If the current state is filtered, re-emit the filtered state
|
||||
if (state is DeviceManagementFiltered) {
|
||||
add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
|
||||
}
|
||||
}
|
||||
|
||||
final filteredDevices = _devices.where((device) {
|
||||
List<AllDevicesModel> devicesToSearch = _devices;
|
||||
|
||||
if (state is DeviceManagementFiltered) {
|
||||
devicesToSearch = (state as DeviceManagementFiltered).filteredDevices;
|
||||
}
|
||||
|
||||
if (devicesToSearch.isNotEmpty) {
|
||||
_selectedDevices.clear();
|
||||
_selectedIndex = _selectedIndex;
|
||||
|
||||
final filteredDevices = devicesToSearch.where((device) {
|
||||
final matchesCommunity = event.community == null ||
|
||||
event.community!.isEmpty ||
|
||||
(device.room?.name
|
||||
@ -157,11 +173,21 @@ class DeviceManagementBloc
|
||||
?.toLowerCase()
|
||||
.contains(event.productName!.toLowerCase()) ??
|
||||
false);
|
||||
return matchesCommunity && matchesUnit && matchesProductName;
|
||||
final matchesDeviceName = event.productName == null ||
|
||||
event.productName!.isEmpty ||
|
||||
(device.categoryName
|
||||
?.toLowerCase()
|
||||
.contains(event.productName!.toLowerCase()) ??
|
||||
false);
|
||||
|
||||
return matchesCommunity &&
|
||||
matchesUnit &&
|
||||
(matchesProductName || matchesDeviceName);
|
||||
}).toList();
|
||||
|
||||
emit(DeviceManagementFiltered(
|
||||
filteredDevices: filteredDevices,
|
||||
selectedIndex: 0,
|
||||
selectedIndex: _selectedIndex,
|
||||
onlineCount: _onlineCount,
|
||||
offlineCount: _offlineCount,
|
||||
lowBatteryCount: _lowBatteryCount,
|
||||
|
||||
@ -119,7 +119,7 @@ class AllDevicesModel {
|
||||
timeZone = json['timeZone']?.toString();
|
||||
updateTime = int.tryParse(json['updateTime']?.toString() ?? '');
|
||||
uuid = json['uuid']?.toString();
|
||||
batteryLevel = int.tryParse(json['batteryLevel']?.toString() ?? '');
|
||||
batteryLevel = int.tryParse(json['battery']?.toString() ?? '');
|
||||
}
|
||||
Map<String, dynamic> toJson() {
|
||||
final data = <String, dynamic>{};
|
||||
@ -151,7 +151,7 @@ class AllDevicesModel {
|
||||
data['timeZone'] = timeZone;
|
||||
data['updateTime'] = updateTime;
|
||||
data['uuid'] = uuid;
|
||||
data['batteryLevel'] = batteryLevel;
|
||||
data['battery'] = batteryLevel;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user