-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpending.html
242 lines (220 loc) · 9.3 KB
/
pending.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pending Tasks</title>
<link rel="stylesheet" href="css/pending.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"/>
<style>
/* Styles for the spinner */
.spinner {
display: none; /* Hidden by default */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1000;
background-color: rgba(255, 255, 255, 0.8);
padding: 10px 20px;
border-radius: 5px;
}
.spinner i {
animation: spin 1s linear infinite; /* CSS animation for spinning */
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</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><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 class="active"><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">
<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>
</div>
<!-- PENDING TASKS TABLE -->
<div class="main-table-container">
<div id="spinner" class="spinner">
<i class="fas fa-spinner fa-spin"></i> Loading...
</div>
<div class="table-container" style="display: none;">
<table id="taskTable">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th>Deadline</th>
<th>Priority Level</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<!-- Dynamic rows will be inserted here -->
</tbody>
</table>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Check if token exists in localStorage
if (!localStorage.getItem('Token')) {
// Redirect to login page if token is missing
window.location.href = '/auth/login.html';
return;
}
fetchPendingTasks();
fetchUserProfile();
document.querySelector('.logout a').addEventListener('click', logout);
});
async function fetchUserProfile() {
try {
const response = await fetch('http://localhost:8080/api/user/profile', {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + localStorage.getItem('Token')
}
});
if (!response.ok) {
throw new Error('Failed to fetch user profile');
}
const userProfile = await response.json();
updateWelcomeMessage(userProfile.userProfileResponseInfo.firstName);
} catch (error) {
console.error('Error fetching user profile:', error);
// Handle error if needed
}
}
function updateWelcomeMessage(firstName) {
const welcomeMessage = document.querySelector('.welcome-message');
if (welcomeMessage) {
welcomeMessage.textContent = `Welcome ${firstName}!`;
}
}
// Function to fetch pending tasks
async function fetchPendingTasks() {
try {
const spinner = document.getElementById('spinner');
const tableContainer = document.querySelector('.table-container');
spinner.style.display = 'block'; // Show spinner
const response = await fetch('http://localhost:8080/api/tasks/status/PENDING', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${localStorage.getItem('Token')}`
}
});
if (response.ok) {
const tasks = await response.json();
populateTable(tasks);
spinner.style.display = 'none'; // Hide spinner
tableContainer.style.display = 'block'; // Show table
} else {
console.error('Failed to fetch tasks:', response.statusText);
alert('Error fetching pending tasks. Please try again.');
}
} catch (error) {
console.error('Error:', error);
}
}
// Function to populate the table with tasks
function populateTable(tasks) {
const tableBody = document.querySelector('#taskTable tbody');
tableBody.innerHTML = '';
tasks.forEach(task => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${task.taskResponseInfo.title}</td>
<td>${task.taskResponseInfo.description}</td>
<td>${task.taskResponseInfo.deadline}</td>
<td>${task.taskResponseInfo.priorityLevel}</td>
<td>${task.taskResponseInfo.status}</td>
<td>
<a href="editTask.html?taskId=${task.taskResponseInfo.id}" class="edit-btn">Edit</a><br><br>
<a href="javascript:void(0);" class="delete-btn" onclick="deleteTask(${task.taskResponseInfo.id})">Delete</a>
</td>
`;
tableBody.appendChild(row);
});
}
// Function to delete a task (needs implementation on the backend)
async function deleteTask(id) {
try {
const response = await fetch(`http://localhost:8080/api/tasks/delete-task/${id}`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${localStorage.getItem('Token')}`
}
});
if (response.ok) {
// Remove the task row from the table
fetchPendingTasks(); // Refresh the table after deletion
} else {
console.error('Failed to delete task:', response.statusText);
alert('Error deleting task. Please try again.');
}
} catch (error) {
console.error('Error:', error);
}
}
async function logout(event) {
event.preventDefault();
localStorage.removeItem('Token');
window.location.href = '/auth/login.html';
}
</script>
</body>
</html>