More UI stuff, and pagination on activity stream

This commit is contained in:
David Taylor
2015-05-23 04:53:17 +01:00
parent 7d0e89eb18
commit 0eb9317fc2
4 changed files with 80 additions and 56 deletions

View File

@@ -1,5 +1,6 @@
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% load static %}
{% load paginator from filters %}
{% block title %}Rigboard Activity Stream{% endblock %}
@@ -40,48 +41,62 @@
{% endblock %}
{% block content %}
{# comment "table view" #}
<div class="col-sm-12">
<div class="row">
<div class="col-sm-12">
<h3>Rigboard Activity Stream</h3>
</div>
<div class="text-right col-sm-12">{% paginator %}</div>
</div>
<div class="table-responsive">
<h2>Rigboard Activity Stream - Table View</h2>
<br>
<table class="table table-striped">
<thead>
<tr>
<td>Date</td>
<td>Event</td>
<td>Version ID</td>
<td>User</td>
<td>Changes</td>
</tr>
</thead>
<tbody>
{% for version in object_list %}
{% if version.item_changes or version.field_changes or version.old == None%}
<tr>
<td>{{ version.revision.date_created|date:"RIGS_DATETIME_FORMAT" }}</td>
<td><a href="{% url 'event_detail' version.new.pk %}">N{{ version.new.pk|stringformat:"05d" }}</a></td>
<td>{{ version.version.pk }}|{{ version.revision.pk }}</td>
<td>{{ version.revision.user.name }}</td>
<td>
{% if version.old == None %}
Event Created
{% else %}
{% include 'RIGS/event_version_changes.html' %}
{% endif %} </td>
</tr>
{% endif %}
{% endfor %}
<table class="table table-striped">
<thead>
<tr>
<td>Date</td>
<td>Event</td>
<td>Version ID</td>
<td>User</td>
<td>Changes</td>
</tr>
</thead>
<tbody>
{% for version in object_list %}
<tr>
<td>{{ version.revision.date_created|date:"RIGS_DATETIME_FORMAT" }}</td>
<td><a href="{% url 'event_detail' version.new.pk %}">N{{ version.new.pk|stringformat:"05d" }}</a></td>
<td>{{ version.version.pk }}|{{ version.revision.pk }}</td>
<td>{{ version.revision.user.name }}</td>
<td>
{% if version.old == None %}
Event Created
{% else %}
{% include 'RIGS/event_version_changes.html' %}
{% endif %} </td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="align-right">{% paginator %}</div>
</div>
</tbody>
</table>
{# endcomment #}
<div>
<br>
<h2>Rigboard Activity Stream - Stream View</h2>
<h2>Rigboard Activity Stream - Scrollable Stream View <br/><small>Possibly to go on homepage</small></h2>
<br>
<div style="
max-height: 500px;
max-width: 300px;
overflow-y:scroll;
border:1px solid black;">
{% for version in object_list %}
{% if version.item_changes or version.field_changes or version.old == None %}
<div class="well">
@@ -97,9 +112,8 @@
</div>
{% endif %}
{% endfor %}
</div>
</div>
{{ thediff }}
{% endblock %}

View File

@@ -10,7 +10,7 @@
{% endfor %}
{% for itemChange in version.item_changes %}
<button title="Changes to item '{{ itemChange.new.name }}'" type="button" class="btn btn-default btn-xs" data-container="body" data-html="true" data-trigger='hover' data-toggle="popover" data-content='
<button title="Changes to item '{{ itemChange.new.name|default:itemChange.old.name }}'" type="button" class="btn btn-default btn-xs" data-container="body" data-html="true" data-trigger='hover' data-toggle="popover" data-content='
{% for change in itemChange.changes %}
<h4>{{ change.field.verbose_name }}</h4>
@@ -19,5 +19,5 @@
{% endfor %}
'>item '{{ itemChange.new.name }}'</button>
'>item '{{ itemChange.new.name|default:itemChange.old.name }}'</button>
{% endfor %}

View File

@@ -8,8 +8,12 @@
<script src="{% static "js/popover.js" %}"></script>
<script>
$(function () {
$('[data-toggle="popover"]').popover()
})
$('[data-toggle="popover"]').popover().click(function(){
if($(this).attr('href')){
window.location.href = $(this).attr('href');
}
});
})
</script>
{% endblock %}

View File

@@ -14,6 +14,7 @@ import reversion
import simplejson
from reversion.models import Version
from django.contrib.contenttypes.models import ContentType # Used to lookup the content_type
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from RIGS import models, forms
import datetime
@@ -85,8 +86,8 @@ def compare_event_items(old, new):
changes = []
for (_, compare) in item_dict.items():
if compare.old != compare.new: # has it changed at all (or been created/deleted)
compare.changes = model_compare(compare.old, compare.new, ['id','event','order']) # see what's changed
compare.changes = model_compare(compare.old, compare.new, ['id','event','order']) # see what's changed
if len(compare.changes) >= 1:
changes.append(compare) # transfer into a sequential array to make it easier to deal with later
return changes
@@ -95,7 +96,7 @@ def get_versions_for_model(model):
content_type = ContentType.objects.get_for_model(model)
versions = reversion.models.Version.objects.filter(
content_type = content_type,
).select_related("revision").order_by("-pk")
).select_related("revision","revision.version_set").order_by("-pk")
return versions
@@ -105,12 +106,12 @@ def get_previous_version(version):
versions = reversion.get_for_object_reference(models.Event, thisEventId)
previousVersions = versions.filter(pk__lt=thisVersionId)
try:
previousVersions = versions.filter(pk__lt=thisVersionId).latest(field_name='pk') # this is very slow :(
except:
return False
if len(previousVersions) >= 1:
return previousVersions[0]
else: #this is probably the initial version
return False
return previousVersions
def get_changes_for_version(newVersion, oldVersion=None):
#Pass in a previous version if you already know it (for efficiancy)
@@ -132,7 +133,7 @@ def get_changes_for_version(newVersion, oldVersion=None):
return compare
class EventRevisions(generic.ListView):
class EventRevisions(generic.TemplateView):
model = reversion.revisions.Version
template_name = "RIGS/event_version_list.html"
@@ -158,19 +159,24 @@ class EventRevisions(generic.ListView):
class ActivityStream(generic.ListView):
model = reversion.revisions.Version
template_name = "RIGS/activity_stream.html"
paginate_by = 25
def get_context_data(self, **kwargs):
versions = get_versions_for_model(models.Event);
def get_queryset(self):
versions = get_versions_for_model(models.Event)
return versions
def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super(ActivityStream, self).get_context_data(**kwargs)
items = []
for thisVersion in versions[:20]:
for thisVersion in context['object_list']:
thisItem = get_changes_for_version(thisVersion, None)
items.append(thisItem)
context = {
'object_list': items,
}
context ['object_list'] = items
return context