Started dashboard implementation
This commit is contained in:
@@ -2,11 +2,26 @@
|
||||
# Banking System Dashboard Page
|
||||
|
||||
import tkinter as tk
|
||||
from tkinter import messagebox
|
||||
from tkinter import messagebox, ttk
|
||||
import customtkinter
|
||||
import json
|
||||
from config import CONFIG
|
||||
|
||||
|
||||
from connection import logout_client
|
||||
from connection import logout_client, get_client, update_client, get_accounts, format_balance
|
||||
|
||||
|
||||
email_entry = None
|
||||
phone_entry = None
|
||||
address_entry = None
|
||||
frame = None
|
||||
|
||||
|
||||
|
||||
|
||||
#################
|
||||
### Functions ###
|
||||
#################
|
||||
|
||||
def logout():
|
||||
response = logout_client() # Call the logout_client function
|
||||
@@ -17,21 +32,174 @@ def logout():
|
||||
else:
|
||||
messagebox.showerror("Logout failed", json_response['message'])
|
||||
|
||||
# Create the main window
|
||||
def display_client_info():
|
||||
global frame # Declare frame as global inside the function
|
||||
if frame is not None:
|
||||
for widget in frame.winfo_children(): # Destroy all widgets in the frame
|
||||
widget.destroy()
|
||||
else:
|
||||
frame = customtkinter.CTkFrame(root)
|
||||
frame.pack(anchor='w', side='left', padx=20, pady=20)
|
||||
with open('application\\session_data.json', 'r') as f:
|
||||
session_data = json.load(f)
|
||||
client_id = session_data['client_id']
|
||||
client_info = get_client(client_id)
|
||||
if 'success' in client_info and client_info['success']:
|
||||
client = client_info['data']
|
||||
fields = [('Name', 'name'),
|
||||
('Client ID', 'client_id'),
|
||||
('Email', 'email'),
|
||||
('Phone', 'phone_number'),
|
||||
('Address', 'address'),
|
||||
('Account Opened', 'opening_timestamp')]
|
||||
for i, (display_name, key) in enumerate(fields):
|
||||
value = client.get(key, 'N/A') # Use 'N/A' as the default value if the key is not found
|
||||
label_key = customtkinter.CTkLabel(frame, text=f"{display_name}: ", font=("Helvetica", 14))
|
||||
label_value = customtkinter.CTkLabel(frame, text=value, font=("Helvetica", 14))
|
||||
label_key.grid(row=i, column=0, sticky='e')
|
||||
label_value.grid(row=i, column=1, sticky='w')
|
||||
else:
|
||||
error_label = customtkinter.CTkLabel(root, text="Error: Could not retrieve client information", font=("Helvetica", 14))
|
||||
error_label.pack(pady=20)
|
||||
|
||||
edit_button = customtkinter.CTkButton(frame, text="Edit Details", command=edit_details)
|
||||
edit_button.grid(row=len(fields), column=0, columnspan=2)
|
||||
|
||||
|
||||
def edit_details():
|
||||
global edit_window, email_entry, phone_entry, address_entry # Declare the variables as global inside the function
|
||||
edit_window = customtkinter.CTkToplevel(root)
|
||||
edit_window.title("Edit Details")
|
||||
edit_window.geometry("300x200")
|
||||
edit_window.attributes('-topmost', True)
|
||||
|
||||
|
||||
email_label = customtkinter.CTkLabel(edit_window, text="Email: ")
|
||||
email_entry = customtkinter.CTkEntry(edit_window)
|
||||
email_label.pack()
|
||||
email_entry.pack()
|
||||
|
||||
phone_label = customtkinter.CTkLabel(edit_window, text="Phone: ")
|
||||
phone_entry = customtkinter.CTkEntry(edit_window)
|
||||
phone_label.pack()
|
||||
phone_entry.pack()
|
||||
|
||||
address_label = customtkinter.CTkLabel(edit_window, text="Address: ")
|
||||
address_entry = customtkinter.CTkEntry(edit_window)
|
||||
address_label.pack()
|
||||
address_entry.pack()
|
||||
|
||||
save_button = customtkinter.CTkButton(edit_window, text="Save", command=save_details)
|
||||
save_button.pack()
|
||||
edit_window.lift()
|
||||
|
||||
def save_details():
|
||||
global edit_window, email_entry, phone_entry, address_entry
|
||||
new_email = email_entry.get() if email_entry.get() != '' else None
|
||||
new_phone = phone_entry.get() if phone_entry.get() != '' else None
|
||||
new_address = address_entry.get() if address_entry.get() != '' else None
|
||||
|
||||
# Get the client_id from the session data
|
||||
with open('application\\session_data.json', 'r') as f:
|
||||
session_data = json.load(f)
|
||||
client_id = session_data['client_id']
|
||||
|
||||
# Display a confirmation dialog box
|
||||
if not messagebox.askyesno("Confirmation", "Are you sure you want to update the details?"):
|
||||
return # If the user clicked 'No', exit the function
|
||||
|
||||
# Update the client details
|
||||
result = update_client(client_id, new_email, new_phone, new_address)
|
||||
# If the request was successful, update the client info displayed in the main window
|
||||
if result['success']:
|
||||
display_client_info()
|
||||
|
||||
# Destroy the window after updating the client info
|
||||
edit_window.destroy()
|
||||
|
||||
def populate_table():
|
||||
# Get the client_id from the session data
|
||||
with open('application\\session_data.json', 'r') as f:
|
||||
session_data = json.load(f)
|
||||
client_id = session_data['client_id']
|
||||
|
||||
# Get the accounts for the client
|
||||
response = get_accounts(client_id)
|
||||
accounts = response['data'] if 'data' in response else []
|
||||
|
||||
# Check if accounts is a list
|
||||
if not isinstance(accounts, list):
|
||||
print(f"Error: Expected a list of accounts, but got {type(accounts)}")
|
||||
return
|
||||
|
||||
# Populate the table with the accounts
|
||||
for account in accounts:
|
||||
formatted_balance = format_balance(account['balance'])
|
||||
table.insert('', 'end', values=(account['description'], account['account_id'], formatted_balance, account['account_type']))
|
||||
|
||||
def on_account_double_click(event):
|
||||
# Get the selected account
|
||||
selected_account = table.item(table.selection())
|
||||
|
||||
# Open a new window
|
||||
account_window = tk.Toplevel(root)
|
||||
|
||||
# Display the account details
|
||||
display_account_details(account_window, selected_account)
|
||||
|
||||
##############
|
||||
### Layout ###
|
||||
##############
|
||||
|
||||
root = customtkinter.CTk()
|
||||
|
||||
# Set the window title, icon, and size
|
||||
root.title("Luxbank Dashboard")
|
||||
root.iconbitmap("application/luxbank.ico")
|
||||
root.geometry("800x600")
|
||||
root.geometry("800x350")
|
||||
|
||||
# Create a label with a welcome message
|
||||
# Check if dark mode is enabled
|
||||
if CONFIG["preferences"]["dark_theme"] == "dark":
|
||||
# Set the style for dark mode
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
else:
|
||||
# Set the style for light mode
|
||||
customtkinter.set_appearance_mode("light")
|
||||
|
||||
# Create a label for the title
|
||||
welcome_label = customtkinter.CTkLabel(root, text="Welcome to the Luxbank Dashboard!", font=("Helvetica", 24))
|
||||
welcome_label.pack(pady=20)
|
||||
|
||||
# Create a Logout button
|
||||
display_client_info()
|
||||
|
||||
logout_button = customtkinter.CTkButton(root, text="Logout", command=logout)
|
||||
logout_button.pack(pady=15)
|
||||
|
||||
# Start the main loop
|
||||
# Create a frame for the table
|
||||
table_frame = ttk.Frame(root)
|
||||
table_frame.pack(side='right', fill='both', expand=True)
|
||||
|
||||
# Create the table
|
||||
table = ttk.Treeview(table_frame, columns=('Description', 'Account ID', 'Balance', 'Account Type'), show='headings')
|
||||
table.heading('Description', text='Description')
|
||||
table.heading('Account ID', text='Account ID')
|
||||
table.heading('Balance', text='Balance')
|
||||
table.heading('Account Type', text='Account Type')
|
||||
|
||||
# Set the column widths
|
||||
table.column('Description', width=200)
|
||||
table.column('Account ID', width=100)
|
||||
table.column('Balance', width=100)
|
||||
table.column('Account Type', width=100)
|
||||
|
||||
table.pack(fill='both', expand=True)
|
||||
|
||||
populate_table()
|
||||
|
||||
# Create a scrollbar for the table
|
||||
scrollbar = ttk.Scrollbar(table_frame, orient='vertical', command=table.yview)
|
||||
scrollbar.pack(side='right', fill='y')
|
||||
table.configure(yscrollcommand=scrollbar.set)
|
||||
|
||||
table.bind("<Double-1>", on_account_double_click)
|
||||
|
||||
root.mainloop()
|
||||
Reference in New Issue
Block a user