Skip to content

Commit

Permalink
added filter
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovNick committed Dec 12, 2024
1 parent 78433f1 commit e23dd5f
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,16 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
List<String>? collapsedEquipment,
Map<String, dynamic>? 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,54 @@ class EquipmentListEntity {
}

const EquipmentListEntity({required this.equipment});

EquipmentListEntity filterEquipment(Map<String, dynamic> filters) {
if (filters.isEmpty) return this;

List<EquipmentEntity> 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);
}
}

0 comments on commit e23dd5f

Please sign in to comment.