feat: Improve notification handling; enhance logging and ensure DocumentController registration before updates
This commit is contained in:
parent
1fafe77211
commit
e6f028d129
@ -209,10 +209,11 @@ class NotificationActionHandler {
|
||||
|
||||
/// ---------------------- DOCUMENT HANDLER ----------------------
|
||||
static void _handleDocumentModified(Map<String, dynamic> data) {
|
||||
late String entityTypeId;
|
||||
late String entityId;
|
||||
String entityTypeId;
|
||||
String entityId;
|
||||
String? documentId = data['DocumentId'];
|
||||
|
||||
// Determine entity type and ID
|
||||
if (data['Keyword'] == 'Employee_Document_Modified') {
|
||||
entityTypeId = Permissions.employeeEntity;
|
||||
entityId = data['EmployeeId'] ?? '';
|
||||
@ -229,30 +230,43 @@ class NotificationActionHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
_safeControllerUpdate<DocumentController>(
|
||||
onFound: (controller) async {
|
||||
await controller.fetchDocuments(
|
||||
entityTypeId: entityTypeId,
|
||||
entityId: entityId,
|
||||
reset: true,
|
||||
);
|
||||
},
|
||||
notFoundMessage: '⚠️ DocumentController not found, cannot refresh list.',
|
||||
successMessage: '✅ DocumentController refreshed from notification.',
|
||||
);
|
||||
_logger.i(
|
||||
"🔔 Document notification received: keyword=${data['Keyword']}, entityTypeId=$entityTypeId, entityId=$entityId, documentId=$documentId");
|
||||
|
||||
if (documentId != null) {
|
||||
// Refresh Document List
|
||||
if (Get.isRegistered<DocumentController>()) {
|
||||
_safeControllerUpdate<DocumentController>(
|
||||
onFound: (controller) async {
|
||||
await controller.fetchDocuments(
|
||||
entityTypeId: entityTypeId,
|
||||
entityId: entityId,
|
||||
reset: true,
|
||||
);
|
||||
},
|
||||
notFoundMessage:
|
||||
'⚠️ DocumentController not found, cannot refresh list.',
|
||||
successMessage: '✅ DocumentController refreshed from notification.',
|
||||
);
|
||||
} else {
|
||||
_logger.w('⚠️ DocumentController not registered, skipping list refresh.');
|
||||
}
|
||||
|
||||
// Refresh Document Details (if open)
|
||||
if (documentId != null && Get.isRegistered<DocumentDetailsController>()) {
|
||||
_safeControllerUpdate<DocumentDetailsController>(
|
||||
onFound: (controller) async {
|
||||
if (controller.documentDetails.value?.data?.id == documentId) {
|
||||
await controller.fetchDocumentDetails(documentId);
|
||||
_logger.i(
|
||||
"✅ DocumentDetailsController refreshed for Document $documentId");
|
||||
}
|
||||
// Refresh details regardless of current document
|
||||
await controller.fetchDocumentDetails(documentId);
|
||||
_logger.i(
|
||||
"✅ DocumentDetailsController refreshed for Document $documentId");
|
||||
},
|
||||
notFoundMessage: 'ℹ️ DocumentDetailsController not active, skipping.',
|
||||
notFoundMessage:
|
||||
'ℹ️ DocumentDetailsController not active, skipping details refresh.',
|
||||
successMessage: '✅ DocumentDetailsController checked for refresh.',
|
||||
);
|
||||
} else if (documentId != null) {
|
||||
_logger.w(
|
||||
'⚠️ DocumentDetailsController not registered, cannot refresh document details.');
|
||||
}
|
||||
}
|
||||
|
||||
@ -313,7 +327,8 @@ class NotificationActionHandler {
|
||||
break;
|
||||
case 'task_updated':
|
||||
await controller.fetchDashboardTasks(
|
||||
projectId: controller.projectController.selectedProjectId.value);
|
||||
projectId:
|
||||
controller.projectController.selectedProjectId.value);
|
||||
break;
|
||||
case 'project_progress_update':
|
||||
await controller.fetchProjectProgress();
|
||||
|
@ -25,7 +25,8 @@ class DocumentDetailsPage extends StatefulWidget {
|
||||
|
||||
class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
final DocumentDetailsController controller =
|
||||
Get.put(DocumentDetailsController());
|
||||
Get.find<DocumentDetailsController>();
|
||||
|
||||
final PermissionController permissionController =
|
||||
Get.find<PermissionController>();
|
||||
@override
|
||||
|
@ -17,9 +17,9 @@ import 'package:marco/helpers/widgets/custom_app_bar.dart';
|
||||
import 'package:marco/helpers/widgets/my_confirmation_dialog.dart';
|
||||
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
||||
import 'package:marco/controller/permission_controller.dart';
|
||||
import 'package:marco/controller/document/document_details_controller.dart';
|
||||
import 'dart:convert';
|
||||
|
||||
|
||||
class UserDocumentsPage extends StatefulWidget {
|
||||
final String? entityId;
|
||||
final bool isEmployee;
|
||||
@ -38,7 +38,8 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
||||
final DocumentController docController = Get.put(DocumentController());
|
||||
final PermissionController permissionController =
|
||||
Get.find<PermissionController>();
|
||||
|
||||
final DocumentDetailsController controller =
|
||||
Get.put(DocumentDetailsController());
|
||||
String get entityTypeId => widget.isEmployee
|
||||
? Permissions.employeeEntity
|
||||
: Permissions.projectEntity;
|
||||
@ -586,8 +587,7 @@ class _UserDocumentsPageState extends State<UserDocumentsPage> {
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (_) => DocumentUploadBottomSheet(
|
||||
isEmployee:
|
||||
widget.isEmployee,
|
||||
isEmployee: widget.isEmployee,
|
||||
onSubmit: (data) async {
|
||||
final success = await uploadController.uploadDocument(
|
||||
name: data["name"],
|
||||
|
Loading…
x
Reference in New Issue
Block a user