fina/backup/fina-2/app/templates/dashboard.html

343 lines
24 KiB
HTML
Raw Normal View History

2025-12-26 00:52:56 +00:00
{% extends "base.html" %}
{% block title %}Dashboard - FINA{% endblock %}
{% block head %}
<style>
/* Custom scrollbar for pie chart legend */
#pie-legend::-webkit-scrollbar {
width: 4px;
}
#pie-legend::-webkit-scrollbar-track {
background: transparent;
}
#pie-legend::-webkit-scrollbar-thumb {
background: #92adc9;
border-radius: 2px;
}
#pie-legend::-webkit-scrollbar-thumb:hover {
background: #5f7a96;
}
.dark #pie-legend::-webkit-scrollbar-thumb {
background: #233648;
}
.dark #pie-legend::-webkit-scrollbar-thumb:hover {
background: #324d67;
}
/* Smooth transform for drag and drop */
.category-card {
transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}
/* Touch user select - prevent text selection during hold */
.category-card {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>
{% endblock %}
{% block body %}
<div class="flex h-screen w-full">
<!-- Side Navigation -->
<aside id="sidebar" class="hidden lg:flex w-64 flex-col bg-sidebar-light dark:bg-background-dark border-r border-border-light dark:border-[#233648] transition-all duration-300 shadow-sm dark:shadow-none">
<div class="p-6 flex flex-col h-full justify-between">
<div class="flex flex-col gap-8">
<!-- User Profile -->
<div class="flex gap-3 items-center">
<img src="{{ current_user.avatar | avatar_url }}" alt="{{ current_user.username }}" class="size-10 rounded-full border-2 border-primary/30 object-cover">
<div class="flex flex-col">
<h1 class="text-text-main dark:text-white text-base font-bold leading-none">{{ current_user.username }}</h1>
<p class="text-text-muted dark:text-[#92adc9] text-xs font-normal mt-1">
{% if current_user.is_admin %}<span data-translate="user.admin">Admin</span>{% else %}<span data-translate="user.user">User</span>{% endif %}
</p>
</div>
</div>
<!-- Navigation Links -->
<nav class="flex flex-col gap-2">
<a class="flex items-center gap-3 px-3 py-2.5 rounded-lg bg-primary/10 text-primary border border-primary/10" href="{{ url_for('main.dashboard') }}">
<span class="material-symbols-outlined text-[20px]">dashboard</span>
<span class="text-sm font-medium" data-translate="nav.dashboard">Dashboard</span>
</a>
<a class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors" href="{{ url_for('main.transactions') }}">
<span class="material-symbols-outlined text-[20px]">receipt_long</span>
<span class="text-sm font-medium" data-translate="nav.transactions">Transactions</span>
</a>
<a class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors" href="{{ url_for('main.reports') }}">
<span class="material-symbols-outlined text-[20px]">pie_chart</span>
<span class="text-sm font-medium" data-translate="nav.reports">Reports</span>
</a>
<a class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors" href="{{ url_for('main.documents') }}">
<span class="material-symbols-outlined text-[20px]">folder_open</span>
<span class="text-sm font-medium" data-translate="nav.documents">Documents</span>
</a>
{% if current_user.is_admin %}
<a class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors" href="/admin">
<span class="material-symbols-outlined text-[20px]">admin_panel_settings</span>
<span class="text-sm font-medium" data-translate="nav.admin">Admin</span>
</a>
{% endif %}
</nav>
</div>
<!-- Bottom Links -->
<div class="flex flex-col gap-2">
<button id="theme-toggle" class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors">
<span class="material-symbols-outlined text-[20px]" id="theme-icon">light_mode</span>
<span class="text-sm font-medium" id="theme-text" data-translate="dashboard.lightMode">Light Mode</span>
</button>
<a class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors" href="{{ url_for('main.settings') }}">
<span class="material-symbols-outlined text-[20px]">settings</span>
<span class="text-sm font-medium" data-translate="nav.settings">Settings</span>
</a>
<a class="flex items-center gap-3 px-3 py-2.5 rounded-lg text-text-muted dark:text-[#92adc9] hover:bg-slate-50 dark:hover:bg-[#233648] hover:text-text-main dark:hover:text-white transition-colors" href="{{ url_for('auth.logout') }}">
<span class="material-symbols-outlined text-[20px]">logout</span>
<span class="text-sm font-medium" data-translate="nav.logout">Log out</span>
</a>
</div>
</div>
</aside>
<!-- Main Content -->
<main class="flex-1 flex flex-col h-full overflow-hidden relative">
<!-- Top Header -->
<header class="h-16 flex items-center justify-between px-6 lg:px-8 border-b border-border-light dark:border-[#233648] bg-white/80 dark:bg-background-dark/95 backdrop-blur z-10 shrink-0 shadow-sm dark:shadow-none">
<div class="flex items-center gap-4">
<button id="menu-toggle" class="lg:hidden text-text-main dark:text-white">
<span class="material-symbols-outlined">menu</span>
</button>
<h2 class="text-text-main dark:text-white text-lg font-bold" data-translate="nav.dashboard">Dashboard</h2>
</div>
<div class="flex items-center gap-6">
<!-- Search Bar -->
<div class="hidden md:flex items-center bg-slate-50 dark:bg-card-dark rounded-lg h-10 px-3 border border-border-light dark:border-[#233648] focus-within:border-primary transition-colors w-64">
<span class="material-symbols-outlined text-text-muted dark:text-[#92adc9] text-[20px]">search</span>
<input id="search-input" class="bg-transparent border-none text-text-main dark:text-white text-sm placeholder-slate-400 dark:placeholder-[#5f7a96] focus:ring-0 w-full ml-2" data-translate="dashboard.search" placeholder="Search expenses..." type="text"/>
</div>
<!-- Actions -->
<div class="flex items-center gap-3">
<button id="add-expense-btn" class="bg-primary hover:bg-primary/90 text-white h-9 px-4 rounded-lg text-sm font-semibold shadow-md shadow-primary/20 transition-all flex items-center gap-2">
<span class="material-symbols-outlined text-[18px]">add</span>
<span class="hidden sm:inline" data-translate="actions.add_expense">Add Expense</span>
</button>
</div>
</div>
</header>
<!-- Scrollable Content -->
<div class="flex-1 overflow-y-auto p-6 lg:p-8 scroll-smooth bg-[#f8fafc] dark:bg-background-dark">
<div class="max-w-7xl mx-auto flex flex-col gap-8 pb-10">
<!-- KPI Cards -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 lg:gap-6">
<!-- Total Spent -->
<div class="p-6 rounded-xl bg-white dark:bg-card-dark border border-border-light dark:border-[#233648] flex flex-col justify-between relative overflow-hidden group shadow-sm dark:shadow-none">
<div class="absolute top-0 right-0 p-4 opacity-5 dark:opacity-10 group-hover:opacity-10 dark:group-hover:opacity-20 transition-opacity">
<span class="material-symbols-outlined text-6xl text-primary">payments</span>
</div>
<div>
<p class="text-text-muted dark:text-[#92adc9] text-sm font-medium" data-translate="dashboard.total_spent">Total Spent</p>
<h3 id="total-spent" class="text-text-main dark:text-white text-3xl font-bold mt-2 tracking-tight">$0.00</h3>
</div>
<div class="flex items-center gap-2 mt-4">
<span id="percent-change" class="bg-green-500/10 text-green-600 dark:text-green-400 text-xs font-semibold px-2 py-1 rounded-full flex items-center gap-1">
<span class="material-symbols-outlined text-[14px]">trending_up</span>
0%
</span>
<span class="text-text-muted dark:text-[#5f7a96] text-xs" data-translate="dashboard.vs_last_month">vs last month</span>
</div>
</div>
<!-- Active Categories -->
<div class="p-6 rounded-xl bg-white dark:bg-card-dark border border-border-light dark:border-[#233648] flex flex-col justify-between shadow-sm dark:shadow-none">
<div>
<p class="text-text-muted dark:text-[#92adc9] text-sm font-medium" data-translate="dashboard.active_categories">Active Categories</p>
<h3 id="active-categories" class="text-text-main dark:text-white text-3xl font-bold mt-2 tracking-tight">0</h3>
</div>
<p class="text-text-muted dark:text-[#5f7a96] text-xs mt-6" data-translate="dashboard.categories_in_use">categories in use</p>
</div>
<!-- Total Transactions -->
<div class="p-6 rounded-xl bg-white dark:bg-card-dark border border-border-light dark:border-[#233648] flex flex-col justify-between shadow-sm dark:shadow-none">
<div>
<p class="text-text-muted dark:text-[#92adc9] text-sm font-medium" data-translate="dashboard.total_transactions">Total Transactions</p>
<h3 id="total-transactions" class="text-text-main dark:text-white text-3xl font-bold mt-2 tracking-tight">0</h3>
</div>
<p class="text-text-muted dark:text-[#5f7a96] text-xs mt-6" data-translate="dashboard.this_month">this month</p>
</div>
</div>
<!-- Charts Row -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-4 lg:gap-6">
<!-- Spending by Category - Smaller, Compact -->
<div class="p-5 rounded-xl bg-white dark:bg-card-dark border border-border-light dark:border-[#233648] shadow-sm dark:shadow-none flex flex-col">
<h3 class="text-text-main dark:text-white text-base font-bold mb-1" data-translate="dashboard.spending_by_category">Spending by Category</h3>
<p class="text-text-muted dark:text-[#92adc9] text-xs mb-4" data-translate="dashboard.categoryBreakdownDesc">Breakdown by category</p>
<div class="flex items-center justify-center relative mb-4">
<!-- CSS Conic Gradient Pie Chart - Smaller Size -->
<div id="pie-chart-wrapper" class="relative flex items-center justify-center">
<div id="pie-chart" class="size-40 rounded-full relative transition-all duration-500" style="background: conic-gradient(#233648 0% 100%);">
<!-- Inner hole for donut effect -->
<div class="absolute inset-3 bg-white dark:bg-card-dark rounded-full flex flex-col items-center justify-center z-10 border border-border-light dark:border-[#233648]">
<span class="text-text-muted dark:text-[#92adc9] text-[10px] font-medium" data-translate="dashboard.totalThisYear">Total This Year</span>
<span id="pie-total" class="text-text-main dark:text-white text-base font-bold">0 lei</span>
</div>
</div>
</div>
</div>
<!-- Legend - Scrollable for 12-14 categories -->
<div id="pie-legend" class="grid grid-cols-1 gap-y-1.5 max-h-[180px] overflow-y-auto pr-2 scrollbar-thin scrollbar-thumb-border-light dark:scrollbar-thumb-[#233648] scrollbar-track-transparent">
<!-- Legend items will be generated here -->
</div>
</div>
<!-- Monthly Trend - Larger Space for 12 Months -->
<div class="lg:col-span-2 p-6 rounded-xl bg-white dark:bg-card-dark border border-border-light dark:border-[#233648] shadow-sm dark:shadow-none">
<h3 class="text-text-main dark:text-white text-lg font-bold mb-4" data-translate="dashboard.monthly_trend">Monthly Trend</h3>
<canvas id="monthly-chart" class="w-full" style="max-height: 320px;"></canvas>
</div>
</div>
<!-- Expense Categories -->
<div>
<div class="flex items-center justify-between mb-4">
<div class="flex items-center gap-2">
<h3 class="text-text-main dark:text-white text-lg font-bold" data-translate="dashboard.expenseCategories">Expense Categories</h3>
<span class="material-symbols-outlined text-text-muted dark:text-[#92adc9] text-[18px]" title="Drag to reorder">drag_indicator</span>
</div>
<div class="flex items-center gap-3">
<button id="manage-categories-btn" class="text-primary hover:text-primary/80 text-sm font-medium flex items-center gap-1">
<span class="material-symbols-outlined text-[18px]">tune</span>
<span data-translate="dashboard.manageCategories">Manage</span>
</button>
<a href="{{ url_for('main.transactions') }}" class="text-primary text-sm font-medium hover:text-primary/80" data-translate="dashboard.view_all">View All</a>
</div>
</div>
<div id="category-cards" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
<!-- Category cards will be loaded here -->
</div>
</div>
<!-- Recent Transactions -->
<div class="p-6 rounded-xl bg-white dark:bg-card-dark border border-border-light dark:border-[#233648] shadow-sm dark:shadow-none">
<div class="flex justify-between items-center mb-4">
<h3 class="text-text-main dark:text-white text-lg font-bold" data-translate="dashboard.recent_transactions">Recent Transactions</h3>
<a href="{{ url_for('main.transactions') }}" class="text-primary text-sm hover:underline" data-translate="dashboard.view_all">View All</a>
</div>
<div id="recent-transactions" class="space-y-3">
<!-- Transactions will be loaded here -->
</div>
</div>
</div>
</div>
</main>
</div>
<!-- Add Expense Modal -->
<div id="expense-modal" class="hidden fixed inset-0 bg-black/50 backdrop-blur-sm z-50 flex items-center justify-center p-4">
<div class="bg-white dark:bg-card-dark border border-border-light dark:border-[#233648] rounded-2xl max-w-md w-full max-h-[90vh] overflow-y-auto shadow-xl">
<div class="p-6">
<div class="flex justify-between items-center mb-6">
<h3 class="text-text-main dark:text-white text-xl font-bold" data-translate="modal.add_expense">Add Expense</h3>
<button id="close-modal" class="text-text-muted dark:text-[#92adc9] hover:text-text-main dark:hover:text-white">
<span class="material-symbols-outlined">close</span>
</button>
</div>
<form id="expense-form" class="space-y-4">
<div>
<label class="text-text-muted dark:text-[#92adc9] text-sm mb-2 block" data-translate="form.amount">Amount</label>
<input type="number" step="0.01" name="amount" required class="w-full bg-slate-50 dark:bg-[#111a22] border border-border-light dark:border-[#233648] rounded-lg px-4 py-2 text-text-main dark:text-white focus:border-primary focus:ring-1 focus:ring-primary">
</div>
<div>
<label class="text-text-muted dark:text-[#92adc9] text-sm mb-2 block" data-translate="form.description">Description</label>
<input type="text" name="description" required class="w-full bg-slate-50 dark:bg-[#111a22] border border-border-light dark:border-[#233648] rounded-lg px-4 py-2 text-text-main dark:text-white focus:border-primary focus:ring-1 focus:ring-primary">
</div>
<div>
<label class="text-text-muted dark:text-[#92adc9] text-sm mb-2 block" data-translate="form.category">Category</label>
<select name="category_id" required class="w-full bg-slate-50 dark:bg-[#111a22] border border-border-light dark:border-[#233648] rounded-lg px-4 py-2 text-text-main dark:text-white focus:border-primary focus:ring-1 focus:ring-primary">
<option value="" data-translate="dashboard.selectCategory">Select category...</option>
</select>
</div>
<div>
<label class="text-text-muted dark:text-[#92adc9] text-sm mb-2 block" data-translate="form.date">Date</label>
<input type="date" name="date" required class="w-full bg-slate-50 dark:bg-[#111a22] border border-border-light dark:border-[#233648] rounded-lg px-4 py-2 text-text-main dark:text-white focus:border-primary focus:ring-1 focus:ring-primary">
</div>
<div>
<label class="text-text-muted dark:text-[#92adc9] text-sm mb-2 block" data-translate="form.tags">Tags (comma separated)</label>
<input type="text" name="tags" class="w-full bg-slate-50 dark:bg-[#111a22] border border-border-light dark:border-[#233648] rounded-lg px-4 py-2 text-text-main dark:text-white focus:border-primary focus:ring-1 focus:ring-primary">
</div>
<div>
<label class="text-text-muted dark:text-[#92adc9] text-sm mb-2 block" data-translate="form.receipt">Receipt (optional)</label>
<input type="file" name="receipt" accept="image/*,.pdf" class="w-full bg-slate-50 dark:bg-[#111a22] border border-border-light dark:border-[#233648] rounded-lg px-4 py-2 text-text-main dark:text-white focus:border-primary focus:ring-1 focus:ring-primary file:mr-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:text-sm file:font-semibold file:bg-primary file:text-white hover:file:bg-primary/90">
</div>
<button type="submit" class="w-full bg-primary hover:bg-primary/90 text-white py-3 rounded-lg font-semibold transition-colors shadow-md" data-translate="actions.save">Save Expense</button>
</form>
</div>
</div>
</div>
<!-- Category Management Modal -->
<div id="category-modal" class="fixed inset-0 bg-black/60 backdrop-blur-sm z-50 hidden flex items-center justify-center p-4">
<div class="bg-white dark:bg-card-dark rounded-2xl max-w-4xl w-full max-h-[90vh] overflow-hidden shadow-2xl">
<div class="p-6 border-b border-border-light dark:border-[#233648] flex justify-between items-center">
<h3 class="text-text-main dark:text-white text-xl font-bold" data-translate="categories.manageTitle">Manage Categories</h3>
<button id="close-category-modal" class="text-text-muted dark:text-[#92adc9] hover:text-text-main dark:hover:text-white">
<span class="material-symbols-outlined">close</span>
</button>
</div>
<div class="p-6 overflow-y-auto max-h-[calc(90vh-140px)]">
<!-- Add New Category Form -->
<div class="mb-6 p-4 bg-slate-50 dark:bg-[#111a22] rounded-lg border border-border-light dark:border-[#233648]">
<h4 class="text-text-main dark:text-white font-semibold mb-4" data-translate="categories.addNew">Add New Category</h4>
<form id="add-category-form" class="grid grid-cols-1 md:grid-cols-4 gap-4">
<div>
<label class="text-text-muted dark:text-[#92adc9] text-sm mb-2 block" data-translate="form.name">Name</label>
<input type="text" name="name" required class="w-full bg-white dark:bg-card-dark border border-border-light dark:border-[#233648] rounded-lg px-4 py-2 text-text-main dark:text-white" />
</div>
<div>
<label class="text-text-muted dark:text-[#92adc9] text-sm mb-2 block" data-translate="form.color">Color</label>
<input type="color" name="color" value="#2b8cee" class="w-full h-10 bg-white dark:bg-card-dark border border-border-light dark:border-[#233648] rounded-lg px-2 cursor-pointer" />
</div>
<div>
<label class="text-text-muted dark:text-[#92adc9] text-sm mb-2 block" data-translate="form.icon">Icon</label>
<input type="text" name="icon" placeholder="category" class="w-full bg-white dark:bg-card-dark border border-border-light dark:border-[#233648] rounded-lg px-4 py-2 text-text-main dark:text-white" />
</div>
<div class="flex items-end">
<button type="submit" class="w-full bg-primary hover:bg-primary/90 text-white py-2 rounded-lg font-semibold transition-colors flex items-center justify-center gap-2">
<span class="material-symbols-outlined text-[18px]">add</span>
<span data-translate="categories.add">Add</span>
</button>
</div>
</form>
</div>
<!-- Category List with Drag & Drop -->
<div>
<div class="flex items-center justify-between mb-4">
<h4 class="text-text-main dark:text-white font-semibold" data-translate="categories.yourCategories">Your Categories</h4>
<p class="text-text-muted dark:text-[#92adc9] text-sm" data-translate="categories.dragToReorder">Drag to reorder</p>
</div>
<div id="categories-list" class="space-y-2">
<!-- Categories will be loaded here -->
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.js"></script>
<script src="{{ url_for('static', filename='js/dashboard.js') }}"></script>
{% endblock %}