mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-24 08:16:51 -04:00
cleaned up init
This commit is contained in:
@@ -20,7 +20,6 @@ from flask import (
|
|||||||
)
|
)
|
||||||
from flask.globals import request_ctx
|
from flask.globals import request_ctx
|
||||||
from flask_login import LoginManager, current_user
|
from flask_login import LoginManager, current_user
|
||||||
from flask_socketio import SocketIO
|
|
||||||
from flask_talisman import Talisman
|
from flask_talisman import Talisman
|
||||||
from flask_wtf import CSRFProtect
|
from flask_wtf import CSRFProtect
|
||||||
from flask_wtf.csrf import CSRFError
|
from flask_wtf.csrf import CSRFError
|
||||||
@@ -122,7 +121,6 @@ from notifications_utils.url_safe_token import generate_token
|
|||||||
login_manager = LoginManager()
|
login_manager = LoginManager()
|
||||||
csrf = CSRFProtect()
|
csrf = CSRFProtect()
|
||||||
talisman = Talisman()
|
talisman = Talisman()
|
||||||
socketio = SocketIO()
|
|
||||||
|
|
||||||
# The current service attached to the request stack.
|
# The current service attached to the request stack.
|
||||||
current_service = LocalProxy(partial(getattr, request_ctx, "service"))
|
current_service = LocalProxy(partial(getattr, request_ctx, "service"))
|
||||||
@@ -159,11 +157,14 @@ def _csp(config):
|
|||||||
"https://www.googletagmanager.com",
|
"https://www.googletagmanager.com",
|
||||||
"https://www.google-analytics.com",
|
"https://www.google-analytics.com",
|
||||||
"https://dap.digitalgov.gov",
|
"https://dap.digitalgov.gov",
|
||||||
|
"https://cdn.socket.io",
|
||||||
],
|
],
|
||||||
"connect-src": [
|
"connect-src": [
|
||||||
"'self'",
|
"'self'",
|
||||||
"https://gov-bam.nr-data.net",
|
"https://gov-bam.nr-data.net",
|
||||||
"https://www.google-analytics.com",
|
"https://www.google-analytics.com",
|
||||||
|
"http://localhost:6011",
|
||||||
|
"ws://localhost:6011"
|
||||||
],
|
],
|
||||||
"style-src": ["'self'", asset_domain],
|
"style-src": ["'self'", asset_domain],
|
||||||
"img-src": ["'self'", asset_domain, logo_domain],
|
"img-src": ["'self'", asset_domain, logo_domain],
|
||||||
@@ -219,7 +220,6 @@ def create_app(application):
|
|||||||
|
|
||||||
init_govuk_frontend(application)
|
init_govuk_frontend(application)
|
||||||
init_jinja(application)
|
init_jinja(application)
|
||||||
socketio.init_app(application, cors_allowed_origins=['http://localhost:6012'])
|
|
||||||
|
|
||||||
for client in (
|
for client in (
|
||||||
csrf,
|
csrf,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const socket = io();
|
const socket = io('http://localhost:6011');
|
||||||
const jobId = document.querySelector("[data-job-id]").dataset.jobId;
|
const jobId = document.querySelector("[data-job-id]").dataset.jobId;
|
||||||
|
|
||||||
socket.on('connect', () => {
|
socket.on('connect', () => {
|
||||||
@@ -6,15 +6,7 @@ socket.on('connect', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Join a room
|
socket.on('job_update', (data) => {
|
||||||
socket.emit("join", { room: `job-${jobId}` });
|
console.log('📡 Received job update:', data);
|
||||||
console.log("🧠 Joined room:", `job-${jobId}`);
|
document.getElementById('status').innerText = `Job ${data.job_id}: ${data.status}`;
|
||||||
|
|
||||||
// Listen for job updates
|
|
||||||
socket.on("job_update", function (data) {
|
|
||||||
const el = document.querySelector(`[data-key="${data.key}"]`);
|
|
||||||
if (el) {
|
|
||||||
el.textContent = "✅ Real-time update success!";
|
|
||||||
el.classList.add("text-success"); // Add a class instead
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ from app import (
|
|||||||
format_datetime_table,
|
format_datetime_table,
|
||||||
notification_api_client,
|
notification_api_client,
|
||||||
service_api_client,
|
service_api_client,
|
||||||
socketio,
|
|
||||||
)
|
)
|
||||||
from app.formatters import get_time_left, message_count_noun
|
from app.formatters import get_time_left, message_count_noun
|
||||||
from app.main import main
|
from app.main import main
|
||||||
@@ -29,7 +28,6 @@ from app.main.forms import SearchNotificationsForm
|
|||||||
from app.models.job import Job
|
from app.models.job import Job
|
||||||
from app.utils import parse_filter_args, set_status_filters
|
from app.utils import parse_filter_args, set_status_filters
|
||||||
from app.utils.csv import generate_notifications_csv
|
from app.utils.csv import generate_notifications_csv
|
||||||
from flask_socketio import emit, SocketIO, send, join_room
|
|
||||||
from app.utils.pagination import (
|
from app.utils.pagination import (
|
||||||
generate_next_dict,
|
generate_next_dict,
|
||||||
generate_previous_dict,
|
generate_previous_dict,
|
||||||
@@ -59,7 +57,6 @@ def view_job(service_id, job_id):
|
|||||||
|
|
||||||
filter_args = parse_filter_args(request.args)
|
filter_args = parse_filter_args(request.args)
|
||||||
filter_args["status"] = set_status_filters(filter_args)
|
filter_args["status"] = set_status_filters(filter_args)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"views/jobs/job.html",
|
"views/jobs/job.html",
|
||||||
job=job,
|
job=job,
|
||||||
@@ -118,38 +115,6 @@ def view_job_updates(service_id, job_id):
|
|||||||
|
|
||||||
return jsonify(**get_job_partials(job))
|
return jsonify(**get_job_partials(job))
|
||||||
|
|
||||||
# def emit_job_update(service_id, job, job_id):
|
|
||||||
# print("⚡️ Emitting job update for:", job_id)
|
|
||||||
# socketio.emit(
|
|
||||||
# "job_update",
|
|
||||||
# {"key": "status", "html": render_template("partials/jobs/status.html", job=job)},
|
|
||||||
# room=f"job-{job_id}"
|
|
||||||
# )
|
|
||||||
|
|
||||||
@socketio.on("join")
|
|
||||||
def on_join(data):
|
|
||||||
room = data["room"]
|
|
||||||
join_room(room)
|
|
||||||
print(f"Client joined room {room}")
|
|
||||||
|
|
||||||
@main.route("/services/<uuid:service_id>/jobs/<uuid:job_id>/test-socket-update")
|
|
||||||
def test_socket_update(service_id,job_id):
|
|
||||||
print(f"⚡️ Emitting job update for: {job_id}")
|
|
||||||
# Replace with a real job ID and service ID for testing
|
|
||||||
job = Job.from_id(job_id, service_id)
|
|
||||||
service_id=service_id
|
|
||||||
job_id = job_id
|
|
||||||
|
|
||||||
# Call your emit function
|
|
||||||
socketio.emit(
|
|
||||||
"job_update",
|
|
||||||
{
|
|
||||||
"key": "status",
|
|
||||||
"html": "<div class='text-success'>✅ Real-time update success!</div>"
|
|
||||||
},
|
|
||||||
room=f"job-{job_id}" # match the room name used in frontend
|
|
||||||
)
|
|
||||||
return "Update sent!"
|
|
||||||
|
|
||||||
@main.route("/services/<uuid:service_id>/notifications", methods=["GET", "POST"])
|
@main.route("/services/<uuid:service_id>/notifications", methods=["GET", "POST"])
|
||||||
@main.route(
|
@main.route(
|
||||||
|
|||||||
Reference in New Issue
Block a user