summaryrefslogtreecommitdiff
path: root/app/views/nodes/sitemap.html.erb
blob: a799c1790871f5bcc82df23d24f99adc3c7d4e83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<h1>Sitemap</h1>

<div id="sitemap">
<%
  open_details = [] # levels with a currently-open <details>
%>
<% @sitemap.each_with_index do |(node, level), index| %>
  <% while open_details.any? && open_details.last >= level %>
    </details>
    <% open_details.pop %>
  <% end %>

  <div class="sitemap_node">
    <h4><%= link_to title_for_node(node), node_path(node) %></h4>
    <span class="field_hint"><%= link_to_path("#{node.unique_name} ↗", node.unique_name) %></span>
    <p class="sitemap_node_actions">
      <%= link_to 'Show', node_path(node) %>
      <%= link_to 'Create Child', new_node_path(:parent_id => node.id) %>
    </p>
  </div>

  <% next_level = @sitemap[index + 1]&.last %>
  <% if next_level && next_level > level %>
    <details<%= ' open' if sitemap_node_open?(node) %>>
      <summary>
        <%= pluralize(@sitemap_descendant_counts[node.id], 'descendant', 'descendants') %>
      </summary>
    <% open_details.push(level) %>
  <% end %>
<% end %>
<% open_details.length.times { %></details><% } %>
</div>