Add paging to the GUI
This commit is contained in:
1 parent
df98b907ca
commit
605ab18b8a
6 files changed
+154
-51
No files matched your search
@@ -188,6 +188,23 @@ body {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#content #pagebrowse {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content .page {
|
||||||
|
border-style: solid;
|
||||||
|
border-width: 1px;
|
||||||
|
border-color: black;
|
||||||
|
border-radius: 16px;
|
||||||
|
text-align: center;
|
||||||
|
display: inline-block;
|
||||||
|
padding-top : 8px;
|
||||||
|
padding-bottom: 8px;
|
||||||
|
width: 5%;
|
||||||
|
}
|
||||||
|
|
||||||
#error {
|
#error {
|
||||||
background-color: #ED7676;
|
background-color: #ED7676;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ urlpatterns = [
|
|||||||
path(r'index/<int:page>/', OpenBench.views.index),
|
path(r'index/<int:page>/', OpenBench.views.index),
|
||||||
path(r'users/', OpenBench.views.users),
|
path(r'users/', OpenBench.views.users),
|
||||||
path(r'viewUser/<str:username>/', OpenBench.views.viewUser),
|
path(r'viewUser/<str:username>/', OpenBench.views.viewUser),
|
||||||
|
path(r'viewUser/<str:username>/<int:page>/', OpenBench.views.viewUser),
|
||||||
path(r'machines/', OpenBench.views.machines),
|
path(r'machines/', OpenBench.views.machines),
|
||||||
path(r'eventLog/', OpenBench.views.eventLog),
|
path(r'eventLog/', OpenBench.views.eventLog),
|
||||||
|
path(r'eventLog/<int:page>/', OpenBench.views.eventLog),
|
||||||
|
|
||||||
path(r'newTest/', OpenBench.views.newTest),
|
path(r'newTest/', OpenBench.views.newTest),
|
||||||
path(r'viewTest/<int:id>/', OpenBench.views.viewTest),
|
path(r'viewTest/<int:id>/', OpenBench.views.viewTest),
|
||||||
|
|||||||
@@ -7,6 +7,36 @@ from django.contrib.auth import authenticate
|
|||||||
from OpenBench.config import *
|
from OpenBench.config import *
|
||||||
from OpenBench.models import Engine, Profile, Machine, Result, Test
|
from OpenBench.models import Engine, Profile, Machine, Result, Test
|
||||||
|
|
||||||
|
def pagingContext(page, pageLength, items, url):
|
||||||
|
|
||||||
|
# Tests within the given page
|
||||||
|
start = page * pageLength
|
||||||
|
end = min(start + pageLength, items)
|
||||||
|
|
||||||
|
# Get page numbers near the current page
|
||||||
|
pagenum = math.ceil(items / pageLength)
|
||||||
|
temp = list(range(0, min(3, pagenum)))
|
||||||
|
temp.extend(range(pagenum-1, pagenum-4, -1))
|
||||||
|
temp.extend(range(max(0, page-2), min(pagenum-1, page+3)))
|
||||||
|
temp = list(set(temp))
|
||||||
|
temp.sort()
|
||||||
|
|
||||||
|
# Fill in gaps with an ellipsis, throw out negatives
|
||||||
|
pages = []
|
||||||
|
for f in range(len(temp)):
|
||||||
|
if temp[f] < 0: continue
|
||||||
|
pages.append(temp[f])
|
||||||
|
if f < len(temp) - 1 and temp[f] != temp[f+1] - 1:
|
||||||
|
pages.append("...")
|
||||||
|
|
||||||
|
# Create context dictionary for paging setup
|
||||||
|
return {
|
||||||
|
"url" : url,
|
||||||
|
"page" : page,
|
||||||
|
"pages" : pages,
|
||||||
|
"prev" : max(0, page - 1),
|
||||||
|
"next" : max(0, min(page + 1, pagenum - 1)),
|
||||||
|
}
|
||||||
|
|
||||||
def getSourceLocation(branch, repo):
|
def getSourceLocation(branch, repo):
|
||||||
|
|
||||||
|
|||||||
+32
-6
@@ -12,6 +12,7 @@ from django.utils.timezone import utc
|
|||||||
from OpenBench.config import *
|
from OpenBench.config import *
|
||||||
from OpenBench.models import LogEvent, Engine, Profile
|
from OpenBench.models import LogEvent, Engine, Profile
|
||||||
from OpenBench.models import Machine, Result, Test
|
from OpenBench.models import Machine, Result, Test
|
||||||
|
from OpenBench.utils import pagingContext
|
||||||
|
|
||||||
import OpenBench.utils, datetime
|
import OpenBench.utils, datetime
|
||||||
|
|
||||||
@@ -106,7 +107,7 @@ def editProfile(request):
|
|||||||
# Send back to see the changes
|
# Send back to see the changes
|
||||||
return HttpResponseRedirect('/viewProfile/')
|
return HttpResponseRedirect('/viewProfile/')
|
||||||
|
|
||||||
def index(request, page=0, username=None, error=''):
|
def index(request, page=0, pageLength=50, username=None, error=''):
|
||||||
|
|
||||||
# Get tests pending approval
|
# Get tests pending approval
|
||||||
pending = Test.objects.filter(approved=False)
|
pending = Test.objects.filter(approved=False)
|
||||||
@@ -130,13 +131,25 @@ def index(request, page=0, username=None, error=''):
|
|||||||
pending = pending.filter(author=username)
|
pending = pending.filter(author=username)
|
||||||
active = active.filter(author=username)
|
active = active.filter(author=username)
|
||||||
completed = completed.filter(author=username)
|
completed = completed.filter(author=username)
|
||||||
|
source = "viewUser/{0}".format(username)
|
||||||
|
else:
|
||||||
|
source = "index"
|
||||||
|
|
||||||
|
# Choose tests within the given page, if any
|
||||||
|
items = len(completed)
|
||||||
|
start = page * pageLength
|
||||||
|
end = start + pageLength
|
||||||
|
start = max(0, min(start, items))
|
||||||
|
end = max(0, min(end, items))
|
||||||
|
paging = pagingContext(page, pageLength, items, source)
|
||||||
|
|
||||||
# Build context dictionary for index template
|
# Build context dictionary for index template
|
||||||
data = {
|
data = {
|
||||||
'pending' : pending,
|
'pending' : pending,
|
||||||
'active' : active,
|
'active' : active,
|
||||||
'completed' : completed[:50],
|
'completed' : completed[start:end],
|
||||||
'error' : error,
|
'error' : error,
|
||||||
|
'paging' : paging,
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, 'index.html', data)
|
return render(request, 'index.html', data)
|
||||||
@@ -147,10 +160,10 @@ def users(request):
|
|||||||
data = {'profiles' : Profile.objects.order_by('games')}
|
data = {'profiles' : Profile.objects.order_by('games')}
|
||||||
return render(request, 'users.html', data)
|
return render(request, 'users.html', data)
|
||||||
|
|
||||||
def viewUser(request, username):
|
def viewUser(request, username, page=0):
|
||||||
|
|
||||||
# Index but with only username's tests
|
# Index but with only username's tests
|
||||||
return index(request, username=username)
|
return index(request, page, username=username)
|
||||||
|
|
||||||
def machines(request):
|
def machines(request):
|
||||||
|
|
||||||
@@ -159,10 +172,23 @@ def machines(request):
|
|||||||
data = {'machines' : Machine.objects.filter(updated__gte=target)}
|
data = {'machines' : Machine.objects.filter(updated__gte=target)}
|
||||||
return render(request, 'machines.html', data)
|
return render(request, 'machines.html', data)
|
||||||
|
|
||||||
def eventLog(request):
|
def eventLog(request, page=0, pageLength=50):
|
||||||
|
|
||||||
|
# Choose events within the given page, if any
|
||||||
|
events = LogEvent.objects.all()
|
||||||
|
items = len(events)
|
||||||
|
start = page * pageLength
|
||||||
|
end = start + pageLength
|
||||||
|
start = max(0, min(start, items))
|
||||||
|
end = max(0, min(end, items))
|
||||||
|
paging = pagingContext(page, pageLength, items, 'eventLog')
|
||||||
|
|
||||||
# Build context dictionary for event log template
|
# Build context dictionary for event log template
|
||||||
data = {'events': LogEvent.objects.all().order_by('-id')[:50]}
|
data = {
|
||||||
|
'events': events[start:end],
|
||||||
|
'paging': paging
|
||||||
|
}
|
||||||
|
|
||||||
return render(request, 'eventLog.html', data)
|
return render(request, 'eventLog.html', data)
|
||||||
|
|
||||||
@login_required(login_url='/login/')
|
@login_required(login_url='/login/')
|
||||||
|
|||||||
@@ -21,4 +21,17 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<table>
|
<table>
|
||||||
|
<div id="pagebrowse">
|
||||||
|
{% if paging.prev != paging.next %}
|
||||||
|
<a class="page" href="/{{paging.url}}/{{paging.prev}}"><--</a>
|
||||||
|
{% for page in paging.pages %}
|
||||||
|
{% if page != "..." %}
|
||||||
|
<a class="page" href="/{{paging.url}}/{{page}}">{{page}}</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="page"> {{page}} </a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
<a class="page" href="/{{paging.url}}/{{paging.next}}">--></a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -2,52 +2,54 @@
|
|||||||
{% load mytags %}
|
{% load mytags %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<table class="datatable">
|
<table class="datatable">
|
||||||
<tr><td class="embedded"><h2>Pending</h2></td></tr>
|
{% if paging.page == 0 %}
|
||||||
{% if pending %}
|
<tr><td class="embedded"><h2>Pending</h2></td></tr>
|
||||||
<tr>
|
{% if pending %}
|
||||||
<th>Creation</th>
|
<tr>
|
||||||
<th>Author</th>
|
<th>Creation</th>
|
||||||
<th>Test</th>
|
<th>Author</th>
|
||||||
<th>Diff</th>
|
<th>Test</th>
|
||||||
<th>P</th>
|
<th>Diff</th>
|
||||||
<th>Time</th>
|
<th>P</th>
|
||||||
<th>Stats</th>
|
<th>Time</th>
|
||||||
</tr>
|
<th>Stats</th>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
{% for test in pending %}
|
||||||
|
<tr>
|
||||||
|
<td>{{test.creation|date:'Y-m-d'}}</td>
|
||||||
|
<td><a href="/viewUser/{{test.author}}">{{test.author}}</a></td>
|
||||||
|
<td><a href="/viewTest/{{test.id}}">{{test.dev.name}}</a></td>
|
||||||
|
<td class="textcenter"><a href="{{test|gitDiffLink}}">diff</a></td>
|
||||||
|
<td>{{test.priority}}</td>
|
||||||
|
<td>{{test.timecontrol}}</td>
|
||||||
|
<td class="statblock"><strong>{{test|shortStatBlock|linebreaksbr}}</strong></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
<tr><td class="embedded"><h2>Active</h2></td></tr>
|
||||||
|
{% if active %}
|
||||||
|
<tr>
|
||||||
|
<th>Creation</th>
|
||||||
|
<th>Author</th>
|
||||||
|
<th>Test</th>
|
||||||
|
<th>Diff</th>
|
||||||
|
<th>P</th>
|
||||||
|
<th>Time</th>
|
||||||
|
<th>Stats</th>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
{% for test in active %}
|
||||||
|
<tr class="{{test|testResultColour}}">
|
||||||
|
<td>{{test.creation|date:'Y-m-d'}}</td>
|
||||||
|
<td><a href="/viewUser/{{test.author}}">{{test.author}}</a></td>
|
||||||
|
<td><a href="/viewTest/{{test.id}}">{{test.dev.name}}</a></td>
|
||||||
|
<td class="textcenter"><a href="{{test|gitDiffLink}}">diff</a></td>
|
||||||
|
<td>{{test.priority}}</td>
|
||||||
|
<td>{{test.timecontrol}}</td>
|
||||||
|
<td class="statblock"><strong>{{test|shortStatBlock|linebreaksbr}}</strong></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for test in pending %}
|
|
||||||
<tr>
|
|
||||||
<td>{{test.creation|date:'Y-m-d'}}</td>
|
|
||||||
<td><a href="/viewUser/{{test.author}}">{{test.author}}</a></td>
|
|
||||||
<td><a href="/viewTest/{{test.id}}">{{test.dev.name}}</a></td>
|
|
||||||
<td class="textcenter"><a href="{{test|gitDiffLink}}">diff</a></td>
|
|
||||||
<td>{{test.priority}}</td>
|
|
||||||
<td>{{test.timecontrol}}</td>
|
|
||||||
<td class="statblock"><strong>{{test|shortStatBlock|linebreaksbr}}</strong></td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
<tr><td class="embedded"><h2>Active</h2></td></tr>
|
|
||||||
{% if active %}
|
|
||||||
<tr>
|
|
||||||
<th>Creation</th>
|
|
||||||
<th>Author</th>
|
|
||||||
<th>Test</th>
|
|
||||||
<th>Diff</th>
|
|
||||||
<th>P</th>
|
|
||||||
<th>Time</th>
|
|
||||||
<th>Stats</th>
|
|
||||||
</tr>
|
|
||||||
{% endif %}
|
|
||||||
{% for test in active %}
|
|
||||||
<tr class="{{test|testResultColour}}">
|
|
||||||
<td>{{test.creation|date:'Y-m-d'}}</td>
|
|
||||||
<td><a href="/viewUser/{{test.author}}">{{test.author}}</a></td>
|
|
||||||
<td><a href="/viewTest/{{test.id}}">{{test.dev.name}}</a></td>
|
|
||||||
<td class="textcenter"><a href="{{test|gitDiffLink}}">diff</a></td>
|
|
||||||
<td>{{test.priority}}</td>
|
|
||||||
<td>{{test.timecontrol}}</td>
|
|
||||||
<td class="statblock"><strong>{{test|shortStatBlock|linebreaksbr}}</strong></td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
<tr><td class="embedded"><h2>Finished</h2></td></tr>
|
<tr><td class="embedded"><h2>Finished</h2></td></tr>
|
||||||
{% if completed %}
|
{% if completed %}
|
||||||
<tr>
|
<tr>
|
||||||
@@ -72,4 +74,17 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
<div id="pagebrowse">
|
||||||
|
{% if paging.prev != paging.next %}
|
||||||
|
<a class="page" href="/{{paging.url}}/{{paging.prev}}"><--</a>
|
||||||
|
{% for page in paging.pages %}
|
||||||
|
{% if page != "..." %}
|
||||||
|
<a class="page" href="/{{paging.url}}/{{page}}">{{page}}</a>
|
||||||
|
{% else %}
|
||||||
|
<a class="page"> {{page}} </a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
<a class="page" href="/{{paging.url}}/{{paging.next}}">--></a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in new issue
Block a user