ui(minor): merge menus

This commit is contained in:
Langhammer, Jens 2019-10-07 16:50:13 +02:00
parent f2acc154cd
commit 15fa7e9652
4 changed files with 95 additions and 119 deletions

View File

@ -65,123 +65,94 @@
<span class="list-group-item-value">{% trans 'Overview' %}</span> <span class="list-group-item-value">{% trans 'Overview' %}</span>
</a> </a>
</li> </li>
{% is_active_app 'passbook_admin' as is_admin %}
{% if user.is_superuser %} {% if user.is_superuser %}
<li class="list-group-item {% is_active_app 'passbook_admin' %} secondary-nav-item-pf"> <li class="list-group-item {% is_active_url 'passbook_admin:overview' %}">
<a>
<span class="pficon pficon-user" data-toggle="tooltip" title=""
data-original-title="{% trans 'Administration' %}"></span>
<span class="list-group-item-value dropdown-title">{% trans 'Administration' %}</span>
</a>
<div id="user-secondary" class="nav-pf-secondary-nav">
<div class="nav-item-pf-header">
<a href="#0" class="secondary-collapse-toggle-pf" data-toggle="collapse-secondary-nav"></a>
<span>{% trans 'Administration' %}</span>
</div>
<ul class="list-group">
<li class="list-group-item {% is_active 'passbook_admin:overview' %}">
<a href="{% url 'passbook_admin:overview' %}"> <a href="{% url 'passbook_admin:overview' %}">
<span class="list-group-item-value"> <span class="fa pficon-build" data-toggle="tooltip" title="{% trans 'System Status' %}"></span>
{% trans 'Overview' %} <span class="list-group-item-value">{% trans 'System Status' %}</span>
</span>
</a> </a>
</li> </li>
<li <li
class="list-group-item {% is_active 'passbook_admin:applications' 'passbook_admin:application-create' 'passbook_admin:application-update' 'passbook_admin:application-delete' %}"> class="list-group-item {% is_active 'passbook_admin:applications' 'passbook_admin:application-create' 'passbook_admin:application-update' 'passbook_admin:application-delete' %}">
<a href="{% url 'passbook_admin:applications' %}"> <a href="{% url 'passbook_admin:applications' %}">
<span class="list-group-item-value"> <span class="fa pficon-applications" data-toggle="tooltip" title="{% trans 'Applications' %}"></span>
{% trans 'Applications' %} <span class="list-group-item-value">{% trans 'Applications' %}</span>
</span>
</a> </a>
</li> </li>
<li <li
class="list-group-item {% is_active 'passbook_admin:sources' 'passbook_admin:source-create' 'passbook_admin:source-update' 'passbook_admin:source-delete' %}"> class="list-group-item {% is_active 'passbook_admin:sources' 'passbook_admin:source-create' 'passbook_admin:source-update' 'passbook_admin:source-delete' %}">
<a href="{% url 'passbook_admin:sources' %}"> <a href="{% url 'passbook_admin:sources' %}">
<span class="list-group-item-value"> <span class="fa pficon-resource-pool" data-toggle="tooltip" title="{% trans 'Sources' %}"></span>
{% trans 'Sources' %} <span class="list-group-item-value">{% trans 'Sources' %}</span>
</span>
</a> </a>
</li> </li>
<li <li
class="list-group-item {% is_active 'passbook_admin:providers' 'passbook_admin:provider-create' 'passbook_admin:provider-update' 'passbook_admin:provider-delete' %}"> class="list-group-item {% is_active 'passbook_admin:providers' 'passbook_admin:provider-create' 'passbook_admin:provider-update' 'passbook_admin:provider-delete' %}">
<a href="{% url 'passbook_admin:providers' %}"> <a href="{% url 'passbook_admin:providers' %}">
<span class="list-group-item-value"> <span class="fa pficon-integration" data-toggle="tooltip" title="{% trans 'Providers' %}"></span>
{% trans 'Providers' %} <span class="list-group-item-value">{% trans 'Providers' %}</span>
</span>
</a> </a>
</li> </li>
<li <li
class="list-group-item {% is_active 'passbook_admin:property-mappings' 'passbook_admin:property-mapping-create' 'passbook_admin:property-mapping-update' 'passbook_admin:property-mapping-delete' %}"> class="list-group-item {% is_active 'passbook_admin:property-mappings' 'passbook_admin:property-mapping-create' 'passbook_admin:property-mapping-update' 'passbook_admin:property-mapping-delete' %}">
<a href="{% url 'passbook_admin:property-mappings' %}"> <a href="{% url 'passbook_admin:property-mappings' %}">
<span class="list-group-item-value"> <span class="fa fa-table" data-toggle="tooltip" title="{% trans 'Property Mappings' %}"></span>
{% trans 'Property Mappings' %} <span class="list-group-item-value">{% trans 'Property Mappings' %}</span>
</span>
</a> </a>
</li> </li>
<li <li
class="list-group-item {% is_active 'passbook_admin:factors' 'passbook_admin:factor-create' 'passbook_admin:factor-update' 'passbook_admin:factor-delete' %}"> class="list-group-item {% is_active 'passbook_admin:factors' 'passbook_admin:factor-create' 'passbook_admin:factor-update' 'passbook_admin:factor-delete' %}">
<a href="{% url 'passbook_admin:factors' %}"> <a href="{% url 'passbook_admin:factors' %}">
<span class="list-group-item-value"> <span class="fa pficon-plugged" data-toggle="tooltip" title="{% trans 'Factors' %}"></span>
{% trans 'Factors' %} <span class="list-group-item-value">{% trans 'Factors' %}</span>
</span>
</a> </a>
</li> </li>
<li <li
class="list-group-item {% is_active 'passbook_admin:policies' 'passbook_admin:policy-create' 'passbook_admin:policy-update' 'passbook_admin:policy-delete' 'passbook_admin:policy-test' %}"> class="list-group-item {% is_active 'passbook_admin:policies' 'passbook_admin:policy-create' 'passbook_admin:policy-update' 'passbook_admin:policy-delete' 'passbook_admin:policy-test' %}">
<a href="{% url 'passbook_admin:policies' %}"> <a href="{% url 'passbook_admin:policies' %}">
<span class="list-group-item-value"> <span class="fa pficon-infrastructure" data-toggle="tooltip" title="{% trans 'Policies' %}"></span>
{% trans 'Policies' %} <span class="list-group-item-value">{% trans 'Policies' %}</span>
</span>
</a> </a>
</li> </li>
<li <li
class="list-group-item {% is_active 'passbook_admin:invitations' 'passbook_admin:invitation-create' 'passbook_admin:invitation-update' 'passbook_admin:invitation-delete' 'passbook_admin:invitation-test' %}"> class="list-group-item {% is_active 'passbook_admin:invitations' 'passbook_admin:invitation-create' 'passbook_admin:invitation-update' 'passbook_admin:invitation-delete' 'passbook_admin:invitation-test' %}">
<a href="{% url 'passbook_admin:invitations' %}"> <a href="{% url 'passbook_admin:invitations' %}">
<span class="list-group-item-value"> <span class="fa pficon-migration" data-toggle="tooltip" title="{% trans 'Invitations' %}"></span>
{% trans 'Invitations' %} <span class="list-group-item-value">{% trans 'Invitations' %}</span>
</span>
</a> </a>
</li> </li>
<li <li
class="list-group-item {% is_active 'passbook_admin:users' 'passbook_admin:user-update' 'passbook_admin:user-delete' %}"> class="list-group-item {% is_active 'passbook_admin:users' 'passbook_admin:user-update' 'passbook_admin:user-delete' %}">
<a href="{% url 'passbook_admin:users' %}"> <a href="{% url 'passbook_admin:users' %}">
<span class="list-group-item-value"> <span class="fa pficon-users" data-toggle="tooltip" title="{% trans 'Users' %}"></span>
{% trans 'Users' %} <span class="list-group-item-value">{% trans 'Users' %}</span>
</span>
</a> </a>
</li> </li>
<li <li
class="list-group-item {% is_active 'passbook_admin:groups' 'passbook_admin:group-update' 'passbook_admin:group-delete' %}"> class="list-group-item {% is_active 'passbook_admin:groups' 'passbook_admin:group-update' 'passbook_admin:group-delete' %}">
<a href="{% url 'passbook_admin:groups' %}"> <a href="{% url 'passbook_admin:groups' %}">
<span class="list-group-item-value"> <span class="fa pficon-users" data-toggle="tooltip" title="{% trans 'Groups' %}"></span>
{% trans 'Groups' %} <span class="list-group-item-value">{% trans 'Groups' %}</span>
</span>
</a> </a>
</li> </li>
<li class="list-group-item {% is_active 'passbook_admin:audit-log' %}"> <li class="list-group-item {% is_active 'passbook_admin:audit-log' %}">
<a href="{% url 'passbook_admin:audit-log' %}"> <a href="{% url 'passbook_admin:audit-log' %}">
<span class="list-group-item-value"> <span class="fa pficon-catalog" data-toggle="tooltip" title="{% trans 'Audit Log' %}"></span>
{% trans 'Audit Log' %} <span class="list-group-item-value">{% trans 'Audit Log' %}</span>
</span>
</a> </a>
</li> </li>
<li class="list-group-item {% is_active_app 'admin' %}"> <li class="list-group-item {% is_active_app 'admin' %}">
<a href="{% url 'admin:index' %}"> <a href="{% url 'admin:index' %}">
<span class="list-group-item-value"> <span class="fa fa-database" data-toggle="tooltip" title="{% trans 'Django' %}"></span>
{% trans 'Django' %} <span class="list-group-item-value">{% trans 'Django' %}</span>
</span>
</a> </a>
</li> </li>
<li class="list-group-item {% is_active 'passbook_admin:debug-request' %}"> <li class="list-group-item {% is_active 'passbook_admin:debug-request' %}">
<a href="{% url 'passbook_admin:debug-request' %}"> <a href="{% url 'passbook_admin:debug-request' %}">
<span class="list-group-item-value"> <span class="fa fa-bug" data-toggle="tooltip" title="{% trans 'Debug' %}"></span>
{% trans 'Debug' %} <span class="list-group-item-value">{% trans 'Debug' %}</span>
</span>
</a> </a>
</li> </li>
</ul>
</div>
</li>
{% endif %} {% endif %}
</ul> </ul>
</div> </div>

