Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +31 -3
templates/index.html
CHANGED
|
@@ -4,11 +4,14 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<title>Pest GeoSpatial Analytics</title>
|
| 6 |
<style>
|
|
|
|
| 7 |
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');
|
|
|
|
| 8 |
@keyframes fadeIn {
|
| 9 |
from { opacity: 0; transform: translateY(20px); }
|
| 10 |
to { opacity: 1; transform: translateY(0); }
|
| 11 |
}
|
|
|
|
| 12 |
body {
|
| 13 |
margin: 0;
|
| 14 |
padding: 0;
|
|
@@ -19,6 +22,7 @@
|
|
| 19 |
align-items: center;
|
| 20 |
min-height: 100vh;
|
| 21 |
}
|
|
|
|
| 22 |
.container {
|
| 23 |
width: 95%;
|
| 24 |
max-width: 800px;
|
|
@@ -29,22 +33,26 @@
|
|
| 29 |
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
|
| 30 |
animation: fadeIn 1s ease-out;
|
| 31 |
}
|
|
|
|
| 32 |
h1 {
|
| 33 |
color: #2e7d32;
|
| 34 |
text-align: center;
|
| 35 |
margin-bottom: 30px;
|
| 36 |
font-size: 2.8em;
|
| 37 |
}
|
|
|
|
| 38 |
form {
|
| 39 |
display: flex;
|
| 40 |
flex-direction: column;
|
| 41 |
gap: 20px;
|
| 42 |
}
|
|
|
|
| 43 |
label {
|
| 44 |
font-weight: 500;
|
| 45 |
margin-bottom: 8px;
|
| 46 |
color: #333;
|
| 47 |
}
|
|
|
|
| 48 |
select, button {
|
| 49 |
width: 100%;
|
| 50 |
padding: 14px 18px;
|
|
@@ -53,11 +61,13 @@
|
|
| 53 |
font-size: 1em;
|
| 54 |
transition: all 0.3s ease;
|
| 55 |
}
|
|
|
|
| 56 |
select:focus, button:focus {
|
| 57 |
outline: none;
|
| 58 |
border-color: #2e7d32;
|
| 59 |
box-shadow: 0 0 8px rgba(46, 125, 50, 0.5);
|
| 60 |
}
|
|
|
|
| 61 |
button {
|
| 62 |
background-color: #2e7d32;
|
| 63 |
color: #fff;
|
|
@@ -65,31 +75,37 @@
|
|
| 65 |
cursor: pointer;
|
| 66 |
margin-top: 10px;
|
| 67 |
}
|
|
|
|
| 68 |
button:hover {
|
| 69 |
background-color: #276a2e;
|
| 70 |
transform: scale(1.02);
|
| 71 |
}
|
|
|
|
| 72 |
.note {
|
| 73 |
font-style: italic;
|
| 74 |
color: #555;
|
| 75 |
margin-top: 10px;
|
| 76 |
text-align: center;
|
| 77 |
}
|
|
|
|
| 78 |
.map {
|
| 79 |
margin-top: 40px;
|
| 80 |
text-align: center;
|
| 81 |
}
|
|
|
|
| 82 |
.map h2 {
|
| 83 |
color: #2e7d32;
|
| 84 |
margin-bottom: 20px;
|
| 85 |
font-size: 2em;
|
| 86 |
}
|
|
|
|
| 87 |
.map img {
|
| 88 |
max-width: 100%;
|
| 89 |
border: 3px solid #2e7d32;
|
| 90 |
border-radius: 8px;
|
| 91 |
transition: opacity 0.5s ease;
|
| 92 |
}
|
|
|
|
| 93 |
.error {
|
| 94 |
color: red;
|
| 95 |
font-weight: 700;
|
|
@@ -116,6 +132,7 @@
|
|
| 116 |
<label for="pest">Pest:</label>
|
| 117 |
<select id="pest" name="pest">
|
| 118 |
<option value="">--Select Pest--</option>
|
|
|
|
| 119 |
</select>
|
| 120 |
|
| 121 |
<!-- Year selection -->
|
|
@@ -149,27 +166,32 @@
|
|
| 149 |
<p class="note">Select a Crop, Pest, Year, Week, and Parameter to load the corresponding map.</p>
|
| 150 |
</form>
|
| 151 |
|
| 152 |
-
{% if
|
| 153 |
<div class="map" id="mapContainer">
|
| 154 |
<h2>Fetched Results</h2>
|
| 155 |
-
<!-- Use the
|
| 156 |
-
<img src="{{
|
| 157 |
<div id="dataNotAvailable" class="error" style="display:none;">Data Not Available. Cannot plot map.</div>
|
| 158 |
</div>
|
| 159 |
{% endif %}
|
| 160 |
</div>
|
| 161 |
|
| 162 |
<script>
|
|
|
|
| 163 |
const cropToPests = {{ crop_to_pests | tojson }};
|
|
|
|
|
|
|
| 164 |
function updatePestDropdown() {
|
| 165 |
const cropSelect = document.getElementById("crop");
|
| 166 |
const pestSelect = document.getElementById("pest");
|
| 167 |
const selectedCrop = cropSelect.value;
|
|
|
|
| 168 |
pestSelect.innerHTML = "";
|
| 169 |
const defaultOption = document.createElement("option");
|
| 170 |
defaultOption.value = "";
|
| 171 |
defaultOption.textContent = "--Select Pest--";
|
| 172 |
pestSelect.appendChild(defaultOption);
|
|
|
|
| 173 |
if (selectedCrop && cropToPests[selectedCrop]) {
|
| 174 |
const pests = cropToPests[selectedCrop];
|
| 175 |
pests.forEach(function(p) {
|
|
@@ -186,11 +208,14 @@
|
|
| 186 |
fetchWeeks();
|
| 187 |
}
|
| 188 |
}
|
|
|
|
|
|
|
| 189 |
function fetchWeeks() {
|
| 190 |
const crop = document.getElementById("crop").value;
|
| 191 |
const pest = document.getElementById("pest").value;
|
| 192 |
const year = document.getElementById("year").value;
|
| 193 |
if (!crop || !pest || !year) return;
|
|
|
|
| 194 |
fetch(`/fetch_weeks?crop=${crop}&pest=${pest}&year=${year}`)
|
| 195 |
.then(response => response.json())
|
| 196 |
.then(data => {
|
|
@@ -200,6 +225,7 @@
|
|
| 200 |
defaultOption.value = "";
|
| 201 |
defaultOption.textContent = "--Select Week--";
|
| 202 |
weekSelect.appendChild(defaultOption);
|
|
|
|
| 203 |
data.weeks.forEach(function(week) {
|
| 204 |
const option = document.createElement("option");
|
| 205 |
option.value = week;
|
|
@@ -212,10 +238,12 @@
|
|
| 212 |
})
|
| 213 |
.catch(err => console.error("Error fetching weeks:", err));
|
| 214 |
}
|
|
|
|
| 215 |
function handleImageError(img) {
|
| 216 |
img.style.display = "none";
|
| 217 |
document.getElementById("dataNotAvailable").style.display = "block";
|
| 218 |
}
|
|
|
|
| 219 |
window.onload = function() {
|
| 220 |
updatePestDropdown();
|
| 221 |
if ("{{ selected_year }}" && "{{ selected_crop }}" && "{{ selected_pest }}") {
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<title>Pest GeoSpatial Analytics</title>
|
| 6 |
<style>
|
| 7 |
+
/* Import a Google Font for a modern look */
|
| 8 |
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');
|
| 9 |
+
|
| 10 |
@keyframes fadeIn {
|
| 11 |
from { opacity: 0; transform: translateY(20px); }
|
| 12 |
to { opacity: 1; transform: translateY(0); }
|
| 13 |
}
|
| 14 |
+
|
| 15 |
body {
|
| 16 |
margin: 0;
|
| 17 |
padding: 0;
|
|
|
|
| 22 |
align-items: center;
|
| 23 |
min-height: 100vh;
|
| 24 |
}
|
| 25 |
+
|
| 26 |
.container {
|
| 27 |
width: 95%;
|
| 28 |
max-width: 800px;
|
|
|
|
| 33 |
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
|
| 34 |
animation: fadeIn 1s ease-out;
|
| 35 |
}
|
| 36 |
+
|
| 37 |
h1 {
|
| 38 |
color: #2e7d32;
|
| 39 |
text-align: center;
|
| 40 |
margin-bottom: 30px;
|
| 41 |
font-size: 2.8em;
|
| 42 |
}
|
| 43 |
+
|
| 44 |
form {
|
| 45 |
display: flex;
|
| 46 |
flex-direction: column;
|
| 47 |
gap: 20px;
|
| 48 |
}
|
| 49 |
+
|
| 50 |
label {
|
| 51 |
font-weight: 500;
|
| 52 |
margin-bottom: 8px;
|
| 53 |
color: #333;
|
| 54 |
}
|
| 55 |
+
|
| 56 |
select, button {
|
| 57 |
width: 100%;
|
| 58 |
padding: 14px 18px;
|
|
|
|
| 61 |
font-size: 1em;
|
| 62 |
transition: all 0.3s ease;
|
| 63 |
}
|
| 64 |
+
|
| 65 |
select:focus, button:focus {
|
| 66 |
outline: none;
|
| 67 |
border-color: #2e7d32;
|
| 68 |
box-shadow: 0 0 8px rgba(46, 125, 50, 0.5);
|
| 69 |
}
|
| 70 |
+
|
| 71 |
button {
|
| 72 |
background-color: #2e7d32;
|
| 73 |
color: #fff;
|
|
|
|
| 75 |
cursor: pointer;
|
| 76 |
margin-top: 10px;
|
| 77 |
}
|
| 78 |
+
|
| 79 |
button:hover {
|
| 80 |
background-color: #276a2e;
|
| 81 |
transform: scale(1.02);
|
| 82 |
}
|
| 83 |
+
|
| 84 |
.note {
|
| 85 |
font-style: italic;
|
| 86 |
color: #555;
|
| 87 |
margin-top: 10px;
|
| 88 |
text-align: center;
|
| 89 |
}
|
| 90 |
+
|
| 91 |
.map {
|
| 92 |
margin-top: 40px;
|
| 93 |
text-align: center;
|
| 94 |
}
|
| 95 |
+
|
| 96 |
.map h2 {
|
| 97 |
color: #2e7d32;
|
| 98 |
margin-bottom: 20px;
|
| 99 |
font-size: 2em;
|
| 100 |
}
|
| 101 |
+
|
| 102 |
.map img {
|
| 103 |
max-width: 100%;
|
| 104 |
border: 3px solid #2e7d32;
|
| 105 |
border-radius: 8px;
|
| 106 |
transition: opacity 0.5s ease;
|
| 107 |
}
|
| 108 |
+
|
| 109 |
.error {
|
| 110 |
color: red;
|
| 111 |
font-weight: 700;
|
|
|
|
| 132 |
<label for="pest">Pest:</label>
|
| 133 |
<select id="pest" name="pest">
|
| 134 |
<option value="">--Select Pest--</option>
|
| 135 |
+
<!-- Options will be set by JavaScript based on selected crop -->
|
| 136 |
</select>
|
| 137 |
|
| 138 |
<!-- Year selection -->
|
|
|
|
| 166 |
<p class="note">Select a Crop, Pest, Year, Week, and Parameter to load the corresponding map.</p>
|
| 167 |
</form>
|
| 168 |
|
| 169 |
+
{% if image_url %}
|
| 170 |
<div class="map" id="mapContainer">
|
| 171 |
<h2>Fetched Results</h2>
|
| 172 |
+
<!-- Use the proxy URL for the image -->
|
| 173 |
+
<img src="{{ image_url }}" alt="Map for {{ selected_param }} parameter" onerror="handleImageError(this)">
|
| 174 |
<div id="dataNotAvailable" class="error" style="display:none;">Data Not Available. Cannot plot map.</div>
|
| 175 |
</div>
|
| 176 |
{% endif %}
|
| 177 |
</div>
|
| 178 |
|
| 179 |
<script>
|
| 180 |
+
// Crop-to-Pest mapping provided from the server
|
| 181 |
const cropToPests = {{ crop_to_pests | tojson }};
|
| 182 |
+
|
| 183 |
+
// Update the pest dropdown based on the selected crop
|
| 184 |
function updatePestDropdown() {
|
| 185 |
const cropSelect = document.getElementById("crop");
|
| 186 |
const pestSelect = document.getElementById("pest");
|
| 187 |
const selectedCrop = cropSelect.value;
|
| 188 |
+
|
| 189 |
pestSelect.innerHTML = "";
|
| 190 |
const defaultOption = document.createElement("option");
|
| 191 |
defaultOption.value = "";
|
| 192 |
defaultOption.textContent = "--Select Pest--";
|
| 193 |
pestSelect.appendChild(defaultOption);
|
| 194 |
+
|
| 195 |
if (selectedCrop && cropToPests[selectedCrop]) {
|
| 196 |
const pests = cropToPests[selectedCrop];
|
| 197 |
pests.forEach(function(p) {
|
|
|
|
| 208 |
fetchWeeks();
|
| 209 |
}
|
| 210 |
}
|
| 211 |
+
|
| 212 |
+
// Fetch week options dynamically from the /fetch_weeks endpoint
|
| 213 |
function fetchWeeks() {
|
| 214 |
const crop = document.getElementById("crop").value;
|
| 215 |
const pest = document.getElementById("pest").value;
|
| 216 |
const year = document.getElementById("year").value;
|
| 217 |
if (!crop || !pest || !year) return;
|
| 218 |
+
|
| 219 |
fetch(`/fetch_weeks?crop=${crop}&pest=${pest}&year=${year}`)
|
| 220 |
.then(response => response.json())
|
| 221 |
.then(data => {
|
|
|
|
| 225 |
defaultOption.value = "";
|
| 226 |
defaultOption.textContent = "--Select Week--";
|
| 227 |
weekSelect.appendChild(defaultOption);
|
| 228 |
+
|
| 229 |
data.weeks.forEach(function(week) {
|
| 230 |
const option = document.createElement("option");
|
| 231 |
option.value = week;
|
|
|
|
| 238 |
})
|
| 239 |
.catch(err => console.error("Error fetching weeks:", err));
|
| 240 |
}
|
| 241 |
+
|
| 242 |
function handleImageError(img) {
|
| 243 |
img.style.display = "none";
|
| 244 |
document.getElementById("dataNotAvailable").style.display = "block";
|
| 245 |
}
|
| 246 |
+
|
| 247 |
window.onload = function() {
|
| 248 |
updatePestDropdown();
|
| 249 |
if ("{{ selected_year }}" && "{{ selected_crop }}" && "{{ selected_pest }}") {
|