Fix: Load autocomplete from database instead of hardcoded array
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
dvirlabs 2026-03-25 11:40:35 +02:00
parent 016d58ac75
commit 7b74c2a37d
3 changed files with 38 additions and 16 deletions

View File

@ -26,7 +26,7 @@ services:
build: build:
context: ./backend context: ./backend
dockerfile: Dockerfile dockerfile: Dockerfile
image: oramap-backend:latest image: harbor.dvirlabs.com/my-apps/oramap-backend:latest
container_name: oramap-backend container_name: oramap-backend
environment: environment:
- NODE_ENV=production - NODE_ENV=production
@ -50,7 +50,7 @@ services:
build: build:
context: ./frontend context: ./frontend
dockerfile: Dockerfile dockerfile: Dockerfile
image: oramap-frontend:latest image: harbor.dvirlabs.com/my-apps/oramap-frontend:latest
container_name: oramap-frontend container_name: oramap-frontend
ports: ports:
- "80:80" - "80:80"

View File

@ -20,6 +20,9 @@ server {
# For Kubernetes: set BACKEND_HOST env var or use service name # For Kubernetes: set BACKEND_HOST env var or use service name
# For Docker Compose: backend service name is 'backend' # For Docker Compose: backend service name is 'backend'
location /api/ { location /api/ {
# Docker's embedded DNS server
resolver 127.0.0.11 valid=30s;
# In Kubernetes, this will be: oramap-backend:3000 # In Kubernetes, this will be: oramap-backend:3000
# In Docker Compose, this will be: backend:3000 # In Docker Compose, this will be: backend:3000
# Default to backend:3000 # Default to backend:3000

View File

@ -65,17 +65,30 @@ function clearMarkers() {
}); });
} }
const familyNames = [ // Autocomplete data - loaded from database
"Kafe (קאפח)", "Shiheb (שחב-שבח)", "Eraki (עראקי)", "Salumi (סלומי-שלומי)", let familyNames = [];
"Afgin (עפג'ין)", "Uzeyri (עזירי-עוזרי)" let fuse;
// Add more families here if you like
];
// Initialize Fuse.js // Load families from database for autocomplete
const fuse = new Fuse(familyNames, { async function loadFamiliesForAutocomplete() {
try {
console.log('📚 Loading families from database for autocomplete...');
const response = await fetch('/api/families');
const families = await response.json();
// Extract unique family names
familyNames = [...new Set(families.map(f => f.family))];
console.log('✅ Loaded', familyNames.length, 'family names for autocomplete');
// Initialize or update Fuse.js
fuse = new Fuse(familyNames, {
includeScore: true, includeScore: true,
threshold: 0.4 // Lower = stricter matching threshold: 0.4 // Lower = stricter matching
}); });
} catch (error) {
console.error('❌ Failed to load families for autocomplete:', error);
}
}
const searchInput = document.getElementById('searchInput'); const searchInput = document.getElementById('searchInput');
const suggestionsBox = document.createElement('div'); const suggestionsBox = document.createElement('div');
@ -87,7 +100,7 @@ searchInput.addEventListener('input', () => {
const value = searchInput.value.trim(); const value = searchInput.value.trim();
suggestionsBox.innerHTML = ''; suggestionsBox.innerHTML = '';
if (!value) return; if (!value || !fuse) return;
const results = fuse.search(value); const results = fuse.search(value);
@ -188,6 +201,9 @@ async function addFamily(event) {
messageEl.textContent = '✅ Family added successfully!'; messageEl.textContent = '✅ Family added successfully!';
messageEl.className = 'form-message success'; messageEl.className = 'form-message success';
// Reload autocomplete with updated family list
await loadFamiliesForAutocomplete();
// Add marker to map // Add marker to map
L.marker([latitude, longitude]).addTo(map) L.marker([latitude, longitude]).addTo(map)
.bindPopup(`<strong>${familyName}</strong><br>City: ${cityName}`) .bindPopup(`<strong>${familyName}</strong><br>City: ${cityName}`)
@ -225,3 +241,6 @@ document.getElementById('searchInput').addEventListener('keypress', (e) => {
searchFamily(); searchFamily();
} }
}); });
// Load families for autocomplete when page loads
loadFamiliesForAutocomplete();