Spaces:
Running
Running
Update main.js
Browse files
main.js
CHANGED
@@ -29,6 +29,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
29 |
const settingsBtn = document.getElementById('settingsBtn');
|
30 |
const settingsModal = document.getElementById('settingsModal');
|
31 |
const closeSettingsModal = document.getElementById('closeSettingsModal');
|
|
|
|
|
32 |
|
33 |
// --- CORE & UI FUNCTIONS ---
|
34 |
|
@@ -84,60 +86,45 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
84 |
}
|
85 |
|
86 |
function showObjectInfo(poiId) {
|
87 |
-
|
88 |
-
|
89 |
-
|
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 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
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>`;
|
@@ -153,6 +140,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
153 |
}
|
154 |
|
155 |
function handleSearch() {
|
|
|
156 |
const searchTerm = userInput.value.trim();
|
157 |
if (!searchTerm) return;
|
158 |
addUserMessage(searchTerm);
|
@@ -162,16 +150,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
162 |
if (isLocalSearch) {
|
163 |
const stopWords = ['show', 'me', 'find', 'is', 'a', 'the', 'for', 'where', 'search', 'of', 'at'];
|
164 |
const searchTokens = searchTerm.toLowerCase().split(' ').filter(word => !stopWords.includes(word) && word.length > 2);
|
165 |
-
if (searchTokens.length === 0)
|
166 |
-
return addAIMessage("Please be more specific in your local search.");
|
167 |
-
}
|
168 |
const results = poisData.filter(poi => {
|
169 |
const poiText = (poi.name + ' ' + (poi.description || '')).toLowerCase();
|
170 |
return searchTokens.some(token => {
|
171 |
if (poiText.includes(token)) return true;
|
172 |
-
if (token.endsWith('s'))
|
173 |
-
return poiText.includes(token.slice(0, -1));
|
174 |
-
}
|
175 |
return false;
|
176 |
});
|
177 |
});
|
|
|
29 |
const settingsBtn = document.getElementById('settingsBtn');
|
30 |
const settingsModal = document.getElementById('settingsModal');
|
31 |
const closeSettingsModal = document.getElementById('closeSettingsModal');
|
32 |
+
const aerodeckSection = document.getElementById('aerodeckSection');
|
33 |
+
const aerodeckList = document.getElementById('aerodeckList');
|
34 |
|
35 |
// --- CORE & UI FUNCTIONS ---
|
36 |
|
|
|
86 |
}
|
87 |
|
88 |
function showObjectInfo(poiId) {
|
89 |
+
objectTitle.textContent = 'Loading...';
|
90 |
+
objectDescription.textContent = '';
|
91 |
+
aerodeckSection.classList.add('hidden');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
+
fetch(`${config.backendUrl}/api/pois/${poiId}`)
|
94 |
+
.then(response => {
|
95 |
+
if (!response.ok) throw new Error('POI not found');
|
96 |
+
return response.json();
|
97 |
+
})
|
98 |
+
.then(data => {
|
99 |
+
objectTitle.textContent = data.name;
|
100 |
+
objectDescription.textContent = data.description || "No description available.";
|
101 |
+
objectImage.src = `https://via.placeholder.com/300x200?text=${encodeURIComponent(data.name)}`;
|
102 |
+
|
103 |
+
if (data.aerodecks && data.aerodecks.length > 0) {
|
104 |
+
aerodeckList.innerHTML = '';
|
105 |
+
data.aerodecks.forEach(deck => {
|
106 |
+
const itemElement = document.createElement('div');
|
107 |
+
itemElement.className = 'flex justify-between items-center p-2 bg-gray-100 rounded';
|
108 |
+
const statusColor = deck.status === 'Operational' ? 'text-green-500' : 'text-orange-500';
|
109 |
+
itemElement.innerHTML = `
|
110 |
+
<div>
|
111 |
+
<div class="font-medium">${deck.deck_name}</div>
|
112 |
+
<div class="text-sm text-gray-600">Size: ${deck.size_meters}m | Charging: ${deck.is_charging_available ? 'Yes' : 'No'}</div>
|
113 |
+
</div>
|
114 |
+
<div class="font-bold text-sm ${statusColor}">${deck.status}</div>
|
115 |
+
`;
|
116 |
+
aerodeckList.appendChild(itemElement);
|
117 |
+
});
|
118 |
+
aerodeckSection.classList.remove('hidden');
|
119 |
+
}
|
120 |
+
objectModal.classList.remove('hidden');
|
121 |
+
})
|
122 |
+
.catch(error => {
|
123 |
+
console.error("Error fetching POI details:", error);
|
124 |
+
alert("Could not load details for this location.");
|
125 |
+
});
|
126 |
+
}
|
127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
function addUserMessage(message) {
|
129 |
const chatContainer = aiAssistant.querySelector('.flex-col');
|
130 |
const msg = `<div class="ai-message user-message"><p>${message}</p></div>`;
|
|
|
140 |
}
|
141 |
|
142 |
function handleSearch() {
|
143 |
+
// This is the latest, most forgiving search function
|
144 |
const searchTerm = userInput.value.trim();
|
145 |
if (!searchTerm) return;
|
146 |
addUserMessage(searchTerm);
|
|
|
150 |
if (isLocalSearch) {
|
151 |
const stopWords = ['show', 'me', 'find', 'is', 'a', 'the', 'for', 'where', 'search', 'of', 'at'];
|
152 |
const searchTokens = searchTerm.toLowerCase().split(' ').filter(word => !stopWords.includes(word) && word.length > 2);
|
153 |
+
if (searchTokens.length === 0) return addAIMessage("Please be more specific in your local search.");
|
|
|
|
|
154 |
const results = poisData.filter(poi => {
|
155 |
const poiText = (poi.name + ' ' + (poi.description || '')).toLowerCase();
|
156 |
return searchTokens.some(token => {
|
157 |
if (poiText.includes(token)) return true;
|
158 |
+
if (token.endsWith('s')) return poiText.includes(token.slice(0, -1));
|
|
|
|
|
159 |
return false;
|
160 |
});
|
161 |
});
|