146 lines
5.0 KiB
Dart
146 lines
5.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:siro_admin/controller/admin/security_v2_controller.dart';
|
|
|
|
class AuditLogsPage extends StatelessWidget {
|
|
const AuditLogsPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cs = Theme.of(context).colorScheme;
|
|
|
|
return Scaffold(
|
|
backgroundColor: cs.surface,
|
|
body: Column(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.fromLTRB(16, 50, 16, 16),
|
|
child: Row(
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () => Get.back(),
|
|
child: Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(10),
|
|
border: Border.all(color: cs.outline),
|
|
),
|
|
child: Icon(Icons.arrow_back_ios_new_rounded,
|
|
color: cs.onSurfaceVariant, size: 16),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Text('سجل العمليات (Audit Logs)',
|
|
style: TextStyle(
|
|
color: cs.onSurface,
|
|
fontSize: 17,
|
|
fontWeight: FontWeight.bold)),
|
|
],
|
|
),
|
|
),
|
|
Expanded(
|
|
child: GetBuilder<SecurityV2Controller>(
|
|
init: SecurityV2Controller(),
|
|
builder: (ctrl) {
|
|
if (ctrl.isLoading) {
|
|
return Center(
|
|
child: CircularProgressIndicator(color: cs.primary));
|
|
}
|
|
|
|
if (ctrl.auditLogs.isEmpty) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(Icons.security_rounded,
|
|
size: 64, color: cs.onSurfaceVariant.withValues(alpha: 0.3)),
|
|
const SizedBox(height: 16),
|
|
Text('لا توجد عمليات مسجلة حالياً',
|
|
style: TextStyle(color: cs.onSurfaceVariant)),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'تأكد من إنشاء جدول سجل العمليات في قاعدة البيانات',
|
|
style: TextStyle(
|
|
color: cs.onSurfaceVariant, fontSize: 10)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
return ListView.builder(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: ctrl.auditLogs.length,
|
|
itemBuilder: (ctx, i) {
|
|
final log = ctrl.auditLogs[i];
|
|
return _buildLogItem(log, cs);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildLogItem(Map<String, dynamic> log, ColorScheme cs) {
|
|
return Container(
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: cs.outline),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(log['admin_name'] ?? 'أدمن غير معروف',
|
|
style: TextStyle(
|
|
color: cs.primary, fontWeight: FontWeight.bold)),
|
|
Text(log['created_at'] ?? '',
|
|
style: TextStyle(
|
|
color: cs.onSurfaceVariant, fontSize: 11)),
|
|
],
|
|
),
|
|
const SizedBox(height: 8),
|
|
Text(log['action'] ?? '',
|
|
style: TextStyle(
|
|
color: cs.onSurface, fontWeight: FontWeight.w600)),
|
|
if (log['details'] != null) ...[
|
|
const SizedBox(height: 4),
|
|
Text(log['details'],
|
|
style: TextStyle(
|
|
color: cs.onSurfaceVariant, fontSize: 12)),
|
|
],
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: cs.tertiary.withValues(alpha: 0.1),
|
|
borderRadius: BorderRadius.circular(6),
|
|
),
|
|
child: Text(log['table_name'] ?? '',
|
|
style: TextStyle(
|
|
color: cs.tertiary,
|
|
fontSize: 10,
|
|
fontWeight: FontWeight.bold)),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text('ID: ${log['record_id']}',
|
|
style: TextStyle(
|
|
color: cs.onSurfaceVariant, fontSize: 10)),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|