Enhance changing page button of list in monasca-ui

Adding missed page - Alarm Histroy

Change-Id: I7e3e93ede35e03d1a7ac8055fbc2db6f0d7e2cd0
Reference: Ibc05b05f8d2a728e4051b1b49e4a9c73be13471b
Closes-Bug: #1486508
This commit is contained in:
Shinya Kawabata 2016-01-12 14:47:52 +09:00
parent c02f05403d
commit d25b5f4cb3
2 changed files with 29 additions and 6 deletions

View File

@ -44,8 +44,11 @@
<div class="pagination">
<span class="step-links">
{% if prev_page_offset != None %}
<a href="?page_offset={{ prev_page_offset }}" class="btn btn-default btn-sm" style="position:relative;top:-35px;">Previous Page</a>
{% endif %}
{% if page_offset %}
<a href="?page_offset={{ page_offset}}" class="btn btn-default btn-sm" style="position:relative;top:-35px;">Next Page</a>
<a href="?page_offset={{ page_offset }}" class="btn btn-default btn-sm" style="position:relative;top:-35px;">Next Page</a>
{% endif %}
</span>
</div>

View File

@ -316,13 +316,20 @@ class AlarmHistoryView(tables.DataTableView):
context['alarm'] = alarm
contacts = []
prev_page_stack = []
page_offset = self.request.GET.get('page_offset')
if page_offset == None:
if self.request.session.has_key('prev_page_stack'):
prev_page_stack = self.request.session['prev_page_stack']
if page_offset is None:
page_offset = 0
prev_page_stack = []
try:
# To judge whether there is next page, get LIMIT + 1
results = api.monitor.alarm_history(self.request, object_id, page_offset,
LIMIT)
LIMIT + 1)
num_results = len(results)
paginator = Paginator(results, LIMIT)
contacts = paginator.page(1)
except EmptyPage:
@ -333,13 +340,26 @@ class AlarmHistoryView(tables.DataTableView):
return context
context["contacts"] = contacts
if len(contacts.object_list) < LIMIT:
context['timestamp_formats'] = alarm_history_ts_formats
context['timestamp_selected'] = ts_mode or ''
if num_results < LIMIT + 1:
context["page_offset"] = None
else:
context["page_offset"] = contacts.object_list[-1]["id"]
context['timestamp_formats'] = alarm_history_ts_formats
context['timestamp_selected'] = ts_mode or ''
if page_offset in prev_page_stack:
index = prev_page_stack.index(page_offset)
prev_page_stack = prev_page_stack[0:index]
prev_page_offset = prev_page_stack[-1] if prev_page_stack else None
if prev_page_offset is not None:
context["prev_page_offset"] = prev_page_offset
if len(prev_page_stack) > PREV_PAGE_LIMIT:
del prev_page_stack[0]
prev_page_stack.append(str(page_offset))
self.request.session['prev_page_stack'] = prev_page_stack
return context