File size: 25,316 Bytes
f5efb5b 50e979b f5efb5b 50e979b f5efb5b 50e979b a5b4f8e 50e979b a5b4f8e c355ad3 a5b4f8e 50e979b 180eae5 | 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 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kanban Board</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/feather-icons"></script>
<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.14.0/Sortable.min.js"></script>
<style>
.kanban-column {
min-height: 500px;
}
.task-card {
transition: all 0.3s ease;
}
.task-card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
.selected-task {
border-left: 4px solid #3b82f6;
background-color: #f8fafc;
}
</style>
</head>
<body class="bg-gray-50">
<div id="app" class="min-h-screen">
<!-- Navigation -->
<nav class="bg-white shadow-sm">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16">
<div class="flex">
<div class="flex-shrink-0 flex items-center">
<i data-feather="trello" class="text-blue-500"></i>
<span class="ml-2 text-xl font-semibold text-gray-800">Kanban Board</span>
</div>
</div>
<div class="flex items-center">
<div class="ml-4 flex items-center md:ml-6">
<div class="ml-3 relative">
<div class="flex items-center space-x-4">
<span id="current-user" class="text-sm font-medium text-gray-700"></span>
<button onclick="logout()" class="px-3 py-1 rounded-md text-sm font-medium text-white bg-blue-500 hover:bg-blue-600">
Logout
</button>
<button onclick="window.location.href='admin.html'" id="admin-btn" class="hidden px-3 py-1 rounded-md text-sm font-medium text-white bg-purple-500 hover:bg-purple-600">
Admin
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</nav>
<!-- Main Content -->
<main class="py-6 px-4 sm:px-6 lg:px-8">
<div class="mb-6 flex justify-between items-center">
<h2 class="text-2xl font-bold text-gray-800">Team Tasks</h2>
<div class="flex space-x-2">
<button id="add-task-btn" class="px-4 py-2 bg-blue-500 text-white rounded-md hover:bg-blue-600 flex items-center">
<i data-feather="plus" class="mr-2"></i> Add Task
</button>
<button onclick="exportToExcel()" class="px-4 py-2 bg-green-500 text-white rounded-md hover:bg-green-600 flex items-center">
<i data-feather="file-text" class="mr-2"></i> Excel
</button>
<button onclick="exportToPDF()" class="px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600 flex items-center">
<i data-feather="file" class="mr-2"></i> PDF
</button>
</div>
</div>
<!-- Kanban Board -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
<!-- Backlog Column -->
<div class="bg-gray-100 rounded-lg p-4 kanban-column">
<div class="flex justify-between items-center mb-4">
<h3 class="font-semibold text-lg text-gray-700">Backlog</h3>
<span id="backlog-count" class="bg-gray-200 text-gray-700 text-xs font-semibold px-2 py-1 rounded-full">0</span>
</div>
<div id="backlog-tasks" class="space-y-3"></div>
</div>
<!-- To Do Column -->
<div class="bg-blue-50 rounded-lg p-4 kanban-column">
<div class="flex justify-between items-center mb-4">
<h3 class="font-semibold text-lg text-blue-700">To Do</h3>
<span id="todo-count" class="bg-blue-200 text-blue-700 text-xs font-semibold px-2 py-1 rounded-full">0</span>
</div>
<div id="todo-tasks" class="space-y-3"></div>
</div>
<!-- In Progress Column -->
<div class="bg-yellow-50 rounded-lg p-4 kanban-column">
<div class="flex justify-between items-center mb-4">
<h3 class="font-semibold text-lg text-yellow-700">In Progress</h3>
<span id="progress-count" class="bg-yellow-200 text-yellow-700 text-xs font-semibold px-2 py-1 rounded-full">0</span>
</div>
<div id="progress-tasks" class="space-y-3"></div>
</div>
<!-- Done Column -->
<div class="bg-green-50 rounded-lg p-4 kanban-column">
<div class="flex justify-between items-center mb-4">
<h3 class="font-semibold text-lg text-green-700">Done</h3>
<span id="done-count" class="bg-green-200 text-green-700 text-xs font-semibold px-2 py-1 rounded-full">0</span>
</div>
<div id="done-tasks" class="space-y-3"></div>
</div>
</div>
</main>
<!-- Add Task Modal -->
<div id="task-modal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center hidden">
<div class="bg-white rounded-lg p-6 w-full max-w-md">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-semibold">Add New Task</h3>
<button onclick="closeModal()" class="text-gray-500 hover:text-gray-700">
<i data-feather="x"></i>
</button>
</div>
<form id="task-form" class="space-y-4">
<div>
<label for="task-title" class="block text-sm font-medium text-gray-700">Title</label>
<input type="text" id="task-title" required class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="task-description" class="block text-sm font-medium text-gray-700">Description</label>
<textarea id="task-description" rows="3" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500"></textarea>
</div>
<div>
<label for="task-priority" class="block text-sm font-medium text-gray-700">Priority</label>
<select id="task-priority" class="mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:ring-blue-500 focus:border-blue-500">
<option value="low">Low</option>
<option value="medium" selected>Medium</option>
<option value="high">High</option>
</select>
</div>
<div class="flex justify-end space-x-3">
<button type="button" onclick="closeModal()" class="px-4 py-2 border border-gray-300 rounded-md text-sm font-medium text-gray-700 hover:bg-gray-50">
Cancel
</button>
<button type="submit" class="px-4 py-2 bg-blue-500 text-white rounded-md text-sm font-medium hover:bg-blue-600">
Add Task
</button>
</div>
</form>
</div>
</div>
</div>
<script>
// Initialize feather icons
feather.replace();
// App state
const state = {
currentUser: null,
users: [],
tasks: [],
permissions: {}
};
// Initialize the app
document.addEventListener('DOMContentLoaded', function() {
// Check if this is first run - initialize default data if no users exist
if (!localStorage.getItem('users')) {
initializeDefaultData();
}
// Check if user is logged in
const user = localStorage.getItem('currentUser');
if (!user) {
window.location.href = 'login.html';
return;
}
state.currentUser = JSON.parse(user);
document.getElementById('current-user').textContent = `Welcome, ${state.currentUser.name}`;
// Load data from localStorage
loadData();
renderBoard();
// Initialize drag and drop
initSortable();
// Check if user is admin
if (state.currentUser.role === 'admin') {
document.getElementById('admin-btn').classList.remove('hidden');
}
// Check if user can add tasks
const canAdd = state.permissions[state.currentUser.id]?.add || false;
document.getElementById('add-task-btn').style.display = canAdd ? 'flex' : 'none';
// Event listeners
document.getElementById('add-task-btn').addEventListener('click', openModal);
document.getElementById('task-form').addEventListener('submit', handleAddTask);
});
function initializeDefaultData() {
// Default users
const defaultUsers = [
{ id: '1', name: 'Admin', username: 'admin', password: 'admin123', role: 'admin' },
{ id: '2', name: 'Regular User', username: 'user', password: 'user123', role: 'user' }
];
localStorage.setItem('users', JSON.stringify(defaultUsers));
// Default permissions
const defaultPermissions = {
'1': { read: true, add: true, move: true, delete: true }, // Admin
'2': { read: true, add: true, move: true, delete: false } // Regular user
};
localStorage.setItem('permissions', JSON.stringify(defaultPermissions));
// Default tasks
const defaultTasks = [
{
id: '1',
title: 'Welcome to Kanban Board',
description: 'This is a sample task. You can drag it between columns.',
priority: 'medium',
status: 'todo',
createdAt: new Date().toISOString(),
createdBy: '1',
assignedTo: null
},
{
id: '2',
title: 'Try moving tasks',
description: 'Drag tasks between columns to change their status.',
priority: 'low',
status: 'backlog',
createdAt: new Date().toISOString(),
createdBy: '1',
assignedTo: null
}
];
localStorage.setItem('tasks', JSON.stringify(defaultTasks));
}
function loadData() {
const users = localStorage.getItem('users');
const tasks = localStorage.getItem('tasks');
const permissions = localStorage.getItem('permissions');
if (users) state.users = JSON.parse(users);
if (tasks) state.tasks = JSON.parse(tasks);
if (permissions) state.permissions = JSON.parse(permissions);
}
function saveData() {
localStorage.setItem('tasks', JSON.stringify(state.tasks));
localStorage.setItem('users', JSON.stringify(state.users));
localStorage.setItem('permissions', JSON.stringify(state.permissions));
}
function renderBoard() {
// Clear all columns
document.getElementById('backlog-tasks').innerHTML = '';
document.getElementById('todo-tasks').innerHTML = '';
document.getElementById('progress-tasks').innerHTML = '';
document.getElementById('done-tasks').innerHTML = '';
// Count tasks in each column
let backlogCount = 0;
let todoCount = 0;
let progressCount = 0;
let doneCount = 0;
// Render tasks
state.tasks.forEach(task => {
const taskElement = createTaskElement(task);
switch(task.status) {
case 'backlog':
document.getElementById('backlog-tasks').appendChild(taskElement);
backlogCount++;
break;
case 'todo':
document.getElementById('todo-tasks').appendChild(taskElement);
todoCount++;
break;
case 'progress':
document.getElementById('progress-tasks').appendChild(taskElement);
progressCount++;
break;
case 'done':
document.getElementById('done-tasks').appendChild(taskElement);
doneCount++;
break;
}
});
// Update counts
document.getElementById('backlog-count').textContent = backlogCount;
document.getElementById('todo-count').textContent = todoCount;
document.getElementById('progress-count').textContent = progressCount;
document.getElementById('done-count').textContent = doneCount;
// Re-initialize feather icons for new elements
feather.replace();
}
function createTaskElement(task) {
const taskElement = document.createElement('div');
taskElement.className = 'task-card bg-white p-4 rounded-md shadow cursor-move';
taskElement.dataset.taskId = task.id;
// Priority color
let priorityColor = 'bg-gray-200';
if (task.priority === 'high') priorityColor = 'bg-red-200';
else if (task.priority === 'medium') priorityColor = 'bg-yellow-200';
// Assigned user indicator
let assignedUser = '';
if (task.assignedTo) {
const user = state.users.find(u => u.id === task.assignedTo);
if (user) {
assignedUser = `<span class="text-xs text-gray-500">Assigned to: ${user.name}</span>`;
}
}
taskElement.innerHTML = `
<div class="flex justify-between items-start">
<div>
<div class="flex items-center space-x-2">
<span class="text-sm font-medium text-gray-900">${task.title}</span>
<span class="text-xs px-2 py-1 rounded-full ${priorityColor}">${task.priority}</span>
</div>
${assignedUser}
</div>
<div class="flex space-x-1">
<button onclick="handleSelectTask('${task.id}')" class="text-blue-500 hover:text-blue-700">
<i data-feather="user-plus" class="w-4 h-4"></i>
</button>
<button onclick="handleDeleteTask('${task.id}')" class="text-red-500 hover:text-red-700">
<i data-feather="trash-2" class="w-4 h-4"></i>
</button>
</div>
</div>
${task.description ? `<p class="mt-2 text-sm text-gray-600">${task.description}</p>` : ''}
<div class="mt-2 flex justify-between items-center">
<span class="text-xs text-gray-500">Created: ${new Date(task.createdAt).toLocaleDateString()}</span>
<span class="text-xs text-gray-500">${task.createdBy === state.currentUser.id ? 'You created this' : ''}</span>
</div>
`;
return taskElement;
}
function initSortable() {
const canMove = state.permissions[state.currentUser.id]?.move || false;
if (!canMove) return;
const columns = [
document.getElementById('backlog-tasks'),
document.getElementById('todo-tasks'),
document.getElementById('progress-tasks'),
document.getElementById('done-tasks')
];
columns.forEach(column => {
new Sortable(column, {
group: 'tasks',
animation: 150,
ghostClass: 'bg-blue-50',
onEnd: function(evt) {
const taskId = evt.item.dataset.taskId;
const newStatus = getStatusFromColumnId(evt.to.id);
updateTaskStatus(taskId, newStatus);
}
});
});
}
function getStatusFromColumnId(columnId) {
switch(columnId) {
case 'backlog-tasks': return 'backlog';
case 'todo-tasks': return 'todo';
case 'progress-tasks': return 'progress';
case 'done-tasks': return 'done';
default: return 'backlog';
}
}
function updateTaskStatus(taskId, newStatus) {
const taskIndex = state.tasks.findIndex(t => t.id === taskId);
if (taskIndex !== -1) {
state.tasks[taskIndex].status = newStatus;
saveData();
renderBoard();
}
}
function handleSelectTask(taskId) {
const taskIndex = state.tasks.findIndex(t => t.id === taskId);
if (taskIndex !== -1) {
if (state.tasks[taskIndex].assignedTo === state.currentUser.id) {
// Unassign if already assigned to current user
state.tasks[taskIndex].assignedTo = null;
} else {
// Assign to current user
state.tasks[taskIndex].assignedTo = state.currentUser.id;
}
saveData();
renderBoard();
}
}
function handleDeleteTask(taskId) {
const canDelete = state.permissions[state.currentUser.id]?.delete || false;
if (!canDelete) {
alert('You do not have permission to delete tasks.');
return;
}
const taskIndex = state.tasks.findIndex(t => t.id === taskId);
if (taskIndex !== -1 && state.tasks[taskIndex].createdBy === state.currentUser.id) {
state.tasks.splice(taskIndex, 1);
saveData();
renderBoard();
} else {
alert('You can only delete tasks you created.');
}
}
function openModal() {
document.getElementById('task-modal').classList.remove('hidden');
}
function closeModal() {
document.getElementById('task-modal').classList.add('hidden');
document.getElementById('task-form').reset();
}
function handleAddTask(e) {
e.preventDefault();
const title = document.getElementById('task-title').value;
const description = document.getElementById('task-description').value;
const priority = document.getElementById('task-priority').value;
const newTask = {
id: Date.now().toString(),
title,
description,
priority,
status: 'backlog',
createdAt: new Date().toISOString(),
createdBy: state.currentUser.id,
assignedTo: null
};
state.tasks.push(newTask);
saveData();
renderBoard();
closeModal();
}
function logout() {
localStorage.removeItem('currentUser');
window.location.href = 'login.html';
}
function exportToExcel() {
// Prepare data
const data = state.tasks.map(task => {
const createdByUser = state.users.find(u => u.id === task.createdBy);
const assignedToUser = state.users.find(u => u.id === task.assignedTo);
return {
'Title': task.title,
'Description': task.description,
'Status': task.status.charAt(0).toUpperCase() + task.status.slice(1),
'Priority': task.priority.charAt(0).toUpperCase() + task.priority.slice(1),
'Created By': createdByUser ? createdByUser.name : 'Unknown',
'Assigned To': assignedToUser ? assignedToUser.name : 'Unassigned',
'Created Date': new Date(task.createdAt).toLocaleString()
};
});
// Create workbook
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet(data);
XLSX.utils.book_append_sheet(wb, ws, "Tasks");
// Generate and download
XLSX.writeFile(wb, `kanban_tasks_${new Date().toISOString().slice(0,10)}.xlsx`);
}
function exportToPDF() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
// Title
doc.setFontSize(20);
doc.setTextColor(40);
doc.text('Kanban Tasks Report', 105, 15, { align: 'center' });
// Date
doc.setFontSize(10);
doc.setTextColor(100);
doc.text(`Generated on: ${new Date().toLocaleString()}`, 105, 22, { align: 'center' });
// Logo
doc.addImage('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTE5IDE5SDVWNUgxOU0xOSAzSDVBMiAyIDAgMCAwIDMgNXYxNGEyIDIgMCAwIDAgMiAyaDE0YTIgMiAwIDAgMCAyLTJWNUEyIDIgMCAwIDAgMTkgM3oiIGZpbGw9IiMzYjgxZjYiLz48L3N2Zz4=', 'SVG', 15, 25, 15, 15);
// Table data
const columns = [
{ header: 'Title', dataKey: 'title' },
{ header: 'Status', dataKey: 'status' },
{ header: 'Priority', dataKey: 'priority' },
{ header: 'Assigned To', dataKey: 'assignedTo' }
];
const rows = state.tasks.map(task => {
const assignedToUser = state.users.find(u => u.id === task.assignedTo);
return {
title: task.title,
status: task.status.charAt(0).toUpperCase() + task.status.slice(1),
priority: task.priority.charAt(0).toUpperCase() + task.priority.slice(1),
assignedTo: assignedToUser ? assignedToUser.name : 'Unassigned'
};
});
// Add table
doc.autoTable({
head: [columns.map(col => col.header)],
body: rows.map(row => columns.map(col => row[col.dataKey])),
startY: 45,
styles: {
halign: 'center',
cellPadding: 3,
fontSize: 10
},
headStyles: {
fillColor: [59, 130, 246],
textColor: 255,
fontStyle: 'bold'
},
alternateRowStyles: {
fillColor: [241, 245, 249]
},
columnStyles: {
0: { cellWidth: 'auto' },
1: { cellWidth: 30 },
2: { cellWidth: 30 },
3: { cellWidth: 40 }
}
});
// Footer
const pageCount = doc.internal.getNumberOfPages();
for(let i = 1; i <= pageCount; i++) {
doc.setPage(i);
doc.setFontSize(8);
doc.setTextColor(150);
doc.text(`Page ${i} of ${pageCount}`, 105, 285, { align: 'center' });
}
// Save
doc.save(`kanban_tasks_${new Date().toISOString().slice(0,10)}.pdf`);
}
</script>
</body>
</html>
|