Update: 2026-07-12 05:40:28
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
// transit_admin_controller.dart — تحكم شاشات مواصلاتي (لوحة إدارة سيرو)
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'transit_admin_models.dart';
|
||||
import 'transit_admin_service.dart';
|
||||
|
||||
class TransitAdminController extends GetxController {
|
||||
bool isLoadingList = false;
|
||||
List<TransitOrgSummary> orgs = [];
|
||||
String? filterCountry;
|
||||
String? filterType;
|
||||
String? filterStatus;
|
||||
String searchQuery = '';
|
||||
|
||||
bool isLoadingDetails = false;
|
||||
TransitOrgDetails? selectedOrgDetails;
|
||||
|
||||
bool isCreating = false;
|
||||
|
||||
// ── مشرفو المؤسسة ────────────────────────────────────────────
|
||||
bool isLoadingAdmins = false;
|
||||
List<Map<String, dynamic>> orgAdmins = [];
|
||||
bool isSavingAdmin = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchOrgs();
|
||||
}
|
||||
|
||||
Future<void> fetchOrgs() async {
|
||||
isLoadingList = true;
|
||||
update();
|
||||
|
||||
final res = await TransitAdminService.listOrgs(
|
||||
country: filterCountry,
|
||||
type: filterType,
|
||||
contractStatus: filterStatus,
|
||||
search: searchQuery,
|
||||
);
|
||||
if (res.success) orgs = res.data ?? [];
|
||||
isLoadingList = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> loadOrgDetails(int orgId) async {
|
||||
isLoadingDetails = true;
|
||||
selectedOrgDetails = null;
|
||||
update();
|
||||
|
||||
final res = await TransitAdminService.getOrgDetails(orgId);
|
||||
if (res.success) selectedOrgDetails = res.data;
|
||||
isLoadingDetails = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<bool> createOrg({
|
||||
required String type,
|
||||
required String country,
|
||||
required String city,
|
||||
required String nameAr,
|
||||
required String nameEn,
|
||||
required String adminName,
|
||||
required String adminPhone,
|
||||
}) async {
|
||||
isCreating = true;
|
||||
update();
|
||||
|
||||
final res = await TransitAdminService.createOrg(
|
||||
type: type,
|
||||
country: country,
|
||||
city: city,
|
||||
nameAr: nameAr,
|
||||
nameEn: nameEn,
|
||||
adminName: adminName,
|
||||
adminPhone: adminPhone,
|
||||
);
|
||||
|
||||
isCreating = false;
|
||||
update();
|
||||
|
||||
if (res.success) {
|
||||
await fetchOrgs();
|
||||
return true;
|
||||
}
|
||||
Get.snackbar('مواصلاتي', res.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> fetchOrgAdmins(int orgId) async {
|
||||
isLoadingAdmins = true;
|
||||
update();
|
||||
final res = await TransitAdminService.listOrgAdmins(orgId);
|
||||
if (res.success) orgAdmins = res.data ?? [];
|
||||
isLoadingAdmins = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<bool> addOrgAdmin({
|
||||
required int orgId,
|
||||
required String name,
|
||||
required String phone,
|
||||
required String role,
|
||||
}) async {
|
||||
isSavingAdmin = true;
|
||||
update();
|
||||
|
||||
final res = await TransitAdminService.addOrgAdmin(
|
||||
orgId: orgId,
|
||||
name: name,
|
||||
phone: phone,
|
||||
role: role,
|
||||
);
|
||||
|
||||
isSavingAdmin = false;
|
||||
update();
|
||||
|
||||
if (res.success) {
|
||||
await fetchOrgAdmins(orgId);
|
||||
return true;
|
||||
}
|
||||
Get.snackbar('مواصلاتي', res.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<void> toggleOrgAdmin(int orgId, int adminId, bool isActive) async {
|
||||
final res = await TransitAdminService.toggleOrgAdmin(adminId: adminId, isActive: isActive);
|
||||
if (res.success) {
|
||||
await fetchOrgAdmins(orgId);
|
||||
} else {
|
||||
Get.snackbar('مواصلاتي', res.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user