mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
SP-1606-FE-Fix-Search-Function-on-Devices-Screen-to-Support-All-Device-Types-Flush-Mounted-Sensor (#281)
…ctionality <!-- Thanks for contributing! Provide a description of your changes below and a general summary in the title Please look at the following checklist to ensure that your PR can be accepted quickly: --> ## Jira Ticket [SP-1606](https://syncrow.atlassian.net/browse/SP-1606) ## Description <!--- Describe your changes in detail --> search by product name and device name ## Type of Change <!--- Put an `x` in all the boxes that apply: --> - [ ] ✨ New feature (non-breaking change which adds functionality) - [x] 🛠️ Bug fix (non-breaking change which fixes an issue) - [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change) - [ ] 🧹 Code refactor - [ ] ✅ Build configuration change - [ ] 📝 Documentation - [ ] 🗑️ Chore [SP-1606]: https://syncrow.atlassian.net/browse/SP-1606?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
This commit is contained in:
@ -40,17 +40,18 @@ class DeviceManagementBloc
|
||||
List<AllDevicesModel> devices = [];
|
||||
_devices.clear();
|
||||
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
|
||||
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
||||
devices = await DevicesManagementApi().fetchDevices('', '', projectUuid);
|
||||
devices =
|
||||
await DevicesManagementApi().fetchDevices('', '', projectUuid);
|
||||
} else {
|
||||
for (var community in spaceBloc.state.selectedCommunities) {
|
||||
List<String> spacesList =
|
||||
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
||||
for (var space in spacesList) {
|
||||
devices.addAll(await DevicesManagementApi().fetchDevices(
|
||||
community, space, projectUuid));
|
||||
devices.addAll(await DevicesManagementApi()
|
||||
.fetchDevices(community, space, projectUuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,7 +101,7 @@ class DeviceManagementBloc
|
||||
));
|
||||
|
||||
if (currentProductName.isNotEmpty) {
|
||||
add(SearchDevices(productName: currentProductName));
|
||||
add(SearchDevices(deviceNameOrProductName: currentProductName));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -269,34 +270,41 @@ class DeviceManagementBloc
|
||||
return 'All';
|
||||
}
|
||||
}
|
||||
|
||||
void _onSearchDevices(
|
||||
SearchDevices event, Emitter<DeviceManagementState> emit) {
|
||||
if ((event.community == null || event.community!.isEmpty) &&
|
||||
(event.unitName == null || event.unitName!.isEmpty) &&
|
||||
(event.productName == null || event.productName!.isEmpty)) {
|
||||
(event.deviceNameOrProductName == null ||
|
||||
event.deviceNameOrProductName!.isEmpty)) {
|
||||
currentProductName = '';
|
||||
if (state is DeviceManagementFiltered) {
|
||||
add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
_filteredDevices = List.from(_devices);
|
||||
emit(DeviceManagementLoaded(
|
||||
devices: _devices,
|
||||
selectedIndex: _selectedIndex,
|
||||
onlineCount: _onlineCount,
|
||||
offlineCount: _offlineCount,
|
||||
lowBatteryCount: _lowBatteryCount,
|
||||
selectedDevice: null,
|
||||
isControlButtonEnabled: false,
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.productName == currentProductName &&
|
||||
if (event.deviceNameOrProductName == currentProductName &&
|
||||
event.community == currentCommunity &&
|
||||
event.unitName == currentUnitName &&
|
||||
event.searchField) {
|
||||
return;
|
||||
}
|
||||
|
||||
currentProductName = event.productName ?? '';
|
||||
currentProductName = event.deviceNameOrProductName ?? '';
|
||||
currentCommunity = event.community;
|
||||
currentUnitName = event.unitName;
|
||||
|
||||
List<AllDevicesModel> devicesToSearch = _filteredDevices;
|
||||
List<AllDevicesModel> devicesToSearch = _devices;
|
||||
|
||||
if (devicesToSearch.isNotEmpty) {
|
||||
final searchText = event.deviceNameOrProductName?.toLowerCase() ?? '';
|
||||
|
||||
final filteredDevices = devicesToSearch.where((device) {
|
||||
final matchesCommunity = event.community == null ||
|
||||
event.community!.isEmpty ||
|
||||
@ -304,31 +312,25 @@ class DeviceManagementBloc
|
||||
?.toLowerCase()
|
||||
.contains(event.community!.toLowerCase()) ??
|
||||
false);
|
||||
|
||||
final matchesUnit = event.unitName == null ||
|
||||
event.unitName!.isEmpty ||
|
||||
(device.spaces != null &&
|
||||
device.spaces!.isNotEmpty &&
|
||||
device.spaces![0].spaceName!
|
||||
.toLowerCase()
|
||||
.contains(event.unitName!.toLowerCase()));
|
||||
final matchesProductName = event.productName == null ||
|
||||
event.productName!.isEmpty ||
|
||||
(device.name
|
||||
?.toLowerCase()
|
||||
.contains(event.productName!.toLowerCase()) ??
|
||||
false);
|
||||
final matchesDeviceName = event.productName == null ||
|
||||
event.productName!.isEmpty ||
|
||||
(device.categoryName
|
||||
?.toLowerCase()
|
||||
.contains(event.productName!.toLowerCase()) ??
|
||||
false);
|
||||
device.spaces!.any((space) =>
|
||||
space.spaceName != null &&
|
||||
space.spaceName!
|
||||
.toLowerCase()
|
||||
.contains(event.unitName!.toLowerCase())));
|
||||
|
||||
return matchesCommunity &&
|
||||
matchesUnit &&
|
||||
(matchesProductName || matchesDeviceName);
|
||||
final matchesSearchText = searchText.isEmpty ||
|
||||
(device.name?.toLowerCase().contains(searchText) ?? false) ||
|
||||
(device.productName?.toLowerCase().contains(searchText) ?? false);
|
||||
|
||||
return matchesCommunity && matchesUnit && matchesSearchText;
|
||||
}).toList();
|
||||
|
||||
_filteredDevices = filteredDevices;
|
||||
|
||||
emit(DeviceManagementFiltered(
|
||||
filteredDevices: filteredDevices,
|
||||
selectedIndex: _selectedIndex,
|
||||
|
@ -38,18 +38,18 @@ class SelectedFilterChanged extends DeviceManagementEvent {
|
||||
class SearchDevices extends DeviceManagementEvent {
|
||||
final String? community;
|
||||
final String? unitName;
|
||||
final String? productName;
|
||||
final String? deviceNameOrProductName;
|
||||
final bool searchField;
|
||||
|
||||
const SearchDevices({
|
||||
this.community,
|
||||
this.unitName,
|
||||
this.productName,
|
||||
this.deviceNameOrProductName,
|
||||
this.searchField = false,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [community, unitName, productName];
|
||||
List<Object?> get props => [community, unitName, deviceNameOrProductName];
|
||||
}
|
||||
|
||||
class SelectDevice extends DeviceManagementEvent {
|
||||
|
@ -53,7 +53,7 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters>
|
||||
controller: controller,
|
||||
onSubmitted: () {
|
||||
final searchDevicesEvent = SearchDevices(
|
||||
productName: _productNameController.text,
|
||||
deviceNameOrProductName: _productNameController.text,
|
||||
unitName: _unitNameController.text,
|
||||
searchField: true,
|
||||
);
|
||||
@ -68,7 +68,7 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters>
|
||||
onSearch: () => context.read<DeviceManagementBloc>().add(
|
||||
SearchDevices(
|
||||
unitName: _unitNameController.text,
|
||||
productName: _productNameController.text,
|
||||
deviceNameOrProductName: _productNameController.text,
|
||||
searchField: true,
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user