From 3e634dc7a2970c4b77f653c07de3425c35feaa84 Mon Sep 17 00:00:00 2001 From: Rafeek-Khoudare Date: Wed, 16 Jul 2025 11:02:32 +0300 Subject: [PATCH] fix communities filtiring issue --- .../device_managment_bloc.dart | 18 +++++++++++------- .../bloc/routine_bloc/routine_bloc.dart | 8 ++++++-- lib/services/devices_mang_api.dart | 8 ++++++-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart b/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart index d8cd04df..f79528f8 100644 --- a/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart +++ b/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart @@ -53,8 +53,9 @@ class DeviceManagementBloc for (var community in spaceBloc.state.selectedCommunities) { final spacesList = spaceBloc.state.selectedCommunityAndSpaces[community] ?? []; - devices.addAll(await DevicesManagementApi() - .fetchDevices(projectUuid, spacesId: spacesList)); + devices.addAll(await DevicesManagementApi().fetchDevices(projectUuid, + spacesId: spacesList, + communities: spaceBloc.state.selectedCommunities)); } } @@ -158,7 +159,8 @@ class DeviceManagementBloc add(FilterDevices(_getFilterFromIndex(_selectedIndex))); } - void _onSelectDevice(SelectDevice event, Emitter emit) { + void _onSelectDevice( + SelectDevice event, Emitter emit) { final selectedUuid = event.selectedDevice.uuid; if (_selectedDevices.any((device) => device.uuid == selectedUuid)) { @@ -254,7 +256,8 @@ class DeviceManagementBloc _onlineCount = _devices.where((device) => device.online == true).length; _offlineCount = _devices.where((device) => device.online == false).length; _lowBatteryCount = _devices - .where((device) => device.batteryLevel != null && device.batteryLevel! < 20) + .where((device) => + device.batteryLevel != null && device.batteryLevel! < 20) .length; } @@ -271,7 +274,8 @@ class DeviceManagementBloc } } - void _onSearchDevices(SearchDevices event, Emitter emit) { + void _onSearchDevices( + SearchDevices event, Emitter emit) { if ((event.community == null || event.community!.isEmpty) && (event.unitName == null || event.unitName!.isEmpty) && (event.deviceNameOrProductName == null || @@ -435,8 +439,8 @@ class DeviceManagementBloc final selectedDevices = loaded.selectedDevice?.map((device) { if (device.uuid == event.deviceId) { return device.copyWith( - subspace: - device.subspace?.copyWith(subspaceName: event.newSubSpaceName)); + subspace: device.subspace + ?.copyWith(subspaceName: event.newSubSpaceName)); } return device; }).toList(); diff --git a/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart index 971f4f8c..a26a2715 100644 --- a/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart +++ b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart @@ -937,13 +937,17 @@ class RoutineBloc extends Bloc { List spacesList = spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? []; - devices.addAll(await DevicesManagementApi() - .fetchDevices(projectUuid, spacesId: spacesList)); + devices.addAll(await DevicesManagementApi().fetchDevices( + projectUuid, + spacesId: spacesList, + communities: spaceBloc.state.selectedCommunities, + )); } } else { devices.addAll(await DevicesManagementApi().fetchDevices( projectUuid, spacesId: [createRoutineBloc.selectedSpaceId], + communities: spaceBloc.state.selectedCommunities, )); } diff --git a/lib/services/devices_mang_api.dart b/lib/services/devices_mang_api.dart index 8c74dbb1..684165e2 100644 --- a/lib/services/devices_mang_api.dart +++ b/lib/services/devices_mang_api.dart @@ -13,11 +13,15 @@ import 'package:syncrow_web/utils/constants/api_const.dart'; class DevicesManagementApi { Future> fetchDevices(String projectId, - {List? spacesId}) async { + {List? spacesId, List? communities}) async { try { final response = await HTTPService().get( 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, expectedResponseModel: (json) { final List jsonData = json['data'] as List;