File size: 7,399 Bytes
126c069 a3e0366 126c069 a3e0366 126c069 a3e0366 126c069 a3e0366 126c069 a3e0366 126c069 a3e0366 126c069 a3e0366 126c069 a3e0366 | 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 | <!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>
|