Display column help text as a tooltip

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-07-28 22:35:52 -04:00
parent 3efd1bd89d
commit fe2de33e98
6 changed files with 68 additions and 11 deletions

View File

@@ -64,6 +64,8 @@
- Remove document image clear link and view.
This is now handled by the file caching app.
- Add web links app.
- Add support to display column help text
as a tooltip.
3.2.6 (2019-07-10)
==================

View File

@@ -79,6 +79,8 @@ Changes
- Remove document image clear link and view.
This is now handled by the file caching app.
- Add web links app.
- Add support to display column help text
as a tooltip.
Removals
--------

View File

@@ -136,6 +136,9 @@
},
{% endfor %}
];
$(function () {
$('[data-toggle="tooltip"]').tooltip();
})
</script>
{% block javascript %}{% endblock %}

View File

@@ -1,6 +1,7 @@
{% load i18n %}
{% load static %}
{% load appearance_tags %}
{% load common_tags %}
{% load navigation_tags %}
@@ -30,30 +31,40 @@
{% if source_column %}
<th>
{% if source_column.is_sortable %}
<a href="{% navigation_get_sort_field_querystring column=source_column %}">{{ source_column.label }}
<a href="{% navigation_get_sort_field_querystring column=source_column %}">{{ source_column.label }}</a>
{% if source_column.get_sort_field == sort_field %}
{% if icon_sort %}{{ icon_sort.render }}{% endif %}
{% endif %}
</a>
{% else %}
{{ source_column.label }}
{% endif %}
{% if source_column.help_text %}
<span data-toggle="tooltip" data-placement="bottom" title="{{ source_column.help_text }}">
{% get_icon icon_path='mayan.apps.navigation.icons.icon_source_column_help_text' %}
</span>
{% endif %}
</th>
{% endif %}
{% endif %}
{% if not hide_columns %}
{% navigation_get_source_columns source=object_list exclude_identifier=True as source_columns %}
{% for column in source_columns %}
{% for source_column in source_columns %}
<th>
{% if column.is_sortable %}
<a href="{% navigation_get_sort_field_querystring column=column %}">{{ column.label }}
{% if column.get_sort_field == sort_field %}
{% if source_column.is_sortable %}
<a href="{% navigation_get_sort_field_querystring column=source_column %}">{{ source_column.label }}</a>
{% if source_column.get_sort_field == sort_field %}
{% if icon_sort %}{{ icon_sort.render }}{% endif %}
{% endif %}
</a>
{% else %}
{{ column.label }}
{{ source_column.label }}
{% endif %}
{% if source_column.help_text %}
<span data-toggle="tooltip" data-placement="bottom" title="{{ source_column.help_text }}">
{% get_icon icon_path='mayan.apps.navigation.icons.icon_source_column_help_text' %}
</span>
{% endif %}
</th>
{% endfor %}

View File

@@ -6,7 +6,9 @@ import logging
from furl import furl
from django.apps import apps
from django.contrib.admin.utils import label_for_field
from django.contrib.admin.utils import (
help_text_for_field, label_for_field
)
from django.core.exceptions import (
FieldDoesNotExist, ImproperlyConfigured, PermissionDenied
)
@@ -689,13 +691,14 @@ class SourceColumn(object):
def __init__(
self, source, attribute=None, empty_value=None, func=None,
include_label=False, is_attribute_absolute_url=False,
help_text=None, include_label=False, is_attribute_absolute_url=False,
is_object_absolute_url=False, is_identifier=False, is_sortable=False,
kwargs=None, label=None, order=None, sort_field=None, views=None,
widget=None
):
self.source = source
self._label = label
self._help_text = help_text
self.source = source
self.attribute = attribute
self.empty_value = empty_value
self.exclude = ()
@@ -715,6 +718,32 @@ class SourceColumn(object):
self.__class__._registry[source].append(self)
self._calculate_label()
self._calculate_help_text()
def _calculate_help_text(self):
if not self._help_text:
if self.attribute:
try:
attribute = resolve_attribute(
obj=self.source, attribute=self.attribute
)
self._help_text = getattr(attribute, 'help_text')
except AttributeError:
try:
name, model = SourceColumn.get_attribute_recursive(
attribute=self.attribute, model=self.source._meta.model
)
self._help_text = help_text_for_field(
name=name, model=model
)
except AttributeError:
self._help_text = self.attribute
else:
self._help_text = getattr(
self.func, 'help_text', _('Unnamed function')
)
self.help_text = self._help_text
def _calculate_label(self):
if not self._label:

View File

@@ -0,0 +1,10 @@
from __future__ import absolute_import, unicode_literals
from mayan.apps.appearance.classes import Icon
icon_source_column_help_text = Icon(
driver_name='fontawesome', symbol='question'
)
icon_source_column_help_text = Icon(
driver_name='fontawesomecss', css_classes='far fa-question-circle'
)