78 lines
2.2 KiB
Dart
78 lines
2.2 KiB
Dart
import 'package:get/get.dart';
|
|
import 'package:on_field_work/helpers/services/api_service.dart';
|
|
import 'package:on_field_work/model/infra_project/infra_project_details.dart';
|
|
import 'package:on_field_work/model/infra_project/infra_team_list_model.dart';
|
|
|
|
class InfraProjectDetailsController extends GetxController {
|
|
final String projectId;
|
|
|
|
InfraProjectDetailsController({required this.projectId});
|
|
|
|
var isLoading = true.obs;
|
|
var projectDetails = Rxn<ProjectData>();
|
|
var teamList = <ProjectAllocation>[].obs;
|
|
var teamLoading = true.obs;
|
|
var errorMessage = ''.obs;
|
|
var teamErrorMessage = ''.obs;
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
fetchProjectDetails();
|
|
fetchProjectTeamList();
|
|
}
|
|
|
|
Map<String, List<ProjectAllocation>> get groupedTeamByRole {
|
|
final Map<String, List<ProjectAllocation>> map = {};
|
|
for (final member in teamList) {
|
|
map.putIfAbsent(member.jobRoleId, () => []).add(member);
|
|
}
|
|
return map;
|
|
}
|
|
|
|
Future<void> fetchProjectDetails() async {
|
|
try {
|
|
isLoading.value = true;
|
|
final response =
|
|
await ApiService.getInfraProjectDetails(projectId: projectId);
|
|
|
|
if (response != null &&
|
|
response.success == true &&
|
|
response.data != null) {
|
|
projectDetails.value = response.data;
|
|
errorMessage.value = '';
|
|
} else {
|
|
errorMessage.value =
|
|
response?.message ?? "Failed to load project details";
|
|
}
|
|
} catch (e) {
|
|
errorMessage.value = "Error fetching project details: $e";
|
|
} finally {
|
|
isLoading.value = false;
|
|
}
|
|
}
|
|
|
|
Future<void> fetchProjectTeamList() async {
|
|
try {
|
|
teamLoading.value = true;
|
|
teamErrorMessage.value = '';
|
|
|
|
final response = await ApiService.getInfraProjectTeamListApi(
|
|
projectId: projectId,
|
|
includeInactive: false,
|
|
);
|
|
|
|
if (response?.success == true && response!.data.isNotEmpty) {
|
|
teamList.assignAll(response.data);
|
|
} else {
|
|
teamList.clear();
|
|
teamErrorMessage.value = response?.message ?? "No team members found.";
|
|
}
|
|
} catch (e) {
|
|
teamList.clear();
|
|
teamErrorMessage.value = "Failed to load team members";
|
|
} finally {
|
|
teamLoading.value = false;
|
|
}
|
|
}
|
|
}
|