Show a GeoJSON icon next to files with a ready cache

GpxStore#tree now reports a "cached" flag per file (reusing the same
mtime freshness check geojson() already does); the file tree shows a
small curly-braces icon next to any file whose conversion is already
on disk, so it's visible which files will toggle on instantly versus
which still need to parse.
This commit is contained in:
randy committed 2026-09-07 22:44:04 +02:00
1 parent dd0ad6d845
commit 44d235bbcf
4 files changed
+56 -4

No files matched your search

+12 -4
View File
@@ -22,7 +22,10 @@ module Maptool
end
# Nested { type:, name:, path:, children: } hash describing every
# folder and .gpx/.fit file under the store root.
# folder and .gpx/.fit file under the store root. Each file also
# carries "cached" — whether its GeoJSON conversion is ready on disk
# (see `geojson` below) — so the tree UI can show a file's ready to
# view instantly, without a round trip just to find out.
def tree
{ "type" => "folder", "name" => "root", "path" => "", "children" => list_children(@root, "") }
end
@@ -112,7 +115,7 @@ module Maptool
raise Errno::ENOENT, path unless File.file?(path)
cache = geojson_cache_path(path)
if !File.file?(cache) || File.mtime(cache) < File.mtime(path)
unless geojson_cached?(path)
data = path.downcase.end_with?(".fit") ? Fit.to_geojson(path) : Gpx.to_geojson(path)
File.write(cache, JSON.generate(data))
end
@@ -136,6 +139,11 @@ module Maptool
"#{path}.geojson"
end
def geojson_cached?(path)
cache = geojson_cache_path(path)
File.file?(cache) && File.mtime(cache) >= File.mtime(path)
end
TRACK_EXTENSIONS = %w[.gpx .fit].freeze
def safe_filename(filename)
@@ -165,9 +173,9 @@ module Maptool
if File.directory?(full)
{ "type" => "folder", "name" => entry, "path" => rel, "children" => list_children(full, rel) }
elsif entry.downcase.end_with?(".gpx")
{ "type" => "file", "name" => entry, "path" => rel, "kinds" => Gpx.kinds(full) }
{ "type" => "file", "name" => entry, "path" => rel, "kinds" => Gpx.kinds(full), "cached" => geojson_cached?(full) }
elsif entry.downcase.end_with?(".fit")
{ "type" => "file", "name" => entry, "path" => rel, "kinds" => Fit.kinds(full) }
{ "type" => "file", "name" => entry, "path" => rel, "kinds" => Fit.kinds(full), "cached" => geojson_cached?(full) }
end
end
end