Spaces:
Running
Running
Update main.js
Browse files
main.js
CHANGED
@@ -84,14 +84,60 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
84 |
}
|
85 |
|
86 |
function showObjectInfo(poiId) {
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
function addUserMessage(message) {
|
96 |
const chatContainer = aiAssistant.querySelector('.flex-col');
|
97 |
const msg = `<div class="ai-message user-message"><p>${message}</p></div>`;
|
|
|
84 |
}
|
85 |
|
86 |
function showObjectInfo(poiId) {
|
87 |
+
// Show loading text while we fetch data
|
88 |
+
objectTitle.textContent = 'Loading...';
|
89 |
+
objectDescription.textContent = '';
|
90 |
+
|
91 |
+
// Hide the AeroDeck section initially
|
92 |
+
const aerodeckSection = document.getElementById('aerodeckSection');
|
93 |
+
aerodeckSection.classList.add('hidden');
|
94 |
+
|
95 |
+
// Fetch data for the SINGLE POI from our new backend route
|
96 |
+
fetch(`${config.backendUrl}/api/pois/${poiId}`)
|
97 |
+
.then(response => {
|
98 |
+
if (!response.ok) throw new Error('POI not found');
|
99 |
+
return response.json();
|
100 |
+
})
|
101 |
+
.then(data => {
|
102 |
+
// Populate the main POI info
|
103 |
+
objectTitle.textContent = data.name;
|
104 |
+
objectDescription.textContent = data.description || "No description available.";
|
105 |
+
objectImage.src = `https://via.placeholder.com/300x200?text=${encodeURIComponent(data.name)}`;
|
106 |
+
|
107 |
+
// Check if there is AeroDeck data in the response
|
108 |
+
if (data.aerodecks && data.aerodecks.length > 0) {
|
109 |
+
const aerodeckList = document.getElementById('aerodeckList');
|
110 |
+
aerodeckList.innerHTML = ''; // Clear any old list items
|
111 |
+
|
112 |
+
// Loop through each AeroDeck and create an HTML element for it
|
113 |
+
data.aerodecks.forEach(deck => {
|
114 |
+
const itemElement = document.createElement('div');
|
115 |
+
itemElement.className = 'flex justify-between items-center p-2 bg-gray-100 rounded';
|
116 |
+
|
117 |
+
const statusColor = deck.status === 'Operational' ? 'text-green-500' : 'text-orange-500';
|
118 |
|
119 |
+
itemElement.innerHTML = `
|
120 |
+
<div>
|
121 |
+
<div class="font-medium">${deck.deck_name}</div>
|
122 |
+
<div class="text-sm text-gray-600">Size: ${deck.size_meters}m | Charging: ${deck.is_charging_available ? 'Yes' : 'No'}</div>
|
123 |
+
</div>
|
124 |
+
<div class="font-bold text-sm ${statusColor}">${deck.status}</div>
|
125 |
+
`;
|
126 |
+
aerodeckList.appendChild(itemElement);
|
127 |
+
});
|
128 |
+
|
129 |
+
// Make the whole AeroDeck section visible
|
130 |
+
aerodeckSection.classList.remove('hidden');
|
131 |
+
}
|
132 |
+
|
133 |
+
// Finally, show the fully populated modal
|
134 |
+
objectModal.classList.remove('hidden');
|
135 |
+
})
|
136 |
+
.catch(error => {
|
137 |
+
console.error("Error fetching POI details:", error);
|
138 |
+
alert("Could not load details for this location.");
|
139 |
+
});
|
140 |
+
}
|
141 |
function addUserMessage(message) {
|
142 |
const chatContainer = aiAssistant.querySelector('.flex-col');
|
143 |
const msg = `<div class="ai-message user-message"><p>${message}</p></div>`;
|