Skip to content

Commit

Permalink
sorting tasks based on lastModifiedTime
Browse files Browse the repository at this point in the history
  • Loading branch information
naveenr-egov committed Sep 25, 2024
1 parent cb7b72f commit 5fb6235
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import '../../models/entities/referral.dart';
import '../../models/entities/side_effect.dart';
import '../../models/entities/task.dart';
import '../../utils/typedefs.dart';
import '../../utils/utils.dart';
import '../search_households/search_households.dart';

part 'household_overview.freezed.dart';
Expand Down Expand Up @@ -173,14 +174,11 @@ class HouseholdOverviewBloc
}

// Search for tasks associated with project beneficiaries.
final tasks = await taskDataRepository.search(TaskSearchModel(
var tasks = await taskDataRepository.search(TaskSearchModel(
projectBeneficiaryClientReferenceId:
projectBeneficiaries.map((e) => e.clientReferenceId).toList()));

tasks.sort((a, b) =>
a.clientAuditDetails?.createdTime
.compareTo(b.clientAuditDetails!.createdTime) ??
0);
tasks = sortTasks(tasks);

// Search for adverse events associated with tasks.
final sideEffects =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ class HouseHoldGlobalSearchBloc extends SearchHouseholdsBloc {
projectBeneficiariesList, taskList, sideEffectsList, referralsList);

taskList = tasksRelated[0];
taskList.sort((a, b) =>
a.clientAuditDetails?.createdTime
.compareTo(b.clientAuditDetails!.createdTime) ??
0);
taskList = sortTasks(taskList);
sideEffectsList = tasksRelated[1];
referralsList = tasksRelated[2];

Expand Down Expand Up @@ -171,10 +168,7 @@ class HouseHoldGlobalSearchBloc extends SearchHouseholdsBloc {
projectBeneficiariesList, taskList, sideEffectsList, referralsList);

taskList = tasksRelated[0];
taskList.sort((a, b) =>
a.clientAuditDetails?.createdTime
.compareTo(b.clientAuditDetails!.createdTime) ??
0);
taskList = sortTasks(taskList);
sideEffectsList = tasksRelated[1];
referralsList = tasksRelated[2];

Expand Down Expand Up @@ -224,10 +218,8 @@ class HouseHoldGlobalSearchBloc extends SearchHouseholdsBloc {
projectBeneficiariesList, taskList, sideEffectsList, referralsList);

taskList = tasksRelated[0];
taskList.sort((a, b) =>
a.clientAuditDetails?.createdTime
.compareTo(b.clientAuditDetails!.createdTime) ??
0);
taskList = sortTasks(taskList);

sideEffectsList = tasksRelated[1];
referralsList = tasksRelated[2];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ class IndividualGlobalSearchBloc extends SearchHouseholdsBloc {
projectBeneficiariesList, taskList, sideEffectsList, referralsList);

taskList = tasksRelated[0];
taskList.sort((a, b) =>
a.clientAuditDetails?.createdTime
.compareTo(b.clientAuditDetails!.createdTime) ??
0);
taskList = sortTasks(taskList);

sideEffectsList = tasksRelated[1];
referralsList = tasksRelated[2];

Expand Down Expand Up @@ -171,10 +169,8 @@ class IndividualGlobalSearchBloc extends SearchHouseholdsBloc {
projectBeneficiariesList, taskList, sideEffectsList, referralsList);

taskList = tasksRelated[0];
taskList.sort((a, b) =>
a.clientAuditDetails?.createdTime
.compareTo(b.clientAuditDetails!.createdTime) ??
0);
taskList = sortTasks(taskList);

sideEffectsList = tasksRelated[1];
referralsList = tasksRelated[2];

Expand Down Expand Up @@ -223,10 +219,8 @@ class IndividualGlobalSearchBloc extends SearchHouseholdsBloc {
projectBeneficiariesList, taskList, sideEffectsList, referralsList);

taskList = tasksRelated[0];
taskList.sort((a, b) =>
a.clientAuditDetails?.createdTime
.compareTo(b.clientAuditDetails!.createdTime) ??
0);
taskList = sortTasks(taskList);

sideEffectsList = tasksRelated[1];
referralsList = tasksRelated[2];

Expand Down
9 changes: 9 additions & 0 deletions packages/registration_delivery/lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,12 @@ Status getTaskStatus(Iterable<TaskModel> tasks) {

return Status.registered.toValue();
}

List<TaskModel> sortTasks(List<TaskModel> tasks) {
tasks.sort((a, b) {
return a.clientAuditDetails?.lastModifiedTime
?.compareTo(b.clientAuditDetails!.lastModifiedTime!) ??
0;
});
return tasks;
}

0 comments on commit 5fb6235

Please sign in to comment.