mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-12 22:10:16 +02:00
Add notifications auto refresh
This commit is contained in:
parent
d92d629c25
commit
7d711a54bc
@ -1,5 +1,4 @@
|
|||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
@ -24,4 +23,9 @@ urlpatterns = [
|
|||||||
name='add_character'
|
name='add_character'
|
||||||
),
|
),
|
||||||
url(r'^dashboard/$', views.dashboard, name='dashboard'),
|
url(r'^dashboard/$', views.dashboard, name='dashboard'),
|
||||||
|
url(
|
||||||
|
r'^notifications_render/$',
|
||||||
|
views.notifications_render,
|
||||||
|
name='notifications_render'
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
@ -6,11 +6,13 @@ from django.contrib.auth import login, authenticate
|
|||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.core import signing
|
from django.core import signing
|
||||||
from django.urls import reverse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from allianceauth.eveonline.models import EveCharacter
|
from allianceauth.eveonline.models import EveCharacter
|
||||||
|
|
||||||
from esi.decorators import token_required
|
from esi.decorators import token_required
|
||||||
from esi.models import Token
|
from esi.models import Token
|
||||||
|
|
||||||
@ -59,6 +61,14 @@ def dashboard(request):
|
|||||||
return render(request, 'authentication/dashboard.html', context)
|
return render(request, 'authentication/dashboard.html', context)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def notifications_render(request):
|
||||||
|
"""returns html to render the notifications item in the top menu"""
|
||||||
|
unread_count = request.user.notification_set.filter(viewed=False).count()
|
||||||
|
context = {'notifications': unread_count}
|
||||||
|
return render(request, 'allianceauth/notifications_menu_item.html', context)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@token_required(scopes=settings.LOGIN_TOKEN_SCOPES)
|
@token_required(scopes=settings.LOGIN_TOKEN_SCOPES)
|
||||||
def main_character_change(request, token):
|
def main_character_change(request, token):
|
||||||
|
27
allianceauth/static/js/base.js
Normal file
27
allianceauth/static/js/base.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
Javascript for the base template
|
||||||
|
*/
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
var elem = document.getElementById("dataExport");
|
||||||
|
var notificationsRenderUrl = elem.getAttribute("data-notificationsRenderUrl");
|
||||||
|
|
||||||
|
// render the notifications item in the top menu
|
||||||
|
function render_notifications(){
|
||||||
|
$("#menu_item_notifications").load(
|
||||||
|
notificationsRenderUrl,
|
||||||
|
function(responseTxt, statusTxt, xhr){
|
||||||
|
if(statusTxt == "error")
|
||||||
|
console.log(
|
||||||
|
"Failed to load HTMl to render notifications item. Error: "
|
||||||
|
+ xhr.status
|
||||||
|
+ ": "
|
||||||
|
+ xhr.statusText
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
render_notifications()
|
||||||
|
|
||||||
|
// re-render notifications every x seconds
|
||||||
|
setInterval(render_notifications, 5000);
|
||||||
|
});
|
@ -45,6 +45,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{% include 'bundles/bootstrap-js.html' %}
|
{% include 'bundles/bootstrap-js.html' %}
|
||||||
{% block extra_javascript %}
|
{% block extra_javascript %}
|
||||||
|
<script src="{% static 'js/base.js' %}"></script>
|
||||||
{% endblock extra_javascript %}
|
{% endblock extra_javascript %}
|
||||||
<script>
|
<script>
|
||||||
{% block extra_script %}
|
{% block extra_script %}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
{% if notifications %}
|
||||||
|
<a href="{% url 'notifications:list' %}">Notifications
|
||||||
|
<span class="badge">{{ notifications }}</span>
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<a href="{% url 'notifications:list' %}">
|
||||||
|
<i class="fa fa-bell-o"></i>
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
@ -20,17 +20,11 @@
|
|||||||
<li>
|
<li>
|
||||||
{% include 'allianceauth/night-toggle.html' %}
|
{% include 'allianceauth/night-toggle.html' %}
|
||||||
</li>
|
</li>
|
||||||
{% if notifications %}
|
<li
|
||||||
<li class="{% navactive request 'notifications:' %}">
|
class="{% navactive request 'notifications:' %}" id="menu_item_notifications"
|
||||||
<a href="{% url 'notifications:list' %}">Notifications
|
>
|
||||||
<span class="badge">{{ notifications }}</span>
|
{% include 'allianceauth/notifications_menu_item.html' %}
|
||||||
</a>
|
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
|
||||||
<li><a href="{% url 'notifications:list' %}">
|
|
||||||
<i class="fa fa-bell-o"></i></a>
|
|
||||||
</li>
|
|
||||||
{% endif %}
|
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
{% if user.is_staff %}
|
{% if user.is_staff %}
|
||||||
<li><a href="{% url 'admin:index' %}">{% trans "Admin" %}</a></li>
|
<li><a href="{% url 'admin:index' %}">{% trans "Admin" %}</a></li>
|
||||||
@ -64,3 +58,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
<!-- share data with JS part -->
|
||||||
|
<div
|
||||||
|
id="dataExport"
|
||||||
|
data-notificationsRenderUrl="{% url 'authentication:notifications_render' %}"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user