summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-07 03:48:09 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-07 03:48:09 +0200
commit1bf719d6ac58187cf406d92a40b665d3fa6e658b (patch)
tree214c0095fe06dd204e31285fbd16df4e07821d80 /app
parent7b6af89509e8439fe2474e623ee97e4db67ab011 (diff)
Add context-aware child-creation shortcuts to nodes#show
parent_match Procs on CccConventions::NODE_KINDS, matched against unique_path, decide which "add child" kinds show on a given node. Fixes nodes#new not honoring a pre-selected kind (radio group and parent-field visibility both defaulted to "generic" unconditionally).
Diffstat (limited to 'app')
-rw-r--r--app/controllers/nodes_controller.rb1
-rw-r--r--app/helpers/nodes_helper.rb5
-rw-r--r--app/views/nodes/new.html.erb4
-rw-r--r--app/views/nodes/show.html.erb29
4 files changed, 29 insertions, 10 deletions
diff --git a/app/controllers/nodes_controller.rb b/app/controllers/nodes_controller.rb
index 69aa268..a72be68 100644
--- a/app/controllers/nodes_controller.rb
+++ b/app/controllers/nodes_controller.rb
@@ -22,6 +22,7 @@ class NodesController < ApplicationController
22 22
23 def new 23 def new
24 @node = Node.new node_params 24 @node = Node.new node_params
25 @selected_kind = CccConventions::NODE_KINDS.key?(params[:kind]) ? params[:kind] : "generic"
25 if params.has_key?(:parent_id) 26 if params.has_key?(:parent_id)
26 @parent_id = params[:parent_id] 27 @parent_id = params[:parent_id]
27 @parent_name = Node.find(@parent_id).title 28 @parent_name = Node.find(@parent_id).title
diff --git a/app/helpers/nodes_helper.rb b/app/helpers/nodes_helper.rb
index 2baf813..a89f879 100644
--- a/app/helpers/nodes_helper.rb
+++ b/app/helpers/nodes_helper.rb
@@ -58,4 +58,9 @@ module NodesHelper
58 t(:event_schedule_none) 58 t(:event_schedule_none)
59 end 59 end
60 end 60 end
61
62 def matching_node_kinds(node)
63 path = node.unique_path
64 CccConventions::NODE_KINDS.select { |_, config| config[:parent_match]&.call(path) }
65 end
61end 66end
diff --git a/app/views/nodes/new.html.erb b/app/views/nodes/new.html.erb
index 0a05325..71f2fbf 100644
--- a/app/views/nodes/new.html.erb
+++ b/app/views/nodes/new.html.erb
@@ -13,7 +13,7 @@
13 <div class="node_content"> 13 <div class="node_content">
14 <% CccConventions::NODE_KINDS.each do |kind, config| %> 14 <% CccConventions::NODE_KINDS.each do |kind, config| %>
15 <p> 15 <p>
16 <%= radio_button_tag :kind, kind, kind == "generic", 16 <%= radio_button_tag :kind, kind, kind == @selected_kind,
17 data: { path_prefix: resolve_kind_text(config[:path_prefix]) } %> 17 data: { path_prefix: resolve_kind_text(config[:path_prefix]) } %>
18 <%= resolve_kind_text(config[:label]) %> 18 <%= resolve_kind_text(config[:label]) %>
19 <% if config[:hint] %> 19 <% if config[:hint] %>
@@ -29,7 +29,7 @@
29 <span class="field_hint">A URL slug will be generated from this automatically. You can review or adjust it afterward under the "metadata" section's Slug field.</span> 29 <span class="field_hint">A URL slug will be generated from this automatically. You can review or adjust it afterward under the "metadata" section's Slug field.</span>
30 </div> 30 </div>
31 31
32 <div id="parent_search_field"> 32 <div id="parent_search_field" style="<%= @selected_kind == "generic" ? "" : "display: none;" %>">
33 <div class="node_description">Parent</div> 33 <div class="node_description">Parent</div>
34 <div class="node_content"> 34 <div class="node_content">
35 <%= text_field_tag :parent_search_term, @parent_name %> 35 <%= text_field_tag :parent_search_term, @parent_name %>
diff --git a/app/views/nodes/show.html.erb b/app/views/nodes/show.html.erb
index 189adb8..963bc37 100644
--- a/app/views/nodes/show.html.erb
+++ b/app/views/nodes/show.html.erb
@@ -101,17 +101,30 @@
101 <%= link_to 'add event', new_event_path(node_id: @node.id, tag_list: mapping&.last, auto_tag_source: mapping&.first, return_to: request.path) %> 101 <%= link_to 'add event', new_event_path(node_id: @node.id, tag_list: mapping&.last, auto_tag_source: mapping&.first, return_to: request.path) %>
102 </div> 102 </div>
103 103
104 <% if @node.children.any? %> 104 <% matches = matching_node_kinds(@node) %>
105 <% if @node.children.any? || matches.any? %>
105 <div class="node_description">Children</div> 106 <div class="node_description">Children</div>
106 <div class="node_content node_info_group"> 107 <div class="node_content node_info_group">
107 <details> 108 <% if @node.children.any? %>
108 <summary><%= pluralize(@node.children.count, 'child', 'children') %></summary> 109 <details>
109 <ul> 110 <summary><%= pluralize(@node.children.count, 'child', 'children') %></summary>
110 <% @node.children.order(:slug).each do |child| %> 111 <ul>
111 <li><%= link_to (child.head&.title || child.draft&.title || child.slug), node_path(child) %></li> 112 <% @node.children.order(:slug).each do |child| %>
113 <li><%= link_to (child.head&.title || child.draft&.title || child.slug), node_path(child) %></li>
114 <% end %>
115 </ul>
116 </details>
117 <% end %>
118 <% if matches.any? %>
119 <p class="add_child_links">
120 <% matches.each_with_index do |(kind, config), index| %>
121 <%= " &middot; ".html_safe if index > 0 %>
122 <% link_params = { kind: kind } %>
123 <% link_params[:parent_id] = @node.id if kind == "generic" %>
124 <%= link_to "add '#{resolve_kind_text(config[:label])}' child", new_node_path(link_params) %>
112 <% end %> 125 <% end %>
113 </ul> 126 </p>
114 </details> 127 <% end %>
115 </div> 128 </div>
116 <% end %> 129 <% end %>
117 130