obilir's picture
e kodlar boş hani
a3e0366 verified
Raw History Blame Contribute Delete
7.4 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Plant Database | FloraFetch</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
</head>
<body class="bg-gray-50 min-h-screen flex flex-col">
<custom-navbar></custom-navbar>
<main class="flex-grow container mx-auto px-4 py-8">
<div class="max-w-6xl mx-auto bg-white rounded-xl shadow-lg p-6">
<h1 class="text-3xl font-bold text-center text-green-800 mb-6">Plant Database 🌱</h1>
<div class="mb-6 flex flex-col sm:flex-row justify-between items-center gap-4">
<div class="relative w-full sm:w-64">
<input type="text" id="searchInput" placeholder="Search plants..."
class="w-full pl-10 pr-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500">
<i data-feather="search" class="absolute left-3 top-3 text-gray-400"></i>
</div>
<button id="downloadBtn" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg font-medium flex items-center transition">
<i data-feather="download" class="mr-2"></i> Download Dataset (CSV)
</button>
</div>
<div class="overflow-x-auto">
<table id="plantTable" class="w-full border-collapse">
<thead>
<tr class="bg-green-50 text-green-800">
<th class="p-3 text-left">Common Name</th>
<th class="p-3 text-left">Scientific Name</th>
<th class="p-3 text-left">Family</th>
<th class="p-3 text-left">Origin</th>
<th class="p-3 text-left">Uses</th>
</tr>
</thead>
<tbody id="plantData" class="divide-y divide-gray-200">
<!-- Data will be loaded here -->
</tbody>
</table>
</div>
<div class="mt-6 flex justify-center">
<div id="pagination" class="flex gap-2">
<!-- Pagination will be added here -->
</div>
</div>
</div>
</main>
<custom-footer></custom-footer>
<script src="components/navbar.js"></script>
<script src="components/footer.js"></script>
<script>
feather.replace();
// Sample plant data since Trefle API requires a token
const samplePlants = [
{ common_name: "Rose", scientific_name: "Rosa rubiginosa", family: "Rosaceae", distribution: "Europe, Asia", uses: "Ornamental, Medicinal" },
{ common_name: "Sunflower", scientific_name: "Helianthus annuus", family: "Asteraceae", distribution: "North America", uses: "Oil production, Food" },
{ common_name: "Lavender", scientific_name: "Lavandula angustifolia", family: "Lamiaceae", distribution: "Mediterranean", uses: "Essential oil, Perfume" },
{ common_name: "Mint", scientific_name: "Mentha spicata", family: "Lamiaceae", distribution: "Europe, Asia", uses: "Culinary, Medicinal" },
{ common_name: "Aloe Vera", scientific_name: "Aloe barbadensis", family: "Asphodelaceae", distribution: "Arabian Peninsula", uses: "Medicinal, Cosmetic" },
{ common_name: "Basil", scientific_name: "Ocimum basilicum", family: "Lamiaceae", distribution: "Central Africa, Southeast Asia", uses: "Culinary, Medicinal" },
{ common_name: "Chamomile", scientific_name: "Matricaria chamomilla", family: "Asteraceae", distribution: "Europe, Asia", uses: "Tea, Medicinal" },
{ common_name: "Echinacea", scientific_name: "Echinacea purpurea", family: "Asteraceae", distribution: "North America", uses: "Immune support, Medicinal" },
{ common_name: "Ginger", scientific_name: "Zingiber officinale", family: "Zingiberaceae", distribution: "Southeast Asia", uses: "Culinary, Medicinal" },
{ common_name: "Ginseng", scientific_name: "Panax ginseng", family: "Araliaceae", distribution: "East Asia", uses: "Energy booster, Medicinal" }
];
// Display plants in table
function displayPlants(plants) {
const tableBody = document.getElementById('plantData');
tableBody.innerHTML = '';
plants.forEach(plant => {
const row = document.createElement('tr');
row.className = 'hover:bg-gray-50';
row.innerHTML = `
<td class="p-3">${plant.common_name || 'N/A'}</td>
<td class="p-3 font-italic">${plant.scientific_name}</td>
<td class="p-3">${plant.family || 'N/A'}</td>
<td class="p-3">${plant.distribution || 'N/A'}</td>
<td class="p-3">${plant.uses || 'N/A'}</td>
`;
tableBody.appendChild(row);
});
}
// Filter plants based on search input
function filterPlants() {
const searchTerm = document.getElementById('searchInput').value.toLowerCase();
const filteredPlants = samplePlants.filter(plant =>
plant.common_name.toLowerCase().includes(searchTerm) ||
plant.scientific_name.toLowerCase().includes(searchTerm) ||
plant.family.toLowerCase().includes(searchTerm)
);
displayPlants(filteredPlants);
}
// Download dataset as CSV
document.getElementById('downloadBtn').addEventListener('click', () => {
const headers = ['Common Name', 'Scientific Name', 'Family', 'Origin', 'Uses'];
const csvRows = [];
// Add header row
csvRows.push(headers.join(','));
// Add data rows
samplePlants.forEach(plant => {
const values = [
`"${plant.common_name || ''}"`,
`"${plant.scientific_name}"`,
`"${plant.family || ''}"`,
`"${plant.distribution || ''}"`,
`"${plant.uses || ''}"`
];
csvRows.push(values.join(','));
});
// Create CSV file
const csvData = csvRows.join('\n');
const blob = new Blob([csvData], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
// Create download link
const a = document.createElement('a');
a.setAttribute('hidden', '');
a.setAttribute('href', url);
a.setAttribute('download', 'florafetch_plant_database.csv');
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
});
// Add event listener for search input
document.getElementById('searchInput').addEventListener('input', filterPlants);
// Initialize
displayPlants(samplePlants);
</script>
</body>
</html>