408 lines
12 KiB
HTML
408 lines
12 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Manage Workouts</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100vh;
|
|
overflow: hidden; /* Prevent multiple scroll bars */
|
|
}
|
|
.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 #ddd;
|
|
}
|
|
|
|
.main-content {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: flex-start; /* Adjusted to flex-start to align items to the top */
|
|
transition: margin-left 0.3s;
|
|
overflow-y: auto; /* Only vertical scroll bar */
|
|
width: 100%;
|
|
}
|
|
|
|
.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; /* Center the content */
|
|
}
|
|
|
|
.workout-list {
|
|
list-style: none;
|
|
padding: 0;
|
|
width: 100%;
|
|
max-width: 1200px;
|
|
}
|
|
|
|
.workout-list li {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 20px;
|
|
border-bottom: 1px solid #ddd;
|
|
margin-bottom: 10px;
|
|
background-color: #f9f9f9;
|
|
border-radius: 5px;
|
|
}
|
|
|
|
.workout-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
width: 100%;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.workout-header h2 {
|
|
margin: 0;
|
|
}
|
|
|
|
.workout-details {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
justify-content: space-around;
|
|
width: 100%;
|
|
}
|
|
|
|
.workout-details div {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
margin: 10px;
|
|
}
|
|
|
|
.workout-details video {
|
|
width: 150px;
|
|
height: 100px;
|
|
background: black;
|
|
}
|
|
|
|
.workout-footer {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
width: 100%;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.delete-button {
|
|
background-color: #ff4b5c;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 5px;
|
|
padding: 10px 20px;
|
|
cursor: pointer;
|
|
}
|
|
.view-button {
|
|
background-color: #095FF6;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 5px;
|
|
padding: 10px 20px;
|
|
cursor: pointer;
|
|
}
|
|
.pagination {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
gap: 10px;
|
|
margin: 20px 0;
|
|
}
|
|
|
|
.pagination button {
|
|
background-color: #095FF6;
|
|
color: white;
|
|
border: none;
|
|
border-radius: 5px;
|
|
padding: 10px 20px;
|
|
cursor: pointer;
|
|
font-size: 16px;
|
|
transition: background-color 0.3s;
|
|
}
|
|
|
|
.pagination button:disabled {
|
|
background-color: #ccc;
|
|
cursor: not-allowed;
|
|
}
|
|
|
|
.pagination button:hover:not(:disabled) {
|
|
background-color: #063d8c;
|
|
}
|
|
|
|
/* Top pagination bar */
|
|
.pagination.top {
|
|
margin-top: 10px; /* Adjust the spacing under the header */
|
|
}
|
|
|
|
/* Bottom pagination bar */
|
|
.pagination.bottom {
|
|
margin-top: auto;
|
|
margin-bottom: 10px;
|
|
}
|
|
</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="/dashboard.html">Dashboard</a>
|
|
<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>
|
|
</div>
|
|
</div>
|
|
<div class="main-content" id="main-content">
|
|
<div class="main-header">
|
|
<img src="VitLogo.png" alt="Logo">
|
|
<h1>Manage Workouts</h1>
|
|
</div>
|
|
<div class="content">
|
|
<ul id="workoutList" class="workout-list"></ul>
|
|
</div>
|
|
</div>
|
|
<div class="pagination">
|
|
<button id="prevPage" disabled>Previous</button>
|
|
<span id="currentPage">Page 1</span>
|
|
<button id="nextPage">Next</button>
|
|
</div>
|
|
<script>
|
|
const drawer = document.getElementById('drawer');
|
|
const mainContent = document.getElementById('main-content');
|
|
const workoutList = document.getElementById('workoutList');
|
|
|
|
function toggleDrawer() {
|
|
drawer.classList.toggle('open');
|
|
mainContent.classList.toggle('open');
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
const token = localStorage.getItem('token');
|
|
if (!token) {
|
|
alert('No token found, redirecting to login');
|
|
window.location.href = '/';
|
|
return;
|
|
}
|
|
|
|
let currentPage = 1;
|
|
const limit = 20;
|
|
|
|
async function fetchWorkouts(page) {
|
|
try {
|
|
const response = await fetch(`/workouts-details?page=${page}&limit=${limit}`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorText = await response.text();
|
|
throw new Error(`Failed to fetch workouts: ${errorText}`);
|
|
}
|
|
|
|
const { workouts, totalPages, currentPage } = await response.json();
|
|
workoutList.innerHTML = '';
|
|
workouts.forEach(workout => {
|
|
const li = document.createElement('li');
|
|
|
|
const workoutHeader = document.createElement('div');
|
|
workoutHeader.className = 'workout-header';
|
|
workoutHeader.innerHTML = `<h2>Workout ID: ${workout.id} Name: ${workout.name || 'Unnamed'} Created: ${new Date(workout.createdAt).toLocaleString()}</h2>`;
|
|
|
|
const workoutDetails = document.createElement('div');
|
|
workoutDetails.className = 'workout-details';
|
|
|
|
[workout.video1Details, workout.video2Details, workout.video3Details, workout.video4Details].forEach(video => {
|
|
if (video) {
|
|
const videoDiv = document.createElement('div');
|
|
videoDiv.innerHTML = `
|
|
<video src="/uploads/${video.filename}" controls></video>
|
|
<p>${video.description}</p>
|
|
<p>${video.category}</p>
|
|
`;
|
|
workoutDetails.appendChild(videoDiv);
|
|
}
|
|
});
|
|
|
|
const workoutFooter = document.createElement('div');
|
|
workoutFooter.className = 'workout-footer';
|
|
const deleteButton = document.createElement('button');
|
|
deleteButton.className = 'delete-button';
|
|
deleteButton.textContent = 'Delete Workout';
|
|
deleteButton.onclick = async () => {
|
|
await deleteWorkout(workout.id);
|
|
};
|
|
const viewButton = document.createElement('button');
|
|
viewButton.className = 'view-button';
|
|
viewButton.textContent = 'View Workout';
|
|
viewButton.onclick = () => viewWorkout(workout.id);
|
|
workoutFooter.appendChild(viewButton);
|
|
workoutFooter.appendChild(deleteButton);
|
|
|
|
li.appendChild(workoutHeader);
|
|
li.appendChild(workoutDetails);
|
|
li.appendChild(workoutFooter);
|
|
workoutList.appendChild(li);
|
|
});
|
|
|
|
// Update pagination controls
|
|
document.getElementById('currentPage').textContent = `Page ${currentPage}`;
|
|
document.getElementById('prevPage').disabled = currentPage === 1;
|
|
document.getElementById('nextPage').disabled = currentPage === totalPages;
|
|
} catch (error) {
|
|
console.error('Error fetching workouts:', error);
|
|
alert(`An error occurred while fetching workouts: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
document.getElementById('prevPage').addEventListener('click', () => {
|
|
if (currentPage > 1) {
|
|
currentPage--;
|
|
fetchWorkouts(currentPage);
|
|
}
|
|
});
|
|
|
|
document.getElementById('nextPage').addEventListener('click', () => {
|
|
currentPage++;
|
|
fetchWorkouts(currentPage);
|
|
});
|
|
// View workout
|
|
function viewWorkout(workoutId) {
|
|
window.location.href = `/workout.html?workoutId=${workoutId}`;
|
|
}
|
|
async function deleteWorkout(workoutId) {
|
|
try {
|
|
const response = await fetch(`/workouts/${workoutId}`, {
|
|
method: 'DELETE',
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorText = await response.text();
|
|
throw new Error(`Failed to delete workout: ${errorText}`);
|
|
}
|
|
|
|
fetchWorkouts(currentPage);
|
|
} catch (error) {
|
|
console.error('Error deleting workout:', error);
|
|
alert(`An error occurred while deleting the workout: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
fetchWorkouts(currentPage);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|