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")
|
||||
write do |db, rev, 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"])
|
||||
# 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",
|
||||
[props["name"], JSON.generate(feature["geometry"]), JSON.generate(props), now, rev, id])
|
||||
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
|
||||
# refreshes the point's name and Google's fields, keeping what was
|
||||
# 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.
|
||||
IMPORTED_TEXT = %w[name description].freeze
|
||||
|
||||
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') = ?",
|
||||
[folder, props["source_id"]])
|
||||
unless row
|
||||
@@ -649,13 +657,18 @@ module Maptool
|
||||
|
||||
old = JSON.parse(old_props)
|
||||
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"]
|
||||
merged.delete("approximate") if exact
|
||||
new_geometry = exact ? JSON.generate(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 = ?",
|
||||
[props["name"], new_geometry, JSON.generate(merged), now, rev, id])
|
||||
[merged["name"], new_geometry, JSON.generate(merged), now, rev, id])
|
||||
id
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user