From e23dd5fb696d6fa0b4742f66775a7db88313afaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=83=D0=B7=D0=BD=D0=B5=D1=86=D0=BE=D0=B2=20=D0=9D?= =?UTF-8?q?=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Thu, 12 Dec 2024 22:00:11 +0300 Subject: [PATCH] added filter --- .../home/presentation/bloc/home_bloc.dart | 7 ++- .../equipment/equipment_list_entity.dart | 50 +++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/flutter_front/lib/features/home/presentation/bloc/home_bloc.dart b/flutter_front/lib/features/home/presentation/bloc/home_bloc.dart index 247d6a7..c1b22c8 100644 --- a/flutter_front/lib/features/home/presentation/bloc/home_bloc.dart +++ b/flutter_front/lib/features/home/presentation/bloc/home_bloc.dart @@ -246,13 +246,16 @@ class HomeBloc extends Bloc { List? collapsedEquipment, Map? filterParams, }) { - final statuses = _getStatuses(equipment, chartData.data); + // Применяем фильтры к equipment + final filteredEquipment = equipment.filterEquipment(filterParams ?? {}); + + final statuses = _getStatuses(filteredEquipment, chartData.data); final maxTemperature = _getMaxTemperature(chartData); final workNum = statuses.values.where((status) => status == EquipmentStatus.work).length; return HomeLoaded( logo, - equipment, + filteredEquipment, chartData.data, chartData.settings, statuses, diff --git a/flutter_front/lib/shared/domain/entities/equipment/equipment_list_entity.dart b/flutter_front/lib/shared/domain/entities/equipment/equipment_list_entity.dart index 4a0c600..8be6005 100644 --- a/flutter_front/lib/shared/domain/entities/equipment/equipment_list_entity.dart +++ b/flutter_front/lib/shared/domain/entities/equipment/equipment_list_entity.dart @@ -31,4 +31,54 @@ class EquipmentListEntity { } const EquipmentListEntity({required this.equipment}); + + EquipmentListEntity filterEquipment(Map filters) { + if (filters.isEmpty) return this; + + List filteredEquipment = equipment.where((item) { + // Check name filter + if (filters.containsKey('name')) { + String nameFilter = filters['name'].toString().toLowerCase(); + if (!item.name.toLowerCase().contains(nameFilter)) { + return false; + } + } + + // Check location filter + if (filters.containsKey('location')) { + String locationFilter = filters['location'].toString().toLowerCase(); + if (!item.details.location.toLowerCase().contains(locationFilter)) { + return false; + } + } + + // Check group filter + if (filters.containsKey('group')) { + String groupFilter = filters['group'].toString().toLowerCase(); + if (!item.details.group.toLowerCase().contains(groupFilter)) { + return false; + } + } + + // Check year filter + if (filters.containsKey('year')) { + int yearFilter = int.parse(filters['year']); + if (item.details.year != yearFilter) { + return false; + } + } + + // Check status filter + if (filters.containsKey('status')) { + String statusFilter = filters['status'].toString().toLowerCase(); + if (!item.details.status.toLowerCase().contains(statusFilter)) { + return false; + } + } + + return true; + }).toList(); + + return EquipmentListEntity(equipment: filteredEquipment); + } } \ No newline at end of file