{#
Displays a tree of groups

NB This template can be slow because it is recursive and uses link_for. At
DGU we speeded up display of the tree 10 times (necessary as we have 1000
groups) by replacing this template with a recursive code routine:
https://github.com/datagovuk/ckanext-dgu/blob/5fb78b354517c2198245bdc9c98fb5d6c82c6bcc/ckanext/dgu/lib/helpers.py#L140

orgs    - List of groups

Example:

{% snippet 'group/snippets/group_tree.html', top_nodes=h.group_tree(type_='group'), use_longnames=False %}

#}

{% set type = 'asset' if h.ckan_version().split('.')[1] | int >= 9 else 'resource' %}
{% include 'hierarchy/snippets/hierarchy_' ~ type ~ '.html' %}

<ul class="hierarchy-tree-top">
  {% for node in top_nodes recursive %} 
      {% set longname = h.group_tree_get_longname(node.name, type_='group') %}
      {% set display_text = node.title %}
      {% if use_longnames and longname%}
          {% set display_text = longname + " (" + display_text + ")" %}
      {% endif %}
      {% if node.highlighted %}
          <li class="highlighted" id="node_{{ node.name }}">
      {% else %}
          <li id="node_{{ node.name }}">
      {% endif %}
      <div class="node-item">
          {% link_for display_text, controller='group', action='read', id=node.name %}
          {% if g.pkg_dict %}
              {% set user_member = h.list_dict_filter(g.pkg_dict.groups, 'id', 'user_member', node.id) %}
              {% if user_member == True %}
                  {{ _('(associated)') }}
                  <input name="group_remove.{{ node.name }}" value="{{ _('Remove') }}" type="submit" class="btn btn-danger btn-sm media-edit" title="{{ _('Remove dataset from this group') }}"/>
              {% endif %}
          {% endif %}
      </div>
          {% if node.children %}
            <ul class="hierarchy-tree"> {{ loop(node.children) }} </ul>
          {% endif %}
    </li>
  {% endfor %}
</ul>
