diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-12 02:15:44 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-12 02:15:44 +0200 |
| commit | 45bf65d04d046c0ea4a1150096b2a9b846d6c0b8 (patch) | |
| tree | 24dad426779cb3b0ac59c405245aac1d28109982 /app/views | |
| parent | 13c8cb415813e90c883a44b0c0888382161de92a (diff) | |
Give the sitemap its own view, with collapse and descendant counts
Extracted from admin#index's inline table into NodesController#sitemap.
Nested <details>/<summary> per branch, one linear pass over the
existing flat [node, level] list (no added queries) -- each node's own
descendant count computed the same way, via a small stack rather than
re-walking the tree per node. Branches under updates/, club/erfas,
club/chaostreffs, and disclosure start collapsed by default
(CccConventions::SITEMAP_COLLAPSED_PATHS); any branch currently
collapsed, whether by that default or because someone just closed it,
is highlighted via a plain :not([open]) selector -- no state tracked
outside the DOM itself.
Dropped the update?-post exclusion this view used to rely on -- no
longer needed now that updates/ collapses instead of being filtered
out, so its real children (previously silently absent) now show up
correctly. admin#index's own, separate @sitemap query is unchanged;
that view has no collapse mechanism to compensate and wasn't part of
this.
Diffstat (limited to 'app/views')
| -rw-r--r-- | app/views/nodes/sitemap.html.erb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/app/views/nodes/sitemap.html.erb b/app/views/nodes/sitemap.html.erb new file mode 100644 index 0000000..a799c17 --- /dev/null +++ b/app/views/nodes/sitemap.html.erb | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | <h1>Sitemap</h1> | ||
| 2 | |||
| 3 | <div id="sitemap"> | ||
| 4 | <% | ||
| 5 | open_details = [] # levels with a currently-open <details> | ||
| 6 | %> | ||
| 7 | <% @sitemap.each_with_index do |(node, level), index| %> | ||
| 8 | <% while open_details.any? && open_details.last >= level %> | ||
| 9 | </details> | ||
| 10 | <% open_details.pop %> | ||
| 11 | <% end %> | ||
| 12 | |||
| 13 | <div class="sitemap_node"> | ||
| 14 | <h4><%= link_to title_for_node(node), node_path(node) %></h4> | ||
| 15 | <span class="field_hint"><%= link_to_path("#{node.unique_name} ↗", node.unique_name) %></span> | ||
| 16 | <p class="sitemap_node_actions"> | ||
| 17 | <%= link_to 'Show', node_path(node) %> | ||
| 18 | <%= link_to 'Create Child', new_node_path(:parent_id => node.id) %> | ||
| 19 | </p> | ||
| 20 | </div> | ||
| 21 | |||
| 22 | <% next_level = @sitemap[index + 1]&.last %> | ||
| 23 | <% if next_level && next_level > level %> | ||
| 24 | <details<%= ' open' if sitemap_node_open?(node) %>> | ||
| 25 | <summary> | ||
| 26 | <%= pluralize(@sitemap_descendant_counts[node.id], 'descendant', 'descendants') %> | ||
| 27 | </summary> | ||
| 28 | <% open_details.push(level) %> | ||
| 29 | <% end %> | ||
| 30 | <% end %> | ||
| 31 | <% open_details.length.times { %></details><% } %> | ||
| 32 | </div> | ||
