51 lines
1.9 KiB
Python
51 lines
1.9 KiB
Python
"""
|
|
views/admin_log_view.py — Admin panel: Activity Log tab.
|
|
"""
|
|
|
|
import tkinter as tk
|
|
from tkinter import ttk
|
|
from utils.ui_helpers import COLOURS, FONT_HEADING, show_error
|
|
|
|
|
|
class AdminLogView(ttk.Frame):
|
|
def __init__(self, parent, current_user: dict):
|
|
super().__init__(parent)
|
|
self.current_user = current_user
|
|
self._build_ui()
|
|
self._load()
|
|
|
|
def _build_ui(self):
|
|
toolbar = ttk.Frame(self)
|
|
toolbar.pack(fill="x", pady=(0, 10))
|
|
ttk.Label(toolbar, text="Activity Log", style="Heading.TLabel").pack(side="left")
|
|
ttk.Button(toolbar, text="↻ Refresh", style="Ghost.TButton",
|
|
command=self._load).pack(side="right")
|
|
|
|
cols = ("Time", "User", "Action", "Entity", "Entity ID", "Detail")
|
|
self.tree = ttk.Treeview(self, columns=cols, show="headings", selectmode="browse")
|
|
widths = [140, 100, 130, 100, 70, 320]
|
|
for col, w in zip(cols, widths):
|
|
self.tree.heading(col, text=col)
|
|
self.tree.column(col, width=w, anchor="w")
|
|
self.tree.pack(fill="both", expand=True)
|
|
|
|
vsb = ttk.Scrollbar(self, orient="vertical", command=self.tree.yview)
|
|
self.tree.configure(yscrollcommand=vsb.set)
|
|
vsb.place(relx=1, rely=0, relheight=1, anchor="ne")
|
|
|
|
def _load(self):
|
|
from models import get_activity_log
|
|
self.tree.delete(*self.tree.get_children())
|
|
try:
|
|
for entry in get_activity_log():
|
|
self.tree.insert("", "end", values=(
|
|
str(entry["logged_at"])[:16],
|
|
entry.get("username") or "—",
|
|
entry["action"],
|
|
entry.get("entity") or "",
|
|
entry.get("entity_id") or "",
|
|
entry.get("detail") or "",
|
|
))
|
|
except Exception as e:
|
|
show_error(f"Failed to load activity log:\n{e}")
|