feat: استيراد كود سيرو إلى تريبز (سيرو @ecfe7568) — بلا تعديل
قرار المالك 2026-07-27: باك إند سيرو PHP هو المعتمد، وتطبيقاته المجرّبة ميدانياً تحل محل إعادة البناء المؤرشفة. سيرو نفسه لم يُمسّ. الخريطة: backend · payment_server · loction_server · ride_server · passenger_server · docker · dashboard · stress_test → الجذر siro_rider → apps/rider siro_driver → apps/driver siro_admin → dashboards/admin siro_service → dashboards/service android_bot → apps/android_bot socialBot → apps/socialBot نُسخ المتعقَّب في git سيرو فقط عبر `git archive` (3,198 ملفاً / ~169 م.ب) لا `cp -r` — فاستُثنيت مخلفات البناء تلقائياً. بلا أي تعديل محتوى عمداً: كل ما يلي يصير فرقاً مقروءاً مقابل المصدر. لم يُستورد وسببه: siromove.com (الموقع التسويقي يبقى marketing/ في تريبز، سيرو فيه 8 ملفات) · docs و planning (تريبز له docs/ الخاص) · deploy.sh (ليس نشراً على سيرفر بل `git add . && git push origin --all` — فخّ في مستودع آخر) · transit_dashboard (بانتظار قرار مصير backend-transit و dashboards/transit-web). ⚠️ لا يبني بعد — ثلاثة نواقص متوقعة ومقصودة: 1. `.env` و `lib/env/env.g.dart` غير متعقَّبين في سيرو (أسرار لكل مستأجر): كل تطبيق فلاتر يحتاج .env خاصاً ثم توليد env.g.dart بـ build_runner. 2. إعدادات Firebase (9 ملفات google-services.json و GoogleService-Info.plist) يستبعدها .gitignore تريبز — ولكل مستأجر مشروع Firebase خاص أصلاً. 3. apps/driver في سيرو يشير إلى `../../Intaleq/packages/get` خارج المستودع → يجب ضمّ الحزم داخله أسوة بـ apps/rider. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
9909d9b4c1
commit
4d8414c96b
@@ -0,0 +1,175 @@
|
||||
// transit_controller.dart — تحكم شاشات مواصلاتي (جهة الراكب)
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../home/map/map_socket_controller.dart';
|
||||
import '../../print.dart';
|
||||
import 'transit_models.dart';
|
||||
import 'transit_service.dart';
|
||||
|
||||
class TransitController extends GetxController {
|
||||
bool isLoadingEnrollments = false;
|
||||
List<TransitEnrollment> myEnrollments = [];
|
||||
|
||||
bool isLoadingOrgs = false;
|
||||
List<TransitOrg> browsableOrgs = [];
|
||||
|
||||
bool isLoadingRoutes = false;
|
||||
List<TransitRouteSummary> currentOrgRoutes = [];
|
||||
int? currentOrgId;
|
||||
|
||||
// ── تتبع الباص الحي ──────────────────────────────────────────
|
||||
int? liveRouteId;
|
||||
int? liveTripId;
|
||||
Map<String, dynamic>? liveTripData;
|
||||
BusPosition? liveBusPosition;
|
||||
String liveError = '';
|
||||
bool isLoadingLiveTrip = false;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchMyEnrollments();
|
||||
}
|
||||
|
||||
Future<void> fetchMyEnrollments() async {
|
||||
isLoadingEnrollments = true;
|
||||
update();
|
||||
final res = await TransitService.getMyEnrollments();
|
||||
if (res.success) myEnrollments = res.data ?? [];
|
||||
isLoadingEnrollments = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> browseOrgs({String? search}) async {
|
||||
isLoadingOrgs = true;
|
||||
update();
|
||||
final res = await TransitService.browseOrgs(search: search);
|
||||
if (res.success) browsableOrgs = res.data ?? [];
|
||||
isLoadingOrgs = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<bool> activateEnrollment(int orgId, String studentId) async {
|
||||
final res = await TransitService.activateEnrollment(
|
||||
orgId: orgId,
|
||||
studentId: studentId,
|
||||
);
|
||||
if (res.success) {
|
||||
await fetchMyEnrollments();
|
||||
// اشترك في topic المؤسسة لاستقبال إشعارات الانطلاق والتأخير
|
||||
try {
|
||||
await FirebaseMessaging.instance.subscribeToTopic('transit_org_$orgId');
|
||||
Log.print('Subscribed to transit_org_$orgId ✅');
|
||||
} catch (_) {}
|
||||
return true;
|
||||
}
|
||||
Get.snackbar('مواصلاتي', res.message);
|
||||
return false;
|
||||
}
|
||||
|
||||
// اشتراك/إلغاء اشتراك في topic الخط المحدد
|
||||
Future<void> subscribeToRouteTopic(int routeId) async {
|
||||
try {
|
||||
await FirebaseMessaging.instance.subscribeToTopic('transit_route_$routeId');
|
||||
Log.print('Subscribed to transit_route_$routeId ✅');
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> unsubscribeFromRouteTopic(int routeId) async {
|
||||
try {
|
||||
await FirebaseMessaging.instance.unsubscribeFromTopic('transit_route_$routeId');
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
Future<void> openOrgRoutes(int orgId) async {
|
||||
currentOrgId = orgId;
|
||||
isLoadingRoutes = true;
|
||||
currentOrgRoutes = [];
|
||||
update();
|
||||
|
||||
final res = await TransitService.getRoutesForOrg(orgId);
|
||||
if (res.success) {
|
||||
currentOrgRoutes = res.data ?? [];
|
||||
} else {
|
||||
Get.snackbar('مواصلاتي', res.message);
|
||||
}
|
||||
isLoadingRoutes = false;
|
||||
update();
|
||||
}
|
||||
|
||||
// ── الخط الحي: تحميل أولي + اشتراك سوكيت ────────────────────
|
||||
Future<void> openLiveRoute(int routeId) async {
|
||||
liveRouteId = routeId;
|
||||
liveTripData = null;
|
||||
liveBusPosition = null;
|
||||
liveError = '';
|
||||
isLoadingLiveTrip = true;
|
||||
update();
|
||||
|
||||
final res = await TransitService.getLiveTrip(routeId: routeId);
|
||||
if (res.success && res.data != null) {
|
||||
liveTripData = res.data;
|
||||
liveTripId = int.tryParse(liveTripData?['trip']?['id']?.toString() ?? '');
|
||||
final pos = liveTripData?['bus_position'];
|
||||
if (pos is Map) liveBusPosition = BusPosition.fromJson(pos);
|
||||
} else {
|
||||
liveError = res.message;
|
||||
}
|
||||
isLoadingLiveTrip = false;
|
||||
update();
|
||||
|
||||
if (Get.isRegistered<MapSocketController>()) {
|
||||
final ms = Get.find<MapSocketController>();
|
||||
ms.onBusLocationUpdate = _handleLiveBusUpdate;
|
||||
ms.onTransitError = _handleTransitError;
|
||||
ms.subscribeToTransitRoute(routeId);
|
||||
}
|
||||
}
|
||||
|
||||
void _handleLiveBusUpdate(Map<String, dynamic> data) {
|
||||
final incomingRouteId = int.tryParse(data['route_id']?.toString() ?? '');
|
||||
if (incomingRouteId == null || incomingRouteId != liveRouteId) return;
|
||||
|
||||
liveBusPosition = BusPosition(
|
||||
lat: double.tryParse(data['latitude']?.toString() ?? '0') ?? 0,
|
||||
lng: double.tryParse(data['longitude']?.toString() ?? '0') ?? 0,
|
||||
heading: double.tryParse(data['heading']?.toString() ?? '0') ?? 0,
|
||||
speed: double.tryParse(data['speed']?.toString() ?? '0') ?? 0,
|
||||
currentStopSeq: data['current_stop_seq'] == null
|
||||
? null
|
||||
: int.tryParse(data['current_stop_seq'].toString()),
|
||||
);
|
||||
Log.print('🚌 Live bus update: ${liveBusPosition?.lat}, ${liveBusPosition?.lng}');
|
||||
update();
|
||||
}
|
||||
|
||||
void _handleTransitError(String errorCode) {
|
||||
if (errorCode == 'NOT_ENROLLED') {
|
||||
liveError = 'غير مشترك في هذا الخط. فعّل عضويتك أولاً.';
|
||||
} else if (errorCode == 'ROUTE_NOT_FOUND') {
|
||||
liveError = 'الخط غير متاح حالياً.';
|
||||
} else {
|
||||
liveError = 'خطأ في الاتصال بالخط: $errorCode';
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void closeLiveRoute() {
|
||||
if (liveRouteId != null && Get.isRegistered<MapSocketController>()) {
|
||||
final ms = Get.find<MapSocketController>();
|
||||
ms.unsubscribeFromTransitRoute(liveRouteId!);
|
||||
ms.onBusLocationUpdate = null;
|
||||
ms.onTransitError = null;
|
||||
}
|
||||
liveRouteId = null;
|
||||
liveTripId = null;
|
||||
liveTripData = null;
|
||||
liveBusPosition = null;
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
closeLiveRoute();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user