-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdashboard.js
More file actions
388 lines (345 loc) · 12.5 KB
/
Copy pathdashboard.js
File metadata and controls
388 lines (345 loc) · 12.5 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
// Dashboard functionality
class DashboardManager {
constructor() {
this.userData = this.loadUserData();
this.progressData = this.loadProgressData();
this.init();
}
init() {
this.updateUserInfo();
this.updateStats();
this.updateLearningPaths();
this.updateActivity();
this.updateAchievements();
this.updateRecommendations();
this.bindEvents();
this.startProgressTracking();
}
loadUserData() {
const saved = localStorage.getItem('wayforge_user_data');
return saved ? JSON.parse(saved) : {
name: 'Learner',
email: '',
joinDate: new Date().toISOString(),
totalTime: 0,
streak: 0,
achievements: [],
level: 1,
xp: 0
};
}
loadProgressData() {
const saved = localStorage.getItem('wayforge_progress_data');
return saved ? JSON.parse(saved) : {
currentPaths: [],
completedModules: [],
quizScores: [],
dailyActivity: [],
weeklyGoals: {
target: 5,
completed: 0
}
};
}
saveUserData() {
localStorage.setItem('wayforge_user_data', JSON.stringify(this.userData));
}
saveProgressData() {
localStorage.setItem('wayforge_progress_data', JSON.stringify(this.progressData));
}
updateUserInfo() {
const nameElement = document.querySelector('.user-name');
if (nameElement) {
nameElement.textContent = this.userData.name;
}
}
updateStats() {
// Update streak
const streakElement = document.querySelector('.stat-card:nth-child(1) .stat-number');
if (streakElement) {
streakElement.textContent = this.calculateStreak();
}
// Update achievements count
const achievementsElement = document.querySelector('.stat-card:nth-child(2) .stat-number');
if (achievementsElement) {
achievementsElement.textContent = this.userData.achievements.length;
}
// Update total time
const timeElement = document.querySelector('.stat-card:nth-child(3) .stat-number');
if (timeElement) {
timeElement.textContent = this.formatTime(this.userData.totalTime);
}
}
calculateStreak() {
const today = new Date();
const dailyActivity = this.progressData.dailyActivity;
let streak = 0;
for (let i = 0; i < 30; i++) {
const checkDate = new Date(today);
checkDate.setDate(today.getDate() - i);
const dateString = checkDate.toDateString();
if (dailyActivity.includes(dateString)) {
streak++;
} else if (i > 0) {
break;
}
}
return streak;
}
formatTime(minutes) {
if (minutes < 60) return `${minutes}m`;
const hours = Math.floor(minutes / 60);
return `${hours}h`;
}
updateLearningPaths() {
// Simulate learning paths data
const paths = [
{
id: 'js-fullstack',
title: 'Full-Stack JavaScript',
description: 'Frontend & Backend Development',
icon: 'fab fa-js-square',
progress: 68,
isActive: true
},
{
id: 'data-science',
title: 'Data Science Fundamentals',
description: 'Python, Statistics & ML',
icon: 'fas fa-chart-bar',
progress: 34,
isActive: false
}
];
const pathsContainer = document.querySelector('.paths-grid');
if (pathsContainer) {
// Clear existing paths (except the "new path" card)
const existingPaths = pathsContainer.querySelectorAll('.path-card:not(.new)');
existingPaths.forEach(path => path.remove());
// Add paths
paths.forEach(path => {
const pathElement = this.createPathCard(path);
pathsContainer.insertBefore(pathElement, pathsContainer.querySelector('.path-card.new'));
});
}
}
createPathCard(path) {
const card = document.createElement('div');
card.className = `path-card ${path.isActive ? 'active' : ''}`;
card.innerHTML = `
<div class="path-header">
<div class="path-icon">
<i class="${path.icon}"></i>
</div>
<div class="path-info">
<h3>${path.title}</h3>
<p>${path.description}</p>
</div>
<div class="path-progress">
<span>${path.progress}%</span>
</div>
</div>
<div class="progress-bar">
<div class="progress-fill" style="width: ${path.progress}%"></div>
</div>
<div class="path-actions">
<button class="btn btn-primary btn-sm" onclick="continuePath('${path.id}')">Continue</button>
<button class="btn btn-outline btn-sm" onclick="viewPathDetails('${path.id}')">View Details</button>
</div>
`;
return card;
}
updateActivity() {
const activities = [
{
icon: 'fas fa-check-circle',
title: 'Completed: React Hooks Module',
subtitle: 'Full-Stack JavaScript Path',
time: '2 hours ago',
type: 'completion'
},
{
icon: 'fas fa-trophy',
title: 'Achievement Unlocked: Quick Learner',
subtitle: 'Completed 5 modules in one day',
time: '1 day ago',
type: 'achievement'
},
{
icon: 'fas fa-star',
title: 'Quiz Score: 95%',
subtitle: 'JavaScript Fundamentals Quiz',
time: '2 days ago',
type: 'quiz'
}
];
const activityList = document.querySelector('.activity-list');
if (activityList) {
activityList.innerHTML = activities.map(activity => `
<div class="activity-item">
<div class="activity-icon">
<i class="${activity.icon}"></i>
</div>
<div class="activity-content">
<h4>${activity.title}</h4>
<p>${activity.subtitle}</p>
<span class="activity-time">${activity.time}</span>
</div>
</div>
`).join('');
}
}
updateAchievements() {
const achievements = [
{ id: 'week-streak', icon: 'fas fa-fire', name: 'Week Streak', earned: true },
{ id: 'first-module', icon: 'fas fa-graduation-cap', name: 'First Module', earned: true },
{ id: 'quick-start', icon: 'fas fa-rocket', name: 'Quick Start', earned: true },
{ id: 'path-master', icon: 'fas fa-crown', name: 'Path Master', earned: false },
{ id: 'top-scorer', icon: 'fas fa-medal', name: 'Top Scorer', earned: false },
{ id: 'community-helper', icon: 'fas fa-users', name: 'Community Helper', earned: false }
];
const achievementsGrid = document.querySelector('.achievements-grid');
if (achievementsGrid) {
achievementsGrid.innerHTML = achievements.map(achievement => `
<div class="achievement-badge ${achievement.earned ? 'earned' : ''}">
<i class="${achievement.icon}"></i>
<span>${achievement.name}</span>
</div>
`).join('');
}
}
updateRecommendations() {
const recommendations = [
{
icon: 'fab fa-react',
title: 'Advanced React Patterns',
description: 'Take your React skills to the next level',
duration: '8 hours',
rating: '4.9'
},
{
icon: 'fas fa-database',
title: 'Database Design',
description: 'Master SQL and database optimization',
duration: '12 hours',
rating: '4.8'
},
{
icon: 'fas fa-mobile-alt',
title: 'Mobile Development',
description: 'Build cross-platform mobile apps',
duration: '15 hours',
rating: '4.7'
}
];
const recsGrid = document.querySelector('.recommendations-grid');
if (recsGrid) {
recsGrid.innerHTML = recommendations.map(rec => `
<div class="recommendation-card">
<div class="rec-icon">
<i class="${rec.icon}"></i>
</div>
<h3>${rec.title}</h3>
<p>${rec.description}</p>
<div class="rec-meta">
<span><i class="fas fa-clock"></i> ${rec.duration}</span>
<span><i class="fas fa-star"></i> ${rec.rating}</span>
</div>
<button class="btn btn-outline btn-sm">Explore</button>
</div>
`).join('');
}
}
bindEvents() {
// Add event listeners for interactive elements
document.addEventListener('click', (e) => {
if (e.target.matches('.btn')) {
this.handleButtonClick(e);
}
});
// Track user activity
this.trackActivity();
}
handleButtonClick(e) {
const button = e.target;
const action = button.textContent.toLowerCase();
// Add click animation
button.style.transform = 'scale(0.95)';
setTimeout(() => {
button.style.transform = 'scale(1)';
}, 150);
// Handle specific actions
if (action.includes('continue')) {
this.addXP(10);
this.trackDailyActivity();
}
}
trackActivity() {
// Track page views and time spent
const startTime = Date.now();
window.addEventListener('beforeunload', () => {
const timeSpent = Math.floor((Date.now() - startTime) / 60000); // minutes
this.userData.totalTime += timeSpent;
this.saveUserData();
});
}
trackDailyActivity() {
const today = new Date().toDateString();
if (!this.progressData.dailyActivity.includes(today)) {
this.progressData.dailyActivity.push(today);
this.saveProgressData();
this.updateStats();
}
}
addXP(amount) {
this.userData.xp += amount;
// Check for level up
const newLevel = Math.floor(this.userData.xp / 100) + 1;
if (newLevel > this.userData.level) {
this.userData.level = newLevel;
this.showLevelUpNotification(newLevel);
}
this.saveUserData();
}
showLevelUpNotification(level) {
// Create and show level up notification
const notification = document.createElement('div');
notification.className = 'level-up-notification';
notification.innerHTML = `
<div class="notification-content">
<i class="fas fa-star"></i>
<h3>Level Up!</h3>
<p>You've reached level ${level}!</p>
</div>
`;
document.body.appendChild(notification);
setTimeout(() => {
notification.classList.add('show');
}, 100);
setTimeout(() => {
notification.classList.remove('show');
setTimeout(() => {
document.body.removeChild(notification);
}, 300);
}, 3000);
}
startProgressTracking() {
// Update progress every minute
setInterval(() => {
this.trackDailyActivity();
}, 60000);
}
}
// Global functions for button actions
function continuePath(pathId) {
// Navigate to learning path
window.location.href = `learning-paths.html?path=${pathId}`;
}
function viewPathDetails(pathId) {
// Show path details modal or navigate to details page
alert(`Viewing details for path: ${pathId}`);
}
// Initialize dashboard when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
new DashboardManager();
});