Skip to content

DASHBOARD IMPROVEMENT #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Dashboard</title>
</head>
<body>
<h1>Welcome to Your Dashboard</h1>
<div>
<h2>Your Visualizations</h2>
<ul>
{% for viz in visualizations %}
<li><a href="{{ url_for('view_visualization', viz_id=viz['id']) }}">{{ viz['name'] }}</a></li>
{% endfor %}
</ul>
</div>
<div>
<h2>Your Uploaded Data</h2>
<ul>
{% for data in uploaded_data %}
<li>{{ data['file_name'] }} (Uploaded on: {{ data['upload_date'] }})</li>
{% endfor %}
</ul>
</div>
<!-- Button to toggle themes -->
<button onclick="toggleTheme()">Toggle Theme</button>

<script src="{{ url_for('static', filename='js/theme.js') }}"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">
</body>
</html>
63 changes: 63 additions & 0 deletions flask_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from flask import Flask, render_template, session, redirect, url_for, request
import mysql.connector

app = Flask(__name__)
app.secret_key = 'supersecretkey'

# Connect to MySQL database
def get_db_connection():
return mysql.connector.connect(
host="localhost",
user="root",
password="yourpassword",
database="finance_data"
)

@app.route('/dashboard')
def dashboard():
if 'user_id' not in session:
return redirect(url_for('login'))

user_id = session['user_id']

connection = get_db_connection()
cursor = connection.cursor(dictionary=True)

# Fetch user's visualizations
cursor.execute("SELECT * FROM visualizations WHERE user_id = %s", (user_id,))
visualizations = cursor.fetchall()

# Fetch user's uploaded data
cursor.execute("SELECT * FROM uploaded_data WHERE user_id = %s", (user_id,))
uploaded_data = cursor.fetchall()

cursor.close()
connection.close()

return render_template('dashboard.html', visualizations=visualizations, uploaded_data=uploaded_data)

@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']

# Check credentials (add hash check for security)
connection = get_db_connection()
cursor = connection.cursor(dictionary=True)
cursor.execute("SELECT * FROM user WHERE username = %s AND password = %s", (username, password))
user = cursor.fetchone()

cursor.close()
connection.close()

if user:
session['user_id'] = user['user_id']
return redirect(url_for('dashboard'))

return "Invalid credentials", 401

return render_template('login.html')

if __name__ == "__main__":
app.run(debug=True)
20 changes: 20 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Light Theme (default) */
body {
background-color: #fff;
color: #000;
}

/* Dark Theme */
body.dark-theme {
background-color: #333;
color: #fff;
}

button {
padding: 10px 20px;
cursor: pointer;
background-color: #007BFF;
color: white;
border: none;
border-radius: 5px;
}
18 changes: 18 additions & 0 deletions theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Function to toggle between light and dark modes
function toggleTheme() {
var body = document.body;
body.classList.toggle('dark-theme');
// Store theme in localStorage so it's persistent
if (body.classList.contains('dark-theme')) {
localStorage.setItem('theme', 'dark');
} else {
localStorage.setItem('theme', 'light');
}
}

// On page load, apply the saved theme
window.onload = function() {
if (localStorage.getItem('theme') === 'dark') {
document.body.classList.add('dark-theme');
}
}
Loading