OSM-Beiträge: "Hund willkommen?" 👍/👎 (dog=yes/no) + Umdrehen
- dog=no zusätzlich zu dog=yes (Pächterwechsel → Ort nicht mehr hundefreundlich). - Map-Popup: ein "Hund willkommen?"-Block mit Daumen hoch/runter statt zwei Buttons. Beide rufen /dog-friendly mit welcome=true|false. - Backend generisch: tag_value yes|no; vorhandene Markierung mit anderem Wert wird umgedreht (Update statt 409); submit_dog_tag(value); Confirm/Revert prüft gegen den jeweiligen tag_value; Changeset-Kommentar wertabhängig.
This commit is contained in:
parent
57849515ea
commit
9afbf24535
7 changed files with 100 additions and 67 deletions
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
|||
1157
|
||||
1158
|
||||
|
|
@ -48,6 +48,7 @@ class DogFriendlyIn(BaseModel):
|
|||
poi_type: Optional[str] = None
|
||||
lat: float
|
||||
lon: float
|
||||
welcome: bool = True # True → dog=yes, False → dog=no (Pächterwechsel)
|
||||
|
||||
|
||||
def _verified_count(conn, uid: int) -> int:
|
||||
|
|
@ -60,13 +61,13 @@ def _verified_count(conn, uid: int) -> int:
|
|||
# ------------------------------------------------------------------
|
||||
# OSM-Changeset-Upload (write_api): Element holen → dog=yes → Changeset.
|
||||
# ------------------------------------------------------------------
|
||||
_CHANGESET_XML = (
|
||||
'<osm><changeset>'
|
||||
'<tag k="created_by" v="BanYaro/1.0"/>'
|
||||
'<tag k="comment" v="Hund willkommen (dog=yes) — via Ban Yaro"/>'
|
||||
'<tag k="source" v="survey"/>'
|
||||
'</changeset></osm>'
|
||||
)
|
||||
def _changeset_xml(value: str) -> str:
|
||||
note = "Hund willkommen" if value == "yes" else "Hund nicht willkommen"
|
||||
return ('<osm><changeset>'
|
||||
'<tag k="created_by" v="BanYaro/1.0"/>'
|
||||
f'<tag k="comment" v="{note} (dog={value}) — via Ban Yaro"/>'
|
||||
'<tag k="source" v="survey"/>'
|
||||
'</changeset></osm>')
|
||||
|
||||
|
||||
def _mark_submitted(contrib_id: int, etype: str, changeset_id):
|
||||
|
|
@ -78,9 +79,9 @@ def _mark_submitted(contrib_id: int, etype: str, changeset_id):
|
|||
)
|
||||
|
||||
|
||||
async def submit_dog_yes(contrib_id: int, osm_id: int, osm_type: str, token: str) -> bool:
|
||||
"""Setzt dog=yes am OSM-Element des Nutzers (eigener OAuth-Token). Idempotent.
|
||||
Wirft bei Fehler → Beitrag bleibt 'pending' (Retry über den Job)."""
|
||||
async def submit_dog_tag(contrib_id: int, osm_id: int, osm_type: str, token: str, value: str) -> bool:
|
||||
"""Setzt dog=<value> (yes|no) am OSM-Element des Nutzers (eigener OAuth-Token).
|
||||
Idempotent. Wirft bei Fehler → Beitrag bleibt 'pending' (Retry über den Job)."""
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
order = [osm_type, "way" if osm_type == "node" else "node"]
|
||||
async with httpx.AsyncClient(timeout=20) as client:
|
||||
|
|
@ -96,21 +97,21 @@ async def submit_dog_yes(contrib_id: int, osm_id: int, osm_type: str, token: str
|
|||
root = ET.fromstring(elem_xml)
|
||||
el = root.find(etype)
|
||||
existing = el.find("./tag[@k='dog']")
|
||||
if existing is not None and existing.get("v") == "yes":
|
||||
if existing is not None and existing.get("v") == value:
|
||||
_mark_submitted(contrib_id, etype, None) # schon gesetzt → fertig
|
||||
return True
|
||||
|
||||
# 2) Changeset öffnen
|
||||
cs = await client.put(f"{OSM_API_BASE}/api/0.6/changeset/create",
|
||||
headers=headers, content=_CHANGESET_XML)
|
||||
headers=headers, content=_changeset_xml(value))
|
||||
cs.raise_for_status()
|
||||
changeset_id = cs.text.strip()
|
||||
|
||||
# 3) dog=yes setzen + Element hochladen (Geometrie/andere Tags bleiben)
|
||||
# 3) dog=<value> setzen + Element hochladen (Geometrie/andere Tags bleiben)
|
||||
if existing is not None:
|
||||
existing.set("v", "yes")
|
||||
existing.set("v", value)
|
||||
else:
|
||||
ET.SubElement(el, "tag", {"k": "dog", "v": "yes"})
|
||||
ET.SubElement(el, "tag", {"k": "dog", "v": value})
|
||||
el.set("changeset", changeset_id)
|
||||
up = await client.put(f"{OSM_API_BASE}/api/0.6/{etype}/{osm_id}",
|
||||
headers=headers, content=ET.tostring(root, encoding="unicode"))
|
||||
|
|
@ -132,12 +133,17 @@ async def mark_dog_friendly(body: DogFriendlyIn, user=Depends(get_current_user))
|
|||
if not conn.execute("SELECT 1 FROM user_osm WHERE user_id=?", (uid,)).fetchone():
|
||||
raise HTTPException(409, "Bitte zuerst dein OSM-Konto verknüpfen.")
|
||||
|
||||
# 1) Dedup — 1× pro POI
|
||||
if conn.execute(
|
||||
"SELECT 1 FROM osm_contributions WHERE user_id=? AND osm_id=? AND tag_key='dog'",
|
||||
value = 'yes' if body.welcome else 'no'
|
||||
|
||||
# 1) Vorhandene Markierung? Gleicher Wert → fertig. Anderer Wert →
|
||||
# umdrehen erlaubt (Pächter wechseln → aus willkommen wird nicht mehr).
|
||||
existing = conn.execute(
|
||||
"SELECT id, tag_value FROM osm_contributions "
|
||||
"WHERE user_id=? AND osm_id=? AND tag_key='dog'",
|
||||
(uid, body.osm_id)
|
||||
).fetchone():
|
||||
raise HTTPException(409, "Diesen Ort hast du schon als hundefreundlich markiert.")
|
||||
).fetchone()
|
||||
if existing and existing['tag_value'] == value:
|
||||
raise HTTPException(409, "Diesen Ort hast du schon so markiert.")
|
||||
|
||||
# 2) Zeitkomponente: Tages-Rate-Limit
|
||||
today_n = conn.execute(
|
||||
|
|
@ -184,16 +190,27 @@ async def mark_dog_friendly(body: DogFriendlyIn, user=Depends(get_current_user))
|
|||
if poi and haversine_m(body.lat, body.lon, poi['lat'], poi['lon']) > POI_NEAR_M:
|
||||
raise HTTPException(422, "Position passt nicht zum gewählten Ort.")
|
||||
|
||||
# 5) verifiziert erfassen (pending; OSM-Upload gleich best-effort)
|
||||
cur = conn.execute(
|
||||
"""INSERT INTO osm_contributions
|
||||
(user_id, osm_id, osm_type, poi_type, tag_key, tag_value, lat, lon,
|
||||
route_id, gps_distance_m, gps_points_near, status)
|
||||
VALUES (?,?,?,?, 'dog','yes', ?,?, ?,?,?, 'pending')""",
|
||||
(uid, body.osm_id, body.osm_type, body.poi_type, body.lat, body.lon,
|
||||
best[0], round(best[1], 1), best[2])
|
||||
)
|
||||
contrib_id = cur.lastrowid
|
||||
# 5) verifiziert erfassen oder umdrehen (pending; OSM-Upload gleich best-effort)
|
||||
if existing:
|
||||
conn.execute(
|
||||
"UPDATE osm_contributions SET tag_value=?, osm_type=?, poi_type=?, "
|
||||
"lat=?, lon=?, route_id=?, gps_distance_m=?, gps_points_near=?, "
|
||||
"status='pending', changeset_id=NULL, submitted_at=NULL, "
|
||||
"created_at=datetime('now') WHERE id=?",
|
||||
(value, body.osm_type, body.poi_type, body.lat, body.lon,
|
||||
best[0], round(best[1], 1), best[2], existing['id'])
|
||||
)
|
||||
contrib_id = existing['id']
|
||||
else:
|
||||
cur = conn.execute(
|
||||
"""INSERT INTO osm_contributions
|
||||
(user_id, osm_id, osm_type, poi_type, tag_key, tag_value, lat, lon,
|
||||
route_id, gps_distance_m, gps_points_near, status)
|
||||
VALUES (?,?,?,?, 'dog',?, ?,?, ?,?,?, 'pending')""",
|
||||
(uid, body.osm_id, body.osm_type, body.poi_type, value, body.lat, body.lon,
|
||||
best[0], round(best[1], 1), best[2])
|
||||
)
|
||||
contrib_id = cur.lastrowid
|
||||
total = _verified_count(conn, uid)
|
||||
token_enc = conn.execute(
|
||||
"SELECT token_enc FROM user_osm WHERE user_id=?", (uid,)
|
||||
|
|
@ -202,14 +219,14 @@ async def mark_dog_friendly(body: DogFriendlyIn, user=Depends(get_current_user))
|
|||
# 6) OSM-Upload best-effort — Fehler → bleibt 'pending', Job versucht erneut
|
||||
submitted = False
|
||||
try:
|
||||
submitted = await submit_dog_yes(contrib_id, body.osm_id, body.osm_type, _decrypt(token_enc))
|
||||
submitted = await submit_dog_tag(contrib_id, body.osm_id, body.osm_type, _decrypt(token_enc), value)
|
||||
except Exception as e:
|
||||
logger.warning("OSM-Upload später erneut (contrib %s): %s", contrib_id, e)
|
||||
|
||||
logger.info("dog=yes erfasst: user %s, osm %s, Tour %s (%.0fm, %d Pkt), submitted=%s",
|
||||
uid, body.osm_id, best[0], best[1], best[2], submitted)
|
||||
logger.info("dog=%s erfasst: user %s, osm %s, Tour %s (%.0fm, %d Pkt), submitted=%s",
|
||||
value, uid, body.osm_id, best[0], best[1], best[2], submitted)
|
||||
return {
|
||||
"status": "erfasst", "verified": True, "submitted": submitted,
|
||||
"status": "erfasst", "value": value, "verified": True, "submitted": submitted,
|
||||
"verified_count": total, "badge": total >= BADGE_AT,
|
||||
"pro_progress": min(total, PRO_AT), "pro_at": PRO_AT,
|
||||
}
|
||||
|
|
@ -264,19 +281,20 @@ async def run_confirmation_round():
|
|||
# (1) Pending-Retry
|
||||
with db() as conn:
|
||||
pend = conn.execute(
|
||||
"SELECT c.id, c.osm_id, c.osm_type, o.token_enc FROM osm_contributions c "
|
||||
"SELECT c.id, c.osm_id, c.osm_type, c.tag_value, o.token_enc FROM osm_contributions c "
|
||||
"JOIN user_osm o ON o.user_id=c.user_id WHERE c.status='pending' LIMIT 50"
|
||||
).fetchall()
|
||||
for r in pend:
|
||||
try:
|
||||
await submit_dog_yes(r["id"], r["osm_id"], r["osm_type"] or "node", _decrypt(r["token_enc"]))
|
||||
await submit_dog_tag(r["id"], r["osm_id"], r["osm_type"] or "node",
|
||||
_decrypt(r["token_enc"]), r["tag_value"])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# (2) Confirm/Revert
|
||||
with db() as conn:
|
||||
subs = conn.execute(
|
||||
"SELECT id, user_id, osm_id, osm_type FROM osm_contributions "
|
||||
"SELECT id, user_id, osm_id, osm_type, tag_value FROM osm_contributions "
|
||||
"WHERE status='submitted' AND submitted_at < datetime('now', ?)",
|
||||
(f"-{CONFIRM_AFTER_DAYS} days",)
|
||||
).fetchall()
|
||||
|
|
@ -290,7 +308,7 @@ async def run_confirmation_round():
|
|||
if resp.status_code == 200:
|
||||
el = ET.fromstring(resp.text).find(etype)
|
||||
tag = el.find("./tag[@k='dog']") if el is not None else None
|
||||
ok = tag is not None and tag.get("v") == "yes"
|
||||
ok = tag is not None and tag.get("v") == r["tag_value"]
|
||||
new_status = "confirmed" if ok else "rejected"
|
||||
except Exception:
|
||||
continue # nächste Runde erneut
|
||||
|
|
|
|||
|
|
@ -86,14 +86,14 @@
|
|||
<title>Ban Yaro</title>
|
||||
|
||||
<!-- Theme + theme-color Statusleiste vor CSS setzen -->
|
||||
<script src="/js/boot-early.js?v=1157"></script>
|
||||
<script src="/js/boot-early.js?v=1158"></script>
|
||||
|
||||
<!-- CSS: Reihenfolge ist wichtig — ?v= zwingt Browser zur Neuladung -->
|
||||
<link rel="stylesheet" href="/css/design-system.css?v=1157">
|
||||
<link rel="stylesheet" href="/css/layout.css?v=1157">
|
||||
<link rel="stylesheet" href="/css/components.css?v=1157">
|
||||
<link rel="stylesheet" href="/css/utilities.css?v=1157">
|
||||
<link rel="stylesheet" href="/css/lists.css?v=1157">
|
||||
<link rel="stylesheet" href="/css/design-system.css?v=1158">
|
||||
<link rel="stylesheet" href="/css/layout.css?v=1158">
|
||||
<link rel="stylesheet" href="/css/components.css?v=1158">
|
||||
<link rel="stylesheet" href="/css/utilities.css?v=1158">
|
||||
<link rel="stylesheet" href="/css/lists.css?v=1158">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
|
@ -617,11 +617,11 @@
|
|||
<div id="modal-container"></div>
|
||||
|
||||
<!-- JS: Reihenfolge ist wichtig — erst Basis, dann Features -->
|
||||
<script src="/js/api.js?v=1157"></script>
|
||||
<script src="/js/ui.js?v=1157"></script>
|
||||
<script src="/js/app.js?v=1157"></script>
|
||||
<script src="/js/worlds.js?v=1157"></script>
|
||||
<script src="/js/offline-indicator.js?v=1157"></script>
|
||||
<script src="/js/api.js?v=1158"></script>
|
||||
<script src="/js/ui.js?v=1158"></script>
|
||||
<script src="/js/app.js?v=1158"></script>
|
||||
<script src="/js/worlds.js?v=1158"></script>
|
||||
<script src="/js/offline-indicator.js?v=1158"></script>
|
||||
|
||||
<!-- Feature-Seiten werden lazy geladen -->
|
||||
|
||||
|
|
@ -631,7 +631,7 @@
|
|||
|
||||
|
||||
<!-- Boot: Offline-Banner + SW-Registration (extrahiert für CSP) -->
|
||||
<script src="/js/boot.js?v=1157"></script>
|
||||
<script src="/js/boot.js?v=1158"></script>
|
||||
|
||||
|
||||
</body>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
Router, State-Management, Navigation, Initialisierung.
|
||||
============================================================ */
|
||||
|
||||
const APP_VER = '1157'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
|
||||
const APP_VER = '1158'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
|
||||
const APP_VERSION = '1.6.0'; // ← semantische Version, wird bei make release gesetzt
|
||||
window.APP_VER = APP_VER; // global verfügbar für andere Module (z.B. offline-indicator)
|
||||
window.APP_VERSION = APP_VERSION;
|
||||
|
|
|
|||
|
|
@ -1103,13 +1103,21 @@ window.Page_map = (() => {
|
|||
? `<button class="btn btn-danger btn-sm" id="mp-action">Löschen</button>`
|
||||
: `<button class="btn btn-secondary btn-sm" id="mp-action">Als ungültig melden</button>`;
|
||||
|
||||
// "Hund war willkommen" (dog=yes) — nur bei OSM-POIs, wo's Sinn ergibt
|
||||
// "Hund willkommen?" — 👍/👎 (dog=yes/no) bei OSM-POIs, wo's Sinn ergibt.
|
||||
// dog=no nötig, weil Pächter wechseln und ein Ort nicht mehr hundefreundlich wird.
|
||||
const DOG_TYPES = ['restaurant', 'hotel', 'shop', 'tierarzt', 'hundesalon'];
|
||||
const dogBtn = (poi.source === 'osm' && DOG_TYPES.includes(layerKey))
|
||||
? `<button class="btn btn-primary btn-sm" id="mp-dogyes" style="width:100%;margin-bottom:6px">
|
||||
<svg class="ph-icon" aria-hidden="true" style="width:14px;height:14px"><use href="/icons/phosphor.svg#dog"></use></svg>
|
||||
Hund war willkommen
|
||||
</button>`
|
||||
? `<div style="margin-bottom:8px">
|
||||
<div style="font-size:11px;color:#666;margin-bottom:4px">Hund willkommen?</div>
|
||||
<div style="display:flex;gap:6px">
|
||||
<button class="btn btn-secondary btn-sm" id="mp-dogyes" style="flex:1" title="Hund willkommen">
|
||||
<svg class="ph-icon" aria-hidden="true" style="width:15px;height:15px"><use href="/icons/phosphor.svg#thumbs-up"></use></svg>
|
||||
</button>
|
||||
<button class="btn btn-secondary btn-sm" id="mp-dogno" style="flex:1" title="Hund nicht willkommen">
|
||||
<svg class="ph-icon" aria-hidden="true" style="width:15px;height:15px"><use href="/icons/phosphor.svg#thumbs-down"></use></svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>`
|
||||
: '';
|
||||
|
||||
const openHours = poi.opening_hours
|
||||
|
|
@ -1139,20 +1147,27 @@ window.Page_map = (() => {
|
|||
if (isOwn) _deleteUserPoi(poi.user_poi_id, marker, layerKey);
|
||||
else _showReportDialog(poi);
|
||||
});
|
||||
document.getElementById('mp-dogyes')?.addEventListener('click', async () => {
|
||||
const b = document.getElementById('mp-dogyes');
|
||||
b.disabled = true;
|
||||
const _sendDog = async (welcome) => {
|
||||
const yes = document.getElementById('mp-dogyes');
|
||||
const no = document.getElementById('mp-dogno');
|
||||
if (yes) yes.disabled = true;
|
||||
if (no) no.disabled = true;
|
||||
try {
|
||||
const r = await API.post('/osm-contrib/dog-friendly', {
|
||||
osm_id: poi.id, osm_type: 'node', poi_type: layerKey, lat: poi.lat, lon: poi.lon,
|
||||
osm_id: poi.id, osm_type: 'node', poi_type: layerKey,
|
||||
lat: poi.lat, lon: poi.lon, welcome,
|
||||
});
|
||||
UI.toast.success(r.submitted ? 'Eingetragen — danke! 🐾' : 'Erfasst — wird übertragen 🐾');
|
||||
b.innerHTML = '✓ Eingetragen';
|
||||
UI.toast.success((welcome ? 'Hund willkommen' : 'Hund nicht willkommen')
|
||||
+ (r.submitted ? ' — eingetragen 🐾' : ' — wird übertragen 🐾'));
|
||||
marker.closePopup();
|
||||
} catch (e) {
|
||||
UI.toast.error(e?.message || 'Konnte nicht eintragen.');
|
||||
b.disabled = false;
|
||||
if (yes) yes.disabled = false;
|
||||
if (no) no.disabled = false;
|
||||
}
|
||||
});
|
||||
};
|
||||
document.getElementById('mp-dogyes')?.addEventListener('click', () => _sendDog(true));
|
||||
document.getElementById('mp-dogno')?.addEventListener('click', () => _sendDog(false));
|
||||
}, 50);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="color-scheme" content="light dark">
|
||||
<script src="/js/landing-init.js?v=1157"></script>
|
||||
<script src="/js/landing-init.js?v=1158"></script>
|
||||
<title>Ban Yaro — Die Hunde-App für Deutschland, Österreich & Schweiz</title>
|
||||
<meta name="description" content="Ban Yaro: Die kostenlose All-in-One Hunde-App für DACH. Tagebuch, Giftköder-Alarm, Training mit KI, Forum, Wurfbörse, Stammbaum, Inzucht-Check — DSGVO-konform, offline-fähig, ohne App Store.">
|
||||
<meta name="keywords" content="Hunde App, Hunde Community, Wurfbörse, Züchter, Welpen kaufen, Stammbaum Hund, Inzuchtkoeffizient, Hundezucht, Impfpass Hund, Giftköder Alarm, Gassi Community, Hundetraining App, Hunde Forum, Hunde KI, Hundefilm Datenbank, Welpen Marktplatz">
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
============================================================ */
|
||||
|
||||
// ← EINZIGE Stelle für die Version — STATIC_ASSETS und CACHE_VERSION leiten sich ab
|
||||
const VER = '1157';
|
||||
const VER = '1158';
|
||||
const CACHE_VERSION = `by-v${VER}`;
|
||||
const CACHE_STATIC = `${CACHE_VERSION}-static`;
|
||||
const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue