-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.html
413 lines (379 loc) · 12.9 KB
/
dashboard.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Dashboard</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
background-color: #f7f7f7;
}
.sidebar {
background-color: #001659;
color: white;
height: 100vh;
position: sticky;
top: 0;
}
.sidebar a {
color: white;
font-size: 18px;
}
.sidebar a.active {
background-color: #ff5e14;
color: white;
}
.main-content {
padding: 20px;
min-height: 100vh;
background-color: #f7f7f7;
}
.btn-primary {
background-color: #ff5e14;
border-color: #ff5e14;
}
.btn-primary:hover {
background-color: #e55d12;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<!-- Sidebar -->
<div class="col-md-3 sidebar p-4">
<h2 class="text-center">Admin Dashboard</h2>
<ul class="nav flex-column mt-4">
<li class="nav-item">
<a href="#" class="nav-link " id="employeeLink">Employee Information</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link" id="emailLink">Email Information</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link" id="messageLink">Message Information</a>
</li>
<li class="nav-item">
<a href="index.html" class="nav-link">Back to Home</a>
</li>
</ul>
</div>
<!-- Main Content -->
<div class="col-md-9 main-content">
<!-- Employee Section -->
<div id="employeeSection">
<h3>Employee Management</h3>
<h4>Total Employees: <span id="employeeCount" class="badge bg-danger"></span></h4>
<!-- Employee Form -->
<form id="employeeForm" class="mb-4">
<div class="mb-3">
<label for="name" class="form-label">Employee Name</label>
<input type="text" class="form-control" id="name" required>
</div>
<div class="mb-3">
<label for="position" class="form-label">Position</label>
<input type="text" class="form-control" id="position" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" required>
</div>
<div class="mb-3">
<label for="phone" class="form-label">Phone</label>
<input type="text" class="form-control" id="phone" required>
</div>
<button type="submit" class="btn btn-primary">Add Employee</button>
</form>
<!-- Employee Table -->
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Email</th>
<th>Phone</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="employeeTable">
<!-- Employees will be dynamically populated here -->
</tbody>
</table>
</div>
<!-- Email Section -->
<div id="emailSection" style="display: none;">
<h3>Email Submissions</h3>
<!-- Email Form -->
<form id="emailForm" class="mb-4">
<div class="mb-3">
<label for="adminEmail" class="form-label">Admin Email</label>
<input type="email" class="form-control" id="adminEmail" required>
</div>
<button type="submit" class="btn btn-primary">Add Email</button>
</form>
<!-- Email Table -->
<table class="table table-striped">
<thead>
<tr>
<th>Email</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="emailTable">
<!-- Emails will be dynamically populated here -->
</tbody>
</table>
</div>
<!-- Message Section -->
<div id="messageSection" style="display: none;">
<h3>Message Submissions</h3>
<!-- Message Table -->
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Message</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="messageTable">
<!-- Messages will be dynamically populated here -->
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Bootstrap Modal for Editing Employee -->
<div class="modal fade" id="editEmployeeModal" tabindex="-1" aria-labelledby="editEmployeeModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editEmployeeModalLabel">Edit Employee</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form id="editEmployeeForm">
<input type="hidden" id="employeeId">
<div class="mb-3">
<label for="editName" class="form-label">Employee Name</label>
<input type="text" class="form-control" id="editName" required>
</div>
<div class="mb-3">
<label for="editPosition" class="form-label">Position</label>
<input type="text" class="form-control" id="editPosition" required>
</div>
<div class="mb-3">
<label for="editEmail" class="form-label">Email</label>
<input type="email" class="form-control" id="editEmail" required>
</div>
<div class="mb-3">
<label for="editPhone" class="form-label">Phone</label>
<input type="text" class="form-control" id="editPhone" required>
</div>
<button type="submit" class="btn btn-primary">Update Employee</button>
</form>
</div>
</div>
</div>
</div>
<!-- JavaScript -->
<script>
const apiBaseUrl = 'http://localhost:5000'; // API base URL
// Fetch and Display Employees
function fetchEmployees() {
fetch(`${apiBaseUrl}/employees`)
.then(response => response.json())
.then(data => {
const employeeTable = document.getElementById("employeeTable");
employeeTable.innerHTML = data
.map(
employee => `
<tr>
<td>${employee.name}</td>
<td>${employee.position}</td>
<td>${employee.email}</td>
<td>${employee.phone}</td>
<td>
<button class="btn btn-sm btn-primary" onclick="editEmployee('${employee._id}', '${employee.name}', '${employee.position}', '${employee.email}', '${employee.phone}')">Edit</button>
<button class="btn btn-sm btn-danger" onclick="deleteEmployee('${employee._id}')">Delete</button>
</td>
</tr>`
)
.join("");
// Update employee count
document.getElementById("employeeCount").textContent = data.length;
});
}
// Fetch and Display Emails
function fetchEmails() {
fetch(`${apiBaseUrl}/emails`)
.then(response => response.json())
.then(data => {
const emailTable = document.getElementById("emailTable");
emailTable.innerHTML = data
.map(
email => `
<tr>
<td>${email.email}</td>
<td>
<button class="btn btn-sm btn-danger" onclick="deleteEmail('${email._id}')">Delete</button>
</td>
</tr>`
)
.join("");
});
}
// Fetch and Display Messages
function fetchMessages() {
fetch(`${apiBaseUrl}/form`)
.then(response => response.json())
.then(data => {
const messageTable = document.getElementById("messageTable");
messageTable.innerHTML = data
.map(
message => `
<tr>
<td>${message.name}</td>
<td>${message.email}</td>
<td>${message.phone}</td>
<td>${message.message}</td>
<td>
<button class="btn btn-sm btn-danger" onclick="deleteMessage('${message._id}')">Delete</button>
</td>
</tr>`
)
.join("");
});
}
// Show Edit Employee Modal
function editEmployee(id, name, position, email, phone) {
document.getElementById("employeeId").value = id;
document.getElementById("editName").value = name;
document.getElementById("editPosition").value = position;
document.getElementById("editEmail").value = email;
document.getElementById("editPhone").value = phone;
// Show the modal
new bootstrap.Modal(document.getElementById('editEmployeeModal')).show();
}
// Handle Edit Employee Form Submission
document.getElementById("editEmployeeForm").addEventListener("submit", function(e) {
e.preventDefault();
const id = document.getElementById("employeeId").value;
const name = document.getElementById("editName").value;
const position = document.getElementById("editPosition").value;
const email = document.getElementById("editEmail").value;
const phone = document.getElementById("editPhone").value;
fetch(`${apiBaseUrl}/employees/${id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name, position, email, phone })
})
.then(response => response.json())
.then(() => {
fetchEmployees();
new bootstrap.Modal(document.getElementById('editEmployeeModal')).hide();
});
});
// Handle Employee Form Submission
document.getElementById("employeeForm").addEventListener("submit", function(e) {
e.preventDefault();
const name = document.getElementById("name").value;
const position = document.getElementById("position").value;
const email = document.getElementById("email").value;
const phone = document.getElementById("phone").value;
fetch(`${apiBaseUrl}/employees`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name, position, email, phone })
})
.then(response => response.json())
.then(() => {
fetchEmployees();
document.getElementById("employeeForm").reset();
});
});
// Handle Email Form Submission
document.getElementById("emailForm").addEventListener("submit", function(e) {
e.preventDefault();
const adminEmail = document.getElementById("adminEmail").value;
fetch(`${apiBaseUrl}/emails`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ email: adminEmail })
})
.then(response => response.json())
.then(() => {
fetchEmails();
document.getElementById("emailForm").reset();
});
});
// Delete Employee
function deleteEmployee(id) {
fetch(`${apiBaseUrl}/employees/${id}`, {
method: 'DELETE'
})
.then(response => response.json())
.then(() => {
fetchEmployees();
});
}
// Delete Email
function deleteEmail(id) {
fetch(`${apiBaseUrl}/emails/${id}`, {
method: 'DELETE'
})
.then(response => response.json())
.then(() => {
fetchEmails();
});
}
// Delete Message
function deleteMessage(id) {
fetch(`${apiBaseUrl}/form/${id}`, {
method: 'DELETE'
})
.then(response => response.json())
.then(() => {
fetchMessages();
});
}
// Handle Tab Switching
document.getElementById("employeeLink").addEventListener("click", function() {
document.getElementById("employeeSection").style.display = 'block';
document.getElementById("emailSection").style.display = 'none';
document.getElementById("messageSection").style.display = 'none';
fetchEmployees();
});
document.getElementById("emailLink").addEventListener("click", function() {
document.getElementById("employeeSection").style.display = 'none';
document.getElementById("emailSection").style.display = 'block';
document.getElementById("messageSection").style.display = 'none';
fetchEmails();
});
document.getElementById("messageLink").addEventListener("click", function() {
document.getElementById("employeeSection").style.display = 'none';
document.getElementById("emailSection").style.display = 'none';
document.getElementById("messageSection").style.display = 'block';
fetchMessages();
});
// Initialize
document.addEventListener("DOMContentLoaded", function() {
fetchEmployees();
fetchEmails();
fetchMessages();
});
</script>
<!-- Bootstrap JS Bundle -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>