Spaces:
Running

taskmaster-pro / script.js
utkuunal's picture
Giriş sistemini kaldır
acc184c verified
Raw History Blame Contribute Delete
10.1 kB
document.addEventListener('DOMContentLoaded', function() {
// Dashboard functionality
if (window.location.pathname.endsWith('index.html')) {
initDashboard();
}
if (window.location.pathname.endsWith('dashboard.html')) {
initDashboard();
}
});
// Dashboard functionality
let tasks = [];
let currentFilter = 'all';
let editingTaskId = null;
function initDashboard() {
loadTasks();
renderTasks();
updateStatistics();
updateCategories();
// Task form submission
document.getElementById('taskForm').addEventListener('submit', function(e) {
e.preventDefault();
saveTask();
});
}
function loadTasks() {
tasks = JSON.parse(localStorage.getItem('tasks')) || [];
}
function saveTasks() {
localStorage.setItem('tasks', JSON.stringify(tasks));
}
function generateId() {
return Date.now().toString(36) + Math.random().toString(36).substr(2);
}
function openAddTaskModal() {
editingTaskId = null;
document.getElementById('modalTitle').textContent = 'Yeni Görev Ekle';
document.getElementById('taskForm').reset();
document.getElementById('taskModal').classList.remove('hidden');
}
function closeTaskModal() {
document.getElementById('taskModal').classList.add('hidden');
document.getElementById('taskForm').reset();
editingTaskId = null;
}
function saveTask() {
const title = document.getElementById('taskTitle').value;
const description = document.getElementById('taskDescription').value;
const category = document.getElementById('taskCategory').value;
const priority = document.getElementById('taskPriority').value;
const date = document.getElementById('taskDate').value;
if (editingTaskId) {
const taskIndex = tasks.findIndex(t => t.id === editingTaskId);
tasks[taskIndex] = {
...tasks[taskIndex],
title,
description,
category,
priority,
date
};
showToast('Görev güncellendi!', 'success');
} else {
const newTask = {
id: generateId(),
title,
description,
category,
priority,
date,
completed: false,
createdAt: new Date().toISOString()
};
tasks.unshift(newTask);
showToast('Görev eklendi!', 'success');
}
saveTasks();
renderTasks();
updateStatistics();
updateCategories();
closeTaskModal();
}
function editTask(id) {
const task = tasks.find(t => t.id === id);
if (task) {
editingTaskId = id;
document.getElementById('modalTitle').textContent = 'Görevi Düzenle';
document.getElementById('taskTitle').value = task.title;
document.getElementById('taskDescription').value = task.description;
document.getElementById('taskCategory').value = task.category;
document.getElementById('taskPriority').value = task.priority;
document.getElementById('taskDate').value = task.date;
document.getElementById('taskModal').classList.remove('hidden');
}
}
function deleteTask(id) {
if (confirm('Bu görevi silmek istediğinizden emin misiniz?')) {
tasks = tasks.filter(t => t.id !== id);
saveTasks();
renderTasks();
updateStatistics();
updateCategories();
showToast('Görev silindi!', 'success');
}
}
function toggleTask(id) {
const task = tasks.find(t => t.id === id);
if (task) {
task.completed = !task.completed;
saveTasks();
renderTasks();
updateStatistics();
updateCategories();
}
}
function filterTasks(filter) {
currentFilter = filter;
// Update filter buttons
document.querySelectorAll('.filter-btn').forEach(btn => {
btn.classList.remove('bg-primary-100', 'text-primary-700');
btn.classList.add('text-gray-600', 'hover:bg-gray-100');
});
event.target.classList.remove('text-gray-600', 'hover:bg-gray-100');
event.target.classList.add('bg-primary-100', 'text-primary-700');
renderTasks();
}
function renderTasks() {
const tasksList = document.getElementById('tasksList');
let filteredTasks = tasks;
if (currentFilter === 'completed') {
filteredTasks = tasks.filter(t => t.completed);
} else if (currentFilter === 'pending') {
filteredTasks = tasks.filter(t => !t.completed);
} else if (currentFilter === 'high') {
filteredTasks = tasks.filter(t => t.priority === 'high');
}
if (filteredTasks.length === 0) {
tasksList.innerHTML = `
<div class="empty-state">
<svg width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/>
<polyline points="14 2 14 8 20 8"/>
<line x1="16" y1="13" x2="8" y2="13"/>
<line x1="16" y1="17" x2="8" y2="17"/>
<polyline points="10 9 9 9 8 9"/>
</svg>
<p class="text-gray-500">Henüz görev bulunmuyor</p>
</div>
`;
return;
}
tasksList.innerHTML = filteredTasks.map(task => `
<div class="task-item bg-white border border-gray-200 rounded-lg p-4 ${task.completed ? 'opacity-60' : ''} animate-slide-in">
<div class="flex items-start gap-3">
<input type="checkbox"
${task.completed ? 'checked' : ''}
onchange="toggleTask('${task.id}')"
class="task-checkbox mt-1 w-5 h-5 text-primary-500 rounded focus:ring-primary-500">
<div class="flex-1">
<h4 class="font-medium text-gray-900 ${task.completed ? 'line-through' : ''}">${task.title}</h4>
${task.description ? `<p class="text-sm text-gray-600 mt-1">${task.description}</p>` : ''}
<div class="flex items-center gap-2 mt-2">
<span class="category-${task.category} text-xs px-2 py-1 rounded-full">${task.category}</span>
<span class="priority-badge priority-${task.priority}">${
task.priority === 'high' ? 'Yüksek' :
task.priority === 'medium' ? 'Orta' : 'Düşük'
}</span>
${task.date ? `<span class="text-xs text-gray-500">📅 ${task.date}</span>` : ''}
</div>
</div>
<div class="flex gap-1">
<button onclick="editTask('${task.id}')" class="p-2 text-gray-500 hover:text-primary-500 hover:bg-primary-50 rounded transition-colors">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7"/>
<path d="M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z"/>
</svg>
</button>
<button onclick="deleteTask('${task.id}')" class="p-2 text-gray-500 hover:text-red-500 hover:bg-red-50 rounded transition-colors">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="3 6 5 6 21 6"/>
<path d="M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"/>
</svg>
</button>
</div>
</div>
</div>
`).join('');
}
function updateStatistics() {
const total = tasks.length;
const completed = tasks.filter(t => t.completed).length;
const pending = tasks.filter(t => !t.completed).length;
const highPriority = tasks.filter(t => t.priority === 'high' && !t.completed).length;
document.getElementById('totalTasks').textContent = total;
document.getElementById('completedTasks').textContent = completed;
document.getElementById('pendingTasks').textContent = pending;
document.getElementById('highPriorityTasks').textContent = highPriority;
}
function updateCategories() {
const categories = {};
tasks.forEach(task => {
categories[task.category] = (categories[task.category] || 0) + 1;
});
const categoriesList = document.getElementById('categoriesList');
categoriesList.innerHTML = Object.entries(categories).map(([category, count]) => `
<div class="flex items-center justify-between p-2 rounded-lg hover:bg-gray-50 transition-colors">
<span class="category-${category} text-sm px-2 py-1 rounded-full">${category}</span>
<span class="text-gray-600 font-medium">${count}</span>
</div>
`).join('');
}
function showToast(message, type = 'success') {
const toast = document.createElement('div');
toast.className = `toast toast-${type} animate-slide-in`;
toast.innerHTML = `
${type === 'success' ?
'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#10b981" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 11-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>' :
'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#ef4444" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>'
}
<span>${message}</span>
`;
document.body.appendChild(toast);
setTimeout(() => {
toast.style.opacity = '0';
setTimeout(() => {
document.body.removeChild(toast);
}, 300);
}, 3000);
}