- Updated import paths across multiple files to reflect the new package name. - Changed application name and identifiers in CMakeLists.txt, Runner.rc, and other configuration files. - Modified web index.html and manifest.json to update the app title and name. - Adjusted macOS and Windows project settings to align with the new application name. - Ensured consistency in naming across all relevant files and directories.
67 lines
1.9 KiB
Dart
67 lines
1.9 KiB
Dart
import 'package:get/get.dart';
|
|
import 'package:on_field_work/helpers/services/app_logger.dart';
|
|
import 'package:on_field_work/helpers/services/api_service.dart';
|
|
import 'package:on_field_work/model/all_organization_model.dart';
|
|
|
|
class AllOrganizationController extends GetxController {
|
|
RxList<AllOrganization> organizations = <AllOrganization>[].obs;
|
|
Rxn<AllOrganization> selectedOrganization = Rxn<AllOrganization>();
|
|
final isLoadingOrganizations = false.obs;
|
|
|
|
String? passedOrgId;
|
|
|
|
AllOrganizationController({this.passedOrgId});
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
fetchAllOrganizations();
|
|
}
|
|
|
|
Future<void> fetchAllOrganizations() async {
|
|
try {
|
|
isLoadingOrganizations.value = true;
|
|
|
|
final response = await ApiService.getAllOrganizations();
|
|
if (response != null && response.data.data.isNotEmpty) {
|
|
organizations.value = response.data.data;
|
|
|
|
// Select organization based on passed ID, or fallback to first
|
|
if (passedOrgId != null) {
|
|
selectedOrganization.value =
|
|
organizations.firstWhere(
|
|
(org) => org.id == passedOrgId,
|
|
orElse: () => organizations.first,
|
|
);
|
|
} else {
|
|
selectedOrganization.value ??= organizations.first;
|
|
}
|
|
} else {
|
|
organizations.clear();
|
|
selectedOrganization.value = null;
|
|
}
|
|
} catch (e, stackTrace) {
|
|
logSafe(
|
|
"Failed to fetch organizations: $e",
|
|
level: LogLevel.error,
|
|
error: e,
|
|
stackTrace: stackTrace,
|
|
);
|
|
organizations.clear();
|
|
selectedOrganization.value = null;
|
|
} finally {
|
|
isLoadingOrganizations.value = false;
|
|
}
|
|
}
|
|
|
|
void selectOrganization(AllOrganization? org) {
|
|
selectedOrganization.value = org;
|
|
}
|
|
|
|
void clearSelection() {
|
|
selectedOrganization.value = null;
|
|
}
|
|
|
|
String get currentSelection => selectedOrganization.value?.name ?? "All Organizations";
|
|
}
|