Skip to content
Snippets Groups Projects
Commit 5ba3ea2c authored by Fredrik Jonsson's avatar Fredrik Jonsson
Browse files

Styling adjustments to notification dropdown.

parent 9b8d7ecd
No related branches found
No related tags found
No related merge requests found
...@@ -5,5 +5,5 @@ def notification_context(request): ...@@ -5,5 +5,5 @@ def notification_context(request):
context_data = dict() context_data = dict()
if hasattr(request, 'user'): if hasattr(request, 'user'):
if request.user.is_authenticated and request.user.is_apply_staff: if request.user.is_authenticated and request.user.is_apply_staff:
context_data['latest_notifications'] = Activity.objects.all().order_by('-timestamp')[:5] context_data['latest_notifications'] = Activity.objects.latest().order_by('-timestamp')[:5]
return context_data return context_data
...@@ -4,6 +4,7 @@ from django.contrib.contenttypes.models import ContentType ...@@ -4,6 +4,7 @@ from django.contrib.contenttypes.models import ContentType
from django.db import models from django.db import models
from django.db.models import Case, Value, When from django.db.models import Case, Value, When
from django.db.models.functions import Concat from django.db.models.functions import Concat
from django.utils import timezone
from .options import MESSAGES from .options import MESSAGES
...@@ -54,6 +55,9 @@ class ActivityQuerySet(BaseActivityQuerySet): ...@@ -54,6 +55,9 @@ class ActivityQuerySet(BaseActivityQuerySet):
def actions(self): def actions(self):
return self.filter(type=ACTION) return self.filter(type=ACTION)
def latest(self):
return self.filter(timestamp__gte=(timezone.now() - timezone.timedelta(days=30)))
class ActivityBaseManager(models.Manager): class ActivityBaseManager(models.Manager):
def create(self, **kwargs): def create(self, **kwargs):
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
<div class="admin-bar__inner"> <div class="admin-bar__inner">
<div class="admin-bar__inner--with-button"> <div class="admin-bar__inner--with-button">
<h1 class="gamma heading heading--no-margin heading--bold">{% trans "Notifications" %}</h1> <h1 class="gamma heading heading--no-margin heading--bold">{% trans "Notifications" %}</h1>
<form class="form notification__filters" method="get"> <form class="form notifications__filters" method="get">
{{ filter.form.as_p }} {{ filter.form }}
<button class="button button--primary" type="submit" value="Filter">{% trans "Filter" %}</button> <button class="button button--primary" type="submit" value="Filter">{% trans "Filter" %}</button>
</form> </form>
</div> </div>
......
...@@ -70,7 +70,7 @@ class NotificationsView(ListView): ...@@ -70,7 +70,7 @@ class NotificationsView(ListView):
def get_queryset(self): def get_queryset(self):
# List only last 30 days' activities # List only last 30 days' activities
queryset = Activity.objects.filter(timestamp__gte=(timezone.now() - timezone.timedelta(days=30))) queryset = Activity.objects.latest()
self.filterset = self.filterset_class(self.request.GET, queryset=queryset) self.filterset = self.filterset_class(self.request.GET, queryset=queryset)
return self.filterset.qs.distinct().order_by('-timestamp') return self.filterset.qs.distinct().order_by('-timestamp')
......
function notificationToggle() { (function () {
'use strict';
document.getElementById('notificationDropdown').classList.toggle('show');
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function (event) {
'use strict'; 'use strict';
if (!event.target.matches('.dropbtn, .dropbtn *')) {
var dropdowns = document.getElementsByClassName('dropdown-content'); // Open/close dropdown when users clicks the bell.
var i; document.querySelector('.notifications__bell').addEventListener('click', function () {
for (i = 0; i < dropdowns.length; i++) { document.querySelector('.notifications__content').classList.toggle('hidden');
var openDropdown = dropdowns[i]; });
if (openDropdown.classList.contains('show')) {
notificationToggle(); // Close the dropdown menu if the user clicks outside of it.
window.onclick = function (event) {
if (!event.target.matches('.notifications--dropdown, .notifications--dropdown *')) {
const dropdown = document.querySelector('.notifications__content');
if (!dropdown.classList.contains('hidden')) {
dropdown.classList.add('hidden');
} }
} }
} };
};
})();
.dropbtn { .notifications {
padding: 7px 12px; &--dropdown {
cursor: pointer; position: relative;
} display: inline-block;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content { &__bell {
display: none; padding: 7px 12px;
position: absolute; cursor: pointer;
right: 0;
font-size: 15px;
background-color: $color--light-grey;
min-width: 400px;
box-shadow: 1px 1px 6px 4px $color--light-mid-grey;
p {
color: $color--black;
padding: 0 10px;
display: block;
} }
}
.dropdown-item { &__content {
border-bottom: .1px solid $color--dark-grey; position: absolute;
} right: 1em;
padding: 1em;
margin-top: .5em;
background-color: $color--light-grey;
min-width: 400px;
box-shadow: 2px 2px 6px 1px $color--dark-grey;
}
.show-all { &__item {
text-align: center; padding-bottom: 1em;
} border-bottom: 1px solid $color--dark-grey;
}
.show { &__more {
display: block; text-align: center;
} font-weight: $weight--semibold;
}
.notification {
&__filters { &__filters {
display: flex; display: flex;
align-items: center; align-items: center;
padding: 4px; padding: 4px;
justify-content: space-between; justify-content: space-between;
p { label {
font-weight: 520; font-weight: $weight--semibold;
padding-right: 10px; padding-right: 1em;
} }
select { select {
padding-right: 1em; padding-right: 1em;
} }
.form__select {
margin-right: 1em;
}
} }
} }
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<script src="{% static 'js/jquery.min.js' %}"></script> <script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/js.cookie.min.js' %}"></script> <script src="{% static 'js/js.cookie.min.js' %}"></script>
<script src="{% static 'js/main-top.js' %}"></script> <script src="{% static 'js/main-top.js' %}"></script>
<script src="{% static 'js/apply/notifications.js' %}"></script> <script defer src="{% static 'js/apply/notifications.js' %}"></script>
{% if COOKIES_ACCEPTED and MATOMO_URL and MATOMO_SITEID %} {% if COOKIES_ACCEPTED and MATOMO_URL and MATOMO_SITEID %}
{# we are only expecting strings, so make sure we escape the values #} {# we are only expecting strings, so make sure we escape the values #}
<script> <script>
...@@ -106,21 +106,21 @@ ...@@ -106,21 +106,21 @@
<div class="header__button-container"> <div class="header__button-container">
{% if latest_notifications %} {% if latest_notifications %}
<div class="dropdown"> <div class="notifications notifications--dropdown">
<a href="#" onclick="return notificationToggle()" class=" button--contains-icons dropbtn" aria-haspopup="activity" aria-expanded="false" role="button"> <a href="#" class="button button--contains-icons notifications__bell" aria-label="{% trans "Notifications" %}" aria-haspopup="activity" aria-expanded="false" role="button">
<svg class="icon"><use xlink:href="#bell-icon"></use></svg> <svg class="icon"><use xlink:href="#bell-icon"></use></svg>
</a> </a>
<div id="notificationDropdown" class="dropdown-content" role="activity"> <div class="notifications__content zeta hidden" role="activity">
<p><b>Notifications</b></p> <h5>Notifications</h5>
{% for notification in latest_notifications %} {% for notification in latest_notifications %}
<p class="dropdown-item"> <p class="notifications__item">
<span><b>{{ notification.source_content_type.name|source_type }}</b></span> <strong>{{ notification.source_content_type.name|source_type }} </strong>
<a href="{{ notification.source.get_absolute_url }}">{{ notification.source.title|capfirst|truncatechars:15 }}</a> <a href="{{ notification.source.get_absolute_url }}">{{ notification.source.title|capfirst|truncatechars:15 }}</a>
: {{ notification.user }} {% ifequal notification.type 'comment' %}made a comment{% else %} {{ notification.message|safe }} : {{ notification.user }} {% ifequal notification.type 'comment' %}made a comment{% else %} {{ notification.message|safe }}
{% if notification.related_object %}<a href="{{ notification.related_object.get_absolute_url }}">{{ notification.related_object|model_verbose_name }}</a>{% endif %}{% endifequal %} {% if notification.related_object %}<a href="{{ notification.related_object.get_absolute_url }}">{{ notification.related_object|model_verbose_name }}</a>{% endif %}{% endifequal %}
</p> </p>
{% endfor %} {% endfor %}
<p class="show-all"><a href="{% url "activity:notifications" %}">Show All</a></p> <p class="notifications__more"><a href="{% url "activity:notifications" %}">Show All</a></p>
</div> </div>
</div> </div>
{% endif %} {% endif %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment