Commit 3035cba4 authored by BERJON Matthieu's avatar BERJON Matthieu
Browse files

Update of active links



I updated the active links system by creating a templatetag `is_active`.
The issue was that the old system was unable to parser several  endpoints. Now
it's possible to specify as many endpoints as required by their related
name (defined in the `urls.py` file. This system is a bit more
cumbersome than trying to just active a link according to its base
directory but the advantage is that if you change the endpoints in the
`urls.py` file you won't have to update the template.
Signed-off-by: BERJON Matthieu's avatarMatthieu Berjon <matthieu.berjon@inria.fr>
parent ba5845c3
from django import template
from django.urls import reverse, resolve
register = template.Library()
@register.simple_tag
def is_active(request, *urlnames):
resolver_match = resolve(request.path)
for urlname in urlnames:
if resolver_match.url_name == urlname:
return 'active'
return ''
{% if request.resolver_match.url_name == link_name %}active{% endif %}
{% load static %}
{% load static activelink %}
<header class="container-fluid">
<div class="container">
<nav class="navbar navbar-expand-xl navbar-dark bg-dark">
......@@ -9,7 +10,8 @@
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item {% include 'macros/active_link.html' with link_name='webapp_list' %}">
<li
class="nav-item {% is_active request 'webapp_list' %}">
<a class="nav-link" href="{% url 'main:webapp_list' %}"><i class="fas fa-cloud"></i> Explore</a>
</li>
<li {# TODO: put active link if possible #}>
......@@ -19,21 +21,23 @@
<ul class="navbar-nav ml-auto">
{% if not user.is_authenticated %}
<li class="nav-item {% include 'macros/active_link.html' with link_name='account_login' %}">
<li class="nav-item
{% is_active request 'account_login' %}">
<a class="nav-link" href="{% url 'account_login' %}">Sign in</a>
</li>
<li class="nav-item nav-link disabled">or</li>
<li class="nav-item {% include 'macros/active_link.html' with link_name='account_signup' %}">
<li class="nav-item {% is_active request 'account_signup' %}">
<a class="nav-link" href="{% url 'account_signup' %}">Sign up</a>
</li>
{% else %}
<li class="nav-item {% include 'macros/active_link.html' with link_name='job_list' %}">
<li class="nav-item {% is_active request 'job_list' %}">
<a class="nav-link" href="{% url 'main:job_list' %}"><i class="fas fa-database"></i> My jobs</a>
</li>
<li class="nav-item {% include 'macros/active_link.html' with link_name='user_settings' %}">
<li class="nav-item
{% is_active request 'user_settings' 'user_webapp_list' 'webapp_update' 'ssh_settings' 'token_settings' 'user_runner_list' 'user_runner_create' 'user_runner_detail' 'user_runner_delete' 'user_password_update' %}">
<a class="nav-link" href="{% url 'main:user_settings' %}"><i class="fas fa-cogs"></i> Settings</a>
</li>
<li class="nav-item {% include 'macros/active_link.html' with link_name='account_logout' %}">
<li class="nav-item {% is_active request 'account_logout' %}">
<a class="nav-link" href="{% url 'account_logout' %}"><i class="fas fa-sign-out-alt"></i> Sign out</a>
</li>
{% endif %}
......
<ul class="tab-menu">
<li class="{% if active_tab == 'tab1' %} active{% endif %}"><a href="#">Tab 1</a></li>
<li class="{% if active_tab == 'tab2' %} active{% endif %}"><a href="#">Tab 2</a></li>
<li class="{% if active_tab == 'tab3' %} active{% endif %}"><a href="#">Tab 3</a></li>
</ul>
{% load activelink %}
<div class="col-2">
<div class="list-group">
<a href="{% url 'main:user_settings' %}"
class="
list-group-item list-group-item-action
{% include 'macros/active_link.html' with link_name='user_settings' %}">
{% is_active request 'user_settings' %}">
<i class="fas fa-user"></i> My profile</a>
<a href="{% url 'main:user_password_update' %}"
class="list-group-item list-group-item-action
{% include 'macros/active_link.html' with link_name='user_password_update' %}">
{% is_active request 'user_password_update' %}">
<i class="fas fa-unlock"></i> Password</a>
<a href="{% url 'main:ssh_settings' %}"
class="list-group-item list-group-item-action"><i class="fas fa-key"></i> SSH key</a>
class="list-group-item list-group-item-action
{% is_active request 'ssh_settings' %}">
<i class="fas fa-key"></i> SSH key</a>
<a href="{% url 'main:token_settings' %}"
class="list-group-item list-group-item-action"><i class="fas fa-ellipsis-h"></i> Token</a>
class="list-group-item list-group-item-action
{% is_active request 'token_settings' %}">
<i class="fas fa-ellipsis-h"></i> Token</a>
<a href="{% url 'main:user_webapp_list' %}"
class="list-group-item list-group-item-action"><i class="fas fa-cloud"></i> My apps</a>
class="list-group-item list-group-item-action
{% is_active request 'user_webapp_list' 'webapp_update' %}">
<i class="fas fa-cloud"></i> My apps</a>
<a href="{% url 'main:user_runner_list' %}"
class="list-group-item list-group-item-action
{% is_active request 'user_runner_list' 'user_runner_create' %}">
<i class="fab fa-hubspot"></i> Runners</a>
</div>
</div>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment