Add support for server side link badges
GitLab issue #562. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -13,6 +13,12 @@
|
||||
{% endfor %}
|
||||
|
||||
href="{{ link.url }}"
|
||||
>{% if link.icon %}{% if not hide_icon %}<i class="hidden-xs hidden-sm hidden-md {{ link.icon }}"></i>{% endif %}{% endif %}{% if link.icon_class and not hide_icon %}{{ link.icon_class.render }}{% endif %} {{ link.text }}{% if link.error %} - {{ link.error }}{% endif %}</a>{% if horizontal %}{% if not forloop.last %} {% endif %}{% endif %}
|
||||
>{% if link.icon %}{% if not hide_icon %}
|
||||
<i class="hidden-xs hidden-sm hidden-md {{ link.icon }}"></i>
|
||||
{% endif %}{% endif %}
|
||||
{% if link.icon_class and not hide_icon %}{{ link.icon_class.render }}{% endif %}
|
||||
{{ link.text|default:'' }}{% if link.badge_text %} <span class="badge">{{ link.badge_text }}</span>
|
||||
{% endif %}{% if link.error %} - {{ link.error }}{% endif %}
|
||||
</a>{% if horizontal %}{% if not forloop.last %} {% endif %}{% endif %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
@@ -32,8 +32,13 @@ def get_kwargs_factory(variable_name):
|
||||
return get_kwargs
|
||||
|
||||
|
||||
def get_notification_count(context):
|
||||
return context['request'].user.notifications.filter(read=False).count()
|
||||
def get_unread_notification_count(context):
|
||||
Notification = apps.get_model(
|
||||
app_label='events', model_name='Notification'
|
||||
)
|
||||
return Notification.objects.filter(
|
||||
user=context.request.user
|
||||
).filter(read=False).count()
|
||||
|
||||
|
||||
link_events_list = Link(
|
||||
@@ -72,6 +77,7 @@ link_user_events = Link(
|
||||
view='events:user_events'
|
||||
)
|
||||
link_user_notifications_list = Link(
|
||||
badge_text=get_unread_notification_count,
|
||||
icon_class=icon_user_notifications_list, text='',
|
||||
view='events:user_notifications_list'
|
||||
)
|
||||
|
||||
@@ -34,6 +34,11 @@ class ResolvedLink(object):
|
||||
def active(self):
|
||||
return self.link.view == self.current_view
|
||||
|
||||
@property
|
||||
def badge_text(self):
|
||||
if self.link.badge_text:
|
||||
return self.link.badge_text(context=self.context)
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
return self.link.description
|
||||
@@ -303,7 +308,7 @@ class Link(object):
|
||||
def remove(cls, name):
|
||||
del cls._registry[name]
|
||||
|
||||
def __init__(self, text, view=None, args=None, condition=None,
|
||||
def __init__(self, badge_text=None, text=None, view=None, args=None, condition=None,
|
||||
conditional_disable=None, description=None, html_data=None,
|
||||
html_extra_classes=None, icon=None, icon_class=None,
|
||||
keep_query=False, kwargs=None, name=None, permissions=None,
|
||||
@@ -311,6 +316,7 @@ class Link(object):
|
||||
url=None):
|
||||
|
||||
self.args = args or []
|
||||
self.badge_text = badge_text
|
||||
self.condition = condition
|
||||
self.conditional_disable = conditional_disable
|
||||
self.description = description
|
||||
|
||||
Reference in New Issue
Block a user