View File

@ -1,6 +1,5 @@
"""passbook lib navbar Templatetag""" """passbook lib navbar Templatetag"""
from django import template from django import template
from django.urls import reverse
from structlog import get_logger from structlog import get_logger
register = template.Library() register = template.Library()
@ -17,7 +16,7 @@ def is_active(context, *args, **kwargs):
return '' return ''
for url in args: for url in args:
short_url = url.split(':')[1] if ':' in url else url short_url = url.split(':')[1] if ':' in url else url
# Check if resolve_match matches # Check if resolver_match matches
if request.resolver_match.url_name.startswith(url) or \ if request.resolver_match.url_name.startswith(url) or \
request.resolver_match.url_name.startswith(short_url): request.resolver_match.url_name.startswith(short_url):
# Monkeypatch app_name: urls from core have app_name == '' # Monkeypatch app_name: urls from core have app_name == ''
@ -30,15 +29,19 @@ def is_active(context, *args, **kwargs):
@register.simple_tag(takes_context=True) @register.simple_tag(takes_context=True)
def is_active_url(context, view, *args, **kwargs): def is_active_url(context, view):
"""Return whether a navbar link is active or not.""" """Return whether a navbar link is active or not."""
matching_url = reverse(view, args=args, kwargs=kwargs) # matching_url = reverse(view, args=args, kwargs=kwargs)
request = context.get('request') request = context.get('request')
current_full_url = f"{request.resolver_match.app_name}:{request.resolver_match.url_name}"
if not request.resolver_match: if not request.resolver_match:
return '' return ''
if matching_url == request.path: if current_full_url == view:
return 'active' return 'active'
# if matching_url == request.path:
# return 'active'
return '' return ''

View File

@ -1,5 +1,6 @@
"""policy structs""" """policy structs"""
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING, List from typing import TYPE_CHECKING, List
from django.http import HttpRequest from django.http import HttpRequest

View File

@ -1,5 +1,6 @@
"""Functions for creating XML output.""" """Functions for creating XML output."""
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from structlog import get_logger from structlog import get_logger