diff --git a/HISTORY.rst b/HISTORY.rst index 595ba20a50..6588ac08c4 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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) ================== diff --git a/docs/releases/3.3.rst b/docs/releases/3.3.rst index c251ab6faa..688283c96b 100644 --- a/docs/releases/3.3.rst +++ b/docs/releases/3.3.rst @@ -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 -------- diff --git a/mayan/apps/appearance/templates/appearance/base.html b/mayan/apps/appearance/templates/appearance/base.html index 09228b5fb5..ce799ff513 100644 --- a/mayan/apps/appearance/templates/appearance/base.html +++ b/mayan/apps/appearance/templates/appearance/base.html @@ -136,6 +136,9 @@ }, {% endfor %} ]; + $(function () { + $('[data-toggle="tooltip"]').tooltip(); + }) {% block javascript %}{% endblock %} diff --git a/mayan/apps/appearance/templates/appearance/generic_list_subtemplate.html b/mayan/apps/appearance/templates/appearance/generic_list_subtemplate.html index c564f56a8b..cf06d88f8a 100644 --- a/mayan/apps/appearance/templates/appearance/generic_list_subtemplate.html +++ b/mayan/apps/appearance/templates/appearance/generic_list_subtemplate.html @@ -1,6 +1,7 @@ {% load i18n %} {% load static %} +{% load appearance_tags %} {% load common_tags %} {% load navigation_tags %} @@ -30,30 +31,40 @@ {% if source_column %} {% if source_column.is_sortable %} - {{ source_column.label }} + {{ source_column.label }} {% if source_column.get_sort_field == sort_field %} {% if icon_sort %}{{ icon_sort.render }}{% endif %} {% endif %} - {% else %} {{ source_column.label }} {% endif %} + + {% if source_column.help_text %} + + {% get_icon icon_path='mayan.apps.navigation.icons.icon_source_column_help_text' %} + + {% endif %} {% 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 %} - {% if column.is_sortable %} - {{ column.label }} - {% if column.get_sort_field == sort_field %} + {% if source_column.is_sortable %} + {{ source_column.label }} + {% if source_column.get_sort_field == sort_field %} {% if icon_sort %}{{ icon_sort.render }}{% endif %} {% endif %} - {% else %} - {{ column.label }} + {{ source_column.label }} + {% endif %} + + {% if source_column.help_text %} + + {% get_icon icon_path='mayan.apps.navigation.icons.icon_source_column_help_text' %} + {% endif %} {% endfor %} diff --git a/mayan/apps/navigation/classes.py b/mayan/apps/navigation/classes.py index 78062aaf05..d544fe6b31 100644 --- a/mayan/apps/navigation/classes.py +++ b/mayan/apps/navigation/classes.py @@ -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: diff --git a/mayan/apps/navigation/icons.py b/mayan/apps/navigation/icons.py new file mode 100644 index 0000000000..d5d2bcdd7a --- /dev/null +++ b/mayan/apps/navigation/icons.py @@ -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' +)