Add file-kind icons to the GPX tree, fix drop into an empty panel
Each tree entry now shows a small waypoint/track icon based on a cheap substring check for <wpt>/<trk> (Maptool::Gpx.kinds) rather than a full REXML parse, since re-parsing a several-thousand-waypoint file on every tree fetch would make the panel noticeably slower to open. Also fix a real drop-target bug: .gpx-tree had no flex:1, so a short/empty tree left blank panel space below it that wasn't part of the drag & drop target — dropping a file there silently did nothing.
This commit is contained in:
1 parent
87df90f75c
commit
06ea8ea141
5 files changed
+58
-3
No files matched your search
@@ -8,6 +8,19 @@ module Maptool
|
||||
module Gpx
|
||||
class ParseError < StandardError; end
|
||||
|
||||
# Cheap content-type check for the file tree's icons: a plain substring
|
||||
# search rather than a full REXML parse, since some uploaded files (e.g.
|
||||
# a several-thousand-waypoint POI export) are large enough that parsing
|
||||
# the whole DOM just to answer "does it have any of these tags" would
|
||||
# make every tree fetch noticeably slower.
|
||||
def self.kinds(path)
|
||||
content = File.read(path)
|
||||
kinds = []
|
||||
kinds << "waypoint" if content.include?("<wpt")
|
||||
kinds << "track" if content.include?("<trk")
|
||||
kinds
|
||||
end
|
||||
|
||||
def self.to_geojson(path)
|
||||
root = REXML::Document.new(File.read(path)).root
|
||||
raise ParseError, "not a GPX file" unless root && root.name == "gpx"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
require "fileutils"
|
||||
require_relative "gpx"
|
||||
|
||||
module Maptool
|
||||
# Filesystem-backed store for uploaded GPX files, organized in
|
||||
@@ -117,7 +118,7 @@ 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 }
|
||||
{ "type" => "file", "name" => entry, "path" => rel, "kinds" => Gpx.kinds(full) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user