Library phase 2: rename/recolor nodes, rename and move folders, split a layer into items; offline routing design
This commit is contained in:
1 parent
4d838395b8
commit
6f5f11cb4d
9 files changed
+467
-39
No files matched your search
@@ -571,6 +571,27 @@ module Maptool
|
||||
halt 404
|
||||
end
|
||||
|
||||
# Rename/recolor a track, route or layer.
|
||||
patch "/api/library/node/:key" do
|
||||
require_login!
|
||||
LIBRARY.update_node(params[:key], name: params[:name], color: params[:color])
|
||||
json tree: LIBRARY.tree
|
||||
rescue Library::InvalidValue
|
||||
halt 400, json(error: "invalid name or color")
|
||||
rescue Library::NotFound
|
||||
halt 404
|
||||
end
|
||||
|
||||
# A migrated layer → ordinary items (Library#split_layer).
|
||||
post "/api/library/node/:key/split" do
|
||||
require_login!
|
||||
json paths: LIBRARY.split_layer(params[:key]), tree: LIBRARY.tree
|
||||
rescue Library::ParseError
|
||||
halt 422, json(error: "could not parse file")
|
||||
rescue Library::NotFound
|
||||
halt 404
|
||||
end
|
||||
|
||||
post "/api/library/move" do
|
||||
require_login!
|
||||
key = LIBRARY.move_node(params[:key].to_s, params[:to_folder].to_s)
|
||||
@@ -589,6 +610,21 @@ module Maptool
|
||||
halt 400, json(error: "invalid path")
|
||||
end
|
||||
|
||||
# Rename (`name`) and/or move (`to_folder`, "" = top level) a folder.
|
||||
patch "/api/library/folder/*" do
|
||||
require_login!
|
||||
path = params[:splat].first
|
||||
path = LIBRARY.rename_folder(path, params[:name]) if params[:name]
|
||||
path = LIBRARY.move_folder(path, params[:to_folder].to_s) if params.key?("to_folder")
|
||||
json path: path, tree: LIBRARY.tree
|
||||
rescue Library::InvalidPath
|
||||
halt 400, json(error: "invalid folder")
|
||||
rescue Library::InvalidValue
|
||||
halt 409, json(error: "a folder with that name already exists there")
|
||||
rescue Library::NotFound
|
||||
halt 404
|
||||
end
|
||||
|
||||
delete "/api/library/folder/*" do
|
||||
require_login!
|
||||
LIBRARY.delete_folder(params[:splat].first)
|
||||
|
||||
Reference in new issue
Block a user