diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-11-28 12:25:25 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-11-28 14:05:18 +0100 |
commit | dc34f0e874c42018e11ed951efc5b3fcfe7e8feb (patch) | |
tree | d9aae53bff1beb78a076ecdbd65c86cefd22c85d | |
parent | c976dc96c79a897b55ca8430b824eb8063cd0403 (diff) | |
download | hyperkitty-dc34f0e874c42018e11ed951efc5b3fcfe7e8feb.tar.gz hyperkitty-dc34f0e874c42018e11ed951efc5b3fcfe7e8feb.tar.xz hyperkitty-dc34f0e874c42018e11ed951efc5b3fcfe7e8feb.zip |
Load the list's recent activity via AJAX
-rw-r--r-- | hyperkitty/static/hyperkitty/css/hyperkitty-index.css | 4 | ||||
-rw-r--r-- | hyperkitty/static/hyperkitty/js/hyperkitty-common.js | 20 | ||||
-rw-r--r-- | hyperkitty/static/hyperkitty/js/hyperkitty-index.js | 53 | ||||
-rw-r--r-- | hyperkitty/templates/base.html | 2 | ||||
-rw-r--r-- | hyperkitty/templates/index.html | 28 | ||||
-rw-r--r-- | hyperkitty/templates/overview.html | 16 | ||||
-rw-r--r-- | hyperkitty/urls.py | 2 | ||||
-rw-r--r-- | hyperkitty/views/index.py | 3 | ||||
-rw-r--r-- | hyperkitty/views/list.py | 21 |
9 files changed, 102 insertions, 47 deletions
diff --git a/hyperkitty/static/hyperkitty/css/hyperkitty-index.css b/hyperkitty/static/hyperkitty/css/hyperkitty-index.css index 963d2de..c34f948 100644 --- a/hyperkitty/static/hyperkitty/css/hyperkitty-index.css +++ b/hyperkitty/static/hyperkitty/css/hyperkitty-index.css @@ -135,6 +135,10 @@ .all-lists table.lists .chart { height: 35px; } +.all-lists table.lists .chart .ajaxloader { + margin: 0 auto; + padding-top: 5px; +} .all-lists table.lists ul.list-stats { margin: 0; text-align: center; diff --git a/hyperkitty/static/hyperkitty/js/hyperkitty-common.js b/hyperkitty/static/hyperkitty/js/hyperkitty-common.js index 464cff5..45c3e47 100644 --- a/hyperkitty/static/hyperkitty/js/hyperkitty-common.js +++ b/hyperkitty/static/hyperkitty/js/hyperkitty-common.js @@ -237,6 +237,26 @@ function chart(elem_id, data, default_props) { } +function ajax_chart(elem, url, props) { + elem = $(elem); + $.ajax({ + dataType: "json", + url: url, + success: function(data) { + chart(elem.get(0), data.evolution, props); + }, + error: function(jqXHR, textStatus, errorThrown) { + //alert(jqXHR.responseText); + }, + complete: function(jqXHR, textStatus) { + // if the list is private we have no info, remove the img anyway + elem.find("img.ajaxloader").remove(); + } + }); +} + + + /* * Misc. diff --git a/hyperkitty/static/hyperkitty/js/hyperkitty-index.js b/hyperkitty/static/hyperkitty/js/hyperkitty-index.js new file mode 100644 index 0000000..a99f06e --- /dev/null +++ b/hyperkitty/static/hyperkitty/js/hyperkitty-index.js @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2012-2013 by the Free Software Foundation, Inc. + * + * This file is part of HyperKitty. + * + * HyperKitty is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * HyperKitty is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * HyperKitty. If not, see <http://www.gnu.org/licenses/>. + * + * Author: Aurelien Bompard <abompard@fedoraproject.org> + */ + + + +function setup_index(url_template) { + $("table.lists tr.list").click(function(e) { + document.location.href = $(this).find("a.list-name").attr("href"); + }); + $(".hide-switches input").click(function() { + var target = $("table.lists tr.list."+$(this).val()); + if ($(this).prop("checked")) { + target.hide(); + } else { + target.show(); + } + }); + + // Initials + $(".initials").animate({ right: 0 }, {duration: 600}); + // Override the scrolling because we have a fixed header + $(".initials a").click(function (e) { + e.preventDefault(); + var target = $("a[name="+$(this).attr("href").substring(1)+"]"); + $(window).scrollTop(target.offset().top - 70); + }); + + // Update list graphs + $(".all-lists table.lists tr.list").each(function() { + var listelem = $(this); + var listname = $.trim(listelem.find(".list-address").text()); + var url = url_template.replace(/PLACEHOLDER@PLACEHOLDER/, listname); + ajax_chart(listelem.find("div.chart"), url, {height: 30}); + }); +} diff --git a/hyperkitty/templates/base.html b/hyperkitty/templates/base.html index a6feb9a..eb8e452 100644 --- a/hyperkitty/templates/base.html +++ b/hyperkitty/templates/base.html @@ -130,7 +130,7 @@ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <script>window.jQuery || document.write('<script src="{{ STATIC_URL }}hyperkitty/libs/jquery/jquery-1.10.1.min.js"><\/script>')</script> <script src="{{ STATIC_URL }}hyperkitty/libs/jquery/jquery-ui-1.10.3.custom.min.js"></script> - {% assets filters="rjsmin", output="gen/hyperkitty.js", "hyperkitty/libs/bootstrap/js/bootstrap.min.js", "hyperkitty/libs/jquery.expander.js", "hyperkitty/libs/d3.v2.min.js", "hyperkitty/libs/jquery.hotkeys.js", "hyperkitty/js/hyperkitty-common.js", "hyperkitty/js/hyperkitty-thread.js", "hyperkitty/js/hyperkitty-userprofile.js" %} + {% assets filters="rjsmin", output="gen/hyperkitty.js", "hyperkitty/libs/bootstrap/js/bootstrap.min.js", "hyperkitty/libs/jquery.expander.js", "hyperkitty/libs/d3.v2.min.js", "hyperkitty/libs/jquery.hotkeys.js", "hyperkitty/js/hyperkitty-common.js", "hyperkitty/js/hyperkitty-index.js", "hyperkitty/js/hyperkitty-thread.js", "hyperkitty/js/hyperkitty-userprofile.js" %} <script src="{{ ASSET_URL }}"></script> {% endassets %} {% block additionaljs %} {% endblock %} diff --git a/hyperkitty/templates/index.html b/hyperkitty/templates/index.html index 3dd9d79..8d2fcf9 100644 --- a/hyperkitty/templates/index.html +++ b/hyperkitty/templates/index.html @@ -109,7 +109,9 @@ {{ mlist.description|default_if_none:"" }} </td> <td class="activity"> - <div class="chart" data-chart-values="{{ mlist.evolution|to_json }}"></div> + <div class="chart"> + <img alt="Loading..." class="ajaxloader" src="{{ STATIC_URL }}hyperkitty/img/ajax-loader.gif" /> + </div> <ul class="list-stats"> <li><span class="participant"> {% if mlist.can_view %} @@ -159,29 +161,7 @@ <script> $(function() { - $("div.chart").each(function() { - chart($(this).get(0), - $.parseJSON($(this).attr("data-chart-values")), - {height: 30}); - }); - $("table.lists tr.list").click(function(e) { - document.location.href = $(this).find("a.list-name").attr("href"); - }); - $(".initials").animate({ right: 0 }, {duration: 600}); - // Override the scrolling because we have a fixed header - $(".initials a").click(function (e) { - e.preventDefault(); - var target = $("a[name="+$(this).attr("href").substring(1)+"]"); - $(window).scrollTop(target.offset().top - 70); - }); - $(".hide-switches input").click(function() { - var target = $("table.lists tr.list."+$(this).val()); - if ($(this).prop("checked")) { - target.hide(); - } else { - target.show(); - } - }); + setup_index("{% url 'list_recent_activity' 'PLACEHOLDER@PLACEHOLDER' %}"); }); </script> diff --git a/hyperkitty/templates/overview.html b/hyperkitty/templates/overview.html index edb98ca..b8be4ae 100644 --- a/hyperkitty/templates/overview.html +++ b/hyperkitty/templates/overview.html @@ -18,7 +18,7 @@ {% include 'threads/month_list.html' %} <section id="overview" class="span10"> - + <section id="title"> <h2> {% if mlist.display_name %} @@ -28,12 +28,13 @@ {% endif %} </h2> <p id="description">{{ mlist.description|default_if_none:"" }}</p> - + <section id="statistics"> - - <div id="chart" data-chart-values="{{ evolution|to_json }}"></div> + + <div id="chart"> + </div> <p class="caption">Post volume over the past <strong>30</strong> days.</p> - + <p class="thread-new"> <a href="{% url "message_new" mlist_fqdn=mlist.name %}" class="thread-new btn{% if not user.is_authenticated %} disabled" title="You must be logged-in to create a thread.{% endif %}"> @@ -151,10 +152,7 @@ <script type="text/javascript" > $(function() { - $("#chart").each(function() { - chart($(this).get(0), - $.parseJSON($(this).attr("data-chart-values"))); - }); + ajax_chart("#chart", "{% url 'list_recent_activity' mlist.name %}"); }); </script> diff --git a/hyperkitty/urls.py b/hyperkitty/urls.py index efee204..e59c0ce 100644 --- a/hyperkitty/urls.py +++ b/hyperkitty/urls.py @@ -61,6 +61,8 @@ urlpatterns = patterns('hyperkitty.views', 'list.archives', name='archives_latest'), url(r'^list/(?P<mlist_fqdn>[^/@]+@[^/@]+)/$', 'list.overview', name='list_overview'), + url(r'^list/(?P<mlist_fqdn>[^/@]+@[^/@]+)/recent-activity$', + 'list.recent_activity', name='list_recent_activity'), # Message url(r'^list/(?P<mlist_fqdn>[^/@]+@[^/@]+)/message/(?P<message_id_hash>\w+)/$', diff --git a/hyperkitty/views/index.py b/hyperkitty/views/index.py index 7265873..cb3c6b1 100644 --- a/hyperkitty/views/index.py +++ b/hyperkitty/views/index.py @@ -34,7 +34,6 @@ from mailmanclient import Client, MailmanConnectionError from mailman.interfaces.archiver import ArchivePolicy from hyperkitty.lib import get_store -from hyperkitty.lib.view_helpers import get_recent_list_activity from hyperkitty.lib.mailman import is_mlist_authorized @@ -53,8 +52,6 @@ def index(request): mlist.can_view = True else: mlist.can_view = False - if mlist.can_view: - mlist.evolution = get_recent_list_activity(store, mlist) if mlist.created_at and \ now - mlist.created_at <= datetime.timedelta(days=30): mlist.is_new = True diff --git a/hyperkitty/views/list.py b/hyperkitty/views/list.py index d9a0ace..d994ba1 100644 --- a/hyperkitty/views/list.py +++ b/hyperkitty/views/list.py @@ -23,13 +23,14 @@ import datetime from collections import namedtuple, defaultdict +import django.utils.simplejson as json from django.shortcuts import redirect, render from django.conf import settings from django.core.urlresolvers import reverse from django.utils import formats from django.utils.dateformat import format as date_format from django.utils.timezone import utc -from django.http import Http404 +from django.http import Http404, HttpResponse from hyperkitty.models import Tag, Favorite from hyperkitty.lib import get_store @@ -197,13 +198,6 @@ def overview(request, mlist_fqdn=None): continue threads_by_category[thread.category].append(thread) - # List activity graph - evolution = get_recent_list_activity(store, mlist) - - archives_baseurl = reverse("archives_latest", - kwargs={'mlist_fqdn': mlist.name}) - archives_baseurl = archives_baseurl.rpartition("/")[0] - context = { 'view_name': 'overview', 'mlist' : mlist, @@ -214,7 +208,14 @@ def overview(request, mlist_fqdn=None): 'pop_threads': pop_threads[:5], 'threads_by_category': threads_by_category, 'months_list': get_months(store, mlist.name), - 'evolution': evolution, - 'archives_baseurl': archives_baseurl, } return render(request, "overview.html", context) + + +@check_mlist_private +def recent_activity(request, mlist_fqdn): + store = get_store(request) + mlist = store.get_list(mlist_fqdn) + evolution = get_recent_list_activity(store, mlist) + return HttpResponse(json.dumps({"evolution": evolution}), + mimetype='application/javascript') |