Files
WebCrawler/src/main/resources/templates/index.html
Σlie * 96ff8da66c secure
2026-02-27 22:42:01 +01:00

77 lines
3.1 KiB
HTML

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Iceberg Price Tracker</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body class="bg-gray-900 text-white p-10">
<h1 class="text-3xl font-bold mb-6">🧊 Iceberg Dashboard</h1>
<form action="/add" method="POST" class="mb-10">
<input type="text" name="name" placeholder="Nom Produit..." class="p-2 rounded bg-gray-800 border border-gray-700 w-1/2">
<input type="text" name="link" placeholder="Lien Amazon..." class="p-2 rounded bg-gray-800 border border-gray-700 w-1/2">
<button type="submit" class="bg-blue-600 px-4 py-2 rounded">Ajouter</button>
</form>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div th:each="product : ${products}" th:if="${product != null}" class="bg-gray-800 p-4 rounded-xl shadow-lg">
<div class="flex items-center gap-4 mb-4">
<img th:src="${product.imageUrl != null ? product.imageUrl : 'https://via.placeholder.com/150'}" class="w-16 h-16 object-contain rounded">
<h2 class="flex-1 font-semibold text-sm" th:text="${product.name ?: 'Produit sans nom'}">Nom</h2>
<a th:href="@{'/delete/' + ${product.id}}" class="text-red-500">🗑️</a>
</div>
<canvas th:id="'chart-' + ${product.id}"></canvas>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<div class="p-4 bg-gray-800 rounded-lg shadow-md mb-4">
<h3 th:text="${product.name}" class="text-xl font-bold mb-2"></h3>
<div style="height: 200px;">
<canvas th:id="'chart-' + ${product.id}"></canvas>
</div>
<script th:inline="javascript">
(function() {
const productId = [[${product.id}]];
const ctx = document.getElementById('chart-' + productId).getContext('2d');
// On va chercher les données via l'API qu'on a créée
fetch('/api/prices/' + productId)
.then(response => response.json())
.then(data => {
const labels = data.map(entry => new Date(entry.dateCheck).toLocaleDateString());
const prices = data.map(entry => entry.price);
new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'Prix (€)',
data: prices,
borderColor: '#3b82f6', // Bleu Tailwind
backgroundColor: 'rgba(59, 130, 246, 0.1)',
fill: true,
tension: 0.4 // Courbe arrondie
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: { legend: { display: false } }
}
});
});
})();
</script>
</div>
</body>
</html>