-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
183 lines (168 loc) · 7.82 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Petflix</title>
<link rel="icon" type="image/png" href="./assets/images/petflix-logo.png">
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@^2.2.19/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="./assets/css/reset.css">
<link rel="stylesheet" href="./assets/css/app.css">
</head>
<body class="bg-gray-900 text-white">
<header class="bg-black py-4">
<div class="container mx-auto flex justify-between items-center gap-x-4">
<a href="index.html">
<img src="assets/images/petflix-logo.png" alt="Petflix" class="h-10">
</a>
<nav class="flex justify-between items-center gap-x-2 w-full">
<ul class="flex space-x-4">
<li><a href="index.html" class="hover:text-gray-400">Accueil</a></li>
<li><a href="video-creation.html" class="hover:text-gray-400">Videos</a></li>
<li><a href="controle.html" class="hover:text-gray-400">Controles</a></li>
</ul>
<a href="adoption.html" class="bg-red-700 text-white-600 px-4 py-2 rounded-md">
Ajouter une adoption
</a>
</nav>
</div>
</header>
<div id="video-cover" class="video-cover">
</div>
<div class="2xl:container mx-auto mt-16 mb-9 px-6">
<h2 class="text-4xl">
Top 10 des vidéos aujourd'hui
</h2>
</div>
<div class="2xl:container mx-auto p-6">
<form id="filter-form" class="mb-8 flex justify-end items-center space-x-2">
<div class="flex flex-wrap items-center space-x-2">
<label for="animal-filter" class="font-semibold">Type d'animal :</label>
<select name="animal-filter" id="animal-filter" class="border border-gray-300 rounded px-2 py-1 text-black">
<option value="">-- Tous les types --</option>
<option value="chien">Chien</option>
<option value="chat">Chat</option>
</select>
</div>
<div class="flex flex-wrap items-center space-x-2">
<label for="city-filter" class="font-semibold">Ville :</label>
<input type="text" name="city-filter" id="city-filter" class="border border-gray-300 rounded px-2 py-1 text-black" placeholder="Ville">
</div>
<button type="submit" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded">Chercher</button>
</form>
</div>
<div id="videos-container"
class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 justify-center mb-20 w-full overflow-hidden">
</div>
<footer class="bg-black py-4">
<div class="container mx-auto flex justify-between items-center">
<ul class="flex">
<li class="mr-4">
<a href="#">
<img src="assets/images/social-media/facebook.png" alt="Facebook" class="h-5">
</a>
</li>
<li class="mr-4">
<a href="#">
<img src="assets/images/social-media/twitter.png" alt="Twitter" class="h-5">
</a>
</li>
<li>
<a href="#">
<img src="assets/images/social-media/youtube.png" alt="YouTube" class="h-5">
</a>
</li>
</ul>
<p class="text-gray-400">2024 - Petflix</p>
</div>
</footer>
<script>
document.addEventListener("DOMContentLoaded", function () {
fetchVideos();
document.getElementById("filter-form").addEventListener("submit", function (event) {
event.preventDefault();
const animalFilter = document.getElementById("animal-filter").value;
const cityFilter = document.getElementById("city-filter").value;
fetchFilteredVideos(animalFilter, cityFilter);
});
});
let coverVideoId = null; // This will store the ID of the cover video
async function fetchVideos() {
try {
const response = await fetch("http://localhost:8000/videos/");
if (!response.ok) {
throw new Error(`Erreur lors de la récupération des vidéos : ${response.status}`);
}
const data = await response.json();
displayVideos(data.videos);
if (data.videos.length > 0) {
coverVideoId = data.videos[0].id; // Assuming each video has an 'id' property
}
} catch (error) {
console.error("Erreur lors de la récupération des vidéos :", error);
}
}
async function fetchFilteredVideos(animalType, memberCity) {
try {
const response = await fetch(`http://localhost:8000/videos/?animal_type=${animalType}&member_city=${memberCity}`);
if (!response.ok) {
throw new Error(`Erreur lors de la récupération des vidéos filtrées : ${response.status}`);
}
const data = await response.json();
displayVideos(data.videos);
} catch (error) {
console.error("Erreur lors de la récupération des vidéos filtrées :", error);
}
}
function displayVideos(videos, updateCover = true) {
if (videos.length === 0) {
console.log("Aucune vidéo à afficher.");
return;
}
if (updateCover) {
// Update the cover video only if required
const videoCoverContainer = document.getElementById("video-cover");
const firstVideo = videos[0];
const videoCoverHtml = `
<div class="relative w-full h-full">
<iframe width="480" height="280"
src="https://www.youtube.com/embed/${firstVideo.url}?autoplay=1&controls=0&modestbranding=1&mute=1&loop=1&playlist=${firstVideo.url}"
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen>
</iframe>
<div class="overlay" onclick="window.location.href='video.html?id=${firstVideo.id}';">
<h2 class="overlay-text">${firstVideo.titre}</h2>
</div>
</div>
`;
videoCoverContainer.innerHTML = videoCoverHtml;
}
// Update other videos
const videosContainer = document.getElementById("videos-container");
videosContainer.innerHTML = ""; // Clear existing videos
videos.forEach(video => {
if (video.id !== coverVideoId || !updateCover) { // Exclude the cover video from the listing
const videoHtml = `
<div class="video relative">
<iframe width="480" height="280"
src="https://www.youtube.com/embed/${video.url}?controls=0&modestbranding=0"
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
reibollo="strict-origin-when-cross-origin"
allowfullscreen>
</iframe>
<div class="overlay" onclick="window.location.href='video.html?id=${video.id}';">
<h2 class="overlay-text">${video.titre}</h2>
</div>
</div>
`;
videosContainer.innerHTML += videoHtml;
}
});
}
</script>
</body>
</html>