okay got to a much more stable state. Fixed race condtion at stat of files. Should be smooth salining for a bit now.
This commit is contained in:
parent
1fc8b52840
commit
ac01d925ca
@ -236,3 +236,9 @@ For issues or questions:
|
|||||||
1. Check the troubleshooting section
|
1. Check the troubleshooting section
|
||||||
2. Review NocoDB documentation
|
2. Review NocoDB documentation
|
||||||
3. Open an issue on GitHub
|
3. Open an issue on GitHub
|
||||||
|
|
||||||
|
# Known Bugs
|
||||||
|
|
||||||
|
- First load of page often fails, need to debug
|
||||||
|
- want ui for dots tohave a edit button that then brings up the form.
|
||||||
|
-
|
||||||
@ -549,6 +549,21 @@ body {
|
|||||||
border-top: 1px solid #eee;
|
border-top: 1px solid #eee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Popup actions section */
|
||||||
|
.popup-content .popup-actions {
|
||||||
|
margin-top: 15px;
|
||||||
|
padding-top: 15px;
|
||||||
|
border-top: 1px solid #eee;
|
||||||
|
display: flex;
|
||||||
|
gap: 10px;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.popup-content .popup-actions .btn {
|
||||||
|
flex: 1;
|
||||||
|
max-width: 120px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Distinctive start location marker styles */
|
/* Distinctive start location marker styles */
|
||||||
.start-location-custom-marker {
|
.start-location-custom-marker {
|
||||||
z-index: 2000 !important;
|
z-index: 2000 !important;
|
||||||
|
|||||||
@ -20,14 +20,29 @@ let startLocationMarker = null;
|
|||||||
let isStartLocationVisible = true;
|
let isStartLocationVisible = true;
|
||||||
|
|
||||||
// Initialize the application
|
// Initialize the application
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
console.log('DOM loaded, initializing application...');
|
console.log('DOM loaded, initializing application...');
|
||||||
checkAuth();
|
|
||||||
initializeMap();
|
try {
|
||||||
loadLocations();
|
// First check authentication
|
||||||
|
await checkAuth();
|
||||||
|
|
||||||
|
// Then initialize the map
|
||||||
|
await initializeMap();
|
||||||
|
|
||||||
|
// Only load locations after map is ready
|
||||||
|
await loadLocations();
|
||||||
|
|
||||||
|
// Setup other features
|
||||||
setupEventListeners();
|
setupEventListeners();
|
||||||
setupAutoRefresh();
|
setupAutoRefresh();
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Initialization error:', error);
|
||||||
|
showStatus('Failed to initialize application', 'error');
|
||||||
|
} finally {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check authentication
|
// Check authentication
|
||||||
@ -38,7 +53,8 @@ async function checkAuth() {
|
|||||||
|
|
||||||
if (!data.authenticated) {
|
if (!data.authenticated) {
|
||||||
window.location.href = '/login.html';
|
window.location.href = '/login.html';
|
||||||
return;
|
// Throw error to stop further initialization
|
||||||
|
throw new Error('Not authenticated');
|
||||||
}
|
}
|
||||||
|
|
||||||
currentUser = data.user;
|
currentUser = data.user;
|
||||||
@ -47,6 +63,8 @@ async function checkAuth() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Auth check failed:', error);
|
console.error('Auth check failed:', error);
|
||||||
window.location.href = '/login.html';
|
window.location.href = '/login.html';
|
||||||
|
// Re-throw to stop initialization chain
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,15 +202,21 @@ async function loadLocations() {
|
|||||||
// Display locations on the map
|
// Display locations on the map
|
||||||
function displayLocations(locations) {
|
function displayLocations(locations) {
|
||||||
// Clear existing markers
|
// Clear existing markers
|
||||||
markers.forEach(marker => map.removeLayer(marker));
|
markers.forEach(marker => {
|
||||||
|
if (marker && map) {
|
||||||
|
map.removeLayer(marker);
|
||||||
|
}
|
||||||
|
});
|
||||||
markers = [];
|
markers = [];
|
||||||
|
|
||||||
// Add new markers
|
// Add new markers
|
||||||
locations.forEach(location => {
|
locations.forEach(location => {
|
||||||
if (location.latitude && location.longitude) {
|
if (location.latitude && location.longitude) {
|
||||||
const marker = createLocationMarker(location);
|
const marker = createLocationMarker(location);
|
||||||
|
if (marker) { // Only add if marker was successfully created
|
||||||
markers.push(marker);
|
markers.push(marker);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(`Displayed ${markers.length} locations`);
|
console.log(`Displayed ${markers.length} locations`);
|
||||||
@ -200,6 +224,12 @@ function displayLocations(locations) {
|
|||||||
|
|
||||||
// Create a location marker
|
// Create a location marker
|
||||||
function createLocationMarker(location) {
|
function createLocationMarker(location) {
|
||||||
|
// Safety check - ensure map exists
|
||||||
|
if (!map) {
|
||||||
|
console.warn('Map not initialized, skipping marker creation');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const lat = parseFloat(location.latitude);
|
const lat = parseFloat(location.latitude);
|
||||||
const lng = parseFloat(location.longitude);
|
const lng = parseFloat(location.longitude);
|
||||||
|
|
||||||
@ -228,16 +258,8 @@ function createLocationMarker(location) {
|
|||||||
const popupContent = createPopupContent(location);
|
const popupContent = createPopupContent(location);
|
||||||
marker.bindPopup(popupContent);
|
marker.bindPopup(popupContent);
|
||||||
|
|
||||||
// Add click handler for editing - Store location data on marker
|
// Store location data on marker for later use
|
||||||
marker._locationData = location;
|
marker._locationData = location;
|
||||||
marker.on('click', () => {
|
|
||||||
if (currentUser) {
|
|
||||||
// Debug: Log the location object to see its structure
|
|
||||||
console.log('Location clicked:', location);
|
|
||||||
console.log('Available fields:', Object.keys(location));
|
|
||||||
setTimeout(() => openEditForm(location), 100);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return marker;
|
return marker;
|
||||||
}
|
}
|
||||||
@ -263,6 +285,14 @@ function createPopupContent(location) {
|
|||||||
<div class="popup-meta">
|
<div class="popup-meta">
|
||||||
<p>ID: ${locationId || 'Unknown'}</p>
|
<p>ID: ${locationId || 'Unknown'}</p>
|
||||||
</div>
|
</div>
|
||||||
|
${currentUser ? `
|
||||||
|
<div class="popup-actions">
|
||||||
|
<button class="btn btn-primary btn-sm edit-location-popup-btn"
|
||||||
|
data-location='${escapeHtml(JSON.stringify(location))}'>
|
||||||
|
✏️ Edit
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
` : ''}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -312,6 +342,20 @@ function setupEventListeners() {
|
|||||||
|
|
||||||
// Geo-location field sync
|
// Geo-location field sync
|
||||||
setupGeoLocationSync();
|
setupGeoLocationSync();
|
||||||
|
|
||||||
|
// Add event delegation for popup edit buttons
|
||||||
|
document.addEventListener('click', (e) => {
|
||||||
|
if (e.target.classList.contains('edit-location-popup-btn')) {
|
||||||
|
e.preventDefault();
|
||||||
|
try {
|
||||||
|
const locationData = JSON.parse(e.target.getAttribute('data-location'));
|
||||||
|
openEditForm(locationData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error parsing location data:', error);
|
||||||
|
showStatus('Error opening edit form', 'error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup geo-location field synchronization
|
// Setup geo-location field synchronization
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user