mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 07:46:23 -04:00
Make the broadcast dashboard update via AJAX
Same technique as we use for other pages that update via AJAX. I’ve split the page up into separate chunks because the DiffDOM library we use finds it easier to work out what’s changed when there are fewer elements/a shallower tree.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from flask import abort, redirect, render_template, request, url_for
|
||||
from flask import abort, jsonify, redirect, render_template, request, url_for
|
||||
|
||||
from app import current_service
|
||||
from app.main import main
|
||||
@@ -11,11 +11,32 @@ from app.utils import service_has_permission, user_has_permissions
|
||||
@user_has_permissions()
|
||||
@service_has_permission('broadcast')
|
||||
def broadcast_dashboard(service_id):
|
||||
broadcast_messages = BroadcastMessages(service_id)
|
||||
return render_template(
|
||||
'views/broadcast/dashboard.html',
|
||||
live_broadcasts=broadcast_messages.with_status('broadcasting'),
|
||||
previous_broadcasts=broadcast_messages.with_status('cancelled', 'completed'),
|
||||
partials=get_broadcast_dashboard_partials(current_service.id)
|
||||
)
|
||||
|
||||
|
||||
@main.route('/services/<uuid:service_id>/broadcast-dashboard.json')
|
||||
@user_has_permissions()
|
||||
@service_has_permission('broadcast')
|
||||
def broadcast_dashboard_updates(service_id):
|
||||
return jsonify(get_broadcast_dashboard_partials(current_service.id))
|
||||
|
||||
|
||||
def get_broadcast_dashboard_partials(service_id):
|
||||
broadcast_messages = BroadcastMessages(service_id)
|
||||
return dict(
|
||||
live_broadcasts=render_template(
|
||||
'views/broadcast/partials/dashboard-table.html',
|
||||
broadcasts=broadcast_messages.with_status('broadcasting'),
|
||||
empty_message='You do not have any live broadcasts at the moment',
|
||||
),
|
||||
previous_broadcasts=render_template(
|
||||
'views/broadcast/partials/dashboard-table.html',
|
||||
broadcasts=broadcast_messages.with_status('cancelled', 'completed'),
|
||||
empty_message='You do not have any previous broadcasts',
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user