Skip to content

Commit

Permalink
- updated error description dialog
Browse files Browse the repository at this point in the history
- added audit log widget for admin
  • Loading branch information
HardMax71 committed Aug 30, 2024
1 parent fa6ff03 commit 16b593b
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 205 deletions.
4 changes: 1 addition & 3 deletions desktop_app/src/ui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from desktop_app.src.ui.views.notifications.notification_center import NotificationCenter
from .audit_log_view import AuditLogView
from desktop_app.src.ui.views.audit_logs.audit_log_view import AuditLogView
from .barcode_designer import BarcodeDesignerWidget
from .dashboard import DashboardWidget
from .main_window import MainWindow
from .offline_mode import OfflineModeWidget
from .report_generator import ReportGeneratorWidget
from .search_filter import AdvancedSearchDialog
from .settings.system_diagnostics import SystemDiagnosticsWidget
Expand Down Expand Up @@ -33,7 +32,6 @@
"BarcodeDesignerWidget",
"SystemDiagnosticsWidget",
"AdvancedSearchDialog",
"OfflineModeWidget",
"UserManagementWidget",
"AuditLogView",
"NotificationCenter",
Expand Down
63 changes: 0 additions & 63 deletions desktop_app/src/ui/audit_log_view.py

This file was deleted.

83 changes: 66 additions & 17 deletions desktop_app/src/ui/components/dialogs/error_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from PySide6.QtCore import Qt
from PySide6.QtWidgets import (QDialog, QPushButton, QVBoxLayout, QTextEdit,
QLabel, QDialogButtonBox, QApplication)
QLabel, QApplication, QFrame,
QHBoxLayout)
from requests.exceptions import HTTPError


Expand All @@ -11,15 +12,64 @@ def __init__(self, exctype, value, traceback, app_context):
super().__init__()
self.app_context = app_context
self.setWindowTitle("Error")
self.setMinimumSize(400, 300)
self.setMinimumSize(450, 200)
self.setWindowFlags(self.windowFlags() | Qt.WindowMaximizeButtonHint | Qt.WindowMinimizeButtonHint)

layout = QVBoxLayout(self)
main_layout = QVBoxLayout(self)
main_layout.setContentsMargins(20, 20, 20, 20)
main_layout.setSpacing(15)

error_label = QLabel("An error has occurred.")
error_label.setStyleSheet("font-weight: bold; color: red;")
layout.addWidget(error_label)
# Error icon and title
header_layout = QHBoxLayout()
error_icon = QLabel("⚠️")
error_icon.setStyleSheet("font-size: 24px;")
header_layout.addWidget(error_icon)
error_title = QLabel("An error has occurred")
error_title.setStyleSheet("font-size: 18px; font-weight: bold;")
header_layout.addWidget(error_title)
header_layout.addStretch()
main_layout.addLayout(header_layout)

# Separator
separator = QFrame()
separator.setFrameShape(QFrame.HLine)
separator.setFrameShadow(QFrame.Sunken)
main_layout.addWidget(separator)

# Error description
self.description_label = QLabel(f"{str(value)}")
self.description_label.setWordWrap(True)
main_layout.addWidget(self.description_label)

# More details button
self.more_details_button = QPushButton("Show Details")
self.more_details_button.clicked.connect(self.toggle_details)
main_layout.addWidget(self.more_details_button)

# Detailed error information
self.text_edit = QTextEdit()
self.text_edit.setReadOnly(True)
self.text_edit.hide()
main_layout.addWidget(self.text_edit)

# Action buttons
button_layout = QHBoxLayout()
button_layout.addStretch()

relogin_button = QPushButton("Re-login")
relogin_button.clicked.connect(self.relogin)
button_layout.addWidget(relogin_button)

ok_button = QPushButton("OK")
ok_button.clicked.connect(self.accept)
ok_button.setDefault(True)
button_layout.addWidget(ok_button)

main_layout.addLayout(button_layout)

self.prepare_detailed_text(exctype, value)

def prepare_detailed_text(self, exctype, value):
detailed_text = f"Error Type: {exctype.__name__}\n"
detailed_text += f"Error Message: {str(value)}\n\n"

Expand All @@ -37,18 +87,17 @@ def __init__(self, exctype, value, traceback, app_context):
except json.JSONDecodeError:
detailed_text += response.text

text_edit = QTextEdit()
text_edit.setPlainText(detailed_text)
text_edit.setReadOnly(True)
layout.addWidget(text_edit)

button_box = QDialogButtonBox(QDialogButtonBox.Ok)
button_box.accepted.connect(self.accept)
layout.addWidget(button_box)
self.text_edit.setPlainText(detailed_text)

relogin_button = QPushButton("Re-login")
relogin_button.clicked.connect(self.relogin)
button_box.addButton(relogin_button, QDialogButtonBox.ActionRole)
def toggle_details(self):
if self.text_edit.isVisible():
self.text_edit.hide()
self.more_details_button.setText("Show Details")
self.setFixedSize(450, 200)
else:
self.text_edit.show()
self.more_details_button.setText("Hide Details")
self.setFixedSize(600, 400)

def relogin(self):
self.accept()
Expand Down
2 changes: 2 additions & 0 deletions desktop_app/src/ui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from desktop_app.src.utils import ConfigManager
from public_api.api import APIClient
from public_api.permissions import PermissionName, PermissionManager
from . import AuditLogView
from .components.dialogs import UserManualDialog, AboutDialog
from .dashboard import DashboardWidget
from .qtutorial import QTutorialManager
Expand Down Expand Up @@ -71,6 +72,7 @@ def initialize_tutorial_manager(self):
def add_tabs_based_on_permissions(self):
tab_classes = {
PermissionName.DASHBOARD: DashboardWidget,
PermissionName.AUDIT_LOGS: AuditLogView,
PermissionName.INVENTORY: InventoryView,
PermissionName.ORDERS: OrderView,
PermissionName.PRODUCTS: ProductView,
Expand Down
72 changes: 0 additions & 72 deletions desktop_app/src/ui/offline_mode.py

This file was deleted.

1 change: 1 addition & 0 deletions desktop_app/src/ui/views/audit_logs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .audit_log_view import AuditLogView
Loading

0 comments on commit 16b593b

Please sign in to comment.