-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.html
300 lines (261 loc) · 9.47 KB
/
1.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Task Manager</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
#task-container {
max-width: 600px; /* Increased max-width */
width: 100%;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 5px;
}
#task-form {
display: flex;
flex-direction: column;
align-items: center;
}
#task-form label {
margin-bottom: 5px;
}
#task-form input {
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 3px;
width: 100%;
box-sizing: border-box;
}
#task-form button {
cursor: pointer;
padding: 10px;
border-radius: 3px;
background-color: #4481eb;
color: white;
border: none;
width: 100%;
box-sizing: border-box;
}
#task-list {
list-style: none;
padding: 0;
}
.task-item {
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #ccc;
padding: 10px 0;
margin: 10px 0;
}
.task-content {
flex: 1; /* Allows task content to expand */
}
.task-item button {
cursor: pointer;
padding: 5px 10px;
border-radius: 3px;
margin-left: 5px; /* Add some space between buttons */
}
.edit-task {
background-color: #5bc0de; /* Edit button color */
color: white;
border: none;
}
.delete-task {
background-color: #d9534f; /* Delete button color */
color: white;
border: none;
}
.complete-task,
.pending-task,
.ongoing-task {
cursor: pointer;
padding: 5px 10px;
border-radius: 3px;
color: white;
border: none;
}
.complete-task {
background-color: #4CAF50;
}
.pending-task {
background-color: #f0ad4e;
}
.ongoing-task {
background-color: #5bc0de;
}
.navbar {
position: fixed;
top: 0;
right: 0;
background-color: #4481eb;
padding: 10px;
}
.navbar a {
color: white;
text-decoration: none;
margin-left: 10px;
}
</style>
</head>
<body>
<div id="task-container">
<h2>Task Manager</h2>
<form id="task-form">
<label for="task">New Task:</label>
<input type="text" id="task" placeholder="Enter task" required>
<label for="deadline">Deadline:</label>
<input type="date" id="deadline" required>
<label for="startDate">Start Date:</label>
<input type="date" id="startDate" required>
<button type="submit">Add New Task</button>
</form>
<div id="task-summary"></div>
<ul id="task-list"></ul>
</div>
<div class="navbar">
<a href="2.html">Home</a>
<a href="about.html">About</a>
<a href="3.html">Contact</a>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
const taskForm = document.getElementById('task-form');
const taskList = document.getElementById('task-list');
const taskSummary = document.getElementById('task-summary');
let tasks = JSON.parse(localStorage.getItem('tasks')) || [];
// Load tasks from localStorage on page load
if (tasks.length > 0) {
tasks.forEach(task => {
addTaskToDOM(task);
});
}
taskForm.addEventListener('submit', function (event) {
event.preventDefault();
addTask();
});
taskList.addEventListener('click', function (event) {
const target = event.target;
if (target.classList.contains('delete-task')) {
deleteTask(target.closest('.task-item'));
} else if (target.classList.contains('edit-task')) {
editTask(target.closest('.task-item'));
} else if (target.classList.contains('complete-task')) {
completeTask(target.closest('.task-item'));
} else if (target.classList.contains('pending-task')) {
pendingTask(target.closest('.task-item'));
} else if (target.classList.contains('ongoing-task')) {
ongoingTask(target.closest('.task-item'));
}
});
function addTask() {
const taskInput = document.getElementById('task');
const taskDeadline = document.getElementById('deadline').value;
const taskStartDate = document.getElementById('startDate').value;
const taskText = taskInput.value.trim();
if (taskText !== '') {
const taskItem = {
text: taskText,
deadline: taskDeadline,
startDate: taskStartDate,
status: 'pending'
};
tasks.push(taskItem);
addTaskToDOM(taskItem);
updateLocalStorage();
taskInput.value = '';
document.getElementById('deadline').value = '';
document.getElementById('startDate').value = '';
updateTaskSummary();
}
}
function deleteTask(taskItem) {
const taskIndex = Array.from(taskList.children).indexOf(taskItem);
taskList.removeChild(taskItem);
tasks.splice(taskIndex, 1);
updateLocalStorage();
updateTaskSummary();
}
function editTask(taskItem) {
const span = taskItem.querySelector('span');
const newText = prompt('Edit task:', span.textContent);
if (newText !== null) {
span.textContent = newText;
const taskIndex = Array.from(taskList.children).indexOf(taskItem);
tasks[taskIndex].text = newText;
updateLocalStorage();
}
}
function completeTask(taskItem) {
taskItem.classList.remove('pending', 'ongoing');
taskItem.classList.add('completed');
updateTaskStatus(taskItem, 'completed');
}
function pendingTask(taskItem) {
taskItem.classList.remove('completed', 'ongoing');
taskItem.classList.add('pending');
updateTaskStatus(taskItem, 'pending');
}
function ongoingTask(taskItem) {
taskItem.classList.remove('completed', 'pending');
taskItem.classList.add('ongoing');
updateTaskStatus(taskItem, 'ongoing');
}
function addTaskToDOM(taskItem) {
const taskListItem = document.createElement('li');
taskListItem.className = 'task-item ' + taskItem.status;
taskListItem.innerHTML = `
<div class="task-content">
<span>${taskItem.text}</span>
<span>Deadline: ${taskItem.deadline}</span>
<span>Start Date: ${taskItem.startDate}</span>
</div>
<div class="task-buttons">
<button class="edit-task">Edit</button>
<button class="delete-task">Delete</button>
<button class="complete-task">Complete</button>
<button class="pending-task">Pending</button>
<button class="ongoing-task">Ongoing</button>
</div>
`;
taskList.appendChild(taskListItem);
}
function updateLocalStorage() {
localStorage.setItem('tasks', JSON.stringify(tasks));
}
function updateTaskSummary() {
const totalTasks = tasks.length;
const completedTasks = tasks.filter(task => task.status === 'completed').length;
const pendingTasks = tasks.filter(task => task.status === 'pending').length;
const ongoingTasks = tasks.filter(task => task.status === 'ongoing').length;
taskSummary.innerHTML = `
Total Tasks: ${totalTasks} <br>
Completed Tasks: ${completedTasks} <br>
Pending Tasks: ${pendingTasks} <br>
Ongoing Tasks: ${ongoingTasks}
`;
}
function updateTaskStatus(taskItem, status) {
const taskIndex = Array.from(taskList.children).indexOf(taskItem);
tasks[taskIndex].status = status;
updateLocalStorage();
updateTaskSummary();
}
});
</script>
</body>
</html>