-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
819 lines (711 loc) · 26.4 KB
/
script.js
File metadata and controls
819 lines (711 loc) · 26.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
// Enhanced Dashboard JavaScript with Animations
class MonezzyDashboard {
constructor() {
this.charts = {};
this.isLoading = true;
this.currentTheme = 'dark';
this.aiChatOpen = false;
this.init();
}
init() {
this.showLoadingScreen();
this.setupEventListeners();
this.updateTimeGreeting();
this.initializeCharts();
this.animateElements();
this.setupSearch();
this.setupAIAssistant();
// Hide loading screen after initialization
setTimeout(() => {
this.hideLoadingScreen();
}, 2000);
}
showLoadingScreen() {
const loadingScreen = document.getElementById('loadingScreen');
if (loadingScreen) {
loadingScreen.style.display = 'flex';
}
}
hideLoadingScreen() {
const loadingScreen = document.getElementById('loadingScreen');
if (loadingScreen) {
loadingScreen.classList.add('hidden');
setTimeout(() => {
loadingScreen.style.display = 'none';
this.isLoading = false;
}, 500);
}
}
setupEventListeners() {
// Mobile menu toggle
const menuToggle = document.getElementById('menuToggle');
const sidebar = document.getElementById('sidebar');
if (menuToggle && sidebar) {
menuToggle.addEventListener('click', () => {
sidebar.classList.toggle('open');
});
}
// Close sidebar when clicking outside on mobile
document.addEventListener('click', (e) => {
if (window.innerWidth <= 768 && sidebar) {
if (!sidebar.contains(e.target) && !menuToggle?.contains(e.target)) {
sidebar.classList.remove('open');
}
}
});
// Navigation items
document.querySelectorAll('.nav-item').forEach(item => {
item.addEventListener('click', (e) => {
e.preventDefault();
this.handleNavigation(item);
});
});
// Theme toggle
const themeToggle = document.getElementById('themeToggle');
if (themeToggle) {
themeToggle.addEventListener('click', () => {
this.toggleTheme();
});
}
// Refresh data
const refreshBtn = document.getElementById('refreshData');
if (refreshBtn) {
refreshBtn.addEventListener('click', () => {
this.refreshData();
});
}
// Quick actions
document.querySelectorAll('.quick-action-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
const action = e.currentTarget.dataset.action;
this.handleQuickAction(action);
});
});
// Notification button
const notificationBtn = document.getElementById('notificationBtn');
if (notificationBtn) {
notificationBtn.addEventListener('click', () => {
this.showNotifications();
});
}
// User profile
const userProfile = document.getElementById('userProfile');
if (userProfile) {
userProfile.addEventListener('click', () => {
this.showUserMenu();
});
}
// Category rows
document.querySelectorAll('.table-row').forEach(row => {
row.addEventListener('click', () => {
this.showCategoryDetails(row.dataset.category);
});
});
}
handleNavigation(item) {
// Remove active class from all items
document.querySelectorAll('.nav-item').forEach(nav => {
nav.classList.remove('active');
});
// Add active class to clicked item
item.classList.add('active');
// Get the navigation text
const navText = item.querySelector('span').textContent;
const page = item.dataset.page;
// Show toast notification
this.showToast('success', 'Navigation', `Switched to ${navText}`);
// Add page transition effect
this.animatePageTransition();
}
animatePageTransition() {
const content = document.querySelector('.dashboard-content');
if (content) {
content.style.opacity = '0.7';
content.style.transform = 'translateY(10px)';
setTimeout(() => {
content.style.opacity = '1';
content.style.transform = 'translateY(0)';
}, 200);
}
}
toggleTheme() {
this.currentTheme = this.currentTheme === 'dark' ? 'light' : 'dark';
document.body.setAttribute('data-theme', this.currentTheme);
const themeIcon = document.querySelector('#themeToggle i');
if (themeIcon) {
themeIcon.className = this.currentTheme === 'dark' ? 'fas fa-moon' : 'fas fa-sun';
}
this.showToast('info', 'Theme Changed', `Switched to ${this.currentTheme} mode`);
// Re-initialize charts with new theme colors
setTimeout(() => {
this.updateChartsTheme();
}, 300);
}
updateTimeGreeting() {
const hour = new Date().getHours();
const greetingElement = document.getElementById('timeGreeting');
let greeting = 'Morning';
if (hour >= 12 && hour < 17) {
greeting = 'Afternoon';
} else if (hour >= 17) {
greeting = 'Evening';
}
if (greetingElement) {
greetingElement.textContent = greeting;
}
}
animateElements() {
// Animate metric cards on load
this.animateMetrics();
// Animate progress bars
this.animateProgressBars();
// Animate frequency bars
this.animateFrequencyBars();
// Setup intersection observer for scroll animations
this.setupScrollAnimations();
}
animateMetrics() {
const metricCards = document.querySelectorAll('.metric-card h3[data-target]');
metricCards.forEach((metric, index) => {
setTimeout(() => {
const target = parseInt(metric.dataset.target);
const isRupee = metric.textContent.includes('₹');
this.animateNumber(metric, 0, target, 2000, (value) => {
if (isRupee) {
return target >= 1000 ? `₹${(value/1000).toFixed(1)}k` : `₹${value}`;
}
return value.toString();
});
}, index * 200);
});
}
animateNumber(element, start, end, duration, formatter) {
const startTime = performance.now();
const animate = (currentTime) => {
const elapsed = currentTime - startTime;
const progress = Math.min(elapsed / duration, 1);
// Easing function
const easeOutCubic = 1 - Math.pow(1 - progress, 3);
const current = Math.floor(start + (end - start) * easeOutCubic);
element.textContent = formatter(current);
if (progress < 1) {
requestAnimationFrame(animate);
}
};
requestAnimationFrame(animate);
}
animateProgressBars() {
setTimeout(() => {
document.querySelectorAll('.progress-fill[data-progress]').forEach(bar => {
const progress = bar.dataset.progress;
bar.style.width = `${progress}%`;
});
}, 1000);
}
animateFrequencyBars() {
setTimeout(() => {
document.querySelectorAll('.frequency-fill[data-width]').forEach(bar => {
const progress = bar.dataset.width;
bar.style.width = `${progress}%`;
});
}, 1000);
}
setupScrollAnimations() {
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
});
document.querySelectorAll('.slide-up, .fade-in').forEach(el => {
observer.observe(el);
});
}
initializeCharts() {
this.createMonthlyTrendsChart();
this.createExpenseBreakdownChart();
this.createSavingsProgressChart();
this.createSparklineCharts();
}
createMonthlyTrendsChart() {
const ctx = document.getElementById('monthlyTrendsChart');
if (!ctx) return;
this.charts.monthlyTrends = new Chart(ctx, {
type: 'bar',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
datasets: [{
label: 'Income',
data: [45000, 52000, 48000, 61000, 55000, 67000],
backgroundColor: 'rgba(167, 66, 240, 0.8)',
borderColor: 'rgb(158, 51, 234)',
borderWidth: 2,
borderRadius: 8,
borderSkipped: false,
}, {
label: 'Expenses',
data: [32000, 38000, 35000, 42000, 39000, 45000],
backgroundColor: 'rgba(222, 203, 255, 0.8)',
borderColor: 'rgb(232, 217, 255)',
borderWidth: 2,
borderRadius: 8,
borderSkipped: false,
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
animation: {
duration: 2000,
easing: 'easeOutCubic'
},
plugins: {
legend: {
labels: {
color: '#a1a1aa',
usePointStyle: true,
padding: 20
}
}
},
scales: {
x: {
ticks: {
color: '#a1a1aa'
},
grid: {
color: 'rgba(51, 51, 51, 0.5)',
drawBorder: false
}
},
y: {
ticks: {
color: '#a1a1aa',
callback: function(value) {
return '₹' + (value / 1000) + 'k';
}
},
grid: {
color: 'rgba(51, 51, 51, 0.5)',
drawBorder: false
}
}
}
}
});
}
createExpenseBreakdownChart() {
const ctx = document.getElementById('expenseBreakdownChart');
if (!ctx) return;
this.charts.expenseBreakdown = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['Food & Dining', 'Transportation', 'Entertainment', 'Shopping', 'Bills'],
datasets: [{
data: [12500, 8200, 5800, 9400, 6100],
backgroundColor: [
'#ef4444',
'#f59e0b',
'#10b981',
'#8b5cf6',
'#06b6d4'
],
borderWidth: 0,
hoverOffset: 10
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
animation: {
animateRotate: true,
duration: 2000
},
plugins: {
legend: {
position: 'bottom',
labels: {
color: '#a1a1aa',
padding: 20,
usePointStyle: true,
font: {
size: 12
}
}
}
}
}
});
}
createSavingsProgressChart() {
const ctx = document.getElementById('savingsProgressChart');
if (!ctx) return;
this.charts.savingsProgress = new Chart(ctx, {
type: 'line',
data: {
labels: ['Week 1', 'Week 2', 'Week 3', 'Week 4'],
datasets: [{
label: 'Savings Goal',
data: [25000, 50000, 75000, 100000],
borderColor: 'rgba(139, 92, 246, 0.5)',
backgroundColor: 'transparent',
borderDash: [5, 5],
pointRadius: 0,
borderWidth: 2
}, {
label: 'Actual Savings',
data: [28000, 52000, 71000, 89000],
borderColor: '#8b5cf6',
backgroundColor: 'rgba(139, 92, 246, 0.1)',
fill: true,
tension: 0.4,
pointBackgroundColor: '#8b5cf6',
pointBorderColor: '#ffffff',
pointBorderWidth: 2,
pointRadius: 6,
pointHoverRadius: 8,
borderWidth: 3
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
animation: {
duration: 2000,
easing: 'easeOutCubic'
},
plugins: {
legend: {
labels: {
color: '#a1a1aa',
usePointStyle: true
}
}
},
scales: {
x: {
ticks: {
color: '#a1a1aa'
},
grid: {
color: 'rgba(51, 51, 51, 0.5)',
drawBorder: false
}
},
y: {
ticks: {
color: '#a1a1aa',
callback: function(value) {
return '₹' + (value / 1000) + 'k';
}
},
grid: {
color: 'rgba(51, 51, 51, 0.5)',
drawBorder: false
}
}
}
}
});
}
createSparklineCharts() {
const sparklineData = {
income: [20, 25, 22, 28, 26, 30, 25],
expense: [15, 18, 16, 20, 19, 22, 17],
savings: [5, 7, 6, 8, 7, 8, 8],
transactions: [10, 12, 11, 15, 14, 16, 12]
};
Object.keys(sparklineData).forEach(key => {
const ctx = document.getElementById(`${key}Sparkline`);
if (ctx) {
new Chart(ctx, {
type: 'line',
data: {
labels: ['', '', '', '', '', '', ''],
datasets: [{
data: sparklineData[key],
borderColor: '#8b5cf6',
backgroundColor: 'rgba(139, 92, 246, 0.1)',
borderWidth: 2,
fill: true,
tension: 0.4,
pointRadius: 0
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: { display: false }
},
scales: {
x: { display: false },
y: { display: false }
},
animation: {
duration: 1500,
delay: 500
}
}
});
}
});
}
setupSearch() {
const searchInput = document.getElementById('searchInput');
const searchSuggestions = document.getElementById('searchSuggestions');
if (searchInput && searchSuggestions) {
searchInput.addEventListener('input', (e) => {
const query = e.target.value.toLowerCase();
if (query.length > 0) {
this.showSearchSuggestions(query, searchSuggestions);
} else {
searchSuggestions.classList.remove('show');
}
});
searchInput.addEventListener('focus', () => {
if (searchInput.value.length > 0) {
searchSuggestions.classList.add('show');
}
});
document.addEventListener('click', (e) => {
if (!searchInput.contains(e.target) && !searchSuggestions.contains(e.target)) {
searchSuggestions.classList.remove('show');
}
});
}
}
showSearchSuggestions(query, container) {
const suggestions = [
'Food & Dining expenses',
'Transportation costs',
'Monthly savings goal',
'Investment portfolio',
'Tax reports',
'Family accounts'
].filter(item => item.toLowerCase().includes(query));
container.innerHTML = suggestions.map(suggestion =>
`<div class="search-suggestion-item" onclick="dashboard.selectSuggestion('${suggestion}')">${suggestion}</div>`
).join('');
container.classList.add('show');
}
selectSuggestion(suggestion) {
const searchInput = document.getElementById('searchInput');
const searchSuggestions = document.getElementById('searchSuggestions');
if (searchInput) {
searchInput.value = suggestion;
}
if (searchSuggestions) {
searchSuggestions.classList.remove('show');
}
this.showToast('info', 'Search', `Searching for: ${suggestion}`);
}
setupAIAssistant() {
const aiToggle = document.getElementById('aiToggle');
const aiChat = document.getElementById('aiChat');
const aiClose = document.getElementById('aiClose');
const aiSend = document.getElementById('aiSend');
const aiInput = document.getElementById('aiInput');
if (aiToggle && aiChat) {
aiToggle.addEventListener('click', () => {
this.toggleAIChat();
});
}
if (aiClose) {
aiClose.addEventListener('click', () => {
this.closeAIChat();
});
}
if (aiSend && aiInput) {
aiSend.addEventListener('click', () => {
this.sendAIMessage();
});
aiInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
this.sendAIMessage();
}
});
}
}
toggleAIChat() {
const aiChat = document.getElementById('aiChat');
if (aiChat) {
this.aiChatOpen = !this.aiChatOpen;
aiChat.classList.toggle('show', this.aiChatOpen);
}
}
closeAIChat() {
const aiChat = document.getElementById('aiChat');
if (aiChat) {
this.aiChatOpen = false;
aiChat.classList.remove('show');
}
}
sendAIMessage() {
const aiInput = document.getElementById('aiInput');
const aiMessages = document.getElementById('aiMessages');
if (aiInput && aiMessages && aiInput.value.trim()) {
const message = aiInput.value.trim();
// Add user message
this.addAIMessage('user', message);
// Clear input
aiInput.value = '';
// Simulate AI response
setTimeout(() => {
const responses = [
"I can help you track your expenses better. Would you like me to categorize your recent transactions?",
"Based on your spending pattern, I suggest setting aside ₹5,000 more for your emergency fund.",
"Your food expenses have increased by 15% this month. Consider meal planning to reduce costs.",
"Great question! I can help you optimize your savings strategy. Let me analyze your data."
];
const randomResponse = responses[Math.floor(Math.random() * responses.length)];
this.addAIMessage('bot', randomResponse);
}, 1000);
}
}
addAIMessage(type, content) {
const aiMessages = document.getElementById('aiMessages');
if (!aiMessages) return;
const messageDiv = document.createElement('div');
messageDiv.className = `ai-message ${type}`;
if (type === 'bot') {
messageDiv.innerHTML = `
<div class="message-avatar">
<i class="fas fa-robot"></i>
</div>
<div class="message-content">${content}</div>
`;
} else {
messageDiv.innerHTML = `
<div class="message-content user-message">${content}</div>
`;
messageDiv.style.flexDirection = 'row-reverse';
}
aiMessages.appendChild(messageDiv);
aiMessages.scrollTop = aiMessages.scrollHeight;
}
refreshData() {
const refreshBtn = document.getElementById('refreshData');
if (refreshBtn) {
const icon = refreshBtn.querySelector('i');
icon.style.animation = 'spin 1s linear infinite';
setTimeout(() => {
icon.style.animation = '';
this.showToast('success', 'Data Refreshed', 'Your financial data has been updated');
// Re-animate metrics
this.animateMetrics();
}, 1000);
}
}
handleQuickAction(action) {
const actions = {
'add-expense': 'Add Expense form opened',
'transfer': 'Money Transfer initiated',
'pay-bill': 'Bill Payment started'
};
this.showToast('info', 'Quick Action', actions[action] || 'Action performed');
}
showNotifications() {
this.showToast('info', 'Notifications', 'You have 3 new notifications');
}
showUserMenu() {
this.showToast('info', 'User Menu', 'Profile menu opened');
}
showCategoryDetails(category) {
const categoryNames = {
food: 'Food & Dining',
transport: 'Transportation',
entertainment: 'Entertainment',
shopping: 'Shopping'
};
this.showToast('info', 'Category Details', `Viewing ${categoryNames[category]} details`);
}
updateChartsTheme() {
// Update chart colors based on theme
Object.values(this.charts).forEach(chart => {
if (chart && chart.options) {
const textColor = this.currentTheme === 'dark' ? '#a1a1aa' : '#475569';
const gridColor = this.currentTheme === 'dark' ? 'rgba(51, 51, 51, 0.5)' : 'rgba(226, 232, 240, 0.5)';
if (chart.options.plugins && chart.options.plugins.legend) {
chart.options.plugins.legend.labels.color = textColor;
}
if (chart.options.scales) {
Object.values(chart.options.scales).forEach(scale => {
if (scale.ticks) scale.ticks.color = textColor;
if (scale.grid) scale.grid.color = gridColor;
});
}
chart.update();
}
});
}
showToast(type, title, message) {
const toastContainer = document.getElementById('toastContainer');
if (!toastContainer) return;
const toast = document.createElement('div');
toast.className = `toast ${type}`;
const icons = {
success: 'fas fa-check',
error: 'fas fa-times',
info: 'fas fa-info'
};
toast.innerHTML = `
<div class="toast-icon">
<i class="${icons[type]}"></i>
</div>
<div class="toast-content">
<div class="toast-title">${title}</div>
<div class="toast-message">${message}</div>
</div>
`;
toastContainer.appendChild(toast);
// Auto remove after 3 seconds
setTimeout(() => {
toast.style.transform = 'translateX(100%)';
setTimeout(() => {
if (toastContainer.contains(toast)) {
toastContainer.removeChild(toast);
}
}, 300);
}, 3000);
}
}
// Initialize dashboard when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
window.dashboard = new MonezzyDashboard();
});
// Add CSS for search suggestions
const additionalStyles = `
.search-suggestion-item {
padding: 0.75rem 1rem;
cursor: pointer;
transition: background-color 0.2s ease;
border-bottom: 1px solid var(--border-color);
}
.search-suggestion-item:hover {
background-color: var(--secondary-bg);
}
.search-suggestion-item:last-child {
border-bottom: none;
}
.user-message {
background: var(--accent-purple) !important;
color: white !important;
margin-left: 2rem;
}
.ai-message.user {
justify-content: flex-end;
}
.visible {
opacity: 1 !important;
transform: translateY(0) !important;
}
`;
// Add the additional styles to the document
const styleSheet = document.createElement('style');
styleSheet.textContent = additionalStyles;
document.head.appendChild(styleSheet);