311 lines
9.8 KiB
HTML
311 lines
9.8 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Dashboard</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100vh;
|
|
overflow: hidden;
|
|
}
|
|
.banner {
|
|
width: 100%;
|
|
background-color: #f1f1f1;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 20px;
|
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
|
position: relative;
|
|
}
|
|
.banner img {
|
|
max-height: 200px;
|
|
}
|
|
.menu-button {
|
|
background: none;
|
|
border: none;
|
|
font-size: 24px;
|
|
cursor: pointer;
|
|
position: absolute;
|
|
top: 0;
|
|
left: 20px;
|
|
}
|
|
.drawer {
|
|
width: 250px;
|
|
background-color: #f9f9f9;
|
|
color: black;
|
|
height: 100%;
|
|
position: fixed;
|
|
top: 0;
|
|
left: -250px;
|
|
transition: left 0.3s;
|
|
z-index: 1000;
|
|
}
|
|
.drawer.open {
|
|
left: 0;
|
|
}
|
|
.drawer-header {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
padding: 15px;
|
|
background-color: #f9f9f9;
|
|
}
|
|
.drawer-header img {
|
|
max-height: 200px;
|
|
margin-bottom: 15px;
|
|
}
|
|
.drawer-header button {
|
|
background: none;
|
|
border: none;
|
|
color: black;
|
|
font-size: 24px;
|
|
cursor: pointer;
|
|
align-self: flex-end;
|
|
}
|
|
.drawer-content {
|
|
padding: 20px;
|
|
}
|
|
.drawer-content a {
|
|
display: block;
|
|
color: black;
|
|
text-decoration: none;
|
|
padding: 10px 0;
|
|
border-bottom: 1px solid #007BFF;
|
|
}
|
|
.main-content {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: flex-start;
|
|
transition: margin-left 0.3s;
|
|
overflow-y: auto; /* Enable vertical scrolling */
|
|
}
|
|
.main-content.open {
|
|
margin-left: 250px;
|
|
}
|
|
.main-header {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
padding: 15px;
|
|
width: 100%;
|
|
}
|
|
.main-header img {
|
|
max-height: 200px;
|
|
}
|
|
.main-header h1 {
|
|
margin: 10px 0;
|
|
}
|
|
.content {
|
|
padding: 20px;
|
|
width: 100%;
|
|
max-width: 1200px;
|
|
display: flex;
|
|
justify-content: space-around;
|
|
flex-wrap: wrap;
|
|
}
|
|
.content div {
|
|
background-color: #f9f9f9;
|
|
padding: 20px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 8px;
|
|
width: 45%;
|
|
text-align: center;
|
|
margin: 10px 0;
|
|
}
|
|
.content h3 {
|
|
margin: 0;
|
|
margin-bottom: 10px;
|
|
}
|
|
.content p {
|
|
font-size: 24px;
|
|
margin: 0;
|
|
}
|
|
.workout-list {
|
|
width: 100%;
|
|
max-width: 1200px;
|
|
padding: 20px;
|
|
}
|
|
.workout-list h3 {
|
|
text-align: center;
|
|
}
|
|
.workout-item {
|
|
background-color: #f9f9f9;
|
|
padding: 15px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 8px;
|
|
margin-bottom: 10px;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
.workout-item a {
|
|
text-decoration: none;
|
|
color: #007BFF;
|
|
font-weight: bold;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="banner">
|
|
<button class="menu-button" onclick="toggleDrawer()">☰</button>
|
|
</div>
|
|
<div class="drawer" id="drawer">
|
|
<div class="drawer-header">
|
|
<img src="VitLogo.png" alt="Logo">
|
|
<button onclick="toggleDrawer()">✕</button>
|
|
</div>
|
|
<div class="drawer-content">
|
|
<a href="/upload.html">Upload Video</a>
|
|
<a href="/videos.html">Manage Videos</a>
|
|
<a href="/create-workout.html">Create Workout</a>
|
|
<a href="/workouts.html">Manage Workouts</a>
|
|
<a href="/create-crossfit-workout.html">Create CrossFit Workout</a>
|
|
<a href="/crossfit-workouts.html">Manage CrossFit Workouts</a>
|
|
<a href="/categories.html">Manage Categories</a>
|
|
<a href="/manage-timers.html">Manage Timers</a>
|
|
<a href="/create-timer.html">Create Timer</a>
|
|
<a href="/settings.html" id="settingsLink" style="display:none;">Settings</a>
|
|
<a href="#" onclick="logout()">Logout</a>
|
|
</div>
|
|
</div>
|
|
<div class="main-content" id="main-content">
|
|
<div class="main-header">
|
|
<img src="VitLogo.png" alt="Logo">
|
|
<h1>Dashboard</h1>
|
|
</div>
|
|
<div class="content">
|
|
<div>
|
|
<h3>Number of Workouts Created</h3>
|
|
<p id="workoutsCount">0</p>
|
|
</div>
|
|
<div>
|
|
<h3>Number of Videos Uploaded</h3>
|
|
<p id="videosCount">0</p>
|
|
</div>
|
|
</div>
|
|
<div class="workout-list" id="workoutList">
|
|
<h3>Workouts</h3>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
const drawer = document.getElementById('drawer');
|
|
const mainContent = document.getElementById('main-content');
|
|
|
|
function toggleDrawer() {
|
|
drawer.classList.toggle('open');
|
|
mainContent.classList.toggle('open');
|
|
}
|
|
|
|
async function checkAdmin() {
|
|
const token = localStorage.getItem('token');
|
|
if (!token) {
|
|
alert('No token found, redirecting to login');
|
|
window.location.href = '/';
|
|
return;
|
|
}
|
|
|
|
const response = await fetch('/profile', {
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`
|
|
}
|
|
});
|
|
|
|
const user = await response.json();
|
|
console.log('User fetched:', user); // Log the fetched user
|
|
if (user.role === 'Admin') {
|
|
document.getElementById('settingsLink').style.display = 'block';
|
|
} else {
|
|
console.log('User is not an admin'); // Log if user is not admin
|
|
}
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
const token = localStorage.getItem('token');
|
|
if (!token) {
|
|
alert('No token found, redirecting to login');
|
|
window.location.href = '/';
|
|
return;
|
|
}
|
|
|
|
await checkAdmin();
|
|
|
|
try {
|
|
const today = new Date().toISOString().split('T')[0];
|
|
|
|
const workoutsResponse = await fetch('/today-workouts', {
|
|
method: 'GET',
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
const allWorkoutsResponse = await fetch('/workouts-details', {
|
|
method: 'GET',
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
const videosResponse = await fetch('/videos', {
|
|
method: 'GET',
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
if (!workoutsResponse.ok || !allWorkoutsResponse.ok || !videosResponse.ok) {
|
|
alert('Failed to load data');
|
|
window.location.href = '/';
|
|
return;
|
|
}
|
|
|
|
const workouts = await workoutsResponse.json();
|
|
const allWorkouts = await allWorkoutsResponse.json();
|
|
const videos = await videosResponse.json();
|
|
|
|
document.getElementById('workoutsCount').innerText = 'A LOT!'//allWorkouts.length;
|
|
document.getElementById('videosCount').innerText = videos.length;
|
|
|
|
const workoutList = document.getElementById('workoutList');
|
|
workoutList.innerHTML = '';
|
|
workouts.forEach(workout => {
|
|
const workoutItem = document.createElement('div');
|
|
workoutItem.className = 'workout-item';
|
|
workoutItem.innerHTML = `
|
|
<span>Workout ID: ${workout.id}</span>
|
|
<span>Name : ${workout.name}</span>
|
|
<span>Created: ${new Date(workout.createdAt).toLocaleString()}</span>
|
|
<a href="#" onclick="event.preventDefault(); viewWorkout(${workout.id});">View Workout</a>
|
|
`;
|
|
workoutList.appendChild(workoutItem);
|
|
});
|
|
} catch (error) {
|
|
console.error('Error during fetch:', error);
|
|
alert('An error occurred, redirecting to login');
|
|
window.location.href = '/';
|
|
}
|
|
});
|
|
|
|
function viewWorkout(workoutId) {
|
|
window.location.href = `/workout.html?workoutId=${workoutId}`;
|
|
}
|
|
function logout() {
|
|
localStorage.removeItem('token');
|
|
window.location.href = '/';
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|