diff --git a/web/server.py b/web/server.py index 6c48351..f7b4e30 100644 --- a/web/server.py +++ b/web/server.py @@ -278,6 +278,15 @@ def list_files(): return jsonify(files) +@app.route('/api/latest-date') +def latest_date(): + """Return the folder name that /data/latest symlinks to (used as data date in filenames).""" + try: + target = os.path.basename(os.path.realpath('/data/latest')) + return jsonify({'date': target}) + except Exception: + return jsonify({'date': ''}) + @app.route('/data/') def serve_data(filename): """Serve GeoJSON files""" diff --git a/web/static/map.js b/web/static/map.js index 091e0e3..1dc8205 100644 --- a/web/static/map.js +++ b/web/static/map.js @@ -21,6 +21,8 @@ let multiSelectMode = false; // Mobile controls state let mobileControlsOpen = false; +let loadedCounty = ''; +let loadedDataType = ''; // Initialize map function initMap() { @@ -926,6 +928,8 @@ async function loadFiles() { const county = document.getElementById('countySelect').value; const dataType = document.getElementById('dataTypeSelect').value; + loadedCounty = county; + loadedDataType = dataType; // Build file paths based on county and data type let osmFile, diffFile, countyFile, diffAddedFile, diffRemovedFile; @@ -1055,43 +1059,29 @@ async function saveAcceptedItems() { } }); - // Create and download added-approved.geojson - if (acceptedAdded.length > 0) { - const addedData = { - type: 'FeatureCollection', - features: acceptedAdded - }; - const addedStr = JSON.stringify(addedData, null, 2); - const addedBlob = new Blob([addedStr], { type: 'application/json' }); - const addedUrl = URL.createObjectURL(addedBlob); + // Get the date of the loaded data from the server + let dataDate = ''; + try { + const dateResp = await fetch('/api/latest-date'); + if (dateResp.ok) dataDate = (await dateResp.json()).date || ''; + } catch (_) {} + const prefix = [loadedCounty, loadedDataType, dataDate].filter(Boolean).join('-'); - const addedLink = document.createElement('a'); - addedLink.href = addedUrl; - addedLink.download = 'added-approved.geojson'; - document.body.appendChild(addedLink); - addedLink.click(); - document.body.removeChild(addedLink); - URL.revokeObjectURL(addedUrl); + function triggerDownload(features, label) { + const blob = new Blob([JSON.stringify({ type: 'FeatureCollection', features }, null, 2)], + { type: 'application/json' }); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = `${prefix}-${label}.geojson`; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); } - // Create and download removed-approved.geojson - if (acceptedRemoved.length > 0) { - const removedData = { - type: 'FeatureCollection', - features: acceptedRemoved - }; - const removedStr = JSON.stringify(removedData, null, 2); - const removedBlob = new Blob([removedStr], { type: 'application/json' }); - const removedUrl = URL.createObjectURL(removedBlob); - - const removedLink = document.createElement('a'); - removedLink.href = removedUrl; - removedLink.download = 'removed-approved.geojson'; - document.body.appendChild(removedLink); - removedLink.click(); - document.body.removeChild(removedLink); - URL.revokeObjectURL(removedUrl); - } + if (acceptedAdded.length > 0) triggerDownload(acceptedAdded, 'added-approved'); + if (acceptedRemoved.length > 0) triggerDownload(acceptedRemoved, 'removed-approved'); showStatus(`Saved ${acceptedAdded.length} added, ${acceptedRemoved.length} removed (approved only)`, 'success');