diff --git a/hypha/apply/activity/context_processors.py b/hypha/apply/activity/context_processors.py new file mode 100644 index 0000000000000000000000000000000000000000..0ce63073fcf61f5eb472298c986193fa8659eee2 --- /dev/null +++ b/hypha/apply/activity/context_processors.py @@ -0,0 +1,8 @@ +from .models import Activity + + +def notification_context(request): + context_data = dict() + if request.user.is_authenticated: + context_data['latest_notifications'] = Activity.objects.filter(user=request.user).order_by('-timestamp')[:5] + return context_data diff --git a/hypha/apply/activity/templates/activity/notifications.html b/hypha/apply/activity/templates/activity/notifications.html index c6bc4e573aa31c41fee487e8a9aa9190d27f4171..f216ae4205b94773ff3fb1b15384d4a8ac068e84 100644 --- a/hypha/apply/activity/templates/activity/notifications.html +++ b/hypha/apply/activity/templates/activity/notifications.html @@ -22,10 +22,24 @@ <div class="wrapper wrapper--large wrapper--tabs js-tabs-content"> {# Tab 1 #} <div class="tabs__content" id="tab-1"> -<!-- <form action="" method="get">--> -<!-- {{ filter.form.as_p }}--> -<!-- <input type="submit" />--> -<!-- </form>--> +<!-- WIP Filters --> +<!-- <div class="filters {% if filter_classes %}{{filter_classes}}{% endif %}">--> +<!-- <div class="filters__header">--> +<!-- <button class="filters__button js-clear-filters">{% trans "Clear" %}</button>--> +<!-- <div>{% trans "Filter by" %}</div>--> +<!-- <button class="filters__button js-close-filters">{% trans "Close" %}</button>--> +<!-- </div>--> + +<!-- <form action="{{ filter_action }}" method="get" class="form form--filters js-filter-form">--> +<!-- <ul class="form__filters select2">--> +<!-- {{ filter.form.as_ul }}--> +<!-- <li>--> +<!-- <button class="button button--primary" type="submit" value="Filter">{% trans "Filter" %}</button>--> +<!-- </li>--> +<!-- </ul>--> +<!-- </form>--> +<!-- </div>--> + {% for comment in comments %} <div class="feed__item feed__item--comment"> <div class="feed__pre-content"> diff --git a/hypha/apply/activity/views.py b/hypha/apply/activity/views.py index 407d0a67af73fdea603a9192b17e71fe72175c1b..67ab9604e71e57a38095166478d724675893c242 100644 --- a/hypha/apply/activity/views.py +++ b/hypha/apply/activity/views.py @@ -2,7 +2,6 @@ from django.utils import timezone from django.utils.decorators import method_decorator from django.views.generic import CreateView, ListView -from hypha.apply.funds.models.submissions import ApplicationSubmission from hypha.apply.users.decorators import login_required from hypha.apply.utils.views import DelegatedViewMixin @@ -70,18 +69,24 @@ class NotificationsView(ListView): def get_context_data(self, *, object_list=None, **kwargs): context = super(NotificationsView, self).get_context_data() user = self.request.user - if user.is_applicant or user.is_partner: - context['comments'] = Activity.comments.filter(source__user=user).order_by('-timestamp') - context['actions'] = Activity.actions.filter(source__user=user).order_by('-timestamp') - elif user.is_reviewer: - reviewer_submissions = ApplicationSubmission.objects.filter(reviewers=user).values_list("id", flat=True) - context['comments'] = Activity.comments.filter(source_object_id__in=reviewer_submissions).order_by('-timestamp') - context['actions'] = Activity.actions.filter(source_object_id__in=reviewer_submissions).order_by('-timestamp') - elif user.is_apply_staff or user.is_apply_staff_admin: - context['comments'] = Activity.comments.all().order_by('-timestamp') - context['actions'] = Activity.actions.all().order_by('-timestamp') + comments = Activity.comments.all() + actions = Activity.actions.all() + + # Getting issues with source's reverse relationship + # if user.is_applicant or user.is_partner: + # context['comments'] = comments.filter(source__user=user).order_by('-timestamp') + # context['actions'] = actions.filter(source__user=user).order_by('-timestamp') + # elif user.is_reviewer: + # reviewer_submissions = ApplicationSubmission.objects.filter(reviewers=user).values_list("id", flat=True) + # context['comments'] = comments.filter(source_object_id__in=reviewer_submissions).order_by('-timestamp') + # context['actions'] = actions.filter(source_object_id__in=reviewer_submissions).order_by('-timestamp') + + if user.is_apply_staff or user.is_apply_staff_admin: + context['comments'] = comments.all().order_by('-timestamp') + context['actions'] = actions.all().order_by('-timestamp') else: - context['comments'] = Activity.comments.filter(user=user).order_by('-timestamp') - context['actions'] = Activity.actions.filter(user=user).order_by('-timestamp') + context['comments'] = comments.filter(user=user).order_by('-timestamp') + context['actions'] = actions.filter(user=user).order_by('-timestamp') + # WIP Filters # context['filter'] = NotificationFilter(self.request.GET, queryset=self.get_queryset()) return context diff --git a/hypha/settings/base.py b/hypha/settings/base.py index 07e5af2b9dc97fad7fbfc133c753e5d03903e143..7524adc3ed3fff2b1c147312881f99f6209d6386 100644 --- a/hypha/settings/base.py +++ b/hypha/settings/base.py @@ -179,6 +179,7 @@ TEMPLATES = [ 'social_django.context_processors.login_redirect', 'hypha.apply.projects.context_processors.projects_enabled', 'hypha.cookieconsent.context_processors.cookies_accepted', + 'hypha.apply.activity.context_processors.notification_context', ], }, }, diff --git a/hypha/static_src/src/sass/apply/components/_activity-notifications.scss b/hypha/static_src/src/sass/apply/components/_activity-notifications.scss new file mode 100644 index 0000000000000000000000000000000000000000..86d2dfdd3db2a8e7e58475141975adf329341092 --- /dev/null +++ b/hypha/static_src/src/sass/apply/components/_activity-notifications.scss @@ -0,0 +1,44 @@ +.dropbtn { + padding: 5px 12px; + cursor: pointer; +} + +.dropdown { + position: relative; + display: inline-block; + + &:hover { + .dropdown-content { + display: block; + } + } +} + +.dropdown-content { + display: none; + position: absolute; + right: 0; + font-size: 15px; + background-color: #F0F0F0; + min-width: 400px; + box-shadow: 8px 8px 16px 8px rgba(0,0,0,0.2); + z-index: 1; + + p { + color: black; + padding: 0px 10px; + display: block; + } +} + +.dropdown-item { + border-bottom: .1px solid grey; +} + +.show-all { + text-align: center; +} + +.source-label { + background-color: #7dc588; +} diff --git a/hypha/static_src/src/sass/apply/main.scss b/hypha/static_src/src/sass/apply/main.scss index 150d659960e74af3bfc4b8da72db452846c236db..c0a9ee4695a03f7b752a13e6e2885f2ef8a5329e 100644 --- a/hypha/static_src/src/sass/apply/main.scss +++ b/hypha/static_src/src/sass/apply/main.scss @@ -68,6 +68,7 @@ @import 'components/reminder-sidebar'; @import 'components/two-factor'; @import 'components/determination'; +@import 'components/activity-notifications'; // Layout @import 'layout/header'; diff --git a/hypha/templates/base-apply.html b/hypha/templates/base-apply.html index 33f22e725619cd2612d509ed6b8ef55fdaa7d3b1..a9d4b8e1fc094a8a0decae97e1e3d56cdc3f6bc4 100644 --- a/hypha/templates/base-apply.html +++ b/hypha/templates/base-apply.html @@ -1,4 +1,4 @@ -{% load i18n static wagtailuserbar wagtailcore_tags wagtailimages_tags navigation_tags util_tags hijack cookieconsent_tags %}<!doctype html> +{% load i18n static wagtailuserbar wagtailcore_tags wagtailimages_tags navigation_tags util_tags hijack cookieconsent_tags activity_tags %}<!doctype html> {% wagtail_site as current_site %} <html class="no-js" lang="en"> <head> @@ -104,6 +104,23 @@ </section> <div class="header__button-container"> + {% if latest_notifications %} + <div class="dropdown"> + <a href="#" class=" button--contains-icons dropbtn" aria-haspopup="activity" aria-expanded="false" role="button"> + <svg class="icon"><use xlink:href="#bell-icon"></use></svg> + </a> + <div class="dropdown-content" role="activity"> + {% for notification in latest_notifications %} + <p class="dropdown-item"> + <span class="source-label">{{ notification.source_content_type.name|source_type }}</span> + <a href="{{ notification.source.get_absolute_url }}">{{ notification.source.title|capfirst }}</a> + : {{ notification.user }} {% ifequal notification.type 'comment' %}made a comment{% else %} {{ notification.message|safe }}{% endifequal %} + </p> + {% endfor %} + <p class="show-all"><a href="{% url "activity:notifications" %}">Show All</a></p> + </div> + </div> + {% endif %} <a href="{% url 'users:account' %}" class="button button--transparent button--narrow button--contains-icons"> <svg class="icon icon--person"><use xlink:href="#person-icon"></use></svg> {{ request.user }} diff --git a/hypha/templates/includes/sprites.html b/hypha/templates/includes/sprites.html index dbd3555ac3bc152ae8e659e76d767b12d7d20373..ed6584bc88c0f78eb1e250d10e41e6fb3f2cb877 100644 --- a/hypha/templates/includes/sprites.html +++ b/hypha/templates/includes/sprites.html @@ -119,6 +119,10 @@ <path d="M17 9.81V16h-3.644v-5.776c0-1.45-.527-2.441-1.846-2.441-1.006 0-1.605.667-1.87 1.313-.095.23-.12.552-.12.875V16H5.875s.05-9.782 0-10.796H9.52v1.53l-.024.035h.024v-.035c.484-.734 1.349-1.783 3.284-1.783C15.202 4.95 17 6.494 17 9.81zM2.062 0C.816 0 0 .806 0 1.865 0 2.9.792 3.73 2.014 3.73h.024c1.272 0 2.062-.83 2.062-1.866C4.076.805 3.31 0 2.062 0zM.216 16H3.86V5.204H.216V16z" fill-rule="nonzero" /> </symbol> + <symbol id="bell-icon" viewBox="0 0 16 16"> + <path d="M8 16a2 2 0 0 0 2-2H6a2 2 0 0 0 2 2zm.995-14.901a1 1 0 1 0-1.99 0A5.002 5.002 0 0 0 3 6c0 1.098-.5 6-2 7h14c-1.5-1-2-5.902-2-7 0-2.42-1.72-4.44-4.005-4.901z"/> + </symbol> + <symbol id="arrow-head-pixels--transparent" viewBox="0 0 50 75"> <g fill="#25AAE1" fill-rule="evenodd"> <path opacity=".2" d="M0 50h25v25H0z" />