Files
osm-import-tools/web/templates/counties.html
T

383 lines
13 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Counties — OSM Import Tools</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
height: 100%;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #eef0f3;
color: #222;
}
.page { display: flex; flex-direction: column; height: 100%; }
.topbar {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 16px;
background: #1a1a2e;
flex-shrink: 0;
}
.topbar h1 { font-size: 16px; font-weight: 700; color: #fff; }
.topbar-sep { width: 1px; height: 20px; background: #ffffff30; }
.btn-topbar {
padding: 5px 12px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 12px;
font-weight: 600;
background: #ffffff18;
color: #ddd;
text-decoration: none;
}
.btn-topbar:hover { background: #ffffff30; }
.btn-topbar.active { background: #ffffff30; color: #fff; }
.btn-topbar.purple { background: #6f42c1; color: white; }
.btn-topbar.purple:hover { background: #5a32a3; }
.content {
flex: 1;
overflow-y: auto;
padding: 24px;
display: flex;
flex-direction: column;
gap: 16px;
align-items: flex-start;
}
/* ── Status bar ── */
#status {
width: 100%;
max-width: 680px;
padding: 9px 14px;
font-size: 13px;
border-radius: 6px;
display: none;
}
#status.success { background: #d4edda; color: #155724; display: block; }
#status.error { background: #f8d7da; color: #721c24; display: block; }
/* ── County card ── */
.county-card {
background: white;
border-radius: 8px;
box-shadow: 0 1px 3px rgba(0,0,0,0.08);
width: 100%;
max-width: 680px;
overflow: hidden;
}
.card-header {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 16px;
background: #f8f9fa;
border-bottom: 1px solid #eee;
}
.color-swatch {
width: 14px;
height: 14px;
border-radius: 50%;
flex-shrink: 0;
}
.card-header-name {
font-size: 14px;
font-weight: 700;
color: #333;
flex: 1;
}
.btn-delete {
background: none;
border: none;
cursor: pointer;
color: #ccc;
font-size: 16px;
padding: 2px 6px;
border-radius: 3px;
line-height: 1;
}
.btn-delete:hover { color: #dc3545; background: #fdecea; }
.card-fields {
padding: 14px 16px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px 16px;
}
.field {
display: flex;
flex-direction: column;
gap: 3px;
}
.field.full { grid-column: 1 / -1; }
.field label {
font-size: 10px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.5px;
color: #888;
}
.field input[type="text"],
.field input[type="color"] {
border: 1px solid #e0e0e0;
border-radius: 4px;
padding: 5px 8px;
font-size: 13px;
color: #333;
font-family: inherit;
outline: none;
transition: border-color 0.15s;
}
.field input[type="text"]:focus { border-color: #17a2b8; }
.field input[type="color"] {
padding: 2px 4px;
height: 30px;
cursor: pointer;
}
.field .hint {
font-size: 10px;
color: #bbb;
margin-top: 1px;
}
/* ── Footer ── */
.footer {
display: flex;
gap: 10px;
align-items: center;
max-width: 680px;
width: 100%;
padding-top: 4px;
}
.btn {
padding: 7px 16px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 13px;
font-weight: 600;
}
.btn-add { background: #e8f5e9; color: #2e7d32; }
.btn-add:hover { background: #c8e6c9; }
.btn-save { background: #17a2b8; color: white; }
.btn-save:hover { filter: brightness(0.9); }
.btn-dl {
padding: 7px 12px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 13px;
font-weight: 600;
background: #e9ecef;
color: #555;
text-decoration: none;
}
.btn-dl:hover { background: #dee2e6; }
</style>
</head>
<body>
<div class="page">
<div class="topbar">
<h1>OSM Import Tools</h1>
<div class="topbar-sep"></div>
<a href="/" class="btn-topbar">&#8592; Back</a>
<div style="flex:1"></div>
<a href="/counties" class="btn-topbar active">Counties</a>
<a href="/exceptions" class="btn-topbar">Street Exceptions</a>
<a href="/map" class="btn-topbar purple">Open Map Viewer</a>
</div>
<div class="content">
<div id="status"></div>
<div id="countyList"></div>
<div class="footer">
<button class="btn btn-add" onclick="addCounty()">+ Add county</button>
<button class="btn btn-save" onclick="save()">Save</button>
{% if current_user %}
<div style="flex:1"></div>
<a href="/api/config/counties.yml" class="btn-dl" title="Download counties.yml">↓ Download</a>
<label class="btn-dl" style="cursor:pointer" title="Upload counties.yml">↑ Upload<input type="file" style="display:none" accept=".yml,.yaml" onchange="uploadConfig(this)"></label>
{% endif %}
</div>
</div>
</div>
<script>
let counties = [];
const PALETTE = ['#28a745','#17a2b8','#fd7e14','#6f42c1','#dc3545','#6610f2','#20c997','#e83e8c'];
function showStatus(msg, type) {
const el = document.getElementById('status');
el.textContent = msg;
el.className = type;
if (type === 'success') setTimeout(() => el.className = '', 3000);
}
function render() {
const container = document.getElementById('countyList');
if (!counties.length) {
container.innerHTML = '<p style="color:#aaa;font-size:13px">No counties configured. Add one to get started.</p>';
return;
}
container.innerHTML = counties.map((c, i) => `
<div class="county-card" data-index="${i}">
<div class="card-header">
<div class="color-swatch" style="background:${esc(c.color || '#888')}"></div>
<div class="card-header-name">${esc(c.name || '(unnamed)')}</div>
<button class="btn-delete" onclick="deleteCounty(${i})" title="Delete">&#x2715;</button>
</div>
<div class="card-fields">
<div class="field">
<label>ID (slug)</label>
<input type="text" value="${esc(c.id)}" placeholder="lake"
oninput="update(${i},'id',this.value)">
<span class="hint">Used in file paths — changing breaks existing data</span>
</div>
<div class="field">
<label>Display name</label>
<input type="text" value="${esc(c.name)}" placeholder="Lake County"
oninput="update(${i},'name',this.value); refreshHeader(${i})">
</div>
<div class="field">
<label>State</label>
<input type="text" value="${esc(c.state)}" placeholder="Florida"
oninput="update(${i},'state',this.value)">
</div>
<div class="field">
<label>Tab color</label>
<input type="color" value="${esc(c.color || '#28a745')}"
oninput="update(${i},'color',this.value); refreshHeader(${i})">
</div>
<div class="field full">
<label>Roads download URL</label>
<input type="text" value="${esc(c.roads_url)}" placeholder="https://…"
oninput="update(${i},'roads_url',this.value)">
</div>
<div class="field full">
<label>Addresses download URL</label>
<input type="text" value="${esc(c.addresses_url)}" placeholder="https://…"
oninput="update(${i},'addresses_url',this.value)">
</div>
<div class="field full">
<label>Paths URL</label>
<input type="text" value="${esc(c.paths_url)}" placeholder="https://… or &quot;upload&quot; or leave empty"
oninput="update(${i},'paths_url',this.value)">
<span class="hint">Empty = not available &nbsp;|&nbsp; "upload" = manual upload &nbsp;|&nbsp; URL = download</span>
</div>
</div>
</div>
`).join('');
}
function esc(s) {
return (s || '').replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/</g,'&lt;');
}
function update(i, key, value) {
counties[i][key] = value;
}
function refreshHeader(i) {
const card = document.querySelector(`.county-card[data-index="${i}"]`);
if (!card) return;
card.querySelector('.color-swatch').style.background = counties[i].color || '#888';
card.querySelector('.card-header-name').textContent = counties[i].name || '(unnamed)';
}
function addCounty() {
const color = PALETTE[counties.length % PALETTE.length];
counties.push({ id: '', name: '', state: 'Florida', color, roads_url: '', addresses_url: '', paths_url: '' });
render();
// Focus the ID field of the new card
const cards = document.querySelectorAll('.county-card');
const last = cards[cards.length - 1];
if (last) last.querySelector('input').focus();
}
function deleteCounty(i) {
counties.splice(i, 1);
render();
}
function collectFromDOM() {
document.querySelectorAll('.county-card[data-index]').forEach(card => {
const i = parseInt(card.dataset.index);
const inputs = card.querySelectorAll('input[type="text"], input[type="color"]');
// order matches render: id, name, state, color, roads_url, addresses_url, paths_url
['id','name','state','color','roads_url','addresses_url','paths_url'].forEach((key, j) => {
counties[i][key] = inputs[j].value;
});
});
}
function save() {
collectFromDOM();
for (const c of counties) {
if (!c.id.trim()) { showStatus('Each county must have an ID.', 'error'); return; }
if (!c.name.trim()) { showStatus('Each county must have a display name.', 'error'); return; }
}
fetch('/api/counties', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ counties })
})
.then(r => r.json())
.then(data => {
if (data.error) showStatus(`Error: ${data.error}`, 'error');
else showStatus('Saved successfully.', 'success');
})
.catch(err => showStatus(`Error: ${err.message}`, 'error'));
}
function uploadConfig(input) {
if (!input.files.length) return;
const formData = new FormData();
formData.append('file', input.files[0]);
showStatus('Uploading…', 'success');
fetch('/api/config/counties.yml', { method: 'POST', body: formData })
.then(r => r.json())
.then(data => {
if (data.error) { showStatus(`Error: ${data.error}`, 'error'); return; }
showStatus('Uploaded — reloading…', 'success');
setTimeout(() => window.location.reload(), 800);
})
.catch(err => showStatus(`Error: ${err.message}`, 'error'))
.finally(() => { input.value = ''; });
}
// Load on open
fetch('/api/counties')
.then(r => r.json())
.then(data => { counties = data.counties || []; render(); })
.catch(err => showStatus(`Failed to load: ${err.message}`, 'error'));
</script>
</body>
</html>