Google saved places: a name or description changed here survives a new export (the last imported text is kept per point, a field differing from it counts as a hand edit); the popup marks such a point as edited
This commit is contained in:
1 parent
3f4b30d737
commit
064871b687
4 files changed
+38
-5
No files matched your search
+16
-3
@@ -319,8 +319,12 @@ module Maptool
|
|||||||
props = (feature["properties"] || {}).except("id")
|
props = (feature["properties"] || {}).except("id")
|
||||||
write do |db, rev, now|
|
write do |db, rev, now|
|
||||||
# Moved by hand: an imported approximate position (GoogleSaved) is checked now.
|
# Moved by hand: an imported approximate position (GoogleSaved) is checked now.
|
||||||
old = db.get_first_value("SELECT geometry FROM items WHERE id = ?", [id])
|
old, old_props = db.get_first_row("SELECT geometry, properties FROM items WHERE id = ?", [id])
|
||||||
props.delete("approximate") if old && round(JSON.parse(old)) != round(feature["geometry"])
|
props.delete("approximate") if old && round(JSON.parse(old)) != round(feature["geometry"])
|
||||||
|
# What the last import said stays, whatever the popup sent back
|
||||||
|
# (upsert_by_source_id tells a hand edit from it).
|
||||||
|
imported = old_props && JSON.parse(old_props)["imported"]
|
||||||
|
props["imported"] = imported if imported
|
||||||
db.execute("UPDATE items SET name = ?, geometry = ?, properties = ?, updated_at = ?, rev = ? WHERE id = ? AND deleted_at IS NULL",
|
db.execute("UPDATE items SET name = ?, geometry = ?, properties = ?, updated_at = ?, rev = ? WHERE id = ? AND deleted_at IS NULL",
|
||||||
[props["name"], JSON.generate(feature["geometry"]), JSON.generate(props), now, rev, id])
|
[props["name"], JSON.generate(feature["geometry"]), JSON.generate(props), now, rev, id])
|
||||||
raise NotFound if db.changes.zero?
|
raise NotFound if db.changes.zero?
|
||||||
@@ -633,9 +637,13 @@ module Maptool
|
|||||||
# saved place's id) is kept once per folder: importing the list again
|
# saved place's id) is kept once per folder: importing the list again
|
||||||
# refreshes the point's name and Google's fields, keeping what was
|
# refreshes the point's name and Google's fields, keeping what was
|
||||||
# changed here (color, icon, a moved position — only an approximate
|
# changed here (color, icon, a moved position — only an approximate
|
||||||
# position gives way to an exact one). One deleted here stays deleted.
|
# position gives way to an exact one, a renamed or redescribed point
|
||||||
|
# keeps its own text). One deleted here stays deleted.
|
||||||
# Returns the id, nil when skipped.
|
# Returns the id, nil when skipped.
|
||||||
|
IMPORTED_TEXT = %w[name description].freeze
|
||||||
|
|
||||||
def upsert_by_source_id(db, folder, props, geometry, rev, now)
|
def upsert_by_source_id(db, folder, props, geometry, rev, now)
|
||||||
|
props = props.merge("imported" => props.slice(*IMPORTED_TEXT))
|
||||||
row = db.get_first_row("SELECT id, geometry, properties, deleted_at FROM items WHERE folder_id IS ? AND json_extract(properties, '$.source_id') = ?",
|
row = db.get_first_row("SELECT id, geometry, properties, deleted_at FROM items WHERE folder_id IS ? AND json_extract(properties, '$.source_id') = ?",
|
||||||
[folder, props["source_id"]])
|
[folder, props["source_id"]])
|
||||||
unless row
|
unless row
|
||||||
@@ -649,13 +657,18 @@ module Maptool
|
|||||||
|
|
||||||
old = JSON.parse(old_props)
|
old = JSON.parse(old_props)
|
||||||
merged = old.merge(props.except("id", "approximate"))
|
merged = old.merge(props.except("id", "approximate"))
|
||||||
|
# A field differing from what the last import said was edited here.
|
||||||
|
# Points imported before "imported" was kept: any difference counts
|
||||||
|
# as an edit, the safe guess.
|
||||||
|
last = old["imported"] || {}
|
||||||
|
IMPORTED_TEXT.each { |f| merged[f] = old[f] if old.key?(f) && old[f] != last.fetch(f, props[f]) }
|
||||||
exact = old["approximate"] && !props["approximate"]
|
exact = old["approximate"] && !props["approximate"]
|
||||||
merged.delete("approximate") if exact
|
merged.delete("approximate") if exact
|
||||||
new_geometry = exact ? JSON.generate(geometry) : old_geometry
|
new_geometry = exact ? JSON.generate(geometry) : old_geometry
|
||||||
return id if merged == old && new_geometry == old_geometry
|
return id if merged == old && new_geometry == old_geometry
|
||||||
|
|
||||||
db.execute("UPDATE items SET name = ?, geometry = ?, properties = ?, updated_at = ?, rev = ? WHERE id = ?",
|
db.execute("UPDATE items SET name = ?, geometry = ?, properties = ?, updated_at = ?, rev = ? WHERE id = ?",
|
||||||
[props["name"], new_geometry, JSON.generate(merged), now, rev, id])
|
[merged["name"], new_geometry, JSON.generate(merged), now, rev, id])
|
||||||
id
|
id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1962,6 +1962,12 @@ body.side-pinned:has(.basemap-panel:not([hidden]), .gpx-panel:not([hidden])) .pr
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.gpx-popup__edited {
|
||||||
|
margin: 4px 0;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #5a6b3a;
|
||||||
|
}
|
||||||
|
|
||||||
.gpx-popup__approximate {
|
.gpx-popup__approximate {
|
||||||
margin: 4px 0;
|
margin: 4px 0;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
|
|||||||
+8
-1
@@ -1536,7 +1536,7 @@ function nodeKeys(node) {
|
|||||||
// for — see _registerPointInteractivity) adds Edit/Delete buttons; the
|
// for — see _registerPointInteractivity) adds Edit/Delete buttons; the
|
||||||
// click handling for them lives in _wireNoteActions, not here, since this
|
// click handling for them lives in _wireNoteActions, not here, since this
|
||||||
// only builds markup, it has no map/store access of its own.
|
// only builds markup, it has no map/store access of its own.
|
||||||
function popupHtml({ name, description, time, category, photos, icon, approximate }, { editable = false, movable = false } = {}) {
|
function popupHtml({ name, description, time, category, photos, icon, approximate, imported }, { editable = false, movable = false } = {}) {
|
||||||
const parts = [];
|
const parts = [];
|
||||||
if (name) {
|
if (name) {
|
||||||
const glyph = icon && POI_ICONS[icon] ? `<span class="gpx-popup__header-icon">${POI_ICONS[icon]}</span>` : "";
|
const glyph = icon && POI_ICONS[icon] ? `<span class="gpx-popup__header-icon">${POI_ICONS[icon]}</span>` : "";
|
||||||
@@ -1546,6 +1546,13 @@ function popupHtml({ name, description, time, category, photos, icon, approximat
|
|||||||
if (photos?.length > 0) parts.push(formatPhotos(photos));
|
if (photos?.length > 0) parts.push(formatPhotos(photos));
|
||||||
// Google saved places Nominatim couldn't pin down (GoogleSaved).
|
// Google saved places Nominatim couldn't pin down (GoogleSaved).
|
||||||
if (approximate) parts.push(`<p class="gpx-popup__approximate">≈ Approximate position, check it</p>`);
|
if (approximate) parts.push(`<p class="gpx-popup__approximate">≈ Approximate position, check it</p>`);
|
||||||
|
// Renamed or redescribed here: a new Google export leaves it as it is
|
||||||
|
// (Library#upsert_by_source_id). MapLibre hands nested properties back
|
||||||
|
// as JSON text.
|
||||||
|
const last = typeof imported === "string" ? JSON.parse(imported) : imported;
|
||||||
|
if (last && ((last.name ?? "") !== (name ?? "") || (last.description ?? "") !== (description ?? ""))) {
|
||||||
|
parts.push(`<p class="gpx-popup__edited">✎ Edited here, Google updates keep your text</p>`);
|
||||||
|
}
|
||||||
// A Note's description is self-authored by the (logged-in) viewer, not
|
// A Note's description is self-authored by the (logged-in) viewer, not
|
||||||
// uploaded/untrusted like every other description here — formatDescription
|
// uploaded/untrusted like every other description here — formatDescription
|
||||||
// is deliberately left alone for that untrusted case (see
|
// is deliberately left alone for that untrusted case (see
|
||||||
|
|||||||
@@ -54,9 +54,13 @@ class GoogleSavedTest < Minitest::Test
|
|||||||
reine = points.call.find { |f| f["properties"]["name"] == "Reine" }
|
reine = points.call.find { |f| f["properties"]["name"] == "Reine" }
|
||||||
reine["properties"]["color"] = "#ff0000"
|
reine["properties"]["color"] = "#ff0000"
|
||||||
library.update_feature("points:x", reine["properties"]["id"], reine)
|
library.update_feature("points:x", reine["properties"]["id"], reine)
|
||||||
|
somewhere = points.call.find { |f| f["properties"]["name"] == "Somewhere" }
|
||||||
|
somewhere["properties"]["name"] = "Bratislava"
|
||||||
|
somewhere["properties"].delete("imported") # the popup needn't send it back
|
||||||
|
library.update_feature("points:x", somewhere["properties"]["id"], somewhere)
|
||||||
|
|
||||||
sleep 1.1 # a newer export (mtime) with a changed note, now found by name
|
sleep 1.1 # a newer export (mtime) with a changed note, now found by name
|
||||||
write_zip.call("takeout-2.zip", CSV_TEXT.sub("red huts", "rorbuer"))
|
write_zip.call("takeout-2.zip", CSV_TEXT.sub("red huts", "rorbuer").sub("Somewhere,,", "Somewhere,a note,"))
|
||||||
Maptool::GoogleSaved.import_takeout(takeout, library: library, state_path: state, lookup: ->(*) { [13.0897, 67.9322] })
|
Maptool::GoogleSaved.import_takeout(takeout, library: library, state_path: state, lookup: ->(*) { [13.0897, 67.9322] })
|
||||||
|
|
||||||
features = points.call
|
features = points.call
|
||||||
@@ -66,5 +70,8 @@ class GoogleSavedTest < Minitest::Test
|
|||||||
assert_equal "#ff0000", reine["properties"]["color"], "own changes kept"
|
assert_equal "#ff0000", reine["properties"]["color"], "own changes kept"
|
||||||
assert_equal [13.0897, 67.9322], reine["geometry"]["coordinates"], "approximate spot replaced by the exact one"
|
assert_equal [13.0897, 67.9322], reine["geometry"]["coordinates"], "approximate spot replaced by the exact one"
|
||||||
refute reine["properties"].key?("approximate")
|
refute reine["properties"].key?("approximate")
|
||||||
|
renamed = features.find { |f| f["properties"]["source_id"].include?("48.1486") }
|
||||||
|
assert_equal "Bratislava", renamed["properties"]["name"], "a name changed here is kept"
|
||||||
|
assert_equal "a note", renamed["properties"]["description"].lines.first.strip, "an untouched description still updates"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user