Spaces:
Running
Running
Download script.js from batteryfix/taskmaster-pro: direct link, hf CLI and curl.
- Browser
- Download file 12.4 kB
-
https://huggingface.co/spaces/batteryfix/taskmaster-pro/resolve/main/script.js
- Command line
-
hf download hf://spaces/batteryfix/taskmaster-pro/script.js
-
curl -L -o script.js https://huggingface.co/spaces/batteryfix/taskmaster-pro/resolve/main/script.js
12.4 kB
| class TaskManager { | |
| constructor() { | |
| this.tasks = JSON.parse(localStorage.getItem('tasks')) || []; | |
| this.currentFilter = 'all'; | |
| this.init(); | |
| } | |
| init() { | |
| this.bindEvents(); | |
| this.renderTasks(); | |
| this.updateSummary(); | |
| } | |
| bindEvents() { | |
| // Modal controls | |
| document.getElementById('addTaskBtn').addEventListener('click', () => this.openModal()); | |
| document.getElementById('closeModalBtn').addEventListener('click', () => this.closeModal()); | |
| document.getElementById('cancelModalBtn').addEventListener('click', () => this.closeModal()); | |
| document.getElementById('taskForm').addEventListener('submit', (e) => { | |
| e.preventDefault(); | |
| this.saveTask(); | |
| }); | |
| // Filter controls | |
| document.getElementById('filterAll').addEventListener('click', () => this.filterTasks('all')); | |
| document.getElementById('filterPending').addEventListener('click', () => this.filterTasks('pending')); | |
| document.getElementById('filterCompleted').addEventListener('click', () => this.filterTasks('completed')); | |
| // Search functionality | |
| document.getElementById('searchTasks').addEventListener('input', (e) => { | |
| this.searchTasks(e.target.value); | |
| }); | |
| } | |
| openModal(task = null) { | |
| const modal = document.getElementById('taskModal'); | |
| const form = document.getElementById('taskForm'); | |
| if (task) { | |
| document.getElementById('modalTitle').textContent = 'Edit Task'; | |
| document.getElementById('taskId').value = task.id; | |
| document.getElementById('taskTitle').value = task.title; | |
| document.getElementById('taskDescription').value = task.description; | |
| document.getElementById('taskPriority').value = task.priority; | |
| document.getElementById('taskDueDate').value = task.dueDate; | |
| } else { | |
| document.getElementById('modalTitle').textContent = 'Add New Task'; | |
| form.reset(); | |
| } | |
| modal.classList.remove('hidden'); | |
| document.body.style.overflow = 'hidden'; | |
| feather.replace(); | |
| } | |
| closeModal() { | |
| document.getElementById('taskModal').classList.add('hidden'); | |
| document.body.style.overflow = 'auto'; | |
| document.getElementById('taskForm').reset(); | |
| } | |
| saveTask() { | |
| const form = document.getElementById('taskForm'); | |
| const taskId = document.getElementById('taskId').value; | |
| const title = document.getElementById('taskTitle').value.trim(); | |
| const description = document.getElementById('taskDescription').value.trim(); | |
| const priority = document.getElementById('taskPriority').value; | |
| const dueDate = document.getElementById('taskDueDate').value; | |
| const taskData = { | |
| id: taskId || Date.now().toString(), | |
| title, | |
| description, | |
| priority, | |
| dueDate, | |
| status: 'pending', | |
| createdAt: new Date().toISOString(), | |
| comments: [] | |
| }; | |
| if (taskId) { | |
| // Update existing task | |
| const index = this.tasks.findIndex(t => t.id === taskId); | |
| if (index !== -1) { | |
| this.tasks[index] = taskData; | |
| } | |
| } else { | |
| // Add new task | |
| this.tasks.unshift(taskData); | |
| } | |
| this.saveToLocalStorage(); | |
| this.closeModal(); | |
| this.renderTasks(); | |
| this.updateSummary(); | |
| } | |
| deleteTask(taskId) { | |
| if (confirm('Are you sure you want to delete this task?')) { | |
| this.tasks = this.tasks.filter(task => task.id !== taskId); | |
| this.saveToLocalStorage(); | |
| this.renderTasks(); | |
| this.updateSummary(); | |
| } | |
| } | |
| addComment(taskId, comment) { | |
| const task = this.tasks.find(t => t.id === taskId); | |
| if (task) { | |
| if (!task.comments) task.comments = []; | |
| task.comments.push(comment); | |
| this.saveToLocalStorage(); | |
| this.renderTasks(); | |
| return true; | |
| } | |
| return false; | |
| } | |
| updateTaskStatus(taskId, newStatus) { | |
| const task = this.tasks.find(t => t.id === taskId); | |
| if (task) { | |
| task.status = newStatus; | |
| this.saveToLocalStorage(); | |
| this.renderTasks(); | |
| this.updateSummary(); | |
| } | |
| } | |
| filterTasks(filter) { | |
| this.currentFilter = filter; | |
| document.querySelectorAll('.filter-btn').forEach(btn => { | |
| btn.classList.remove('active'); | |
| if (btn.textContent.toLowerCase().includes(filter)) { | |
| btn.classList.add('active'); | |
| } | |
| }); | |
| this.renderTasks(); | |
| } | |
| searchTasks(query) { | |
| this.renderTasks(query.toLowerCase()); | |
| } | |
| renderTasks(searchQuery = '') { | |
| const container = document.getElementById('tasksContainer'); | |
| // Filter tasks based on current filter and search query | |
| let filteredTasks = this.tasks; | |
| if (this.currentFilter !== 'all') { | |
| filteredTasks = filteredTasks.filter(task => task.status === this.currentFilter); | |
| } | |
| if (searchQuery) { | |
| filteredTasks = filteredTasks.filter(task => | |
| task.title.toLowerCase().includes(searchQuery) || | |
| task.description.toLowerCase().includes(searchQuery) | |
| ); | |
| } | |
| if (filteredTasks.length === 0) { | |
| container.innerHTML = ` | |
| <div class="p-6 text-center text-gray-500"> | |
| <i data-feather="inbox" class="w-12 h-12 mx-auto text-gray-300 mb-2"></i> | |
| <p>No tasks found. ${searchQuery ? 'Try a different search.' : 'Add your first task!'}</p> | |
| </div> | |
| `; | |
| feather.replace(); | |
| return; | |
| } | |
| container.innerHTML = filteredTasks.map(task => ` | |
| <div class="task-card p-4 hover:bg-gray-50 ${'priority-' + task.priority}"> | |
| <div class="flex justify-between items-start gap-4"> | |
| <div class="flex-1"> | |
| <div class="flex items-center gap-2 mb-1"> | |
| <h3 class="font-medium text-gray-800">${task.title}</h3> | |
| <span class="status-badge ${'status-' + task.status.replace(' ', '-')}"> | |
| ${task.status.replace('-', ' ')} | |
| </span> | |
| </div> | |
| <p class="text-gray-600 text-sm mb-2">${task.description || 'No description'}</p> | |
| <div class="flex items-center gap-4 text-sm text-gray-500"> | |
| <div class="flex items-center gap-1"> | |
| <i data-feather="calendar" class="w-4 h-4"></i> | |
| <span>${task.dueDate || 'No due date'}</span> | |
| </div> | |
| <div class="flex items-center gap-1"> | |
| <i data-feather="clock" class="w-4 h-4"></i> | |
| <span>${new Date(task.createdAt).toLocaleDateString()}</span> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="flex gap-2 task-actions"> | |
| <button class="edit-task p-2 text-gray-500 hover:text-primary rounded-full hover:bg-gray-100" data-id="${task.id}"> | |
| <i data-feather="edit" class="w-4 h-4"></i> | |
| </button> | |
| <button class="delete-task p-2 text-gray-500 hover:text-red-500 rounded-full hover:bg-gray-100" data-id="${task.id}"> | |
| <i data-feather="trash-2" class="w-4 h-4"></i> | |
| </button> | |
| <select class="status-select p-1.5 text-sm border border-gray-200 rounded-md focus:ring-primary focus:border-primary outline-none" data-id="${task.id}"> | |
| <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> | |
| </div> | |
| `).join(''); | |
| // Add event listeners to dynamic elements | |
| document.querySelectorAll('.edit-task').forEach(btn => { | |
| btn.addEventListener('click', (e) => { | |
| const taskId = e.currentTarget.getAttribute('data-id'); | |
| const task = this.tasks.find(t => t.id === taskId); | |
| if (task) this.openModal(task); | |
| }); | |
| }); | |
| document.querySelectorAll('.delete-task').forEach(btn => { | |
| btn.addEventListener('click', (e) => { | |
| const taskId = e.currentTarget.getAttribute('data-id'); | |
| this.deleteTask(taskId); | |
| }); | |
| }); | |
| document.querySelectorAll('.status-select').forEach(select => { | |
| select.addEventListener('change', (e) => { | |
| const taskId = e.currentTarget.getAttribute('data-id'); | |
| const newStatus = e.target.value; | |
| this.updateTaskStatus(taskId, newStatus); | |
| }); | |
| }); | |
| feather.replace(); | |
| } | |
| updateSummary() { | |
| const total = this.tasks.length; | |
| const completed = this.tasks.filter(task => task.status === 'completed').length; | |
| const pending = this.tasks.filter(task => task.status === 'pending').length; | |
| const highPriority = this.tasks.filter(task => task.priority === 'high').length; | |
| document.getElementById('totalTasks').textContent = total; | |
| document.getElementById('completedTasks').textContent = completed; | |
| document.getElementById('pendingTasks').textContent = pending; | |
| document.getElementById('highPriorityTasks').textContent = highPriority; | |
| } | |
| saveToLocalStorage() { | |
| localStorage.setItem('tasks', JSON.stringify(this.tasks)); | |
| } | |
| } | |
| // Initialize the app when DOM is loaded | |
| document.addEventListener('DOMContentLoaded', () => { | |
| const app = new TaskManager(); | |
| // Email notification toggle | |
| const emailCheckbox = document.getElementById('emailNotifications'); | |
| const emailInput = document.getElementById('notificationEmail'); | |
| if (emailCheckbox && emailInput) { | |
| emailCheckbox.addEventListener('change', function() { | |
| emailInput.classList.toggle('hidden', !this.checked); | |
| if (this.checked) emailInput.focus(); | |
| }); | |
| } | |
| }); | |
| // Data management functions | |
| function exportTasks() { | |
| const tasks = JSON.parse(localStorage.getItem('tasks')) || []; | |
| const dataStr = JSON.stringify(tasks); | |
| const dataUri = 'data:application/json;charset=utf-8,'+ encodeURIComponent(dataStr); | |
| const exportName = 'taskmaster-export-' + new Date().toISOString().slice(0,10) + '.json'; | |
| const linkElement = document.createElement('a'); | |
| linkElement.setAttribute('href', dataUri); | |
| linkElement.setAttribute('download', exportName); | |
| linkElement.click(); | |
| } | |
| function importTasks() { | |
| const input = document.createElement('input'); | |
| input.type = 'file'; | |
| input.accept = '.json'; | |
| input.onchange = e => { | |
| const file = e.target.files[0]; | |
| const reader = new FileReader(); | |
| reader.onload = event => { | |
| try { | |
| const importedTasks = JSON.parse(event.target.result); | |
| localStorage.setItem('tasks', JSON.stringify(importedTasks)); | |
| alert('Tasks imported successfully!'); | |
| location.reload(); | |
| } catch (error) { | |
| alert('Error importing tasks: Invalid file format'); | |
| } | |
| }; | |
| reader.readAsText(file); | |
| }; | |
| input.click(); | |
| } | |
| function clearAllData() { | |
| if (confirm('Are you sure you want to delete ALL tasks? This cannot be undone.')) { | |
| localStorage.removeItem('tasks'); | |
| alert('All tasks have been deleted.'); | |
| location.reload(); | |
| } | |
| } | |