Skip to content

Commit

Permalink
Hlm 3091 proximity based search (#190)
Browse files Browse the repository at this point in the history
* added filter for stock recon

* removed un-used code

* added fallback code

* added query

* enabled proximity bases search

* modified the query

* modfied the query

* added clearing the  search bar when proximity search is triggered

* added filters

* Update dart.yml (#200)

* Update dart.yml

* Update dart.yml

* Update dart.yml

* Update dart.yml

* HLM-3379: Fixed proximity based search

* Revert "HLM-3379: Fixed proximity based search"

This reverts commit a22ef1c.

* HLM-3379: Fixed proximity based search (#205)

* HLM-3379: Fixed proximity based search

* HLM-3379: Code updated

* HLM-3379: Updated code

* Proximity Based search Code review changes

* HLM-3379:Updated distance display info inside brackets

---------

Co-authored-by: Ramkrishna-egov <[email protected]>

* HLM-3950:: Digit Components changes pull out from CBO App (#210)

* HLM-3560::Black Screen fixes on App launch (#211)

* HLM-3560::Black Screen fixes on App launch

* HLM-3560::Black Screen and Offline data fetch on App launch

* HLM-3560:: added Code commenting for Blank screen fixes

* Blank screen localizations changed to English

* Hlm 2982 added seperate server client time (#209)

* added client-audit-time

* added roles actions

* removed commented code

* added client audit details

* updated the mason scripts - added client audit details

* added client audit details

* added time log in audiit

* added audit details

* added client modified Time

* added client audit details for member

* added client audit details

* added client audit details on household update

* added client audit details for delete

* added client aduit details for project beneficary

* added client audit details

* added null check

* added null check

* added missing routers

* added fix for task client audit details

* added time stamp and removed the print statements

* removed TODO as it's been completed

* Update auth_model.dart

---------

Co-authored-by: Anil Singha <[email protected]>
Co-authored-by: Ramkrishna-egov <[email protected]>
Co-authored-by: Ramkrishna-egov <[email protected]>
  • Loading branch information
4 people authored Oct 5, 2023
1 parent 984549f commit e954073
Show file tree
Hide file tree
Showing 35 changed files with 1,682 additions and 422 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Flutter action
uses: subosito/[email protected]
with:
flutter-version: '3.10.5'
flutter-version: "3.10.5"

- name: Generate models
run: ./tools/install_bricks.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:stream_transform/stream_transform.dart';

import '../../data/repositories/local/address.dart';
import '../../data/repositories/local/project_beneficiary.dart';
import '../../data/repositories/local/task.dart';
import '../../models/data_model.dart';
Expand All @@ -26,6 +27,7 @@ class SearchHouseholdsBloc
final String userUid;
final IndividualDataRepository individual;
final HouseholdDataRepository household;
final AddressLocalRepository addressRepository;
final HouseholdMemberDataRepository householdMember;
final ProjectBeneficiaryDataRepository projectBeneficiary;
final TaskDataRepository taskDataRepository;
Expand All @@ -39,13 +41,15 @@ class SearchHouseholdsBloc
required this.projectBeneficiary,
required this.taskDataRepository,
required this.beneficiaryType,
required this.addressRepository,
}) : super(const SearchHouseholdsState()) {
on(
_handleSearchByHouseholdHead,
transformer: debounce<SearchHouseholdsSearchByHouseholdHeadEvent>(
const Duration(milliseconds: 100),
),
);
on(_handleSearchByProximitity);
on(_handleClear);
on(_handleSearchByHousehold);
on(_handleInitialize);
Expand Down Expand Up @@ -144,8 +148,6 @@ class SearchHouseholdsBloc
beneficiaryType == BeneficiaryType.individual
? individuals.map((e) => e.clientReferenceId).toList()
: [event.householdModel.clientReferenceId],

//[TODO] Need to check for beneficiaryId
),
);

Expand Down Expand Up @@ -193,6 +195,83 @@ class SearchHouseholdsBloc
}
}

FutureOr<void> _handleSearchByProximitity(
SearchHouseholdsByProximityEvent event,
SearchHouseholdsEmitter emit,
) async {
emit(state.copyWith(loading: true));
final results =
await addressRepository.searchHouseHoldbyAddress(AddressSearchModel(
latitude: event.latitude,
longitude: event.longititude,
maxRadius: event.maxRadius,
));
final containers = <HouseholdMemberWrapper>[];
for (final element in results) {
final members = await householdMember.search(
HouseholdMemberSearchModel(
householdClientReferenceId: element.clientReferenceId,
),
);
final head = await householdMember.search(
HouseholdMemberSearchModel(
householdClientReferenceId: element.clientReferenceId,
isHeadOfHousehold: true,
),
);

final individualIds = members
.map((element) => element.individualClientReferenceId)
.whereNotNull()
.toList();

final allHouseholdMembers = await individual.search(
IndividualSearchModel(
clientReferenceId: individualIds,
),
);

final headOfHousehold = allHouseholdMembers.firstWhere((element) =>
element.clientReferenceId == head.first.individualClientReferenceId);

final projectBeneficiaries = beneficiaryType != BeneficiaryType.individual
? await projectBeneficiary.search(
ProjectBeneficiarySearchModel(
beneficiaryClientReferenceId: [element.clientReferenceId],
projectId: event.projectId,
),
)
: await projectBeneficiary.search(
ProjectBeneficiarySearchModel(
beneficiaryClientReferenceId: individualIds,
projectId: event.projectId,
),
);

final tasks = await taskDataRepository.search(TaskSearchModel(
projectBeneficiaryClientReferenceId:
projectBeneficiaries.map((e) => e.clientReferenceId).toList(),
));

containers.add(
HouseholdMemberWrapper(
household: element,
headOfHousehold: headOfHousehold,
members: allHouseholdMembers,
projectBeneficiaries: projectBeneficiaries,
tasks: tasks.isEmpty ? null : tasks,
),
);
}
emit(state.copyWith(
householdMembers: containers,
loading: false,
searchQuery: null,
));

return;
}

FutureOr<void> _handleSearchByHouseholdHead(
SearchHouseholdsSearchByHouseholdHeadEvent event,
SearchHouseholdsEmitter emit,
Expand All @@ -211,21 +290,36 @@ class SearchHouseholdsBloc
searchQuery: event.searchText,
));

final results = await individual.search(
final List<HouseholdModel> proximityBasedResults =
await addressRepository.searchHouseHoldbyAddress(AddressSearchModel(
latitude: event.latitude,
longitude: event.longitude,
maxRadius: event.maxRadius,
));
final List<IndividualModel> results = await individual.search(
IndividualSearchModel(
name: NameSearchModel(givenName: event.searchText.trim()),
),
);

final householdMembers = <HouseholdMemberModel>[];

for (final element in results) {
final members = await householdMember.search(
HouseholdMemberSearchModel(
individualClientReferenceId: element.clientReferenceId,
isHeadOfHousehold: true,
),
);
final r = event.isProximityEnabled ? proximityBasedResults : results;
for (final element in r) {
final members = event.isProximityEnabled
? await householdMember.search(
HouseholdMemberSearchModel(
householdClientReferenceId:
(element as HouseholdModel).clientReferenceId,
isHeadOfHousehold: true,
),
)
: await householdMember.search(
HouseholdMemberSearchModel(
individualClientReferenceId:
(element as IndividualModel).clientReferenceId,
isHeadOfHousehold: true,
),
);

for (final member in members) {
final allHouseholdMembers = await householdMember.search(
Expand All @@ -250,20 +344,31 @@ class SearchHouseholdsBloc
.toList();

if (householdId == null) continue;

final households = await household.search(
HouseholdSearchModel(
clientReferenceId: [householdId],
latitude: event.latitude,
longitude: event.longitude,
maxRadius: event.maxRadius,
),
);

if (households.isEmpty) continue;

final resultHousehold = households.first;

final individuals = await individual.search(
IndividualSearchModel(clientReferenceId: individualIds),
);
final individuals = event.isProximityEnabled
? await individual.search(
IndividualSearchModel(
clientReferenceId: individualIds,
name: NameSearchModel(givenName: event.searchText.trim()),
),
)
: await individual.search(
IndividualSearchModel(
clientReferenceId: individualIds,
),
);

final head = individuals.firstWhereOrNull(
(element) =>
Expand All @@ -283,14 +388,12 @@ class SearchHouseholdsBloc
beneficiaryClientReferenceId: [
resultHousehold.clientReferenceId,
],
//[TODO] Need to check for beneficiaryId
projectId: event.projectId,
),
)
: await projectBeneficiary.search(
ProjectBeneficiarySearchModel(
beneficiaryClientReferenceId: individualIds,
//[TODO] Need to check for beneficiaryId
projectId: event.projectId,
),
);
Expand Down Expand Up @@ -336,14 +439,29 @@ class SearchHouseholdsEvent with _$SearchHouseholdsEvent {

const factory SearchHouseholdsEvent.searchByHousehold({
required String projectId,
double? latitude,
double? longitude,
double? maxRadius,
required final bool isProximityEnabled,
required HouseholdModel householdModel,
}) = SearchHouseholdsByHouseholdsEvent;

const factory SearchHouseholdsEvent.searchByHouseholdHead({
required String searchText,
required String projectId,
required final bool isProximityEnabled,
double? latitude,
double? longitude,
double? maxRadius,
}) = SearchHouseholdsSearchByHouseholdHeadEvent;

const factory SearchHouseholdsEvent.searchByProximity({
required double latitude,
required double longititude,
required String projectId,
required double maxRadius,
}) = SearchHouseholdsByProximityEvent;

const factory SearchHouseholdsEvent.clear() = SearchHouseholdsClearEvent;
}

Expand Down Expand Up @@ -374,6 +492,7 @@ class HouseholdMemberWrapper with _$HouseholdMemberWrapper {
required IndividualModel headOfHousehold,
required List<IndividualModel> members,
required List<ProjectBeneficiaryModel> projectBeneficiaries,
double? distance,
List<TaskModel>? tasks,
}) = _HouseholdMemberWrapper;
}
Loading

0 comments on commit e954073

Please sign in to comment.