-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndex.html
More file actions
715 lines (662 loc) · 40.6 KB
/
Copy pathIndex.html
File metadata and controls
715 lines (662 loc) · 40.6 KB
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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manajemen Tugas Prana</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
/* Custom animations */
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.task-item {
animation: fadeIn 0.3s ease-out forwards;
}
/* Custom scrollbar */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-thumb {
background: #cbd5e0;
border-radius: 10px;
}
/* Priority markers */
.priority-high { border-left: 4px solid #ef4444; }
.priority-medium { border-left: 4px solid #f59e0b; }
.priority-low { border-left: 4px solid #10b981; }
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="max-w-6xl mx-auto px-4 py-8">
<!-- Header Section -->
<header class="mb-8">
<div class="flex items-center justify-between mb-6">
<div>
<h1 class="text-3xl font-bold text-gray-800">
<i class="fas fa-tasks mr-3 text-blue-600"></i>
Manajemen Tugas Prana
</h1>
<p class="text-gray-600">kabeh tak garap, penting ga mlarat </p>
</div>
<div class="flex items-center space-x-4">
<div class="relative">
<div class="flex items-center bg-white rounded-full p-2 shadow">
<img src="https://placehold.co/40x40" alt="Profile picture of employee smiling wearing business attire"
class="w-10 h-10 rounded-full">
<span class="ml-2 font-medium text-gray-700">hayyu kurniawan</span>
</div>
<span class="absolute -top-1 -right-1 bg-green-500 w-3 h-3 rounded-full border-2 border-white"></span>
</div>
</div>
</div>
<div class="bg-white rounded-xl shadow-md p-6 mb-6">
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="bg-blue-50 p-4 rounded-lg border-l-4 border-blue-500">
<h3 class="text-sm font-medium text-gray-500">Jumlah Tugas</h3>
<p class="text-2xl font-bold text-gray-800">15</p>
</div>
<div class="bg-yellow-50 p-4 rounded-lg border-l-4 border-yellow-500">
<h3 class="text-sm font-medium text-gray-500">Tertunda</h3>
<p class="text-2xl font-bold text-gray-800">8</p>
</div>
<div class="bg-green-50 p-4 rounded-lg border-l-4 border-green-500">
<h3 class="text-sm font-medium text-gray-500">Selesai</h3>
<p class="text-2xl font-bold text-gray-800">7</p>
</div>
</div>
</div>
</header>
<!-- Main Content -->
<div class="flex flex-col lg:flex-row gap-8">
<!-- Sidebar / Filters -->
<div class="lg:w-1/4">
<div class="bg-white rounded-xl shadow-md p-6 sticky top-6">
<div class="mb-6">
<h2 class="text-lg font-semibold text-gray-800 mb-4">Add New Task</h2>
<form id="taskForm" class="space-y-4">
<div>
<label for="taskTitle" class="block text-sm font-medium text-gray-700 mb-1">Task Title</label>
<input type="text" id="taskTitle"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
placeholder="What needs to be done?" required>
</div>
<div>
<label for="taskDescription" class="block text-sm font-medium text-gray-700 mb-1">Description</label>
<textarea id="taskDescription" rows="3"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
placeholder="More details..."></textarea>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label for="taskDue" class="block text-sm font-medium text-gray-700 mb-1">Due Date</label>
<input type="date" id="taskDue"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label for="taskPriority" class="block text-sm font-medium text-gray-700 mb-1">Priority</label>
<select id="taskPriority"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 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>
<div>
<label for="taskCategory" class="block text-sm font-medium text-gray-700 mb-1">Category</label>
<select id="taskCategory"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500">
<option value="general">General</option>
<option value="meeting">Meeting</option>
<option value="project">Project</option>
<option value="personal">Personal</option>
</select>
</div>
<button type="submit"
class="w-full bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded-lg transition duration-200 flex items-center justify-center">
<i class="fas fa-plus mr-2"></i> Add Task
</button>
</form>
</div>
<div>
<h2 class="text-lg font-semibold text-gray-800 mb-4">Quick Filters</h2>
<div class="space-y-2">
<button class="filter-btn w-full text-left px-4 py-2 rounded-lg hover:bg-gray-100 transition flex items-center justify-between" data-filter="all">
<span class="flex items-center">
<i class="fas fa-list-ul text-gray-500 mr-3"></i>
All Tasks
</span>
<span class="bg-gray-200 text-gray-800 text-xs font-semibold px-2 py-1 rounded-full">15</span>
</button>
<button class="filter-btn w-full text-left px-4 py-2 rounded-lg hover:bg-gray-100 transition flex items-center justify-between" data-filter="today">
<span class="flex items-center">
<i class="fas fa-calendar-day text-blue-500 mr-3"></i>
Today
</span>
<span class="bg-gray-200 text-gray-800 text-xs font-semibold px-2 py-1 rounded-full">3</span>
</button>
<button class="filter-btn w-full text-left px-4 py-2 rounded-lg hover:bg-gray-100 transition active-filter flex items-center justify-between" data-filter="pending">
<span class="flex items-center">
<i class="fas fa-clock text-orange-500 mr-3"></i>
Pending
</span>
<span class="bg-gray-200 text-gray-800 text-xs font-semibold px-2 py-1 rounded-full">8</span>
</button>
<button class="filter-btn w-full text-left px-4 py-2 rounded-lg hover:bg-gray-100 transition flex items-center justify-between" data-filter="completed">
<span class="flex items-center">
<i class="fas fa-check-circle text-green-500 mr-3"></i>
Completed
</span>
<span class="bg-gray-200 text-gray-800 text-xs font-semibold px-2 py-1 rounded-full">7</span>
</button>
</div>
<h3 class="text-md font-semibold text-gray-700 mt-6 mb-2">Categories</h3>
<div class="space-y-2">
<button class="category-filter w-full text-left px-4 py-2 rounded-lg hover:bg-gray-100 transition flex items-center justify-between" data-category="all">
<span class="flex items-center">
<i class="fas fa-tag text-gray-500 mr-3"></i>
All Categories
</span>
</button>
<button class="category-filter w-full text-left px-4 py-2 rounded-lg hover:bg-gray-100 transition flex items-center justify-between" data-category="general">
<span class="flex items-center">
<span class="w-3 h-3 rounded-full bg-gray-400 mr-3"></span>
General
</span>
<span class="bg-gray-200 text-gray-800 text-xs font-semibold px-2 py-1 rounded-full">5</span>
</button>
<button class="category-filter w-full text-left px-4 py-2 rounded-lg hover:bg-gray-100 transition flex items-center justify-between" data-category="meeting">
<span class="flex items-center">
<span class="w-3 h-3 rounded-full bg-blue-400 mr-3"></span>
Meetings
</span>
<span class="bg-gray-200 text-gray-800 text-xs font-semibold px-2 py-1 rounded-full">4</span>
</button>
<button class="category-filter w-full text-left px-4 py-2 rounded-lg hover:bg-gray-100 transition flex items-center justify-between" data-category="project">
<span class="flex items-center">
<span class="w-3 h-3 rounded-full bg-purple-400 mr-3"></span>
Projects
</span>
<span class="bg-gray-200 text-gray-800 text-xs font-semibold px-2 py-1 rounded-full">4</span>
</button>
<button class="category-filter w-full text-left px-4 py-2 rounded-lg hover:bg-gray-100 transition flex items-center justify-between" data-category="personal">
<span class="flex items-center">
<span class="w-3 h-3 rounded-full bg-yellow-400 mr-3"></span>
Personal
</span>
<span class="bg-gray-200 text-gray-800 text-xs font-semibold px-2 py-1 rounded-full">2</span>
</button>
</div>
</div>
</div>
</div>
<!-- Tasks List -->
<div class="lg:w-3/4">
<div class="bg-white rounded-xl shadow-md p-6">
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center mb-6">
<div class="mb-4 sm:mb-0">
<h2 class="text-xl font-semibold text-gray-800">Tugas Tertunda (8)</h2>
<p class="text-sm text-gray-500">Tugas yang memerlukan perhatian Anda</p>
</div>
<div class="flex space-x-2">
<div class="relative">
<select id="sortTasks" class="appearance-none bg-white border border-gray-300 rounded-lg px-4 py-2 pr-8 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm">
<option value="date-asc">Tanggal (Terlama)</option>
<option value="date-desc" selected>Tanggal (Terbaru)</option>
<option value="priority">Prioritas</option>
</select>
<div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2 text-gray-700">
<i class="fas fa-chevron-down text-xs"></i>
</div>
</div>
<button id="searchToggle" class="bg-gray-100 hover:bg-gray-200 p-2 rounded-lg text-gray-700 transition">
<i class="fas fa-search"></i>
</button>
</div>
</div>
<!-- Search Box (Hidden by default) -->
<div id="searchBox" class="mb-6 hidden">
<div class="relative">
<input type="text" placeholder="Search tasks..." class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 pl-10">
<i class="fas fa-search absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
</div>
</div>
<!-- Tasks List -->
<div id="tasksContainer" class="space-y-4">
<!-- Task Item -->
<div class="task-item bg-white border border-gray-200 rounded-xl p-5 shadow-sm hover:shadow-md transition cursor-move priority-high">
<div class="flex items-start justify-between mb-3">
<div class="flex items-center">
<input type="checkbox" class="h-5 w-5 rounded border-gray-300 text-blue-600 focus:ring-blue-500 mr-3 mt-0.5">
<div>
<h3 class="text-lg font-medium text-gray-800">Complete Q2 Financial Report</h3>
<div class="flex items-center mt-1 flex-wrap gap-2">
<span class="px-2 py-1 text-xs rounded-full bg-red-100 text-red-800 flex items-center">
<i class="fas fa-exclamation-circle mr-1"></i>
High Priority
</span>
<span class="px-2 py-1 text-xs rounded-full bg-purple-100 text-purple-800 flex items-center">
<i class="fas fa-project-diagram mr-1"></i>
Project
</span>
<span class="px-2 py-1 text-xs rounded-full bg-orange-100 text-orange-800 flex items-center">
<i class="fas fa-calendar-day mr-1"></i>
Due Today
</span>
</div>
</div>
</div>
<div class="flex space-x-2">
<button class="task-action-btn text-gray-400 hover:text-blue-500 transition">
<i class="fas fa-pencil-alt"></i>
</button>
<button class="task-action-btn text-gray-400 hover:text-red-500 transition">
<i class="fas fa-trash-alt"></i>
</button>
</div>
</div>
<p class="text-gray-600 mb-4">Prepare the financial presentation for the quarterly review meeting with the board. Include all department budgets and forecasts.</p>
<div class="flex justify-between items-center text-sm text-gray-500">
<div class="flex items-center">
<i class="fas fa-user-circle mr-1"></i>
<span>Assigned to you</span>
</div>
<span><i class="fas fa-clock mr-1"></i> Created: Jun 10, 2023</span>
</div>
</div>
<!-- Task Item -->
<div class="task-item bg-white border border-gray-200 rounded-xl p-5 shadow-sm hover:shadow-md transition cursor-move priority-medium">
<div class="flex items-start justify-between mb-3">
<div class="flex items-center">
<input type="checkbox" class="h-5 w-5 rounded border-gray-300 text-blue-600 focus:ring-blue-500 mr-3 mt-0.5">
<div>
<h3 class="text-lg font-medium text-gray-800">Team Standup Meeting</h3>
<div class="flex items-center mt-1 flex-wrap gap-2">
<span class="px-2 py-1 text-xs rounded-full bg-yellow-100 text-yellow-800 flex items-center">
<i class="fas fa-info-circle mr-1"></i>
Medium Priority
</span>
<span class="px-2 py-1 text-xs rounded-full bg-blue-100 text-blue-800 flex items-center">
<i class="fas fa-users mr-1"></i>
Meeting
</span>
</div>
</div>
</div>
<div class="flex space-x-2">
<button class="task-action-btn text-gray-400 hover:text-blue-500 transition">
<i class="fas fa-pencil-alt"></i>
</button>
<button class="task-action-btn text-gray-400 hover:text-red-500 transition">
<i class="fas fa-trash-alt"></i>
</button>
</div>
</div>
<p class="text-gray-600 mb-4">Daily standup with development team. Review blockers and progress on current sprint tasks.</p>
<div class="flex justify-between items-center text-sm text-gray-500">
<div class="flex items-center">
<i class="fas fa-user-circle mr-1"></i>
<span>Assigned to you</span>
</div>
<span><i class="fas fa-clock mr-1"></i> Created: Jun 12, 2023</span>
</div>
</div>
<!-- Task Item -->
<div class="task-item bg-white border border-gray-200 rounded-xl p-5 shadow-sm hover:shadow-md transition cursor-move priority-low">
<div class="flex items-start justify-between mb-3">
<div class="flex items-center">
<input type="checkbox" class="h-5 w-5 rounded border-gray-300 text-blue-600 focus:ring-blue-500 mr-3 mt-0.5">
<div>
<h3 class="text-lg font-medium text-gray-800">Update Employee Handbook</h3>
<div class="flex items-center mt-1 flex-wrap gap-2">
<span class="px-2 py-1 text-xs rounded-full bg-green-100 text-green-800 flex items-center">
<i class="fas fa-check-circle mr-1"></i>
Low Priority
</span>
<span class="px-2 py-1 text-xs rounded-full bg-gray-100 text-gray-800 flex items-center">
<i class="fas fa-file-alt mr-1"></i>
General
</span>
</div>
</div>
</div>
<div class="flex space-x-2">
<button class="task-action-btn text-gray-400 hover:text-blue-500 transition">
<i class="fas fa-pencil-alt"></i>
</button>
<button class="task-action-btn text-gray-400 hover:text-red-500 transition">
<i class="fas fa-trash-alt"></i>
</button>
</div>
</div>
<p class="text-gray-600 mb-4">Review and update the remote work policy in the employee handbook to reflect new company guidelines.</p>
<div class="flex justify-between items-center text-sm text-gray-500">
<div class="flex items-center">
<i class="fas fa-user-circle mr-1"></i>
<span>Assigned to you</span>
</div>
<span><i class="fas fa-clock mr-1"></i> Created: Jun 8, 2023</span>
</div>
</div>
<!-- More tasks would appear here -->
</div>
<!-- Completed Tasks - Initially hidden -->
<div class="mt-8 pt-6 border-t border-gray-200">
<h3 class="text-lg font-semibold text-gray-800 mb-4">
<i class="fas fa-check-circle text-green-500 mr-2"></i>
Recently Completed
<span class="text-sm font-normal text-gray-500 ml-1">(7 tasks)</span>
</h3>
<div class="space-y-4 opacity-70">
<!-- Completed Task Item -->
<div class="bg-gray-50 border border-gray-200 rounded-xl p-5">
<div class="flex items-center justify-between">
<div class="flex items-center">
<input type="checkbox" class="h-5 w-5 rounded border-gray-300 text-green-600 focus:ring-green-500 mr-3" checked>
<div>
<h3 class="text-gray-600 line-through">Review job applications</h3>
<div class="text-xs text-gray-500 mt-1">Completed: Today, 10:30 AM</div>
</div>
</div>
<button class="text-gray-400 hover:text-red-500 transition">
<i class="fas fa-trash-alt"></i>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
// Sample tasks data
let tasks = [
{
id: 1,
title: "Complete Q2 Financial Report",
description: "Prepare the financial presentation for the quarterly review meeting with the board. Include all department budgets and forecasts.",
dueDate: "2023-06-15",
priority: "high",
category: "project",
status: "pending",
createdAt: "2023-06-10",
assignedTo: "You",
completedAt: null
},
{
id: 2,
title: "Team Standup Meeting",
description: "Daily standup with development team. Review blockers and progress on current sprint tasks.",
dueDate: "2023-06-15",
priority: "medium",
category: "meeting",
status: "pending",
createdAt: "2023-06-12",
assignedTo: "You",
completedAt: null
},
{
id: 3,
title: "Update Employee Handbook",
description: "Review and update the remote work policy in the employee handbook to reflect new company guidelines.",
dueDate: "2023-06-20",
priority: "low",
category: "general",
status: "pending",
createdAt: "2023-06-08",
assignedTo: "You",
completedAt: null
},
{
id: 4,
title: "Review job applications",
description: "Screen candidates for the frontend developer position.",
dueDate: "2023-06-14",
priority: "medium",
category: "personal",
status: "completed",
createdAt: "2023-06-05",
assignedTo: "You",
completedAt: "2023-06-14T10:30:00"
}
];
// DOM Elements
const taskForm = document.getElementById('taskForm');
const tasksContainer = document.getElementById('tasksContainer');
const filterButtons = document.querySelectorAll('.filter-btn');
const categoryFilters = document.querySelectorAll('.category-filter');
const searchToggle = document.getElementById('searchToggle');
const searchBox = document.getElementById('searchBox');
const sortTasks = document.getElementById('sortTasks');
// Event Listeners
taskForm.addEventListener('submit', addTask);
searchToggle.addEventListener('click', toggleSearch);
sortTasks.addEventListener('change', sortTasksList);
filterButtons.forEach(btn => {
btn.addEventListener('click', () => filterTasks(btn.getAttribute('data-filter')));
});
categoryFilters.forEach(btn => {
btn.addEventListener('click', () => filterByCategory(btn.getAttribute('data-category')));
});
// Initialize the app
document.addEventListener('DOMContentLoaded', () => {
renderTasks();
updateTaskCounts();
});
// Functions
function addTask(e) {
e.preventDefault();
const title = document.getElementById('taskTitle').value;
const description = document.getElementById('taskDescription').value;
const dueDate = document.getElementById('taskDue').value;
const priority = document.getElementById('taskPriority').value;
const category = document.getElementById('taskCategory').value;
const newTask = {
id: Date.now(),
title,
description: description || "No description provided",
dueDate,
priority,
category,
status: "pending",
createdAt: new Date().toISOString().split('T')[0],
assignedTo: "You",
completedAt: null
};
tasks.unshift(newTask);
renderTasks();
updateTaskCounts();
taskForm.reset();
}
function renderTasks(filter = 'pending', category = 'all') {
tasksContainer.innerHTML = '';
let filteredTasks = tasks.filter(task => {
if (filter === 'pending') return task.status === 'pending';
if (filter === 'completed') return task.status === 'completed';
if (filter === 'today') {
const today = new Date().toISOString().split('T')[0];
return task.dueDate === today;
}
return true;
});
if (category !== 'all') {
filteredTasks = filteredTasks.filter(task => task.category === category);
}
if (filteredTasks.length === 0) {
tasksContainer.innerHTML = `
<div class="text-center py-10">
<i class="fas fa-check-circle text-4xl text-gray-300 mb-3"></i>
<h3 class="text-lg font-medium text-gray-500">No tasks found</h3>
<p class="text-gray-400">Add a new task to get started</p>
</div>
`;
return;
}
filteredTasks.forEach(task => {
const taskEl = createTaskElement(task);
tasksContainer.appendChild(taskEl);
});
}
function createTaskElement(task) {
const taskEl = document.createElement('div');
taskEl.className = `task-item bg-white border border-gray-200 rounded-xl p-5 shadow-sm hover:shadow-md transition cursor-move priority-${task.priority}`;
const priorityBadgeColor = {
high: 'red',
medium: 'yellow',
low: 'green'
};
const categoryBadgeColor = {
general: 'gray',
meeting: 'blue',
project: 'purple',
personal: 'yellow'
};
const today = new Date().toISOString().split('T')[0];
const dueTodayClass = task.dueDate === today ? 'orange' : 'gray';
taskEl.innerHTML = `
<div class="flex items-start justify-between mb-3">
<div class="flex items-center">
<input type="checkbox" class="h-5 w-5 rounded border-gray-300 ${task.status === 'completed' ? 'text-green-600' : 'text-blue-600'} focus:ring-${task.status === 'completed' ? 'green' : 'blue'}-500 mr-3 mt-0.5" ${task.status === 'completed' ? 'checked' : ''} data-id="${task.id}">
<div>
<h3 class="text-lg font-medium ${task.status === 'completed' ? 'text-gray-600 line-through' : 'text-gray-800'}">${task.title}</h3>
<div class="flex items-center mt-1 flex-wrap gap-2">
<span class="px-2 py-1 text-xs rounded-full bg-${priorityBadgeColor[task.priority]}-100 text-${priorityBadgeColor[task.priority]}-800 flex items-center">
<i class="fas ${task.priority === 'high' ? 'fa-exclamation-circle' : task.priority === 'medium' ? 'fa-info-circle' : 'fa-check-circle'} mr-1"></i>
${task.priority.charAt(0).toUpperCase() + task.priority.slice(1)} Priority
</span>
<span class="px-2 py-1 text-xs rounded-full bg-${categoryBadgeColor[task.category]}-100 text-${categoryBadgeColor[task.category]}-800 flex items-center">
<i class="fas ${task.category === 'meeting' ? 'fa-users' : task.category === 'project' ? 'fa-project-diagram' : task.category === 'personal' ? 'fa-user' : 'fa-file-alt'} mr-1"></i>
${task.category.charAt(0).toUpperCase() + task.category.slice(1)}
</span>
${task.dueDate === today ? `
<span class="px-2 py-1 text-xs rounded-full bg-${dueTodayClass}-100 text-${dueTodayClass}-800 flex items-center">
<i class="fas fa-calendar-day mr-1"></i>
Due Today
</span>
` : ''}
</div>
</div>
</div>
<div class="flex space-x-2">
<button class="task-action-btn text-gray-400 hover:text-blue-500 transition" data-id="${task.id}" data-action="edit">
<i class="fas fa-pencil-alt"></i>
</button>
<button class="task-action-btn text-gray-400 hover:text-red-500 transition" data-id="${task.id}" data-action="delete">
<i class="fas fa-trash-alt"></i>
</button>
</div>
</div>
<p class="text-gray-600 mb-4 ${task.status === 'completed' ? 'line-through' : ''}">${task.description}</p>
<div class="flex justify-between items-center text-sm text-gray-500">
<div class="flex items-center">
<i class="fas fa-user-circle mr-1"></i>
<span>Assigned to ${task.assignedTo}</span>
</div>
<span><i class="fas fa-clock mr-1"></i> Created: ${formatDate(task.createdAt)}</span>
</div>
`;
// Add event listeners to action buttons
const checkbox = taskEl.querySelector('input[type="checkbox"]');
const editBtn = taskEl.querySelector('[data-action="edit"]');
const deleteBtn = taskEl.querySelector('[data-action="delete"]');
checkbox.addEventListener('change', () => toggleTaskStatus(task.id));
editBtn.addEventListener('click', () => editTask(task.id));
deleteBtn.addEventListener('click', () => deleteTask(task.id));
return taskEl;
}
function toggleTaskStatus(taskId) {
const taskIndex = tasks.findIndex(task => task.id == taskId);
if (taskIndex !== -1) {
tasks[taskIndex].status = tasks[taskIndex].status === 'pending' ? 'completed' : 'pending';
tasks[taskIndex].completedAt = tasks[taskIndex].status === 'completed' ? new Date().toISOString() : null;
renderTasks('pending');
updateTaskCounts();
}
}
function editTask(taskId) {
const task = tasks.find(task => task.id == taskId);
if (task) {
// In a real app, we would show a modal/pre-fill the form
document.getElementById('taskTitle').value = task.title;
document.getElementById('taskDescription').value = task.description;
document.getElementById('taskDue').value = task.dueDate;
document.getElementById('taskPriority').value = task.priority;
document.getElementById('taskCategory').value = task.category;
// Remove the task being edited
tasks = tasks.filter(t => t.id != taskId);
alert('Task loaded for editing. Update the fields and click "Add Task" to save changes.');
renderTasks();
updateTaskCounts();
}
}
function deleteTask(taskId) {
if (confirm('Are you sure you want to delete this task?')) {
tasks = tasks.filter(task => task.id != taskId);
renderTasks();
updateTaskCounts();
}
}
function filterTasks(filter) {
filterButtons.forEach(btn => btn.classList.remove('active-filter'));
document.querySelector(`.filter-btn[data-filter="${filter}"]`).classList.add('active-filter');
renderTasks(filter);
}
function filterByCategory(category) {
const currentFilter = document.querySelector('.filter-btn.active-filter').getAttribute('data-filter');
categoryFilters.forEach(btn => btn.classList.remove('active-filter'));
document.querySelector(`.category-filter[data-category="${category}"]`).classList.add('active-filter');
renderTasks(currentFilter, category);
}
function toggleSearch() {
searchBox.classList.toggle('hidden');
}
function sortTasksList() {
const sortValue = sortTasks.value;
if (sortValue === 'date-asc') {
tasks.sort((a, b) => new Date(a.createdAt) - new Date(b.createdAt));
} else if (sortValue === 'date-desc') {
tasks.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));
} else if (sortValue === 'priority') {
const priorityOrder = { high: 1, medium: 2, low: 3 };
tasks.sort((a, b) => priorityOrder[a.priority] - priorityOrder[b.priority]);
}
renderTasks(document.querySelector('.filter-btn.active-filter').getAttribute('data-filter'));
}
function updateTaskCounts() {
// Task status counts
const totalTasks = tasks.length;
const pendingTasks = tasks.filter(task => task.status === 'pending').length;
const completedTasks = tasks.filter(task => task.status === 'completed').length;
// Update status counts
document.querySelector('[data-filter="all"] span:last-child').textContent = totalTasks;
document.querySelector('[data-filter="pending"] span:last-child').textContent = pendingTasks;
document.querySelector('[data-filter="completed"] span:last-child').textContent = completedTasks;
// Update today's tasks count (example)
const todayTasks = tasks.filter(task => {
const today = new Date().toISOString().split('T')[0];
return task.dueDate === today && task.status === 'pending';
}).length;
document.querySelector('[data-filter="today"] span:last-child').textContent = todayTasks;
// Update category counts
const categories = ['general', 'meeting', 'project', 'personal'];
categories.forEach(category => {
const count = tasks.filter(task => task.category === category).length;
document.querySelector(`[data-category="${category}"] span:last-child`).textContent = count;
});
// Update the pending tasks header
const pendingHeader = document.querySelector('#tasksContainer').previousElementSibling.querySelector('h2');
if (pendingHeader) {
pendingHeader.textContent = `Pending Tasks (${pendingTasks})`;
}
}
function formatDate(dateString) {
const options = { year: 'numeric', month: 'short', day: 'numeric' };
return new Date(dateString).toLocaleDateString('en-US', options);
}
</script>
</body>
</html>