233 lines
8.2 KiB
HTML
233 lines
8.2 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Pool Oscars 2025 - Checklist</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<style>
|
|
.navbar-custom {
|
|
background-color: black;
|
|
color: white;
|
|
}
|
|
.navbar-custom .navbar-brand,
|
|
.navbar-custom .nav-link {
|
|
color: white;
|
|
}
|
|
.navbar-custom .nav-link:hover {
|
|
color: #ddd;
|
|
}
|
|
.movie-table {
|
|
margin-top: 20px;
|
|
}
|
|
|
|
/* New styles for the first column */
|
|
.movie-table th:first-child,
|
|
.movie-table td:first-child {
|
|
width: 1%; /* Shrink to fit the content */
|
|
white-space: nowrap; /* Prevent wrapping */
|
|
}
|
|
|
|
.movie-table {
|
|
table-layout: auto; /* Allow the browser to size columns automatically */
|
|
}
|
|
.ratio {
|
|
font-weight: bold;
|
|
margin-top: 10px;
|
|
}
|
|
.navbar-toggler {
|
|
border-color: white;
|
|
}
|
|
.navbar-toggler-icon {
|
|
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3E%3Cpath stroke='white' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E");
|
|
}
|
|
/* New styles for table */
|
|
.table-hover tbody tr:hover {
|
|
background-color: #f1f1f1;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="bg-light">
|
|
|
|
<!-- Black banner with buttons and user info -->
|
|
<nav class="navbar navbar-expand-lg navbar-custom">
|
|
<div class="container">
|
|
<a class="navbar-brand">
|
|
<img src="img/logo_w.png" style="max-width: 180px; height: 70px; object-fit: contain;">
|
|
</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<div class="navbar-nav">
|
|
<a href="movies.html" class="nav-link btn btn-outline-light me-2">Films</a>
|
|
<a href="checklist.html" class="nav-link btn btn-outline-light me-2">Checklist</a>
|
|
<a href="user-stat.html" class="nav-link btn btn-outline-light">Statistiques</a>
|
|
</div>
|
|
</div>
|
|
<div class="d-flex">
|
|
<span id="user-name" class="navbar-text me-3"></span>
|
|
<button id="log-off" class="btn btn-danger">Déconnexion</button>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mt-5">
|
|
<h2>Checklist</h2>
|
|
<div id="watched-ratio" class="ratio"></div>
|
|
<h3 class="fs-6">Temps avant les Oscars (2 mars 2025) - <span id="time-left"></span></h3>
|
|
<div class="progress my-3">
|
|
<div id="progress-bar" class="progress-bar" role="progressbar" style="width: 0%; background-color: red;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
|
|
</div>
|
|
<!-- Table for movies -->
|
|
<table class="table table-hover movie-table">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">Regardé</th>
|
|
<th scope="col">Titre</th>
|
|
<th scope="col">Date du visionnage</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="movie-table-body">
|
|
<!-- Movie rows will be inserted here -->
|
|
</tbody>
|
|
</table>
|
|
<br><br>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
window.onload = async function () {
|
|
const token = localStorage.getItem('auth_token');
|
|
|
|
const targetDate = new Date('March 2, 2025');
|
|
const currentDate = new Date();
|
|
const timeDifference = targetDate - currentDate;
|
|
const daysLeft = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
|
|
document.getElementById('time-left').textContent = `${daysLeft} jours`;
|
|
|
|
if (token) {
|
|
try {
|
|
const decoded = JSON.parse(atob(token.split('.')[1]));
|
|
const userName = decoded.name;
|
|
document.getElementById('user-name').textContent = userName;
|
|
const currentTime = Math.floor(Date.now() / 1000);
|
|
if (decoded.exp && decoded.exp < currentTime) {
|
|
localStorage.removeItem('auth_token');
|
|
window.location.href = '/';
|
|
}
|
|
} catch (error) {
|
|
localStorage.removeItem('auth_token');
|
|
window.location.href = '/';
|
|
}
|
|
} else {
|
|
window.location.href = '/';
|
|
}
|
|
|
|
const res = await fetch('/api/movies', {
|
|
method: 'GET',
|
|
headers: { 'Authorization': `Bearer ${token}` }
|
|
});
|
|
|
|
if (!res.ok) {
|
|
localStorage.removeItem('auth_token');
|
|
window.location.href = '/';
|
|
return;
|
|
}
|
|
|
|
const movies = await res.json();
|
|
const watchedRes = await fetch('/api/movies/watchedMovies', {
|
|
method: 'GET',
|
|
headers: { 'Authorization': `Bearer ${token}` }
|
|
});
|
|
|
|
let watchedMovies = [];
|
|
if (watchedRes.ok) {
|
|
watchedMovies = await watchedRes.json();
|
|
}
|
|
|
|
const totalMoviesCount = movies.length;
|
|
const watchedMoviesCount = watchedMovies.length;
|
|
document.getElementById('watched-ratio').innerText = `Regardé: ${watchedMoviesCount} / ${totalMoviesCount} (${((watchedMoviesCount / totalMoviesCount) * 100).toFixed(1)}%)`;
|
|
|
|
function updateProgressBar(watchedCount, totalCount) {
|
|
const progressBar = document.getElementById('progress-bar');
|
|
const percentage = (watchedCount / totalCount) * 100;
|
|
progressBar.style.width = `${percentage}%`;
|
|
|
|
if (percentage <= 50) {
|
|
progressBar.style.backgroundColor = `rgb(${255}, ${Math.floor((percentage / 50) * 255)}, 0)`;
|
|
} else {
|
|
progressBar.style.backgroundColor = `rgb(${Math.floor(255 - ((percentage - 50) / 50) * 255)}, 255, 0)`;
|
|
}
|
|
|
|
progressBar.setAttribute('aria-valuenow', Math.round(percentage));
|
|
}
|
|
|
|
updateProgressBar(watchedMoviesCount, totalMoviesCount);
|
|
|
|
const movieTableBody = document.getElementById('movie-table-body');
|
|
movies.forEach(movie => {
|
|
const watchedMovie = watchedMovies.find(wm => wm.imdb_id === movie.imdb_id);
|
|
const watchedDate = watchedMovie ? new Date(watchedMovie.watchedDate).toLocaleString() : '';
|
|
const movieRow = document.createElement('tr');
|
|
movieRow.innerHTML = `
|
|
<td>
|
|
<input type="checkbox" class="form-check-input" id="movie-${movie.imdb_id}" ${watchedMovie ? 'checked' : ''} />
|
|
</td>
|
|
<td>${movie.title}</td>
|
|
<td id="watched-date-${movie.imdb_id}">${watchedDate}</td>
|
|
`;
|
|
|
|
movieTableBody.appendChild(movieRow);
|
|
|
|
movieRow.addEventListener('click', (event) => {
|
|
const checkbox = document.getElementById(`movie-${movie.imdb_id}`);
|
|
if (event.target.tagName !== 'INPUT') {
|
|
checkbox.checked = !checkbox.checked;
|
|
checkbox.dispatchEvent(new Event('change'));
|
|
}
|
|
});
|
|
|
|
const checkbox = document.getElementById(`movie-${movie.imdb_id}`);
|
|
checkbox.addEventListener('change', async (event) => {
|
|
const isChecked = event.target.checked;
|
|
const watchedDateCell = document.getElementById(`watched-date-${movie.imdb_id}`);
|
|
if (isChecked) {
|
|
watchedDateCell.textContent = new Date().toLocaleString();
|
|
} else {
|
|
watchedDateCell.textContent = '';
|
|
}
|
|
|
|
await fetch('/api/movies/users/updateWatchedMovies', {
|
|
method: 'PATCH',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Authorization': `Bearer ${token}`
|
|
},
|
|
body: JSON.stringify({ imdb_id: movie.imdb_id, isChecked })
|
|
});
|
|
|
|
const updatedWatchedMoviesRes = await fetch('/api/movies/watchedMovies', {
|
|
method: 'GET',
|
|
headers: { 'Authorization': `Bearer ${token}` }
|
|
});
|
|
|
|
if (updatedWatchedMoviesRes.ok) {
|
|
const updatedWatchedMovies = await updatedWatchedMoviesRes.json();
|
|
const updatedWatchedCount = updatedWatchedMovies.length;
|
|
document.getElementById('watched-ratio').innerText = `Regardé: ${updatedWatchedCount} / ${totalMoviesCount} (${((updatedWatchedCount / totalMoviesCount) * 100).toFixed(1)}%)`;
|
|
updateProgressBar(updatedWatchedCount, totalMoviesCount);
|
|
}
|
|
});
|
|
});
|
|
|
|
document.getElementById('log-off').addEventListener('click', () => {
|
|
localStorage.removeItem('auth_token');
|
|
window.location.href = '/';
|
|
});
|
|
};
|
|
</script>
|
|
</body>
|
|
</html> |