Initial
This commit is contained in:
@@ -0,0 +1,355 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Create Workout</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: center;
|
||||
transition: margin-left 0.3s;
|
||||
}
|
||||
.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;
|
||||
}
|
||||
.content form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
.content form .input-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin: 10px 0;
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
}
|
||||
.content form select,
|
||||
.content form input {
|
||||
padding: 10px;
|
||||
font-size: 16px;
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
.content form input {
|
||||
margin-left: 10px;
|
||||
}
|
||||
.content form button {
|
||||
padding: 10px 20px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
background-color: #007BFF;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.error-message {
|
||||
color: red;
|
||||
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="/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>
|
||||
<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>Create Workout</h1>
|
||||
</div>
|
||||
<div class="content">
|
||||
<form id="createWorkoutForm">
|
||||
<div class="input-group">
|
||||
<input type="text" id="name" name="name" placeholder="Workout Name" required>
|
||||
<input type="date" id="workoutDate" name="workoutDate" required>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<select id="videoCount" name="videoCount" required>
|
||||
<option value="1">1 Video</option>
|
||||
<option value="2">2 Videos</option>
|
||||
<option value="3">3 Videos</option>
|
||||
<option value="4">4 Videos</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="input-group" id="video1-group">
|
||||
<select id="video1" name="video1" required>
|
||||
<option value="">Select Video 1</option>
|
||||
<!-- Options loaded dynamically -->
|
||||
</select>
|
||||
<input type="number" name="number1" placeholder="Number for Video 1" required>
|
||||
</div>
|
||||
<div class="input-group" id="video2-group">
|
||||
<select id="video2" name="video2">
|
||||
<option value="">Select Video 2</option>
|
||||
<!-- Options loaded dynamically -->
|
||||
</select>
|
||||
<input type="number" name="number2" placeholder="Number for Video 2">
|
||||
</div>
|
||||
<div class="input-group" id="video3-group">
|
||||
<select id="video3" name="video3">
|
||||
<option value="">Select Video 3</option>
|
||||
<!-- Options loaded dynamically -->
|
||||
</select>
|
||||
<input type="number" name="number3" placeholder="Number for Video 3">
|
||||
</div>
|
||||
<div class="input-group" id="video4-group">
|
||||
<select id="video4" name="video4">
|
||||
<option value="">Select Video 4</option>
|
||||
<!-- Options loaded dynamically -->
|
||||
</select>
|
||||
<input type="number" name="number4" placeholder="Number for Video 4">
|
||||
</div>
|
||||
<button type="submit">Create Workout</button>
|
||||
<div id="errorMessage" class="error-message"></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
const drawer = document.getElementById('drawer');
|
||||
const mainContent = document.getElementById('main-content');
|
||||
const createWorkoutForm = document.getElementById('createWorkoutForm');
|
||||
const errorMessage = document.getElementById('errorMessage');
|
||||
|
||||
function toggleDrawer() {
|
||||
drawer.classList.toggle('open');
|
||||
mainContent.classList.toggle('open');
|
||||
}
|
||||
function logout() {
|
||||
localStorage.removeItem('token');
|
||||
window.location.href = '/';
|
||||
}
|
||||
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();
|
||||
|
||||
const videoCountSelector = document.getElementById('videoCount');
|
||||
const video2Group = document.getElementById('video2-group');
|
||||
const video3Group = document.getElementById('video3-group');
|
||||
const video4Group = document.getElementById('video4-group');
|
||||
|
||||
videoCountSelector.addEventListener('change', (e) => {
|
||||
const count = parseInt(e.target.value);
|
||||
video2Group.style.display = count >= 2 ? 'flex' : 'none';
|
||||
video3Group.style.display = count >= 3 ? 'flex' : 'none';
|
||||
video4Group.style.display = count >= 4 ? 'flex' : 'none';
|
||||
});
|
||||
|
||||
// Initial hide
|
||||
video2Group.style.display = 'none';
|
||||
video3Group.style.display = 'none';
|
||||
video4Group.style.display = 'none';
|
||||
|
||||
// Fetch and populate video options
|
||||
const fetchVideos = async () => {
|
||||
const response = await fetch('/videos', {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
const videos = await response.json();
|
||||
videos.sort((a, b) => a.description.localeCompare(b.description));
|
||||
videos.forEach(video => {
|
||||
const option = new Option(`${video.description} - ${video.category}`, video.id);
|
||||
document.getElementById('video1').appendChild(option.cloneNode(true));
|
||||
document.getElementById('video2').appendChild(option.cloneNode(true));
|
||||
document.getElementById('video3').appendChild(option.cloneNode(true));
|
||||
document.getElementById('video4').appendChild(option.cloneNode(true));
|
||||
});
|
||||
};
|
||||
|
||||
await fetchVideos();
|
||||
|
||||
document.getElementById('createWorkoutForm').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
const formData = new FormData(e.target);
|
||||
const workoutData = {
|
||||
name: formData.get('name'),
|
||||
workoutDate: formData.get('workoutDate'),
|
||||
video1: formData.get('video1'),
|
||||
number1: formData.get('number1'),
|
||||
video2: formData.get('video2') || null,
|
||||
number2: formData.get('number2') || null,
|
||||
video3: formData.get('video3') || null,
|
||||
number3: formData.get('number3') || null,
|
||||
video4: formData.get('video4') || null,
|
||||
number4: formData.get('number4') || null
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await fetch('/create-workout', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(workoutData)
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
window.location.href = '/workouts.html';
|
||||
} else {
|
||||
const error = await response.text();
|
||||
document.getElementById('errorMessage').textContent = error;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error creating workout:', error);
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user