Skip to content

Commit

Permalink
Do not render contextmenu if it contains no elements
Browse files Browse the repository at this point in the history
  • Loading branch information
rnixx committed May 22, 2024
1 parent 0834483 commit c7fe8b4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
8 changes: 4 additions & 4 deletions examples/cone.example/example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ cone.root.title = cone.example
#cone.root.mainmenu_empty_title = false

ugm.backend = file
ugm.users_file = var/ugm/users
ugm.groups_file = var/ugm/groups
ugm.roles_file = var/ugm/roles
ugm.datadir = var/ugm/data
ugm.users_file = examples/cone.example/var/ugm/users
ugm.groups_file = examples/cone.example/var/ugm/groups
ugm.roles_file = examples/cone.example/var/ugm/roles
ugm.datadir = examples/cone.example/var/ugm/data

[pipeline:main]
pipeline =
Expand Down
8 changes: 8 additions & 0 deletions src/cone/app/browser/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ def __call__(self, model, request):
return u'<div>%s</div>' % rendered_actions
return u'<div class="%s">%s</div>' % (self.css, rendered_actions)

def __repr__(self):
return (
f'<{self.__class__.__module__}.{self.__class__.__name__} '
f'({self.keys()}) at {id(self)}>'
)

__str__ = __repr__


class Action(object):
"""Abstract Action.
Expand Down
12 changes: 10 additions & 2 deletions src/cone/app/browser/contextmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def display(self):
def __call__(self, model, request):
self.model = model
self.request = request
if not self.display:
return u''
return render_template(
self.template,
request=request,
Expand Down Expand Up @@ -162,5 +164,11 @@ class ContextActionsToolbar(ContextMenuToolbar):
class ContextMenu(Tile):

@property
def toolbars(self):
return context_menu.values()
def rendered_toolbars(self):
rendered_toolbars = []
for toolbar in context_menu.values():
rendered_toolbar = toolbar(self.model, self.request)
if not rendered_toolbar:
continue
rendered_toolbars.append(rendered_toolbar)
return rendered_toolbars
8 changes: 5 additions & 3 deletions src/cone/app/browser/templates/contextmenu.pt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
role="contextmenu"
ajax:bind="contextactionschanged"
ajax:action="contextmenu:#contextmenu:replace"
class="navbar mt-2 p-0 contextsensitiv navbar-expand rounded shadow-sm card">
class="navbar mt-2 p-0 contextsensitiv navbar-expand rounded shadow-sm card"
tal:define="rendered_toolbars context.rendered_toolbars"
tal:condition="rendered_toolbars">
<div class="container-fluid p-0">
<ul class="navbar-nav">
<tal:toolbars repeat="toolbar context.toolbars">
<tal:toolbar replace="structure toolbar(model, request)" />
<tal:toolbars repeat="rendered_toolbar rendered_toolbars">
<tal:toolbar replace="structure rendered_toolbar" />
</tal:toolbars>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/cone/app/browser/templates/contextmenu_dropdown.pt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<tal:block xmlns:tal="http://xml.zope.org/namespaces/tal"
omit-tag="True">

<li tal:condition="context.display" class="nav-item dropdown py-2">
<li class="nav-item dropdown py-2">
<a class="nav-link dropdown-toggle py-0 px-3" href="#" role="button" data-bs-toggle="dropdown">
<span tal:condition="context.icon"
class="${context.icon}"></span>
Expand Down

0 comments on commit c7fe8b4

Please sign in to comment.