Spaces:
Running
Running
Download script.js from Deepak3635/taskflow-nexus: direct link, hf CLI and curl.
- Browser
- Download file 34.4 kB
-
https://huggingface.co/spaces/Deepak3635/taskflow-nexus/resolve/main/script.js
- Command line
-
hf download hf://spaces/Deepak3635/taskflow-nexus/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Deepak3635/taskflow-nexus/resolve/main/script.js
34.4 kB
| // 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(); | |
| }); |