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 - 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 - 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 - 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 # 0.23.6 - 2025-02-06

View file

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

View file

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

View file

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