Spaces:
Running
Running
File size: 34,441 Bytes
07992ae 9631523 07992ae 9631523 07992ae 9631523 07992ae 16e5118 07992ae 16e5118 07992ae | 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 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 | // TaskFlow Nexus - Main Application Script
// ==================== DATA STORE ====================
const DataStore = {
// Current user session
currentUser: null,
// Users data (in production, this would be server-side)
users: [
{ id: 'admin', password: 'admin123', name: 'System Administrator', role: 'admin', email: 'admin@taskflow.com' },
{ id: 'member1', password: 'pass123', name: 'Alex Chen', role: 'member', email: 'alex@taskflow.com' },
{ id: 'member2', password: 'pass123', name: 'Sarah Johnson', role: 'member', email: 'sarah@taskflow.com' },
{ id: 'member3', password: 'pass123', name: 'Mike Ross', role: 'member', email: 'mike@taskflow.com' },
{ id: 'member4', password: 'pass123', name: 'Emily Davis', role: 'member', email: 'emily@taskflow.com' },
{ id: 'member5', password: 'pass123', name: 'James Wilson', role: 'member', email: 'james@taskflow.com' },
{ id: 'member6', password: 'pass123', name: 'Lisa Anderson', role: 'member', email: 'lisa@taskflow.com' },
{ id: 'member7', password: 'pass123', name: 'David Brown', role: 'member', email: 'david@taskflow.com' },
{ id: 'member8', password: 'pass123', name: 'Anna Martinez', role: 'member', email: 'anna@taskflow.com' },
{ id: 'member9', password: 'pass123', name: 'Chris Taylor', role: 'member', email: 'chris@taskflow.com' },
],
// Tasks data
tasks: [
{
id: 'task-001',
title: 'Design System Architecture',
description: 'Create comprehensive design system including color palette, typography, and component library for the new product line.',
priority: 'high',
status: 'in-progress',
startDate: '2024-01-15',
dueDate: '2024-01-25',
assignee: 'member1',
progress: 65,
createdBy: 'admin',
createdAt: '2024-01-10'
},
{
id: 'task-002',
title: 'API Integration',
description: 'Integrate third-party payment gateway APIs and ensure secure transaction processing.',
priority: 'high',
status: 'pending',
startDate: '2024-01-20',
dueDate: '2024-01-30',
assignee: 'member2',
progress: 0,
createdBy: 'admin',
createdAt: '2024-01-12'
},
{
id: 'task-003',
title: 'User Testing Sessions',
description: 'Conduct usability testing with 20 participants and compile feedback report.',
priority: 'medium',
status: 'completed',
startDate: '2024-01-05',
dueDate: '2024-01-18',
assignee: 'member3',
progress: 100,
createdBy: 'admin',
createdAt: '2024-01-03'
},
{
id: 'task-004',
title: 'Database Optimization',
description: 'Optimize database queries and implement caching strategy for improved performance.',
priority: 'high',
status: 'in-progress',
startDate: '2024-01-16',
dueDate: '2024-01-28',
assignee: 'member4',
progress: 45,
createdBy: 'admin',
createdAt: '2024-01-14'
},
{
id: 'task-005',
title: 'Documentation Update',
description: 'Update API documentation and user guides for the latest release.',
priority: 'low',
status: 'pending',
startDate: '2024-01-22',
dueDate: '2024-02-05',
assignee: 'member5',
progress: 0,
createdBy: 'admin',
createdAt: '2024-01-15'
},
{
id: 'task-006',
title: 'Security Audit',
description: 'Perform comprehensive security audit and vulnerability assessment.',
priority: 'high',
status: 'overdue',
startDate: '2024-01-08',
dueDate: '2024-01-15',
assignee: 'member6',
progress: 30,
createdBy: 'admin',
createdAt: '2024-01-05'
},
{
id: 'task-007',
title: 'Mobile App Testing',
description: 'Test mobile application on iOS and Android devices, report bugs.',
priority: 'medium',
status: 'in-progress',
startDate: '2024-01-17',
dueDate: '2024-01-26',
assignee: 'member7',
progress: 55,
createdBy: 'admin',
createdAt: '2024-01-16'
},
{
id: 'task-008',
title: 'Marketing Campaign',
description: 'Plan and execute Q1 marketing campaign across social media channels.',
priority: 'medium',
status: 'pending',
startDate: '2024-01-25',
dueDate: '2024-02-10',
assignee: 'member8',
progress: 0,
createdBy: 'admin',
createdAt: '2024-01-18'
},
{
id: 'task-009',
title: 'Customer Support Training',
description: 'Develop training materials and conduct sessions for new support team members.',
priority: 'low',
status: 'completed',
startDate: '2024-01-10',
dueDate: '2024-01-20',
assignee: 'member9',
progress: 100,
createdBy: 'admin',
createdAt: '2024-01-08'
},
{
id: 'task-010',
title: 'Analytics Dashboard',
description: 'Build real-time analytics dashboard for monitoring key business metrics.',
priority: 'high',
status: 'in-progress',
startDate: '2024-01-12',
dueDate: '2024-01-29',
assignee: 'member1',
progress: 75,
createdBy: 'admin',
createdAt: '2024-01-10'
}
],
// App settings
settings: {
dailyAlertTime: '09:00',
alertEnabled: true
},
// Initialize from localStorage if available
init() {
const savedUser = localStorage.getItem('taskflow_currentUser');
const savedTasks = localStorage.getItem('taskflow_tasks');
const savedSettings = localStorage.getItem('taskflow_settings');
if (savedUser) {
this.currentUser = JSON.parse(savedUser);
}
if (savedTasks) {
this.tasks = JSON.parse(savedTasks);
}
if (savedSettings) {
this.settings = JSON.parse(savedSettings);
}
this.updateOverdueStatus();
},
// Save to localStorage
save() {
localStorage.setItem('taskflow_tasks', JSON.stringify(this.tasks));
localStorage.setItem('taskflow_settings', JSON.stringify(this.settings));
},
// Update overdue status
updateOverdueStatus() {
const today = new Date().toISOString().split('T')[0];
this.tasks.forEach(task => {
if (task.dueDate < today && task.status !== 'completed') {
task.status = 'overdue';
}
});
this.save();
},
// Get user by ID
getUser(id) {
return this.users.find(u => u.id === id);
},
// Get user name
getUserName(id) {
const user = this.getUser(id);
return user ? user.name : id;
},
// Add user (admin only)
addUser(userData) {
this.users.push(userData);
},
// Update user password
updatePassword(userId, newPassword) {
const user = this.users.find(u => u.id === userId);
if (user) {
user.password = newPassword;
return true;
}
return false;
},
// Delete user
deleteUser(userId) {
this.users = this.users.filter(u => u.id !== userId);
},
// Add task
addTask(task) {
this.tasks.push(task);
this.save();
},
// Update task
updateTask(taskId, updates) {
const index = this.tasks.findIndex(t => t.id === taskId);
if (index !== -1) {
this.tasks[index] = { ...this.tasks[index], ...updates };
this.save();
return true;
}
return false;
},
// Delete task
deleteTask(taskId) {
this.tasks = this.tasks.filter(t => t.id !== taskId);
this.save();
},
// Login
login(userId, password) {
const user = this.users.find(u => u.id === userId && u.password === password);
if (user) {
this.currentUser = { ...user, password: undefined };
localStorage.setItem('taskflow_currentUser', JSON.stringify(this.currentUser));
return this.currentUser;
}
return null;
},
// Logout
logout() {
this.currentUser = null;
localStorage.removeItem('taskflow_currentUser');
},
// Check if logged in
isLoggedIn() {
return this.currentUser !== null;
},
// Check if admin
isAdmin() {
return this.currentUser && this.currentUser.role === 'admin';
}
};
// ==================== UI COMPONENTS ====================
const UI = {
// Initialize
init() {
DataStore.init();
this.bindEvents();
this.renderTasks();
this.updateStats();
this.populateAssigneeFilter();
this.checkDailyAlert();
// Check for daily alert every minute
setInterval(() => this.checkDailyAlert(), 60000);
},
// Bind events
bindEvents() {
// Login modal
document.getElementById('loginPromptBtn').addEventListener('click', () => this.showLoginModal());
// Listen for navbar login event
window.addEventListener('showLoginModal', () => this.showLoginModal());
document.getElementById('closeLoginModal').addEventListener('click', () => this.hideLoginModal());
document.getElementById('loginModalOverlay').addEventListener('click', () => this.hideLoginModal());
document.getElementById('loginForm').addEventListener('submit', (e) => this.handleLogin(e));
// Task detail modal
document.getElementById('closeTaskDetail').addEventListener('click', () => this.hideTaskDetail());
document.getElementById('taskDetailOverlay').addEventListener('click', () => this.hideTaskDetail());
// Filters
document.getElementById('searchInput').addEventListener('input', () => this.renderTasks());
document.getElementById('statusFilter').addEventListener('change', () => this.renderTasks());
document.getElementById('priorityFilter').addEventListener('change', () => this.renderTasks());
document.getElementById('assigneeFilter').addEventListener('change', () => this.renderTasks());
document.getElementById('resetFilters').addEventListener('click', () => this.resetFilters());
// View toggle
document.getElementById('gridView').addEventListener('click', () => this.setViewMode('grid'));
document.getElementById('listView').addEventListener('click', () => this.setViewMode('list'));
// Daily alert
document.getElementById('dismissAlert').addEventListener('click', () => this.hideDailyAlert());
document.getElementById('viewTasksFromAlert').addEventListener('click', () => {
this.hideDailyAlert();
document.getElementById('tasksSection').scrollIntoView({ behavior: 'smooth' });
});
// View tasks button
document.getElementById('viewTasksBtn').addEventListener('click', () => {
document.getElementById('tasksSection').scrollIntoView({ behavior: 'smooth' });
});
},
// Show login modal
showLoginModal() {
document.getElementById('loginModal').classList.remove('hidden');
document.getElementById('loginUserId').focus();
},
// Hide login modal
hideLoginModal() {
document.getElementById('loginModal').classList.add('hidden');
document.getElementById('loginForm').reset();
document.getElementById('loginError').classList.add('hidden');
},
// Handle login
handleLogin(e) {
e.preventDefault();
const userId = document.getElementById('loginUserId').value;
const password = document.getElementById('loginPassword').value;
const user = DataStore.login(userId, password);
if (user) {
this.hideLoginModal();
this.showToast(`Welcome back, ${user.name}!`, 'success');
this.updateUIForUser();
window.dispatchEvent(new CustomEvent('userLoggedIn', { detail: user }));
} else {
document.getElementById('loginError').classList.remove('hidden');
}
},
// Update UI for logged in user
updateUIForUser() {
// UI updates are now handled by the nav-bar component
// This method is kept for compatibility with existing code
feather.replace();
},
// Logout
logout() {
DataStore.logout();
this.showToast('Logged out successfully', 'info');
this.updateUIForUser();
window.dispatchEvent(new CustomEvent('userLoggedOut'));
},
// Show task detail
showTaskDetail(taskId) {
const task = DataStore.tasks.find(t => t.id === taskId);
if (!task) return;
const modal = document.getElementById('taskDetailModal');
// Set content
document.getElementById('taskDetailTitle').textContent = task.title;
document.getElementById('taskDetailDescription').textContent = task.description;
// Priority badge
const priorityEl = document.getElementById('taskDetailPriority');
priorityEl.textContent = task.priority;
priorityEl.className = `px-2.5 py-1 rounded-full text-xs font-semibold uppercase tracking-wide priority-${task.priority}`;
// Status badge
const statusEl = document.getElementById('taskDetailStatus');
statusEl.textContent = task.status.replace('-', ' ');
statusEl.className = `px-2.5 py-1 rounded-full text-xs font-semibold uppercase tracking-wide status-${task.status}`;
// Dates
document.getElementById('taskDetailStartDate').innerHTML = `
<i data-feather="calendar" class="w-4 h-4 text-primary-400"></i>
${this.formatDate(task.startDate)}
`;
document.getElementById('taskDetailDueDate').innerHTML = `
<i data-feather="clock" class="w-4 h-4 text-secondary-400"></i>
${this.formatDate(task.dueDate)}
`;
// Assignee
document.getElementById('taskDetailAssignee').innerHTML = `
<i data-feather="user" class="w-4 h-4 text-primary-400"></i>
${DataStore.getUserName(task.assignee)}
`;
// Progress
document.getElementById('taskDetailProgressBar').style.width = `${task.progress}%`;
document.getElementById('taskDetailProgressText').textContent = `${task.progress}%`;
// Actions based on role
const actionsEl = document.getElementById('taskDetailActions');
if (DataStore.isLoggedIn()) {
if (DataStore.isAdmin()) {
actionsEl.innerHTML = `
<div class="flex gap-3">
<button onclick="UI.editTask('${task.id}')" class="flex-1 py-2.5 bg-primary-600 hover:bg-primary-500 text-white rounded-lg font-medium transition-colors flex items-center justify-center gap-2">
<i data-feather="edit-2" class="w-4 h-4"></i>
Edit Task
</button>
<button onclick="UI.deleteTask('${task.id}')" class="px-4 py-2.5 bg-red-600/20 hover:bg-red-600/30 text-red-400 rounded-lg font-medium transition-colors">
<i data-feather="trash-2" class="w-4 h-4"></i>
</button>
</div>
`;
} else if (DataStore.currentUser.id === task.assignee) {
actionsEl.innerHTML = `
<div class="space-y-3">
<div>
<label class="text-sm text-dark-400 mb-2 block">Update Progress</label>
<input type="range" min="0" max="100" value="${task.progress}"
onchange="UI.updateTaskProgress('${task.id}', this.value)"
class="w-full h-2 bg-dark-600 rounded-lg appearance-none cursor-pointer">
</div>
<div class="flex gap-3">
<select onchange="UI.updateTaskStatus('${task.id}', this.value)"
class="flex-1 px-4 py-2 bg-dark-700 border border-dark-600 rounded-lg text-dark-100">
<option value="pending" ${task.status === 'pending' ? 'selected' : ''}>Pending</option>
<option value="in-progress" ${task.status === 'in-progress' ? 'selected' : ''}>In Progress</option>
<option value="completed" ${task.status === 'completed' ? 'selected' : ''}>Completed</option>
</select>
</div>
</div>
`;
} else {
actionsEl.innerHTML = `
<p class="text-center text-dark-400 text-sm">
<i data-feather="lock" class="w-4 h-4 inline mr-1"></i>
You don't have permission to modify this task
</p>
`;
}
} else {
actionsEl.innerHTML = `
<div class="text-center">
<p class="text-dark-400 text-sm mb-3">Sign in to manage this task</p>
<button onclick="UI.showLoginModal(); UI.hideTaskDetail();"
class="px-6 py-2 bg-primary-600 hover:bg-primary-500 text-white rounded-lg font-medium transition-colors">
Sign In
</button>
</div>
`;
}
modal.classList.remove('hidden');
feather.replace();
},
// Hide task detail
hideTaskDetail() {
document.getElementById('taskDetailModal').classList.add('hidden');
},
// Edit task (admin)
editTask(taskId) {
// This would open an edit modal in full implementation
this.showToast('Edit functionality would open here', 'info');
},
// Delete task (admin)
deleteTask(taskId) {
if (!DataStore.isAdmin()) {
this.showToast('Only administrators can delete tasks', 'error');
return;
}
if (confirm('Are you sure you want to delete this task? This action cannot be undone.')) {
DataStore.deleteTask(taskId);
this.hideTaskDetail();
this.renderTasks();
this.updateStats();
this.showToast('Task deleted successfully', 'success');
}
},
// Update task progress (member)
updateTaskProgress(taskId, progress) {
DataStore.updateTask(taskId, { progress: parseInt(progress) });
document.getElementById('taskDetailProgressBar').style.width = `${progress}%`;
document.getElementById('taskDetailProgressText').textContent = `${progress}%`;
this.renderTasks();
this.updateStats();
this.showToast('Progress updated', 'success');
},
// Update task status (member)
updateTaskStatus(taskId, status) {
DataStore.updateTask(taskId, { status });
this.showTaskDetail(taskId); // Refresh modal
this.renderTasks();
this.updateStats();
this.showToast('Status updated', 'success');
},
// Render tasks
renderTasks() {
const grid = document.getElementById('tasksGrid');
const emptyState = document.getElementById('emptyState');
const viewMode = grid.classList.contains('grid') ? 'grid' : 'list';
// Get filter values
const search = document.getElementById('searchInput').value.toLowerCase();
const statusFilter = document.getElementById('statusFilter').value;
const priorityFilter = document.getElementById('priorityFilter').value;
const assigneeFilter = document.getElementById('assigneeFilter').value;
// Filter tasks
let filtered = DataStore.tasks.filter(task => {
const matchesSearch = task.title.toLowerCase().includes(search) ||
task.description.toLowerCase().includes(search) ||
DataStore.getUserName(task.assignee).toLowerCase().includes(search);
const matchesStatus = !statusFilter || task.status === statusFilter;
const matchesPriority = !priorityFilter || task.priority === priorityFilter;
const matchesAssignee = !assigneeFilter || task.assignee === assigneeFilter;
return matchesSearch && matchesStatus && matchesPriority && matchesAssignee;
});
// Update showing text
document.getElementById('tasksShowing').textContent =
filtered.length === DataStore.tasks.length
? 'Showing all tasks'
: `Showing ${filtered.length} of ${DataStore.tasks.length} tasks`;
// Clear grid
grid.innerHTML = '';
if (filtered.length === 0) {
emptyState.classList.remove('hidden');
return;
}
emptyState.classList.add('hidden');
// Render task cards
filtered.forEach(task => {
const card = this.createTaskCard(task, viewMode);
grid.appendChild(card);
});
feather.replace();
},
// Create task card element
createTaskCard(task, viewMode) {
const div = document.createElement('div');
const isList = viewMode === 'list';
div.className = `task-card bg-dark-900 rounded-xl border border-dark-700/50 overflow-hidden cursor-pointer ${isList ? 'flex items-center p-4 gap-4' : ''}`;
div.onclick = () => this.showTaskDetail(task.id);
const assignee = DataStore.getUser(task.assignee);
const assigneeInitials = assignee ? assignee.name.split(' ').map(n => n[0]).join('') : '?';
if (isList) {
div.innerHTML = `
<div class="flex items-center gap-3 flex-1">
<div class="w-10 h-10 rounded-lg bg-primary-500/20 flex items-center justify-center flex-shrink-0">
<span class="text-primary-400 font-bold text-sm">${assigneeInitials}</span>
</div>
<div class="min-w-0">
<h3 class="font-semibold text-dark-100 truncate">${task.title}</h3>
<p class="text-sm text-dark-400 truncate">${DataStore.getUserName(task.assignee)}</p>
</div>
</div>
<div class="flex items-center gap-3">
<span class="px-2.5 py-1 rounded-full text-xs font-semibold uppercase tracking-wide priority-${task.priority}">${task.priority}</span>
<span class="px-2.5 py-1 rounded-full text-xs font-semibold uppercase tracking-wide status-${task.status}">${task.status.replace('-', ' ')}</span>
<div class="w-24">
<div class="h-1.5 bg-dark-700 rounded-full overflow-hidden">
<div class="h-full bg-primary-500 rounded-full progress-animate" style="width: ${task.progress}%"></div>
</div>
</div>
</div>
`;
} else {
div.innerHTML = `
<div class="p-5">
<div class="flex items-start justify-between mb-3">
<div class="flex gap-2">
<span class="px-2.5 py-1 rounded-full text-xs font-semibold uppercase tracking-wide priority-${task.priority}">${task.priority}</span>
<span class="px-2.5 py-1 rounded-full text-xs font-semibold uppercase tracking-wide status-${task.status}">${task.status.replace('-', ' ')}</span>
</div>
<div class="w-8 h-8 rounded-full bg-primary-500/20 flex items-center justify-center flex-shrink-0" title="${DataStore.getUserName(task.assignee)}">
<span class="text-primary-400 font-bold text-xs">${assigneeInitials}</span>
</div>
</div>
<h3 class="font-semibold text-dark-100 mb-2 line-clamp-2">${task.title}</h3>
<p class="text-sm text-dark-400 mb-4 line-clamp-2">${task.description}</p>
<div class="flex items-center justify-between text-xs text-dark-400 mb-3">
<span class="flex items-center gap-1">
<i data-feather="clock" class="w-3 h-3"></i>
${this.formatDate(task.dueDate)}
</span>
<span>${task.progress}%</span>
</div>
<div class="h-2 bg-dark-700 rounded-full overflow-hidden">
<div class="h-full bg-gradient-to-r from-primary-500 to-secondary-500 rounded-full progress-animate" style="width: ${task.progress}%"></div>
</div>
</div>
`;
}
return div;
},
// Set view mode
setViewMode(mode) {
const grid = document.getElementById('tasksGrid');
const gridBtn = document.getElementById('gridView');
const listBtn = document.getElementById('listView');
if (mode === 'grid') {
grid.className = 'grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4';
gridBtn.classList.add('bg-dark-700', 'text-primary-400');
gridBtn.classList.remove('text-dark-400');
listBtn.classList.remove('bg-dark-700', 'text-primary-400');
listBtn.classList.add('text-dark-400');
} else {
grid.className = 'space-y-3';
listBtn.classList.add('bg-dark-700', 'text-primary-400');
listBtn.classList.remove('text-dark-400');
gridBtn.classList.remove('bg-dark-700', 'text-primary-400');
gridBtn.classList.add('text-dark-400');
}
this.renderTasks();
},
// Update statistics
updateStats() {
const today = new Date().toISOString().split('T')[0];
const total = DataStore.tasks.length;
const pending = DataStore.tasks.filter(t => t.status === 'pending').length;
const inProgress = DataStore.tasks.filter(t => t.status === 'in-progress').length;
const completed = DataStore.tasks.filter(t => t.status === 'completed').length;
document.getElementById('totalTasksCount').textContent = total;
document.getElementById('pendingTasksCount').textContent = pending;
document.getElementById('inProgressCount').textContent = inProgress;
document.getElementById('completedCount').textContent = completed;
},
// Populate assignee filter
populateAssigneeFilter() {
const select = document.getElementById('assigneeFilter');
const members = DataStore.users.filter(u => u.role === 'member');
members.forEach(member => {
const option = document.createElement('option');
option.value = member.id;
option.textContent = member.name;
select.appendChild(option);
});
},
// Reset filters
resetFilters() {
document.getElementById('searchInput').value = '';
document.getElementById('statusFilter').value = '';
document.getElementById('priorityFilter').value = '';
document.getElementById('assigneeFilter').value = '';
this.renderTasks();
},
// Check daily alert
checkDailyAlert() {
if (!DataStore.settings.alertEnabled) return;
const now = new Date();
const currentTime = now.toTimeString().slice(0, 5);
// Check if it's time for alert and we haven't shown it today
const lastAlert = localStorage.getItem('taskflow_lastAlert');
const today = now.toISOString().split('T')[0];
if (currentTime === DataStore.settings.dailyAlertTime && lastAlert !== today) {
this.showDailyAlert();
localStorage.setItem('taskflow_lastAlert', today);
}
},
// Show daily alert
showDailyAlert() {
const today = new Date().toISOString().split('T')[0];
const overdue = DataStore.tasks.filter(t => t.status === 'overdue');
const dueToday = DataStore.tasks.filter(t => t.dueDate === today && t.status !== 'completed');
const pending = DataStore.tasks.filter(t => t.status === 'pending');
// Set date/time
document.getElementById('alertDateTime').textContent = new Date().toLocaleString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
// Overdue
const overdueSection = document.getElementById('alertOverdue');
if (overdue.length > 0) {
overdueSection.classList.remove('hidden');
document.getElementById('overdueCount').textContent = overdue.length;
document.getElementById('overdueList').innerHTML = overdue.map(t =>
`<li class="text-dark-300 text-sm">• ${t.title}</li>`
).join('');
} else {
overdueSection.classList.add('hidden');
}
// Due today
const dueTodaySection = document.getElementById('alertDueToday');
if (dueToday.length > 0) {
dueTodaySection.classList.remove('hidden');
document.getElementById('dueTodayCount').textContent = dueToday.length;
document.getElementById('dueTodayList').innerHTML = dueToday.map(t =>
`<li class="text-dark-300 text-sm">• ${t.title}</li>`
).join('');
} else {
dueTodaySection.classList.add('hidden');
}
// Pending
const pendingSection = document.getElementById('alertPending');
if (pending.length > 0) {
pendingSection.classList.remove('hidden');
document.getElementById('pendingCount').textContent = pending.length;
document.getElementById('pendingList').innerHTML = pending.slice(0, 5).map(t =>
`<li class="text-dark-300 text-sm">• ${t.title}</li>`
).join('');
if (pending.length > 5) {
document.getElementById('pendingList').innerHTML +=
`<li class="text-dark-400 text-sm italic">...and ${pending.length - 5} more</li>`;
}
} else {
pendingSection.classList.add('hidden');
}
// No tasks
const noTasksSection = document.getElementById('alertNoTasks');
if (overdue.length === 0 && dueToday.length === 0 && pending.length === 0) {
noTasksSection.classList.remove('hidden');
} else {
noTasksSection.classList.add('hidden');
}
document.getElementById('dailyAlertModal').classList.remove('hidden');
},
// Hide daily alert
hideDailyAlert() {
document.getElementById('dailyAlertModal').classList.add('hidden');
},
// Show toast notification
showToast(message, type = 'info') {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
const colors = {
success: 'bg-green-500/20 border-green-500/30 text-green-400',
error: 'bg-red-500/20 border-red-500/30 text-red-400',
info: 'bg-primary-500/20 border-primary-500/30 text-primary-400',
warning: 'bg-yellow-500/20 border-yellow-500/30 text-yellow-400'
};
const icons = {
success: 'check-circle',
error: 'x-circle',
info: 'info',
warning: 'alert-triangle'
};
toast.className = `toast-enter flex items-center gap-3 px-4 py-3 rounded-lg border ${colors[type]} shadow-lg backdrop-blur`;
toast.innerHTML = `
<i data-feather="${icons[type]}" class="w-5 h-5"></i>
<span class="font-medium">${message}</span>
`;
container.appendChild(toast);
feather.replace();
setTimeout(() => {
toast.classList.remove('toast-enter');
toast.classList.add('toast-exit');
setTimeout(() => toast.remove(), 300);
}, 4000);
},
// Format date
formatDate(dateString) {
const date = new Date(dateString);
const today = new Date();
const diffTime = date - today;
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
let relative = '';
if (diffDays === 0) relative = ' (Today)';
else if (diffDays === 1) relative = ' (Tomorrow)';
else if (diffDays === -1) relative = ' (Yesterday)';
else if (diffDays < 0) relative = ` (${Math.abs(diffDays)} days ago)`;
else if (diffDays <= 7) relative = ` (in ${diffDays} days)`;
return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }) + relative;
}
};
// ==================== INITIALIZATION ====================
document.addEventListener('DOMContentLoaded', () => {
UI.init();
}); |