diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-07 03:48:09 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-07 03:48:09 +0200 |
| commit | 1bf719d6ac58187cf406d92a40b665d3fa6e658b (patch) | |
| tree | 214c0095fe06dd204e31285fbd16df4e07821d80 /app/views | |
| parent | 7b6af89509e8439fe2474e623ee97e4db67ab011 (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/views')
| -rw-r--r-- | app/views/nodes/new.html.erb | 4 | ||||
| -rw-r--r-- | app/views/nodes/show.html.erb | 29 |
2 files changed, 23 insertions, 10 deletions
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 | <%= " · ".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 | ||
