fix communities filtiring issue

This commit is contained in:
Rafeek-Khoudare
2025-07-16 11:02:32 +03:00
parent 08e2ed4b4c
commit 3e634dc7a2
3 changed files with 23 additions and 11 deletions

View File

@ -53,8 +53,9 @@ class DeviceManagementBloc
for (var community in spaceBloc.state.selectedCommunities) { for (var community in spaceBloc.state.selectedCommunities) {
final spacesList = final spacesList =
spaceBloc.state.selectedCommunityAndSpaces[community] ?? []; spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
devices.addAll(await DevicesManagementApi() devices.addAll(await DevicesManagementApi().fetchDevices(projectUuid,
.fetchDevices(projectUuid, spacesId: spacesList)); spacesId: spacesList,
communities: spaceBloc.state.selectedCommunities));
} }
} }
@ -158,7 +159,8 @@ class DeviceManagementBloc
add(FilterDevices(_getFilterFromIndex(_selectedIndex))); add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
} }
void _onSelectDevice(SelectDevice event, Emitter<DeviceManagementState> emit) { void _onSelectDevice(
SelectDevice event, Emitter<DeviceManagementState> emit) {
final selectedUuid = event.selectedDevice.uuid; final selectedUuid = event.selectedDevice.uuid;
if (_selectedDevices.any((device) => device.uuid == selectedUuid)) { if (_selectedDevices.any((device) => device.uuid == selectedUuid)) {
@ -254,7 +256,8 @@ class DeviceManagementBloc
_onlineCount = _devices.where((device) => device.online == true).length; _onlineCount = _devices.where((device) => device.online == true).length;
_offlineCount = _devices.where((device) => device.online == false).length; _offlineCount = _devices.where((device) => device.online == false).length;
_lowBatteryCount = _devices _lowBatteryCount = _devices
.where((device) => device.batteryLevel != null && device.batteryLevel! < 20) .where((device) =>
device.batteryLevel != null && device.batteryLevel! < 20)
.length; .length;
} }
@ -271,7 +274,8 @@ class DeviceManagementBloc
} }
} }
void _onSearchDevices(SearchDevices event, Emitter<DeviceManagementState> emit) { void _onSearchDevices(
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.deviceNameOrProductName == null || (event.deviceNameOrProductName == null ||
@ -435,8 +439,8 @@ class DeviceManagementBloc
final selectedDevices = loaded.selectedDevice?.map((device) { final selectedDevices = loaded.selectedDevice?.map((device) {
if (device.uuid == event.deviceId) { if (device.uuid == event.deviceId) {
return device.copyWith( return device.copyWith(
subspace: subspace: device.subspace
device.subspace?.copyWith(subspaceName: event.newSubSpaceName)); ?.copyWith(subspaceName: event.newSubSpaceName));
} }
return device; return device;
}).toList(); }).toList();

View File

@ -937,13 +937,17 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
List<String> spacesList = List<String> spacesList =
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? []; spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
devices.addAll(await DevicesManagementApi() devices.addAll(await DevicesManagementApi().fetchDevices(
.fetchDevices(projectUuid, spacesId: spacesList)); projectUuid,
spacesId: spacesList,
communities: spaceBloc.state.selectedCommunities,
));
} }
} else { } else {
devices.addAll(await DevicesManagementApi().fetchDevices( devices.addAll(await DevicesManagementApi().fetchDevices(
projectUuid, projectUuid,
spacesId: [createRoutineBloc.selectedSpaceId], spacesId: [createRoutineBloc.selectedSpaceId],
communities: spaceBloc.state.selectedCommunities,
)); ));
} }

View File

@ -13,11 +13,15 @@ import 'package:syncrow_web/utils/constants/api_const.dart';
class DevicesManagementApi { class DevicesManagementApi {
Future<List<AllDevicesModel>> fetchDevices(String projectId, Future<List<AllDevicesModel>> fetchDevices(String projectId,
{List<String>? spacesId}) async { {List<String>? spacesId, List<String>? communities}) async {
try { try {
final response = await HTTPService().get( final response = await HTTPService().get(
path: ApiEndpoints.getSpaceDevices.replaceAll('{projectId}', projectId), path: ApiEndpoints.getSpaceDevices.replaceAll('{projectId}', projectId),
queryParameters: {if (spacesId != null) 'spaces': spacesId}, queryParameters: {
if (spacesId != null && spacesId.isNotEmpty) 'spaces': spacesId,
if (communities != null && communities.isNotEmpty)
'communities': communities,
},
showServerMessage: true, showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
final List<dynamic> jsonData = json['data'] as List<dynamic>; final List<dynamic> jsonData = json['data'] as List<dynamic>;