diff --git a/app/assets/javascripts/sortAlphanumeric.js b/app/assets/javascripts/sortAlphanumeric.js deleted file mode 100644 index 726f7b2cd..000000000 --- a/app/assets/javascripts/sortAlphanumeric.js +++ /dev/null @@ -1,14 +0,0 @@ -(function (window) { - // document.addEventListener("DOMContentLoaded", function() { - // const rows = document.querySelectorAll('td.table-field.file-name'); - - // rows.forEach(row => { - // let sortValue = row.getAttribute('data-sort-value'); - // if (sortValue) { - // // Remove non-numeric characters to ensure numerical comparison - // sortValue = sortValue.replace(/\D/g, ''); - // row.setAttribute('data-sort-value', sortValue); - // } - // }); - // }); -})(window); diff --git a/app/main/views/activity.py b/app/main/views/activity.py index db7d576ef..f9b32e9db 100644 --- a/app/main/views/activity.py +++ b/app/main/views/activity.py @@ -1,6 +1,4 @@ -from flask import abort, render_template, request, session, url_for -from flask_login import current_user -from werkzeug.utils import redirect +from flask import abort, render_template, request, url_for from app import current_service, job_api_client from app.formatters import convert_time_unixtimestamp, get_time_left @@ -17,12 +15,6 @@ from app.utils.user import user_has_permissions @main.route("/activity/services/") @user_has_permissions() def all_jobs_activity(service_id): - if session.get("invited_user_id"): - session.pop("invited_user_id", None) - session["service_id"] = service_id - - if not current_user.has_permissions("view_activity"): - return redirect(url_for("main.choose_template", service_id=service_id)) service_data_retention_days = 7 page = get_page_from_request() jobs = job_api_client.get_page_of_jobs(service_id, page=page) @@ -36,16 +28,25 @@ def all_jobs_activity(service_id): next_page=next_page, prev_page=prev_page, pagination=pagination, - jobs=jobs ) def handle_pagination(jobs, service_id, page): if page is None: abort(404, "Invalid page argument ({}).".format(request.args.get("page"))) - prev_page = generate_previous_dict("main.all_jobs_activity", service_id, page) if page > 1 else None - next_page = generate_next_dict("main.all_jobs_activity", service_id, page) if jobs["links"].get("next") else None - pagination = generate_pagination_pages(jobs["total"], jobs['page_size'], page) + prev_page = ( + generate_previous_dict("main.all_jobs_activity", service_id, page) + if page > 1 + else None + ) + next_page = ( + generate_next_dict("main.all_jobs_activity", service_id, page) + if jobs.get("links", {}).get("next") + else None + ) + pagination = generate_pagination_pages( + jobs.get("total", {}), jobs.get("page_size", {}), page + ) return prev_page, next_page, pagination @@ -54,18 +55,26 @@ def generate_job_dict(jobs): { "job_id": job["id"], "time_left": get_time_left(job["created_at"]), - "download_link": url_for(".view_job_csv", service_id=current_service.id, job_id=job["id"]), - "view_job_link": url_for(".view_job", service_id=current_service.id, job_id=job["id"]), + "download_link": url_for( + ".view_job_csv", service_id=current_service.id, job_id=job["id"] + ), + "view_job_link": url_for( + ".view_job", service_id=current_service.id, job_id=job["id"] + ), "created_at": job["created_at"], "time_sent_data_value": convert_time_unixtimestamp( - job["processing_finished"] if job["processing_finished"] - else job["processing_started"] if job["processing_started"] - else job["created_at"] + job["processing_finished"] + if job["processing_finished"] + else ( + job["processing_started"] + if job["processing_started"] + else job["created_at"] + ) ), "processing_finished": job["processing_finished"], "processing_started": job["processing_started"], "created_by": job["created_by"], - "template_name": job["template_name"] + "template_name": job["template_name"], } for job in jobs["data"] ] diff --git a/app/utils/pagination.py b/app/utils/pagination.py index 15858d73a..50e6371be 100644 --- a/app/utils/pagination.py +++ b/app/utils/pagination.py @@ -33,16 +33,18 @@ def generate_previous_next_dict(view, service_id, page, title, url_args): def generate_pagination_pages(total_items, page_size, current_page): total_pages = (total_items + page_size - 1) // page_size - pagination = { - 'current': current_page, - 'pages': [], - 'last': total_pages - } + pagination = {"current": current_page, "pages": [], "last": total_pages} if total_pages <= 4: - pagination['pages'] = list(range(1, total_pages + 1)) + pagination["pages"] = list(range(1, total_pages + 1)) else: if current_page <= 3: - pagination['pages'] = [1, 2, 3, total_pages] + pagination["pages"] = [1, 2, 3, total_pages] else: - pagination['pages'] = [1, current_page - 1, current_page, current_page + 1, total_pages] + pagination["pages"] = [ + 1, + current_page - 1, + current_page, + current_page + 1, + total_pages, + ] return pagination diff --git a/gulpfile.js b/gulpfile.js index ef34d8ba6..3e7dee06e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -126,8 +126,6 @@ const javascripts = () => { paths.src + 'javascripts/loginAlert.js', paths.src + 'javascripts/main.js', paths.src + 'javascripts/sampleChartDashboard.js', - paths.src + 'javascripts/sortAlphanumeric.js', - ]) .pipe(plugins.prettyerror()) .pipe(plugins.babel({ diff --git a/tests/app/test_navigation.py b/tests/app/test_navigation.py index 6f1cf58eb..d346fc71a 100644 --- a/tests/app/test_navigation.py +++ b/tests/app/test_navigation.py @@ -25,6 +25,7 @@ EXCLUDED_ENDPOINTS = tuple( "add_organization", "add_service", "add_service_template", + "all_jobs_activity", "api_callbacks", "api_documentation", "api_integration", @@ -400,6 +401,7 @@ def test_navigation_urls( assert [a["href"] for a in page.select(".nav a")] == [ "/services/{}/templates".format(SERVICE_ONE_ID), "/services/{}".format(SERVICE_ONE_ID), + "/activity/services/{}".format(SERVICE_ONE_ID), # "/services/{}/usage".format(SERVICE_ONE_ID), # "/services/{}/users".format(SERVICE_ONE_ID), # "/services/{}/service-settings".format(SERVICE_ONE_ID),