mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
refactor: rename productName to deviceNameOrProductName in search functionality
This commit is contained in:
@ -40,17 +40,18 @@ class DeviceManagementBloc
|
|||||||
List<AllDevicesModel> devices = [];
|
List<AllDevicesModel> devices = [];
|
||||||
_devices.clear();
|
_devices.clear();
|
||||||
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
||||||
devices = await DevicesManagementApi().fetchDevices('', '', projectUuid);
|
devices =
|
||||||
|
await DevicesManagementApi().fetchDevices('', '', projectUuid);
|
||||||
} else {
|
} else {
|
||||||
for (var community in spaceBloc.state.selectedCommunities) {
|
for (var community in spaceBloc.state.selectedCommunities) {
|
||||||
List<String> spacesList =
|
List<String> spacesList =
|
||||||
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
||||||
for (var space in spacesList) {
|
for (var space in spacesList) {
|
||||||
devices.addAll(await DevicesManagementApi().fetchDevices(
|
devices.addAll(await DevicesManagementApi()
|
||||||
community, space, projectUuid));
|
.fetchDevices(community, space, projectUuid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,7 +101,7 @@ class DeviceManagementBloc
|
|||||||
));
|
));
|
||||||
|
|
||||||
if (currentProductName.isNotEmpty) {
|
if (currentProductName.isNotEmpty) {
|
||||||
add(SearchDevices(productName: currentProductName));
|
add(SearchDevices(deviceNameOrProductName: currentProductName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -269,34 +270,41 @@ class DeviceManagementBloc
|
|||||||
return 'All';
|
return 'All';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSearchDevices(
|
void _onSearchDevices(
|
||||||
SearchDevices event, Emitter<DeviceManagementState> emit) {
|
SearchDevices event, Emitter<DeviceManagementState> emit) {
|
||||||
if ((event.community == null || event.community!.isEmpty) &&
|
if ((event.community == null || event.community!.isEmpty) &&
|
||||||
(event.unitName == null || event.unitName!.isEmpty) &&
|
(event.unitName == null || event.unitName!.isEmpty) &&
|
||||||
(event.productName == null || event.productName!.isEmpty)) {
|
(event.deviceNameOrProductName == null ||
|
||||||
|
event.deviceNameOrProductName!.isEmpty)) {
|
||||||
currentProductName = '';
|
currentProductName = '';
|
||||||
if (state is DeviceManagementFiltered) {
|
_filteredDevices = List.from(_devices);
|
||||||
add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
|
emit(DeviceManagementLoaded(
|
||||||
} else {
|
devices: _devices,
|
||||||
return;
|
selectedIndex: _selectedIndex,
|
||||||
}
|
onlineCount: _onlineCount,
|
||||||
|
offlineCount: _offlineCount,
|
||||||
|
lowBatteryCount: _lowBatteryCount,
|
||||||
|
selectedDevice: null,
|
||||||
|
isControlButtonEnabled: false,
|
||||||
|
));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
if (event.deviceNameOrProductName == currentProductName &&
|
||||||
if (event.productName == currentProductName &&
|
|
||||||
event.community == currentCommunity &&
|
event.community == currentCommunity &&
|
||||||
event.unitName == currentUnitName &&
|
event.unitName == currentUnitName &&
|
||||||
event.searchField) {
|
event.searchField) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentProductName = event.productName ?? '';
|
currentProductName = event.deviceNameOrProductName ?? '';
|
||||||
currentCommunity = event.community;
|
currentCommunity = event.community;
|
||||||
currentUnitName = event.unitName;
|
currentUnitName = event.unitName;
|
||||||
|
|
||||||
List<AllDevicesModel> devicesToSearch = _filteredDevices;
|
List<AllDevicesModel> devicesToSearch = _devices;
|
||||||
|
|
||||||
if (devicesToSearch.isNotEmpty) {
|
if (devicesToSearch.isNotEmpty) {
|
||||||
|
final searchText = event.deviceNameOrProductName?.toLowerCase() ?? '';
|
||||||
|
|
||||||
final filteredDevices = devicesToSearch.where((device) {
|
final filteredDevices = devicesToSearch.where((device) {
|
||||||
final matchesCommunity = event.community == null ||
|
final matchesCommunity = event.community == null ||
|
||||||
event.community!.isEmpty ||
|
event.community!.isEmpty ||
|
||||||
@ -304,31 +312,25 @@ class DeviceManagementBloc
|
|||||||
?.toLowerCase()
|
?.toLowerCase()
|
||||||
.contains(event.community!.toLowerCase()) ??
|
.contains(event.community!.toLowerCase()) ??
|
||||||
false);
|
false);
|
||||||
|
|
||||||
final matchesUnit = event.unitName == null ||
|
final matchesUnit = event.unitName == null ||
|
||||||
event.unitName!.isEmpty ||
|
event.unitName!.isEmpty ||
|
||||||
(device.spaces != null &&
|
(device.spaces != null &&
|
||||||
device.spaces!.isNotEmpty &&
|
device.spaces!.any((space) =>
|
||||||
device.spaces![0].spaceName!
|
space.spaceName != null &&
|
||||||
.toLowerCase()
|
space.spaceName!
|
||||||
.contains(event.unitName!.toLowerCase()));
|
.toLowerCase()
|
||||||
final matchesProductName = event.productName == null ||
|
.contains(event.unitName!.toLowerCase())));
|
||||||
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);
|
|
||||||
|
|
||||||
return matchesCommunity &&
|
final matchesSearchText = searchText.isEmpty ||
|
||||||
matchesUnit &&
|
(device.name?.toLowerCase().contains(searchText) ?? false) ||
|
||||||
(matchesProductName || matchesDeviceName);
|
(device.productName?.toLowerCase().contains(searchText) ?? false);
|
||||||
|
|
||||||
|
return matchesCommunity && matchesUnit && matchesSearchText;
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
|
_filteredDevices = filteredDevices;
|
||||||
|
|
||||||
emit(DeviceManagementFiltered(
|
emit(DeviceManagementFiltered(
|
||||||
filteredDevices: filteredDevices,
|
filteredDevices: filteredDevices,
|
||||||
selectedIndex: _selectedIndex,
|
selectedIndex: _selectedIndex,
|
||||||
|
@ -38,18 +38,18 @@ class SelectedFilterChanged extends DeviceManagementEvent {
|
|||||||
class SearchDevices extends DeviceManagementEvent {
|
class SearchDevices extends DeviceManagementEvent {
|
||||||
final String? community;
|
final String? community;
|
||||||
final String? unitName;
|
final String? unitName;
|
||||||
final String? productName;
|
final String? deviceNameOrProductName;
|
||||||
final bool searchField;
|
final bool searchField;
|
||||||
|
|
||||||
const SearchDevices({
|
const SearchDevices({
|
||||||
this.community,
|
this.community,
|
||||||
this.unitName,
|
this.unitName,
|
||||||
this.productName,
|
this.deviceNameOrProductName,
|
||||||
this.searchField = false,
|
this.searchField = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [community, unitName, productName];
|
List<Object?> get props => [community, unitName, deviceNameOrProductName];
|
||||||
}
|
}
|
||||||
|
|
||||||
class SelectDevice extends DeviceManagementEvent {
|
class SelectDevice extends DeviceManagementEvent {
|
||||||
|
@ -53,7 +53,7 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters>
|
|||||||
controller: controller,
|
controller: controller,
|
||||||
onSubmitted: () {
|
onSubmitted: () {
|
||||||
final searchDevicesEvent = SearchDevices(
|
final searchDevicesEvent = SearchDevices(
|
||||||
productName: _productNameController.text,
|
deviceNameOrProductName: _productNameController.text,
|
||||||
unitName: _unitNameController.text,
|
unitName: _unitNameController.text,
|
||||||
searchField: true,
|
searchField: true,
|
||||||
);
|
);
|
||||||
@ -68,7 +68,7 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters>
|
|||||||
onSearch: () => context.read<DeviceManagementBloc>().add(
|
onSearch: () => context.read<DeviceManagementBloc>().add(
|
||||||
SearchDevices(
|
SearchDevices(
|
||||||
unitName: _unitNameController.text,
|
unitName: _unitNameController.text,
|
||||||
productName: _productNameController.text,
|
deviceNameOrProductName: _productNameController.text,
|
||||||
searchField: true,
|
searchField: true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user