Name saved files with county, data type, and data date

This commit is contained in:
zyphlar
2026-04-09 22:24:38 -07:00
parent d904fb4f3d
commit 973b2350af
2 changed files with 33 additions and 34 deletions
+9
View File
@@ -278,6 +278,15 @@ def list_files():
return jsonify(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/<path:filename>') @app.route('/data/<path:filename>')
def serve_data(filename): def serve_data(filename):
"""Serve GeoJSON files""" """Serve GeoJSON files"""
+24 -34
View File
@@ -21,6 +21,8 @@ let multiSelectMode = false;
// Mobile controls state // Mobile controls state
let mobileControlsOpen = false; let mobileControlsOpen = false;
let loadedCounty = '';
let loadedDataType = '';
// Initialize map // Initialize map
function initMap() { function initMap() {
@@ -926,6 +928,8 @@ async function loadFiles() {
const county = document.getElementById('countySelect').value; const county = document.getElementById('countySelect').value;
const dataType = document.getElementById('dataTypeSelect').value; const dataType = document.getElementById('dataTypeSelect').value;
loadedCounty = county;
loadedDataType = dataType;
// Build file paths based on county and data type // Build file paths based on county and data type
let osmFile, diffFile, countyFile, diffAddedFile, diffRemovedFile; let osmFile, diffFile, countyFile, diffAddedFile, diffRemovedFile;
@@ -1055,43 +1059,29 @@ async function saveAcceptedItems() {
} }
}); });
// Create and download added-approved.geojson // Get the date of the loaded data from the server
if (acceptedAdded.length > 0) { let dataDate = '';
const addedData = { try {
type: 'FeatureCollection', const dateResp = await fetch('/api/latest-date');
features: acceptedAdded if (dateResp.ok) dataDate = (await dateResp.json()).date || '';
}; } catch (_) {}
const addedStr = JSON.stringify(addedData, null, 2); const prefix = [loadedCounty, loadedDataType, dataDate].filter(Boolean).join('-');
const addedBlob = new Blob([addedStr], { type: 'application/json' });
const addedUrl = URL.createObjectURL(addedBlob);
const addedLink = document.createElement('a'); function triggerDownload(features, label) {
addedLink.href = addedUrl; const blob = new Blob([JSON.stringify({ type: 'FeatureCollection', features }, null, 2)],
addedLink.download = 'added-approved.geojson'; { type: 'application/json' });
document.body.appendChild(addedLink); const url = URL.createObjectURL(blob);
addedLink.click(); const a = document.createElement('a');
document.body.removeChild(addedLink); a.href = url;
URL.revokeObjectURL(addedUrl); 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 (acceptedAdded.length > 0) triggerDownload(acceptedAdded, 'added-approved');
if (acceptedRemoved.length > 0) { if (acceptedRemoved.length > 0) triggerDownload(acceptedRemoved, 'removed-approved');
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);
}
showStatus(`Saved ${acceptedAdded.length} added, ${acceptedRemoved.length} removed (approved only)`, 'success'); showStatus(`Saved ${acceptedAdded.length} added, ${acceptedRemoved.length} removed (approved only)`, 'success');