add new featurs like realtime 2026-5-10-25
This commit is contained in:
75
lib/controller/admin/analytics_v2_controller.dart
Normal file
75
lib/controller/admin/analytics_v2_controller.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import 'dart:convert';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:sefer_admin1/constant/links.dart';
|
||||
import 'package:sefer_admin1/controller/functions/crud.dart';
|
||||
import '../../print.dart';
|
||||
|
||||
class AnalyticsV2Controller extends GetxController {
|
||||
bool isLoading = true;
|
||||
|
||||
Map<String, dynamic> growthData = {};
|
||||
Map<String, dynamic> revenueData = {};
|
||||
List<dynamic> topDrivers = [];
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchAllAnalytics();
|
||||
}
|
||||
|
||||
Future<void> fetchAllAnalytics() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
|
||||
await Future.wait([
|
||||
fetchGrowth(),
|
||||
fetchRevenue(),
|
||||
fetchDriverRanking(),
|
||||
]);
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> fetchGrowth() async {
|
||||
try {
|
||||
var res = await CRUD().get(link: AppLink.growthV2, payload: {});
|
||||
if (res != 'failure' && res != null) {
|
||||
var d = res is String ? jsonDecode(res) : res;
|
||||
if (d['status'] == 'success') {
|
||||
growthData = d['data'];
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('Error fetching growth analytics: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchRevenue() async {
|
||||
try {
|
||||
var res = await CRUD().get(link: AppLink.revenueV2, payload: {});
|
||||
if (res != 'failure' && res != null) {
|
||||
var d = res is String ? jsonDecode(res) : res;
|
||||
if (d['status'] == 'success') {
|
||||
revenueData = d['data'];
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('Error fetching revenue analytics: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchDriverRanking() async {
|
||||
try {
|
||||
var res = await CRUD().get(link: AppLink.driverRankingV2, payload: {});
|
||||
if (res != 'failure' && res != null) {
|
||||
var d = res is String ? jsonDecode(res) : res;
|
||||
if (d['status'] == 'success') {
|
||||
topDrivers = d['data'];
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('Error fetching driver ranking: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
62
lib/controller/admin/dashboard_v2_controller.dart
Normal file
62
lib/controller/admin/dashboard_v2_controller.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:sefer_admin1/constant/links.dart';
|
||||
import 'package:sefer_admin1/controller/functions/crud.dart';
|
||||
import '../../print.dart';
|
||||
|
||||
class DashboardV2Controller extends GetxController {
|
||||
bool isLoading = true;
|
||||
Map<String, dynamic> realtimeData = {};
|
||||
List<dynamic> smartAlerts = [];
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchRealtimeData();
|
||||
fetchSmartAlerts();
|
||||
// Auto refresh every 30 seconds
|
||||
_timer = Timer.periodic(const Duration(seconds: 30), (timer) {
|
||||
fetchRealtimeData();
|
||||
fetchSmartAlerts();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
_timer?.cancel();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
Future<void> fetchRealtimeData() async {
|
||||
try {
|
||||
var res = await CRUD().get(link: AppLink.realtimeDashboardV2, payload: {});
|
||||
if (res != 'failure' && res != null) {
|
||||
var d = res is String ? jsonDecode(res) : res;
|
||||
if (d['status'] == 'success') {
|
||||
realtimeData = d['message'];
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('Error fetching realtime dashboard: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchSmartAlerts() async {
|
||||
try {
|
||||
var res = await CRUD().get(link: AppLink.smartAlertsV2, payload: {});
|
||||
if (res != 'failure' && res != null) {
|
||||
var d = res is String ? jsonDecode(res) : res;
|
||||
if (d['status'] == 'success') {
|
||||
smartAlerts = d['message'];
|
||||
update();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('Error fetching smart alerts: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
59
lib/controller/admin/financial_v2_controller.dart
Normal file
59
lib/controller/admin/financial_v2_controller.dart
Normal file
@@ -0,0 +1,59 @@
|
||||
import 'dart:convert';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:sefer_admin1/constant/links.dart';
|
||||
import 'package:sefer_admin1/controller/functions/crud.dart';
|
||||
import '../../print.dart';
|
||||
|
||||
class FinancialV2Controller extends GetxController {
|
||||
bool isLoading = true;
|
||||
|
||||
Map<String, dynamic> stats = {};
|
||||
List<dynamic> settlements = [];
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchAllFinancials();
|
||||
}
|
||||
|
||||
Future<void> fetchAllFinancials() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
|
||||
await Future.wait([
|
||||
fetchStats(),
|
||||
fetchSettlements(),
|
||||
]);
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
|
||||
Future<void> fetchStats() async {
|
||||
try {
|
||||
var res = await CRUD().get(link: AppLink.financialStatsV2, payload: {});
|
||||
if (res != 'failure' && res != null) {
|
||||
var d = res is String ? jsonDecode(res) : res;
|
||||
if (d['status'] == 'success') {
|
||||
stats = d['data'];
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('Error fetching financial stats: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchSettlements() async {
|
||||
try {
|
||||
var res = await CRUD().get(link: AppLink.settlementsV2, payload: {});
|
||||
if (res != 'failure' && res != null) {
|
||||
var d = res is String ? jsonDecode(res) : res;
|
||||
if (d['status'] == 'success') {
|
||||
settlements = d['data'];
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('Error fetching settlements: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
102
lib/controller/admin/quality_controller.dart
Normal file
102
lib/controller/admin/quality_controller.dart
Normal file
@@ -0,0 +1,102 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import '../../constant/links.dart';
|
||||
import '../functions/crud.dart';
|
||||
|
||||
class QualityController extends GetxController {
|
||||
bool isLoading = false;
|
||||
List driversBlacklist = [];
|
||||
List passengersBlacklist = [];
|
||||
Map scorecardData = {};
|
||||
|
||||
Future<void> fetchBlacklist() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
try {
|
||||
var res = await CRUD().post(
|
||||
link: AppLink.blacklistManager,
|
||||
payload: {"action_type": "get_all"},
|
||||
);
|
||||
if (res is Map && res['status'] == 'success') {
|
||||
driversBlacklist = res['message']['drivers'] ?? [];
|
||||
passengersBlacklist = res['message']['passengers'] ?? [];
|
||||
} else {
|
||||
Get.snackbar("Error", "Failed to fetch blacklist");
|
||||
}
|
||||
} catch (e) {
|
||||
Get.snackbar("Error", "Network error");
|
||||
} finally {
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> unblockDriver(String phone) async {
|
||||
try {
|
||||
var res = await CRUD().post(
|
||||
link: AppLink.blacklistManager,
|
||||
payload: {
|
||||
"action_type": "unblock_driver",
|
||||
"phone": phone,
|
||||
},
|
||||
);
|
||||
if (res is Map && res['status'] == 'success') {
|
||||
Get.snackbar("Success", "Driver unblocked successfully");
|
||||
fetchBlacklist(); // Refresh
|
||||
} else {
|
||||
Get.snackbar("Error", res['message'] ?? "Failed to unblock driver");
|
||||
}
|
||||
} catch (e) {
|
||||
Get.snackbar("Error", "Network error");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> unblockPassenger(String phoneNormalized) async {
|
||||
try {
|
||||
var res = await CRUD().post(
|
||||
link: AppLink.blacklistManager,
|
||||
payload: {
|
||||
"action_type": "unblock_passenger",
|
||||
"phone_normalized": phoneNormalized,
|
||||
},
|
||||
);
|
||||
if (res is Map && res['status'] == 'success') {
|
||||
Get.snackbar("Success", "Passenger unblocked successfully");
|
||||
fetchBlacklist(); // Refresh
|
||||
} else {
|
||||
Get.snackbar("Error", res['message'] ?? "Failed to unblock passenger");
|
||||
}
|
||||
} catch (e) {
|
||||
Get.snackbar("Error", "Network error");
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> fetchDriverScorecard(String driverId) async {
|
||||
isLoading = true;
|
||||
update();
|
||||
try {
|
||||
var res = await CRUD().post(
|
||||
link: AppLink.driverScorecard,
|
||||
payload: {"driver_id": driverId},
|
||||
);
|
||||
if (res is Map && res['status'] == 'success') {
|
||||
scorecardData = res['message'];
|
||||
} else {
|
||||
Get.snackbar("Error", "Failed to fetch scorecard");
|
||||
scorecardData = {};
|
||||
}
|
||||
} catch (e) {
|
||||
Get.snackbar("Error", "Network error");
|
||||
scorecardData = {};
|
||||
} finally {
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
// fetchBlacklist() can be called when opening the page
|
||||
}
|
||||
}
|
||||
62
lib/controller/admin/security_v2_controller.dart
Normal file
62
lib/controller/admin/security_v2_controller.dart
Normal file
@@ -0,0 +1,62 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:sefer_admin1/constant/links.dart';
|
||||
import 'package:sefer_admin1/controller/functions/crud.dart';
|
||||
import '../../print.dart';
|
||||
|
||||
class SecurityV2Controller extends GetxController {
|
||||
bool isLoading = true;
|
||||
List<dynamic> auditLogs = [];
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchAuditLogs();
|
||||
}
|
||||
|
||||
Future<void> fetchAuditLogs() async {
|
||||
isLoading = true;
|
||||
update();
|
||||
|
||||
try {
|
||||
Log.print('Fetching from: ${AppLink.auditLogsV2}');
|
||||
var res = await CRUD().get(link: AppLink.auditLogsV2, payload: {});
|
||||
Log.print('Raw audit res type: ${res.runtimeType} | value: $res');
|
||||
|
||||
if (res == 'failure' || res == 'token_expired') {
|
||||
Log.print('CRUD returned: $res');
|
||||
Get.snackbar("خطأ بالاتصال", "السيرفر أرجع: $res",
|
||||
backgroundColor: const Color(0x88FF0000),
|
||||
colorText: const Color(0xFFFFFFFF));
|
||||
auditLogs = [];
|
||||
} else if (res != null) {
|
||||
var d = res is String ? jsonDecode(res) : res;
|
||||
Log.print('Decoded audit response: $d');
|
||||
if (d['status'] == 'success') {
|
||||
var message = d['message'];
|
||||
if (message is List) {
|
||||
auditLogs = message;
|
||||
Log.print('Loaded ${auditLogs.length} audit logs');
|
||||
} else {
|
||||
auditLogs = [];
|
||||
Log.print('message is not List: ${message.runtimeType}');
|
||||
}
|
||||
} else {
|
||||
Log.print('Status not success: ${d['status']}');
|
||||
Get.snackbar("خطأ من السيرفر", "${d['message'] ?? d['status']}",
|
||||
backgroundColor: const Color(0x88FF0000),
|
||||
colorText: const Color(0xFFFFFFFF));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Log.print('Error fetching audit logs: $e');
|
||||
Get.snackbar("خطأ برمجي", "$e",
|
||||
backgroundColor: const Color(0x88FF0000),
|
||||
colorText: const Color(0xFFFFFFFF));
|
||||
}
|
||||
|
||||
isLoading = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user