Spaces:
Running
Running
File size: 10,092 Bytes
90ebc2a acc184c 90ebc2a acc184c 90ebc2a acc184c 90ebc2a | 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 |
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);
} |