41 lines
1.2 KiB
Dart
41 lines
1.2 KiB
Dart
import 'package:get/get.dart';
|
|
import 'package:marco/helpers/services/app_logger.dart';
|
|
import 'package:marco/helpers/services/api_service.dart';
|
|
import 'package:marco/model/attendance/organization_per_project_list_model.dart';
|
|
|
|
class OrganizationController extends GetxController {
|
|
List<Organization> organizations = [];
|
|
Organization? selectedOrganization;
|
|
final isLoadingOrganizations = false.obs;
|
|
|
|
Future<void> fetchOrganizations(String projectId) async {
|
|
try {
|
|
isLoadingOrganizations.value = true;
|
|
final response = await ApiService.getAssignedOrganizations(projectId);
|
|
if (response != null) {
|
|
organizations = response.data;
|
|
logSafe("Organizations fetched: ${organizations.length}");
|
|
} else {
|
|
logSafe("Failed to fetch organizations for project $projectId",
|
|
level: LogLevel.error);
|
|
}
|
|
} finally {
|
|
isLoadingOrganizations.value = false;
|
|
update();
|
|
}
|
|
}
|
|
|
|
void selectOrganization(Organization? org) {
|
|
selectedOrganization = org;
|
|
update();
|
|
}
|
|
|
|
void clearSelection() {
|
|
selectedOrganization = null;
|
|
update();
|
|
}
|
|
|
|
String get currentSelection =>
|
|
selectedOrganization?.name ?? "All Organizations";
|
|
}
|