251 lines
5.9 KiB
Plaintext
251 lines
5.9 KiB
Plaintext
<!-- views/inusers.ejs -->
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>In-House Users</title>
|
|
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
|
|
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.4/xlsx.full.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.5/xlsx.full.min.js"></script>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
font-family: 'Arial', sans-serif;
|
|
}
|
|
|
|
#sidebar {
|
|
height: 100%;
|
|
width: 250px;
|
|
position: fixed;
|
|
background-color: #333;
|
|
padding-top: 60px;
|
|
transition: 0.5s;
|
|
}
|
|
|
|
#sidebar img {
|
|
width: 100%;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
#sidebar a {
|
|
padding: 10px 15px;
|
|
text-decoration: none;
|
|
font-size: 18px;
|
|
color: white;
|
|
display: block;
|
|
transition: 0.3s;
|
|
}
|
|
|
|
#sidebar a:hover {
|
|
background-color: #555;
|
|
}
|
|
|
|
#content {
|
|
margin-left: 250px;
|
|
padding: 16px;
|
|
}
|
|
|
|
@media screen and (max-width: 600px) {
|
|
#sidebar {
|
|
width: 0;
|
|
overflow-x: hidden;
|
|
}
|
|
|
|
#content {
|
|
margin-left: 0;
|
|
}
|
|
}
|
|
|
|
#sidebarCollapse {
|
|
width: 40px;
|
|
height: 40px;
|
|
position: absolute;
|
|
top: 10px;
|
|
left: 10px;
|
|
cursor: pointer;
|
|
z-index: 1;
|
|
}
|
|
|
|
#sidebarCollapse span {
|
|
display: block;
|
|
background: white;
|
|
height: 5px;
|
|
width: 30px;
|
|
margin: 6px auto;
|
|
transition: 0.3s;
|
|
}
|
|
|
|
#sidebarCollapse:hover span:nth-child(1) {
|
|
transform: rotate(-45deg) translate(-5px, 6px);
|
|
}
|
|
|
|
#sidebarCollapse:hover span:nth-child(2) {
|
|
opacity: 0;
|
|
}
|
|
|
|
#sidebarCollapse:hover span:nth-child(3) {
|
|
transform: rotate(45deg) translate(-5px, -6px);
|
|
}
|
|
|
|
/* Add additional styles specific to inusers.ejs below */
|
|
#userDataContainer {
|
|
margin-top: 20px;
|
|
}
|
|
|
|
table {
|
|
border-collapse: collapse;
|
|
width: 100%;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
th, td {
|
|
border: 1px solid #dddddd;
|
|
text-align: left;
|
|
padding: 12px;
|
|
}
|
|
|
|
th {
|
|
background-color: #f2f2f2;
|
|
}
|
|
|
|
tr:hover {
|
|
background-color: #f5f5f5;
|
|
}
|
|
|
|
td {
|
|
white-space: nowrap;
|
|
}
|
|
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="sidebar">
|
|
<img src="LOGO.PNG" alt="Custom Image">
|
|
<div id="sidebarCollapse">
|
|
<span></span>
|
|
<span></span>
|
|
<span></span>
|
|
</div>
|
|
<a href="#" id="userDataLink">User Data</a>
|
|
<a href="/inusers/edituserdata">Edit User Data</a>
|
|
<a href="/home" id="homeLink">Home</a>
|
|
</div>
|
|
|
|
<div id="content">
|
|
<h2>Welcome to the In-House Users Page</h2>
|
|
<div id="downloadButtonContainer">
|
|
<button id="downloadButton">Download as Excel</button>
|
|
</div>
|
|
<div id="userDataContainer">
|
|
<h3>All Users</h3>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Username</th>
|
|
<th>Email</th>
|
|
<th>Password</th>
|
|
<th>Last Login</th>
|
|
<th>Job Title</th>
|
|
<!-- Add more table headers as needed -->
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<% if (allUsers && allUsers.length > 0) { %>
|
|
<% allUsers.forEach(user => { %>
|
|
<tr>
|
|
<td><%= user.name %></td>
|
|
<td><%= user.username %></td>
|
|
<td><%= user.email %></td>
|
|
<td><%= user.password %></td>
|
|
<td><%= new Date(user.lastLogin).toLocaleString('en-US', { timeZone: 'Asia/Singapore' }) %></td>
|
|
<td><%= user.jobTitle %></td>
|
|
<!-- Add more table data cells as needed -->
|
|
</tr>
|
|
<% }); %>
|
|
<% } else { %>
|
|
<tr>
|
|
<td colspan="6">No users available.</td>
|
|
</tr>
|
|
<% } %>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- Additional content for In-House Users page goes here -->
|
|
<!-- Additional content for In-House Users page goes here -->
|
|
|
|
<!-- Additional content for In-House Users page goes here -->
|
|
|
|
<!-- Additional content for In-House Users page goes here -->
|
|
|
|
<script>
|
|
// Use the JSON data provided by the server
|
|
const allUsers = <%- JSON.stringify(allUsers) %>;
|
|
|
|
|
|
// Attach click event to the download button
|
|
document.getElementById('downloadButton').addEventListener('click', function () {
|
|
console.log('Download button clicked');
|
|
downloadExcel(allUsers);
|
|
});
|
|
|
|
// Function to download data as Excel
|
|
function downloadExcel(allUsers) {
|
|
if (allUsers && allUsers.length > 0) {
|
|
const data = allUsers.map(user => [
|
|
user.name,
|
|
user.username,
|
|
user.email,
|
|
user.password,
|
|
new Date(user.lastLogin).toLocaleString('en-US', { timeZone: 'Asia/Singapore' }),
|
|
user.jobTitle
|
|
]);
|
|
|
|
const ws = XLSX.utils.aoa_to_sheet([['Name', 'Username', 'Email', 'Password', 'Last Login', 'Job Title'], ...data]);
|
|
const wb = XLSX.utils.book_new();
|
|
XLSX.utils.book_append_sheet(wb, ws, 'All Users');
|
|
|
|
// Use the correct MIME type for the blob
|
|
const blob = XLSX.write(wb, { bookType: 'xlsx', mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
|
|
|
// Create a Blob containing the Excel file data
|
|
const blobData = new Blob([blob], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
|
|
|
// Create a Blob URL
|
|
const blobUrl = URL.createObjectURL(blobData);
|
|
|
|
// Create an anchor element and trigger the download
|
|
const a = document.createElement('a');
|
|
a.href = blobUrl;
|
|
a.download = 'user_data.xlsx';
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
|
|
// Clean up resources
|
|
document.body.removeChild(a);
|
|
URL.revokeObjectURL(blobUrl);
|
|
} else {
|
|
console.error('No data available for download.');
|
|
}
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|