Skip to content

Commit

Permalink
✨(pagetree) Page node can be foldable or not according to a limit
Browse files Browse the repository at this point in the history
Add a setting `CMS_PAGETREE_DESCENDANTS_LIMIT` to define a limit of
descendants to allow a page node to be foldable or not. If this setting is not defined,
there is no descendants limit.
  • Loading branch information
jbpenrath committed May 22, 2024
1 parent b294ea3 commit 4d53d0a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cms/admin/pageadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,7 @@ def get_tree_rows(self, request, pages, language, root_pages, open_nodes=[]):
is_popup = (IS_POPUP_VAR in request.POST or IS_POPUP_VAR in request.GET)
languages = get_language_list(site.pk)
user_can_add = page_permissions.user_can_add_subpage
descendants_limit = get_cms_setting('PAGETREE_DESCENDANTS_LIMIT')

def render_page_row(page):
page.title_cache = {trans.language: trans for trans in page.filtered_translations}
Expand All @@ -1486,6 +1487,7 @@ def render_page_row(page):
'node': page.node,
'ancestors': [node.item for node in page.node.get_cached_ancestors()],
'descendants': [node.item for node in page.node.get_cached_descendants()],
'follow_descendants': page.node.numchild <= descendants_limit,
'request': request,
'lang': language,
'metadata': metadata,
Expand Down
4 changes: 4 additions & 0 deletions cms/static/cms/sass/components/pagetree/_tree.scss
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,9 @@
.jstree-closed > .jstree-ocl {
@include icon(arrow-right);
}
.jstree-unfoldable > .jstree-ocl {
@include icon(minus);
}
.jstree-loading > .jstree-ocl {
@include icon(loader);
&:before {
Expand Down Expand Up @@ -905,6 +908,7 @@
}

.jstree-open,
.jstree-unfoldable,
.jstree-closed,
.jstree-loading {
> .jstree-anchor {
Expand Down
9 changes: 7 additions & 2 deletions cms/templates/admin/cms/page/tree/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

{# INFO: columns are defined in base.html options #}
{% spaceless %}
<li class="cms-tree-node {{ css_class }}
{% if descendants %} jstree-open{% elif node.is_branch %} jstree-closed{% endif %}
<li {% if not follow_descendants %}title="{% blocktrans %}There are too many descendants to unfold this page. Please search the page you are looking for.{% endblocktrans %}"{% endif %}class="cms-tree-node {{ css_class }}
{% spaceless %}
{% if follow_descendants %}
{% if descendants %} jstree-open{% elif node.is_branch %} jstree-closed{% endif %}
{% else %}
jstree-unfoldable
{% endif %}{% endspaceless %}
{% if page.reverse_id == 'page_types' %} cms-tree-node-pagetype{% endif %}
{% if node.depth == 0 %} cms-tree-node-top{% endif %}
{% if filtered %} cms-tree-node-filtered{% endif %}
Expand Down
1 change: 1 addition & 0 deletions cms/utils/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def wrapper():
'TOOLBAR_HIDE': False,
'INTERNAL_IPS': [],
'REQUEST_IP_RESOLVER': 'cms.utils.request_ip_resolvers.default_request_ip_resolver',
'PAGETREE_DESCENDANTS_LIMIT': float('inf'),
'PAGE_WIZARD_DEFAULT_TEMPLATE': constants.TEMPLATE_INHERITANCE_MAGIC,
'PAGE_WIZARD_CONTENT_PLUGIN': 'TextPlugin',
'PAGE_WIZARD_CONTENT_PLUGIN_BODY': 'body',
Expand Down
12 changes: 12 additions & 0 deletions docs/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1212,3 +1212,15 @@ default

This indicates to the CMS that it should redirect requests with an non-lowercase
slug to its lowercase version if no page with that slug is found.

.. setting:: CMS_PAGETREE_DESCENDANTS_LIMIT

PAGETREE_DESCENDANTS_LIMIT
===================================

default
``float('inf')``

A limit that prevents a node from being unfoldable if it contains too many
descendants. This setting can be useful for sites with a very large tree
structure to avoid performance drawbacks.

0 comments on commit 4d53d0a

Please sign in to comment.