-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditTask.html
254 lines (234 loc) · 9.66 KB
/
editTask.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Task</title>
<link rel="stylesheet" href="css/editTask.css">
<link rel="stylesheet" href="css/header.css">
<link rel="stylesheet" href="css/side.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"/>
</head>
<body>
<div class="hamburger-menu">
<i class="fas fa-bars"></i>
</div>
<!-- Sidebar for large screens -->
<div class="sidebar">
<div class="logo">
<ul class="menu">
<li class="active">
<a href="dashboard.html">
<i class="fas fa-tachometer-alt"></i>
<span>Dashboard</span>
</a>
</li>
<li>
<a href="profile.html">
<i class="fas fa-user"></i>
<span>Profile</span>
</a>
</li>
<li>
<a href="addTask.html">
<i class="fas fa-plus"></i>
<span>Add Task</span>
</a>
</li>
<li>
<a href="all-tasks.html">
<i class="fas fa-tasks"></i>
<span>All Tasks</span>
</a>
</li>
<li>
<a href="completed-tasks.html">
<i class="fas fa-check"></i>
<span>Completed Tasks</span>
</a>
</li>
<li>
<a href="pending.html">
<i class="fas fa-clock"></i>
<span>Pending Tasks</span>
</a>
</li>
<li>
<a href="in-progress.html">
<i class="fas fa-spinner"></i>
<span>In-progress</span>
</a>
</li>
<li class="logout">
<a href="#"> <i class="fas fa-sign-out-alt"></i>
<span>Logout</span>
</a>
</li>
</ul>
</div>
</div>
<!-- Navbar for small screens -->
<div class="navbar">
<div class="navbar-header">
<span>Menu</span>
<i class="fas fa-times close-icon"></i>
</div>
<ul class="nav-menu">
<li><a href="#">Dashboard</a></li>
<li><a href="profile.html">Profile</a></li>
<li><a href="addTask.html">Add Tasks</a></li>
<li><a href="all-tasks.html">All Tasks</a></li>
<li><a href="completed-tasks.html">Completed Tasks</a></li>
<li><a href="pending.html">Pending Tasks</a></li>
<li><a href="in-progress.html">In-Progress Tasks</a></li>
<li><a href="#">Logout</a></li>
</ul>
</div>
<!-- HEADER SECTION -->
<div class="main--content">
<!--HEADER SECTION-->
<div class="header--wrapper">
<div class="header--title">
<h2>TaskFlow</h2>
<span>Dashboard</span>
</div>
<!-- <div class="user--info">
<div class="search--box">
<i class="fa-solid fa-search"></i>
<input type="text" placeholder="Search"/>
</div> -->
<!-- <div class="welcome-message">
Welcome Dami!
</div> -->
</div>
<!--EDIT TASKS TABLE-->
<div class="form-main-container">
<div class="form-container">
<h2>Edit Task</h2>
<form id="editTaskForm">
<div class="form-group">
<label for="edit-title">Title</label>
<input type="text" id="edit-title" name="title" required>
</div>
<div class="form-group">
<label for="edit-description">Description</label>
<textarea id="edit-description" name="description" required></textarea>
</div>
<div class="form-group">
<label for="edit-deadline">Deadline</label>
<input type="date" id="edit-deadline" name="deadline" required>
</div>
<div class="form-group">
<label for="edit-priority">Priority Level</label>
<select id="edit-priority" name="priority" required>
<option value="LOW">Low</option>
<option value="MEDIUM">Medium</option>
<option value="HIGH">High</option>
</select>
</div>
<div class="form-group">
<label for="edit-status">Status</label>
<select id="edit-status" name="status" required>
<option value="PENDING">Pending</option>
<option value="IN_PROGRESS">In Progress</option>
<option value="COMPLETED">Completed</option>
</select>
</div>
<button type="submit" class="btn" id="updateBtn">
<span id="updateBtnText">Update Task</span>
<span id="updateSpinner" class="spinner" style="display: none;">
<i class="fa fa-spinner fa-spin"></i>
</span>
</button>
</form>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const editTaskForm = document.getElementById('editTaskForm');
const updateBtnText = document.getElementById('updateBtnText');
const updateSpinner = document.getElementById('updateSpinner');
// Function to get the task ID from URL query parameters
function getTaskIdFromUrl() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get('taskId');
}
// Function to fetch task details and populate the form
async function fetchTaskDetails(taskId) {
try {
const response = await fetch(`http://localhost:8080/api/tasks/get-task/${taskId}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.getItem('Token') // Assuming token is stored in localStorage
}
});
if (!response.ok) {
throw new Error('Failed to fetch task details');
}
const task = await response.json();
document.getElementById('edit-title').value = task.taskResponseInfo.title;
document.getElementById('edit-description').value = task.taskResponseInfo.description;
document.getElementById('edit-deadline').value = task.taskResponseInfo.deadline.split('T')[0]; // Extract date part
document.getElementById('edit-priority').value = task.taskResponseInfo.priorityLevel;
document.getElementById('edit-status').value = task.taskResponseInfo.status;
} catch (error) {
console.error('Error fetching task details:', error);
alert('Error fetching task details. Please try again.');
}
}
// Function to update task details
async function updateTask(event) {
event.preventDefault();
const taskId = getTaskIdFromUrl();
const updatedTask = {
title: editTaskForm.title.value,
description: editTaskForm.description.value,
deadline: editTaskForm.deadline.value + 'T23:59:59', // Format deadline to include time
priorityLevel: editTaskForm.priority.value,
status: editTaskForm.status.value
};
try {
// Show spinner and hide text
updateBtnText.style.display = 'none';
updateSpinner.style.display = 'inline-block';
const response = await fetch(`http://localhost:8080/api/tasks/edit-task/${taskId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.getItem('Token')
},
body: JSON.stringify(updatedTask)
});
if (!response.ok) {
throw new Error('Failed to update task');
}
const result = await response.json();
alert(result.responseMessage);
window.location.href = 'dashboard.html'; // Redirect to dashboard after successful update
} catch (error) {
console.error('Error updating task:', error);
alert('Error updating task. Please try again.');
} finally {
// Hide spinner and show text
updateBtnText.style.display = 'inline';
updateSpinner.style.display = 'none';
}
}
// Get the task ID from URL and fetch task details
const taskId = getTaskIdFromUrl();
if (taskId) {
fetchTaskDetails(taskId);
} else {
alert('No task ID found. Please try again.');
window.location.href = 'dashboard.html'; // Redirect to dashboard if no task ID found
}
// Event listener for form submission
editTaskForm.addEventListener('submit', updateTask);
});
</script>
<script src="js/dashboard.js"></script>
</body>
</html>