Clean up some code

This commit is contained in:
Eugene Burmakin 2025-02-08 23:00:34 +01:00
parent d101d5e544
commit 0b08af87af
4 changed files with 6 additions and 28 deletions

View file

@ -45,6 +45,11 @@ This will select points tracked between January 1st and January 31st 2025. Then
- After deleting one point from the map, other points can now be deleted as well. #723 #678
- Fixed a bug where export file was not being deleted from the server after it was deleted. #808
- After an area was drawn on the map, a popup is now being shown to allow user to provide a name and save the area. #740
- Docker entrypoints now use database name to fix problem with custom database names.
### Added
- `X-Dawarich-Version` header to the `GET /api/v1/health` endpoint response.
# 0.23.6 - 2025-02-06

View file

@ -107,8 +107,3 @@
transform: rotate(360deg);
}
}
.clickable-area,
.leaflet-interactive {
cursor: pointer !important;
}

View file

@ -128,7 +128,7 @@ export default class extends Controller {
Heatmap: this.heatmapLayer,
"Fog of War": new this.fogOverlay(),
"Scratch map": this.scratchLayer,
Areas: this.areasLayer, // Add areasLayer to the control
Areas: this.areasLayer,
Photos: this.photoMarkers
};
@ -573,9 +573,6 @@ export default class extends Controller {
fillOpacity: 0.5,
},
},
},
edit: {
featureGroup: this.drawnItems
}
});

View file

@ -35,7 +35,6 @@ export function handleAreaCreated(areasLayer, layer, apiKey) {
</div>
`;
console.log('Binding popup to layer');
layer.bindPopup(formHtml, {
maxWidth: "auto",
minWidth: 300,
@ -44,20 +43,14 @@ export function handleAreaCreated(areasLayer, layer, apiKey) {
className: 'area-form-popup'
}).openPopup();
console.log('Adding layer to areasLayer');
areasLayer.addLayer(layer);
// Bind the event handler immediately after opening the popup
setTimeout(() => {
console.log('Setting up form handlers');
const form = document.getElementById('circle-form');
const saveButton = document.getElementById('save-area-btn');
const nameInput = document.getElementById('circle-name');
console.log('Form:', form);
console.log('Save button:', saveButton);
console.log('Name input:', nameInput);
if (!form || !saveButton || !nameInput) {
console.error('Required elements not found');
return;
@ -77,28 +70,20 @@ export function handleAreaCreated(areasLayer, layer, apiKey) {
e.stopPropagation();
if (!nameInput.value.trim()) {
console.log('Name is empty');
nameInput.classList.add('input-error');
return;
}
console.log('Creating FormData');
const formData = new FormData(form);
formData.forEach((value, key) => {
console.log(`FormData: ${key} = ${value}`);
});
console.log('Calling saveArea');
saveArea(formData, areasLayer, layer, apiKey);
});
}, 100); // Small delay to ensure DOM is ready
}
export function saveArea(formData, areasLayer, layer, apiKey) {
console.log('saveArea called with apiKey:', apiKey);
const data = {};
formData.forEach((value, key) => {
console.log('FormData entry:', key, value);
const keys = key.split('[').map(k => k.replace(']', ''));
if (keys.length > 1) {
if (!data[keys[0]]) data[keys[0]] = {};
@ -108,21 +93,18 @@ export function saveArea(formData, areasLayer, layer, apiKey) {
}
});
console.log('Sending fetch request with data:', data);
fetch(`/api/v1/areas?api_key=${apiKey}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json'},
body: JSON.stringify(data)
})
.then(response => {
console.log('Received response:', response);
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log('Area saved successfully:', data);
layer.closePopup();
layer.bindPopup(`
Name: ${data.name}<br>
@ -170,7 +152,6 @@ export function deleteArea(id, areasLayer, layer, apiKey) {
}
export function fetchAndDrawAreas(areasLayer, apiKey) {
console.log('Fetching areas...');
fetch(`/api/v1/areas?api_key=${apiKey}`, {
method: 'GET',
headers: {