Skip to content

Commit

Permalink
Display component title popups properly
Browse files Browse the repository at this point in the history
As noticed in code review, the refactored version of the maintenance
UI did not display the same descriptive title tooltips on component
trails as the original did.

This solves the issue by adding a separate `component_description`
template tag.
  • Loading branch information
lunkwill42 committed Nov 25, 2024
1 parent b203a0f commit 4078ddd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions python/nav/django/templatetags/maintenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ def component_name(component):
return component.pk


@register.filter
def component_description(component):
"""Returns a description of a component useful as a link title tooltip. Returns
an empty string if there is no further description than the component's name.
"""
if isinstance(component, MissingComponent):
return str(component)
if hasattr(component, "ip"):
return str(component.ip)
return getattr(component, "description", "")


@register.filter
def component_db_table(component):
"""Returns the database table name of a model object used as a maintenance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% load maintenance %}
{% for element in trail %}
{% with element|component_name as title %}
{% with element|component_name as name %}
{% if element.get_absolute_url %}
<a href="{{ element.get_absolute_url }}" title="{{ title }}">{{ title }}</a>
<a href="{{ element.get_absolute_url }}" title="{{ element|component_description }}">{{ name }}</a>
{% else %}
{{ title }}
{{ name }}
{% endif %}
{% endwith %}
{% if not forloop.last %} → {% endif %}
Expand Down

0 comments on commit 4078ddd

Please sign in to comment.