update checklist, update filter
This commit is contained in:
+39
-24
@@ -18,18 +18,34 @@
|
|||||||
color: #ddd;
|
color: #ddd;
|
||||||
}
|
}
|
||||||
.movie-table {
|
.movie-table {
|
||||||
margin-top: 20px;
|
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 {
|
.ratio {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
.navbar-toggler {
|
.navbar-toggler {
|
||||||
border-color: white; /* Make the border white */
|
border-color: white;
|
||||||
}
|
}
|
||||||
.navbar-toggler-icon {
|
.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");
|
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>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-light">
|
<body class="bg-light">
|
||||||
@@ -65,12 +81,12 @@
|
|||||||
<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 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>
|
</div>
|
||||||
<!-- Table for movies -->
|
<!-- Table for movies -->
|
||||||
<table class="table movie-table">
|
<table class="table table-hover movie-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Titre</th>
|
|
||||||
<th scope="col">Regardé</th>
|
<th scope="col">Regardé</th>
|
||||||
<th scope="col">Date du visionnage</th> <!-- New column for watched date -->
|
<th scope="col">Titre</th>
|
||||||
|
<th scope="col">Date du visionnage</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="movie-table-body">
|
<tbody id="movie-table-body">
|
||||||
@@ -93,30 +109,20 @@
|
|||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
try {
|
try {
|
||||||
// Decode the token (using a library like jwt-decode or manually)
|
const decoded = JSON.parse(atob(token.split('.')[1]));
|
||||||
const decoded = JSON.parse(atob(token.split('.')[1])); // Manually decoding JWT
|
|
||||||
|
|
||||||
// Access the user's name from the decoded token
|
|
||||||
const userName = decoded.name;
|
const userName = decoded.name;
|
||||||
|
|
||||||
// Update the user name in the navbar
|
|
||||||
document.getElementById('user-name').textContent = userName;
|
document.getElementById('user-name').textContent = userName;
|
||||||
|
const currentTime = Math.floor(Date.now() / 1000);
|
||||||
// Verify JWT Token expiration
|
|
||||||
const currentTime = Math.floor(Date.now() / 1000); // Current time in seconds
|
|
||||||
if (decoded.exp && decoded.exp < currentTime) {
|
if (decoded.exp && decoded.exp < currentTime) {
|
||||||
console.warn("Token is expired");
|
localStorage.removeItem('auth_token');
|
||||||
localStorage.removeItem('auth_token'); // Remove the expired token
|
window.location.href = '/';
|
||||||
window.location.href = '/'; // Redirect to the login page
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error decoding token:", error);
|
localStorage.removeItem('auth_token');
|
||||||
localStorage.removeItem('auth_token'); // Remove invalid token
|
window.location.href = '/';
|
||||||
window.location.href = '/'; // Redirect to the login page
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Handle case if no token is available
|
window.location.href = '/';
|
||||||
window.location.href = '/'; // Redirect to the login page if no token
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch('/api/movies', {
|
const res = await fetch('/api/movies', {
|
||||||
@@ -167,14 +173,23 @@
|
|||||||
const watchedDate = watchedMovie ? new Date(watchedMovie.watchedDate).toLocaleString() : '';
|
const watchedDate = watchedMovie ? new Date(watchedMovie.watchedDate).toLocaleString() : '';
|
||||||
const movieRow = document.createElement('tr');
|
const movieRow = document.createElement('tr');
|
||||||
movieRow.innerHTML = `
|
movieRow.innerHTML = `
|
||||||
<td>${movie.title}</td>
|
|
||||||
<td>
|
<td>
|
||||||
<input type="checkbox" class="form-check-input" id="movie-${movie.imdb_id}" ${watchedMovie ? 'checked' : ''} />
|
<input type="checkbox" class="form-check-input" id="movie-${movie.imdb_id}" ${watchedMovie ? 'checked' : ''} />
|
||||||
</td>
|
</td>
|
||||||
|
<td>${movie.title}</td>
|
||||||
<td id="watched-date-${movie.imdb_id}">${watchedDate}</td>
|
<td id="watched-date-${movie.imdb_id}">${watchedDate}</td>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
movieTableBody.appendChild(movieRow);
|
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}`);
|
const checkbox = document.getElementById(`movie-${movie.imdb_id}`);
|
||||||
checkbox.addEventListener('change', async (event) => {
|
checkbox.addEventListener('change', async (event) => {
|
||||||
const isChecked = event.target.checked;
|
const isChecked = event.target.checked;
|
||||||
@@ -215,4 +230,4 @@
|
|||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
+35
-95
@@ -87,9 +87,6 @@
|
|||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
<div class="d-flex justify-content-between align-items-center">
|
<div class="d-flex justify-content-between align-items-center">
|
||||||
<h2>Films</h2>
|
<h2>Films</h2>
|
||||||
<h3 class="fs-6 mb-0">
|
|
||||||
<img src="/img/filter.png" style="height: 25px;"><button id="filter-button" class="btn btn-primary btn-sm"></button>
|
|
||||||
</h3>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Displaying the ratio of watched movies -->
|
<!-- Displaying the ratio of watched movies -->
|
||||||
@@ -98,6 +95,13 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h3 class="fs-6">Temps avant les Oscars (2 mars 2025) - <span id="time-left"></span></h3>
|
<h3 class="fs-6">Temps avant les Oscars (2 mars 2025) - <span id="time-left"></span></h3>
|
||||||
|
<h3 class="fs-6 mb-0">
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input class="form-check-input" type="checkbox" id="flexSwitchCheckDefault">
|
||||||
|
<label class="form-check-label" for="flexSwitchCheckDefault">Films non regardés seulement</label>
|
||||||
|
</div>
|
||||||
|
</h3>
|
||||||
|
<br>
|
||||||
<div id="movies-list" class="row">
|
<div id="movies-list" class="row">
|
||||||
<!-- Movies will be displayed here -->
|
<!-- Movies will be displayed here -->
|
||||||
</div>
|
</div>
|
||||||
@@ -106,95 +110,65 @@
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
window.onload = async function () {
|
window.onload = async function () {
|
||||||
// Calculate the time left until March 2, 2025
|
|
||||||
const targetDate = new Date('March 2, 2025');
|
const targetDate = new Date('March 2, 2025');
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
|
|
||||||
// Calculate the difference in milliseconds
|
|
||||||
const timeDifference = targetDate - currentDate;
|
const timeDifference = targetDate - currentDate;
|
||||||
|
|
||||||
// Convert milliseconds to days
|
|
||||||
const daysLeft = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
|
const daysLeft = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
|
||||||
|
|
||||||
// Update the "Time Left" text
|
|
||||||
document.getElementById('time-left').textContent = `${daysLeft} jours`;
|
document.getElementById('time-left').textContent = `${daysLeft} jours`;
|
||||||
|
|
||||||
// Get token from localStorage (assuming it's set after login)
|
|
||||||
const token = localStorage.getItem('auth_token');
|
const token = localStorage.getItem('auth_token');
|
||||||
// Check if token exists
|
|
||||||
if (token) {
|
if (token) {
|
||||||
try {
|
try {
|
||||||
// Decode the token (using a library like jwt-decode or manually)
|
const decoded = JSON.parse(atob(token.split('.')[1]));
|
||||||
const decoded = JSON.parse(atob(token.split('.')[1])); // Manually decoding JWT
|
|
||||||
|
|
||||||
// Access the user's name from the decoded token
|
|
||||||
const userName = decoded.name;
|
const userName = decoded.name;
|
||||||
|
|
||||||
// Update the user name in the navbar
|
|
||||||
document.getElementById('user-name').textContent = userName;
|
document.getElementById('user-name').textContent = userName;
|
||||||
|
|
||||||
// Verify JWT Token expiration
|
const currentTime = Math.floor(Date.now() / 1000);
|
||||||
const currentTime = Math.floor(Date.now() / 1000); // Current time in seconds
|
|
||||||
if (decoded.exp && decoded.exp < currentTime) {
|
if (decoded.exp && decoded.exp < currentTime) {
|
||||||
console.warn("Token is expired");
|
localStorage.removeItem('auth_token');
|
||||||
localStorage.removeItem('auth_token'); // Remove the expired token
|
window.location.href = '/';
|
||||||
window.location.href = '/'; // Redirect to the login page
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error decoding token:", error);
|
localStorage.removeItem('auth_token');
|
||||||
localStorage.removeItem('auth_token'); // Remove invalid token
|
window.location.href = '/';
|
||||||
window.location.href = '/'; // Redirect to the login page
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Handle case if no token is available
|
window.location.href = '/';
|
||||||
window.location.href = '/'; // Redirect to the login page if no token
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetching the movies from your API with Authorization header
|
|
||||||
const res = await fetch('/api/movies', {
|
const res = await fetch('/api/movies', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: { 'Authorization': `Bearer ${token}` },
|
||||||
'Authorization': `Bearer ${token}` // Send the token in the Authorization header
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
// If unauthorized or any error, log out the user
|
localStorage.removeItem('auth_token');
|
||||||
localStorage.removeItem('auth_token'); // Clear the token
|
window.location.href = '/';
|
||||||
window.location.href = '/'; // Redirect to login page
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const movies = await res.json();
|
const movies = await res.json();
|
||||||
|
|
||||||
// Fetch watched movies for the logged-in user
|
|
||||||
const watchedRes = await fetch('/api/movies/watchedMovies', {
|
const watchedRes = await fetch('/api/movies/watchedMovies', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
headers: {
|
headers: { 'Authorization': `Bearer ${token}` },
|
||||||
'Authorization': `Bearer ${token}` // Send the token to verify the user
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let watchedMovies = [];
|
let watchedMovies = [];
|
||||||
if (watchedRes.ok) {
|
if (watchedRes.ok) {
|
||||||
watchedMovies = await watchedRes.json(); // Get the list of watched movies from the user's profile
|
watchedMovies = await watchedRes.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
const moviesList = document.getElementById('movies-list');
|
const moviesList = document.getElementById('movies-list');
|
||||||
|
|
||||||
// Calculate the watched-to-total ratio
|
|
||||||
const totalMoviesCount = movies.length;
|
const totalMoviesCount = movies.length;
|
||||||
const watchedMoviesCount = watchedMovies.length;
|
const watchedMoviesCount = watchedMovies.length;
|
||||||
const ratioText = `Regardé: ${watchedMoviesCount} / ${totalMoviesCount} (${((watchedMoviesCount / totalMoviesCount) * 100).toFixed(1)}%)`;
|
const ratioText = `Regardé: ${watchedMoviesCount} / ${totalMoviesCount} (${((watchedMoviesCount / totalMoviesCount) * 100).toFixed(1)}%)`;
|
||||||
|
|
||||||
// Display the ratio below the Movies heading
|
|
||||||
document.getElementById('watched-ratio').innerText = ratioText;
|
document.getElementById('watched-ratio').innerText = ratioText;
|
||||||
|
|
||||||
// Loop through the movies and create cards for them
|
|
||||||
movies.forEach(movie => {
|
movies.forEach(movie => {
|
||||||
const isChecked = watchedMovies.some(watchedMovie => watchedMovie.imdb_id === movie.imdb_id); // Check if the movie is watched
|
const isChecked = watchedMovies.some(watchedMovie => watchedMovie.imdb_id === movie.imdb_id);
|
||||||
const watchedMovie = watchedMovies.find(wm => wm.imdb_id === movie.imdb_id);
|
const watchedMovie = watchedMovies.find(wm => wm.imdb_id === movie.imdb_id);
|
||||||
const watchedDate = watchedMovie ? new Date(watchedMovie.watchedDate).toLocaleString() : ''; // Get the watched date if available
|
const watchedDate = watchedMovie ? new Date(watchedMovie.watchedDate).toLocaleString() : '';
|
||||||
|
|
||||||
const movieDiv = document.createElement('div');
|
const movieDiv = document.createElement('div');
|
||||||
movieDiv.classList.add('col-md-4', 'mb-4', 'movie-card');
|
movieDiv.classList.add('col-md-4', 'mb-4', 'movie-card');
|
||||||
@@ -205,74 +179,41 @@
|
|||||||
<a href="${movie.vod_link}"><img src="${movie.poster}" class="card-img-top" alt="${movie.title}" style="width: 75%; display: block; margin: 0 auto; padding: 10px;"></a>
|
<a href="${movie.vod_link}"><img src="${movie.poster}" class="card-img-top" alt="${movie.title}" style="width: 75%; display: block; margin: 0 auto; padding: 10px;"></a>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h5 class="card-title d-flex justify-content-between align-items-center">
|
<h5 class="card-title d-flex justify-content-between align-items-center">
|
||||||
${movie.title}
|
${movie.title}
|
||||||
<span>⭐ ${movie.rating} <a href="https://www.imdb.com/title/${movie.imdb_id}/"><img src="/img/imdb.png"></a></span>
|
<span>⭐ ${movie.rating} <a href="https://www.imdb.com/title/${movie.imdb_id}/"><img src="/img/imdb.png"></a></span>
|
||||||
</h5>
|
</h5>
|
||||||
<p class="fw-bold fst-italic card-text" style="font-size: 0.75rem;">${movie.category}</p>
|
<p class="fw-bold fst-italic card-text" style="font-size: 0.75rem;">${movie.category}</p>
|
||||||
<p class="card-text">${movie.description}</p>
|
<p class="card-text">${movie.description}</p>
|
||||||
${isChecked ? `<p class="card-text"><strong>Regardé le:</strong> ${watchedDate}</p>` : ''} <!-- Display watched date and time if movie is watched -->
|
${isChecked ? `<p class="card-text"><strong>Regardé le:</strong> ${watchedDate}</p>` : ''}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>`;
|
||||||
`;
|
|
||||||
moviesList.appendChild(movieDiv);
|
moviesList.appendChild(movieDiv);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log off functionality
|
document.getElementById('log-off').addEventListener('click', function () {
|
||||||
document.getElementById('log-off').addEventListener('click', function() {
|
localStorage.removeItem('auth_token');
|
||||||
localStorage.removeItem('auth_token'); // Remove token from localStorage
|
window.location.href = '/';
|
||||||
window.location.href = '/'; // Redirect to login page
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Retrieve filter state from localStorage
|
const filterSwitch = document.getElementById('flexSwitchCheckDefault');
|
||||||
const savedFilterState = localStorage.getItem('filter-checkbox');
|
const savedFilterState = localStorage.getItem('filter-checkbox');
|
||||||
let isFilterActive = savedFilterState === 'checked';
|
const isFilterActive = savedFilterState === 'checked';
|
||||||
|
filterSwitch.checked = isFilterActive;
|
||||||
|
|
||||||
// Update button text and color based on the filter state
|
filterSwitch.addEventListener('change', function () {
|
||||||
const filterButton = document.getElementById('filter-button');
|
const filterState = filterSwitch.checked ? 'checked' : 'unchecked';
|
||||||
filterButton.textContent = isFilterActive ? 'Tous les films' : 'Films non regardé';
|
|
||||||
|
|
||||||
// Change the button color to red when "Tous les films" is displayed
|
|
||||||
if (isFilterActive) {
|
|
||||||
filterButton.classList.remove('btn-danger');
|
|
||||||
filterButton.classList.add('btn-primary');
|
|
||||||
} else {
|
|
||||||
filterButton.classList.remove('btn-primary');
|
|
||||||
filterButton.classList.add('btn-danger');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Event listener for the button
|
|
||||||
filterButton.addEventListener('click', function () {
|
|
||||||
// Toggle the filter state
|
|
||||||
isFilterActive = !isFilterActive;
|
|
||||||
|
|
||||||
// Update the button text and color based on the new state
|
|
||||||
filterButton.textContent = isFilterActive ? 'Tous les films' : 'Films non regardé';
|
|
||||||
if (isFilterActive) {
|
|
||||||
filterButton.classList.remove('btn-danger');
|
|
||||||
filterButton.classList.add('btn-primary');
|
|
||||||
} else {
|
|
||||||
filterButton.classList.remove('btn-primary');
|
|
||||||
filterButton.classList.add('btn-danger');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the filter state to localStorage
|
|
||||||
const filterState = isFilterActive ? 'checked' : 'unchecked';
|
|
||||||
localStorage.setItem('filter-checkbox', filterState);
|
localStorage.setItem('filter-checkbox', filterState);
|
||||||
|
|
||||||
// Apply the filter to the movie cards
|
|
||||||
filterMovies();
|
filterMovies();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Function to filter the movies based on the button state
|
|
||||||
function filterMovies() {
|
function filterMovies() {
|
||||||
const showUnwatchedOnly = isFilterActive;
|
const showUnwatchedOnly = filterSwitch.checked;
|
||||||
const movieCards = document.querySelectorAll('.movie-card');
|
const movieCards = document.querySelectorAll('.movie-card');
|
||||||
|
|
||||||
movieCards.forEach(card => {
|
movieCards.forEach(card => {
|
||||||
const imdbId = card.getAttribute('data-imdb-id');
|
const imdbId = card.getAttribute('data-imdb-id');
|
||||||
const isWatched = watchedMovies.some(watchedMovie => watchedMovie.imdb_id === imdbId);
|
const isWatched = watchedMovies.some(watchedMovie => watchedMovie.imdb_id === imdbId);
|
||||||
|
|
||||||
// Hide the movie card if it's watched and the filter is on
|
|
||||||
if (showUnwatchedOnly && isWatched) {
|
if (showUnwatchedOnly && isWatched) {
|
||||||
card.style.display = 'none';
|
card.style.display = 'none';
|
||||||
} else {
|
} else {
|
||||||
@@ -281,7 +222,6 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initial filter application
|
|
||||||
filterMovies();
|
filterMovies();
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user