Update: 2026-07-05 00:06:55
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jwt_decoder/jwt_decoder.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:siro_admin/controller/functions/device_info.dart';
|
||||
import 'package:siro_admin/views/auth/login_page.dart';
|
||||
|
||||
@@ -184,6 +185,8 @@ class OtpHelper extends GetxController {
|
||||
await box.write(BoxName.phoneVerified, true);
|
||||
await box.write('admin_password', password);
|
||||
|
||||
FirebaseMessaging.instance.subscribeToTopic('admin_alerts');
|
||||
|
||||
mySnackbarSuccess('تم تسجيل الدخول بنجاح');
|
||||
return true;
|
||||
}
|
||||
@@ -238,6 +241,7 @@ class OtpHelper extends GetxController {
|
||||
String token = r(rawJwt.toString()).split(AppInformation.addd)[0];
|
||||
if (!JwtDecoder.isExpired(token)) {
|
||||
Log.print('Valid JWT found, skipping login.php (no OTP needed)');
|
||||
FirebaseMessaging.instance.subscribeToTopic('admin_alerts');
|
||||
Get.offAll(() => const AdminHomePage());
|
||||
return;
|
||||
}
|
||||
@@ -275,6 +279,7 @@ class OtpHelper extends GetxController {
|
||||
} else if (response['jwt'] != null) {
|
||||
box.write(BoxName.jwt, c(response['jwt']));
|
||||
}
|
||||
FirebaseMessaging.instance.subscribeToTopic('admin_alerts');
|
||||
try {
|
||||
if (Get.isRegistered<DashboardController>()) {
|
||||
Get.find<DashboardController>().getDashBoard();
|
||||
|
||||
@@ -241,6 +241,20 @@ class FirebaseMessagesController extends GetxController {
|
||||
fireBaseTitles(message);
|
||||
}
|
||||
});
|
||||
|
||||
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
|
||||
if (message.data['type'] == 'marketing_report') {
|
||||
Get.toNamed('/social-intelligence');
|
||||
}
|
||||
});
|
||||
|
||||
FirebaseMessaging.instance.getInitialMessage().then((RemoteMessage? message) {
|
||||
if (message != null && message.data['type'] == 'marketing_report') {
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
Get.toNamed('/social-intelligence');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void fireBaseTitles(RemoteMessage message) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'views/admin/complaints/complaint_list_page.dart';
|
||||
import 'views/admin/drivers/driver_documents_review_page.dart';
|
||||
import 'views/admin/marketing/marketing_page.dart';
|
||||
import 'views/admin/marketing/heatmap_page.dart';
|
||||
import 'views/admin/marketing/social_intelligence_screen.dart';
|
||||
|
||||
List<GetPage<dynamic>> routes = [
|
||||
GetPage(name: "/", page: () => const AdminHomePage()),
|
||||
@@ -19,4 +20,5 @@ List<GetPage<dynamic>> routes = [
|
||||
GetPage(name: "/driver-docs", page: () => DriverDocsReviewPage()),
|
||||
GetPage(name: "/marketing", page: () => const MarketingPage()),
|
||||
GetPage(name: "/heatmap", page: () => const HeatmapPage()),
|
||||
GetPage(name: "/social-intelligence", page: () => const SocialIntelligenceScreen()),
|
||||
];
|
||||
|
||||
@@ -757,6 +757,8 @@ class _AdminHomePageState extends State<AdminHomePage>
|
||||
() => Get.toNamed('/complaints')),
|
||||
ActionItem('مراجعة الوثائق', Icons.assignment_ind_rounded, _info,
|
||||
() => Get.toNamed('/driver-docs')),
|
||||
ActionItem('استخبارات السوشيال', Icons.insights_rounded, const Color(0xFFC792EA),
|
||||
() => Get.toNamed('/social-intelligence')),
|
||||
],
|
||||
),
|
||||
ActionCategory(
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
|
||||
import '../../../constant/colors.dart';
|
||||
import '../../../constant/links.dart';
|
||||
|
||||
class SocialIntelligenceController extends GetxController {
|
||||
var isLoading = true.obs;
|
||||
var reports = [].obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
fetchReports();
|
||||
}
|
||||
|
||||
Future<void> fetchReports() async {
|
||||
try {
|
||||
isLoading(true);
|
||||
final url = Uri.parse(
|
||||
'${AppLink.server}/marketing_engine/index.php?action=get_reports');
|
||||
final response = await http.get(url);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = json.decode(response.body);
|
||||
if (data['status'] == 'success') {
|
||||
reports.value = data['data'] ?? [];
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error fetching reports: $e');
|
||||
} finally {
|
||||
isLoading(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SocialIntelligenceScreen extends StatelessWidget {
|
||||
const SocialIntelligenceScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final controller = Get.put(SocialIntelligenceController());
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColor.bg,
|
||||
appBar: AppBar(
|
||||
title: const Text(
|
||||
'استخبارات السوشيال ميديا (Social Intelligence)',
|
||||
style: TextStyle(fontWeight: FontWeight.w700, fontSize: 16),
|
||||
),
|
||||
backgroundColor: AppColor.bg,
|
||||
elevation: 0,
|
||||
foregroundColor: AppColor.textPrimary,
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: () => controller.fetchReports(),
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Obx(() {
|
||||
if (controller.isLoading.value) {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(color: AppColor.accent));
|
||||
}
|
||||
|
||||
if (controller.reports.isEmpty) {
|
||||
return const Center(
|
||||
child: Text(
|
||||
'لا توجد تقارير حالياً',
|
||||
style: TextStyle(color: AppColor.textSecondary),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: controller.reports.length,
|
||||
itemBuilder: (context, index) {
|
||||
final report = controller.reports[index];
|
||||
final isWeekly = report['is_weekly'].toString() == '1';
|
||||
|
||||
return Card(
|
||||
color: AppColor.surface,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: BorderSide(
|
||||
color: isWeekly ? AppColor.accent : AppColor.divider,
|
||||
width: isWeekly ? 1.5 : 1.0),
|
||||
),
|
||||
margin: const EdgeInsets.only(bottom: 16),
|
||||
child: ExpansionTile(
|
||||
iconColor: AppColor.accent,
|
||||
collapsedIconColor: AppColor.textSecondary,
|
||||
title: Text(
|
||||
isWeekly
|
||||
? '📈 تقرير السوق الأسبوعي الشامل'
|
||||
: '📊 تقرير ${report['platform'].toString().toUpperCase()}',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isWeekly ? AppColor.accent : AppColor.textPrimary,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
report['created_at'].toString(),
|
||||
style: const TextStyle(
|
||||
color: AppColor.textSecondary, fontSize: 11),
|
||||
),
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
width: double.infinity,
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(top: BorderSide(color: AppColor.divider)),
|
||||
),
|
||||
child: Directionality(
|
||||
textDirection: TextDirection.rtl,
|
||||
child: HtmlWidget(
|
||||
report['report_html'] ?? '',
|
||||
textStyle: const TextStyle(
|
||||
color: AppColor.textPrimary,
|
||||
fontSize: 13,
|
||||
height: 1.6),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user