From 1a4d069d91d437deb74a64bcd5002a6010498105 Mon Sep 17 00:00:00 2001 From: "Allen, Chris (Boston)" Date: Wed, 8 May 2024 11:33:13 -0400 Subject: [PATCH 1/8] First crack --- notebooker/web/routes/report_execution.py | 20 ++++++++++++++ .../web/static/notebooker/result_listing.js | 27 +++++++++++++++++++ notebooker/web/templates/result_listing.html | 12 +++++++++ 3 files changed, 59 insertions(+) diff --git a/notebooker/web/routes/report_execution.py b/notebooker/web/routes/report_execution.py index d837a17c..e1ba74be 100644 --- a/notebooker/web/routes/report_execution.py +++ b/notebooker/web/routes/report_execution.py @@ -300,3 +300,23 @@ def delete_report(job_id): except Exception: error_info = traceback.format_exc() return jsonify({"status": "error", "error": error_info}), 500 + + +@run_report_bp.route("/delete_all_reports/", methods=["POST"]) +def delete_all_reports(report_name): + """ + Deletes all reports associated with a particular report_name from the underlying storage. + Only marks as "status=deleted" so the report is retrievable at a later date. + + :param report_name: The parameter here should be a "/"-delimited string which mirrors the directory structure of \ + the notebook templates. + + :return: A JSON which contains "status" which will either be "ok" or "error". + """ + try: + get_serializer().delete_many({"report_name": report_name}) + get_all_result_keys(get_serializer(), limit=DEFAULT_RESULT_LIMIT, force_reload=True) + return jsonify({"status": "ok"}), 200 + except Exception: + error_info = traceback.format_exc() + return jsonify({"status": "error", "error": error_info}), 500 \ No newline at end of file diff --git a/notebooker/web/static/notebooker/result_listing.js b/notebooker/web/static/notebooker/result_listing.js index 4f3a831e..a6a4e9e0 100644 --- a/notebooker/web/static/notebooker/result_listing.js +++ b/notebooker/web/static/notebooker/result_listing.js @@ -25,6 +25,33 @@ deleteReport = (delete_url) => { .modal("show"); }; +deleteAllReports = (delete_url) => { + $("#deleteAllModal") + .modal({ + closable: true, + onDeny() { + return true; + }, + onApprove() { + $.ajax({ + type: "POST", + url: delete_all_url, // We get this from loading.html, which comes from flask + dataType: "json", + success(data, status, request) { + if (data.status === "error") { + $("#errorMsg").text(data.content); + $("#errorPopup").show(); + } else { + window.location.reload(); + } + }, + error(xhr, error) {}, + }); + }, + }) + .modal("show"); +}; + create_datatable = (result, readonly_mode) => { let columns = [ { diff --git a/notebooker/web/templates/result_listing.html b/notebooker/web/templates/result_listing.html index c2360052..2c82c2e1 100644 --- a/notebooker/web/templates/result_listing.html +++ b/notebooker/web/templates/result_listing.html @@ -42,6 +42,9 @@

{{ titleised_report_name }} ({{ report_name Manually run this report + {% endif %} @@ -56,5 +59,14 @@

{{ titleised_report_name }} ({{ report_name
Cancel
+ From e1183d31c4d08e6cfca918c529d8ca088c93897e Mon Sep 17 00:00:00 2001 From: "Allen, Chris (Boston)" Date: Wed, 8 May 2024 12:37:29 -0400 Subject: [PATCH 2/8] Remove unused code --- notebooker/web/routes/report_execution.py | 6 ++--- .../web/static/notebooker/result_listing.js | 26 ------------------- notebooker/web/templates/result_listing.html | 6 ++--- 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/notebooker/web/routes/report_execution.py b/notebooker/web/routes/report_execution.py index e1ba74be..9c1c6d59 100644 --- a/notebooker/web/routes/report_execution.py +++ b/notebooker/web/routes/report_execution.py @@ -7,7 +7,7 @@ from typing import Any, Dict, List, Tuple, NamedTuple, Optional, AnyStr import nbformat -from flask import Blueprint, abort, jsonify, render_template, request, url_for, current_app +from flask import Blueprint, abort, jsonify, render_template, request, url_for, current_app, redirect from nbformat import NotebookNode from notebooker.constants import DEFAULT_RESULT_LIMIT @@ -302,7 +302,7 @@ def delete_report(job_id): return jsonify({"status": "error", "error": error_info}), 500 -@run_report_bp.route("/delete_all_reports/", methods=["POST"]) +@run_report_bp.route("/delete_all_reports/", methods=["GET", "POST"]) def delete_all_reports(report_name): """ Deletes all reports associated with a particular report_name from the underlying storage. @@ -314,7 +314,7 @@ def delete_all_reports(report_name): :return: A JSON which contains "status" which will either be "ok" or "error". """ try: - get_serializer().delete_many({"report_name": report_name}) + get_serializer().delete_all_for_report_name(report_name) get_all_result_keys(get_serializer(), limit=DEFAULT_RESULT_LIMIT, force_reload=True) return jsonify({"status": "ok"}), 200 except Exception: diff --git a/notebooker/web/static/notebooker/result_listing.js b/notebooker/web/static/notebooker/result_listing.js index a6a4e9e0..2f6fa3df 100644 --- a/notebooker/web/static/notebooker/result_listing.js +++ b/notebooker/web/static/notebooker/result_listing.js @@ -25,32 +25,6 @@ deleteReport = (delete_url) => { .modal("show"); }; -deleteAllReports = (delete_url) => { - $("#deleteAllModal") - .modal({ - closable: true, - onDeny() { - return true; - }, - onApprove() { - $.ajax({ - type: "POST", - url: delete_all_url, // We get this from loading.html, which comes from flask - dataType: "json", - success(data, status, request) { - if (data.status === "error") { - $("#errorMsg").text(data.content); - $("#errorPopup").show(); - } else { - window.location.reload(); - } - }, - error(xhr, error) {}, - }); - }, - }) - .modal("show"); -}; create_datatable = (result, readonly_mode) => { let columns = [ diff --git a/notebooker/web/templates/result_listing.html b/notebooker/web/templates/result_listing.html index 2c82c2e1..9712aeea 100644 --- a/notebooker/web/templates/result_listing.html +++ b/notebooker/web/templates/result_listing.html @@ -38,11 +38,11 @@

{{ titleised_report_name }} ({{ report_name {% endif %} {% if not readonly_mode %} -
- +
+ Manually run this report -
From fe78135362f4720faeafcf896bcb2b65d8bdbf56 Mon Sep 17 00:00:00 2001 From: "Allen, Chris (Boston)" Date: Wed, 8 May 2024 12:47:05 -0400 Subject: [PATCH 3/8] remove diff --- notebooker/web/static/notebooker/result_listing.js | 1 - 1 file changed, 1 deletion(-) diff --git a/notebooker/web/static/notebooker/result_listing.js b/notebooker/web/static/notebooker/result_listing.js index 2f6fa3df..4f3a831e 100644 --- a/notebooker/web/static/notebooker/result_listing.js +++ b/notebooker/web/static/notebooker/result_listing.js @@ -25,7 +25,6 @@ deleteReport = (delete_url) => { .modal("show"); }; - create_datatable = (result, readonly_mode) => { let columns = [ { From 540ef0e3a0f5c4873b70de1e1093c74bca1cb1ad Mon Sep 17 00:00:00 2001 From: "Allen, Chris (Boston)" Date: Wed, 8 May 2024 12:52:13 -0400 Subject: [PATCH 4/8] newline --- notebooker/web/routes/report_execution.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/notebooker/web/routes/report_execution.py b/notebooker/web/routes/report_execution.py index 9c1c6d59..d25ca06a 100644 --- a/notebooker/web/routes/report_execution.py +++ b/notebooker/web/routes/report_execution.py @@ -319,4 +319,5 @@ def delete_all_reports(report_name): return jsonify({"status": "ok"}), 200 except Exception: error_info = traceback.format_exc() - return jsonify({"status": "error", "error": error_info}), 500 \ No newline at end of file + return jsonify({"status": "error", "error": error_info}), 500 + \ No newline at end of file From 705207b9cf56ec411f883e469ac7ce56cf886464 Mon Sep 17 00:00:00 2001 From: "Allen, Chris (Boston)" Date: Wed, 8 May 2024 13:01:30 -0400 Subject: [PATCH 5/8] flake8 again --- notebooker/web/routes/report_execution.py | 1 - 1 file changed, 1 deletion(-) diff --git a/notebooker/web/routes/report_execution.py b/notebooker/web/routes/report_execution.py index d25ca06a..2333059d 100644 --- a/notebooker/web/routes/report_execution.py +++ b/notebooker/web/routes/report_execution.py @@ -320,4 +320,3 @@ def delete_all_reports(report_name): except Exception: error_info = traceback.format_exc() return jsonify({"status": "error", "error": error_info}), 500 - \ No newline at end of file From 9d3808840a9956c0e7d9c1d153040bf1f92dd41c Mon Sep 17 00:00:00 2001 From: "Allen, Chris (Boston)" Date: Tue, 14 May 2024 15:35:11 -0400 Subject: [PATCH 6/8] Redirect to front page if successful --- notebooker/web/routes/report_execution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooker/web/routes/report_execution.py b/notebooker/web/routes/report_execution.py index 2333059d..f95ab789 100644 --- a/notebooker/web/routes/report_execution.py +++ b/notebooker/web/routes/report_execution.py @@ -316,7 +316,7 @@ def delete_all_reports(report_name): try: get_serializer().delete_all_for_report_name(report_name) get_all_result_keys(get_serializer(), limit=DEFAULT_RESULT_LIMIT, force_reload=True) - return jsonify({"status": "ok"}), 200 + return redirect("/") except Exception: error_info = traceback.format_exc() return jsonify({"status": "error", "error": error_info}), 500 From 936048210fd5561a7d10055dbba9f2ed95126880 Mon Sep 17 00:00:00 2001 From: "Allen, Chris (Boston)" Date: Mon, 20 May 2024 14:13:20 -0400 Subject: [PATCH 7/8] Missing delete_all_for_report_name serialization function --- notebooker/serialization/mongo.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/notebooker/serialization/mongo.py b/notebooker/serialization/mongo.py index 4ddf97b2..73f696e4 100644 --- a/notebooker/serialization/mongo.py +++ b/notebooker/serialization/mongo.py @@ -535,6 +535,10 @@ def delete_result(self, job_id: AnyStr) -> Dict[str, Any]: self.result_data_store.delete(filename) return {"deleted_result_document": result, "gridfs_filenames": gridfs_filenames} + def delete_all_for_report_name(self, report_name: AnyStr) -> Dict[str, Any]: + results = self.get_all_result_keys(mongo_filter={"report_name": report_name}) + return {job_id: self.delete_result(job_id) for _, job_id in results} + def _pdf_filename(job_id: str) -> str: return f"{job_id}.pdf" From a4c884e23d6b43224f11c1cadb85a590e77f4f3c Mon Sep 17 00:00:00 2001 From: "Allen, Chris (Boston)" Date: Mon, 20 May 2024 14:53:04 -0400 Subject: [PATCH 8/8] added spinner --- notebooker/web/templates/result_listing.html | 62 +++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/notebooker/web/templates/result_listing.html b/notebooker/web/templates/result_listing.html index 9712aeea..1fa4e2e9 100644 --- a/notebooker/web/templates/result_listing.html +++ b/notebooker/web/templates/result_listing.html @@ -64,9 +64,69 @@

{{ titleised_report_name }} ({{ report_name e.preventDefault(); var confirmed = confirm('Are you sure you wish to delete all reports?'); if (confirmed) { - window.location.href = this.getAttribute('data-href'); + // Show the spinner + document.getElementById('spinner').style.display = 'block'; + + // Use fetch API to make the request + fetch(this.getAttribute('data-href')) + .then(response => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + // Hide the spinner + document.getElementById('spinner').style.display = 'none'; + // Refresh the page or redirect as needed + window.location.reload(); + }) + .catch(error => { + console.error('There has been a problem with your fetch operation:', error); + // Hide the spinner + document.getElementById('spinner').style.display = 'none'; + }); } }); + + + + +