Merge pull request #1985 from alphagov/add-pagination-to-inbox-page

add pagination to inbox page
This commit is contained in:
Chris Waszczuk
2018-04-04 13:15:29 +01:00
committed by GitHub
7 changed files with 90 additions and 32 deletions

View File

@@ -105,7 +105,7 @@ def get_sms_thread(service_id, user_number):
notification_api_client.get_notifications_for_service(service_id,
to=user_number,
template_type='sms')['notifications'] +
service_api_client.get_inbound_sms(service_id, user_number=user_number)
service_api_client.get_inbound_sms(service_id, user_number=user_number)['data']
), key=lambda notification: notification['created_at']):
is_inbound = ('notify_number' in notification)

View File

@@ -31,6 +31,8 @@ from app.utils import (
FAILURE_STATUSES,
REQUESTED_STATUSES,
Spreadsheet,
generate_next_dict,
generate_previous_dict,
get_current_financial_year,
user_has_permissions,
)
@@ -193,7 +195,7 @@ def inbox(service_id):
return render_template(
'views/dashboard/inbox.html',
partials=get_inbox_partials(service_id),
updates_url=url_for('.inbox_updates', service_id=service_id),
updates_url=url_for('.inbox_updates', service_id=service_id, page=request.args.get('page')),
)
@@ -219,7 +221,7 @@ def inbox_download(service_id):
message['user_number'],
message['content'].lstrip(('=+-@')),
format_datetime_numeric(message['created_at']),
] for message in service_api_client.get_inbound_sms(service_id)]
] for message in service_api_client.get_inbound_sms(service_id)['data']]
).as_csv_data,
mimetype='text/csv',
headers={
@@ -231,11 +233,12 @@ def inbox_download(service_id):
def get_inbox_partials(service_id):
page = int(request.args.get('page', 1))
if 'inbound_sms' not in current_service['permissions']:
abort(403)
inbound_messages = service_api_client.get_inbound_sms(service_id)
inbound_messages_data = service_api_client.get_inbound_sms(service_id, page=page)
inbound_messages = inbound_messages_data['data']
messages_to_show = {}
# get the most recent message for each number
@@ -252,12 +255,22 @@ def get_inbox_partials(service_id):
else:
inbound_number = None
prev_page = None
if page > 1:
prev_page = generate_previous_dict('main.inbox', service_id, page)
next_page = None
if inbound_messages_data['has_next']:
next_page = generate_next_dict('main.inbox', service_id, page)
return {'messages': render_template(
'views/dashboard/_inbox_messages.html',
messages=list(messages_to_show),
count_of_messages=len(inbound_messages),
count_of_users=count_of_users,
inbound_number=inbound_number,
prev_page=prev_page,
next_page=next_page
)}

View File

@@ -261,13 +261,16 @@ class ServiceAPIClient(NotifyAdminAPIClient):
def update_whitelist(self, service_id, data):
return self.put(url='/service/{}/whitelist'.format(service_id), data=data)
def get_inbound_sms(self, service_id, user_number=''):
def get_inbound_sms(self, service_id, user_number='', page=None):
return self.get(
'/service/{}/inbound-sms?user_number={}'.format(
'/service/{}/inbound-sms'.format(
service_id,
user_number,
)
)['data']
),
params={
'user_number': user_number,
'page': page
}
)
def get_inbound_sms_by_id(self, service_id, notification_id):
return self.get(

View File

@@ -1,4 +1,5 @@
{% from "components/table.html" import list_table, field, hidden_field_heading, right_aligned_field_heading, row_heading %}
{% from "components/previous-next-navigation.html" import previous_next_navigation %}
{% from "components/message-count-label.html" import message_count_label %}
<div class="ajax-block-container">
@@ -39,4 +40,7 @@
from {{ count_of_users }} user{{ '' if 1 == count_of_users else 's' }}
</p>
{% endif %}
{{ previous_next_navigation(prev_page, next_page) }}
</div>