Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

123 delete all button on report listing screen #181

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion notebooker/web/routes/report_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/<path:report_name>", methods=["GET", "POST"])
def delete_all_reports(report_name):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a test please

"""
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_all_for_report_name(report_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this implemented?

get_all_result_keys(get_serializer(), limit=DEFAULT_RESULT_LIMIT, force_reload=True)
return jsonify({"status": "ok"}), 200
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some enhancement - exposing the JSON to the end user is a bit too low-level

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've set this up to redirect to the front page.

except Exception:
error_info = traceback.format_exc()
return jsonify({"status": "error", "error": error_info}), 500
16 changes: 14 additions & 2 deletions notebooker/web/templates/result_listing.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ <h1 class="ui huge centered header">{{ titleised_report_name }} ({{ report_name
</div>
{% endif %}
{% if not readonly_mode %}
<div class="three wide column">
<a class="ui button green" id="runReportButton" href="/run_report/{{ report_name }}">
<div class="three wide column" style="display: flex;">
<a class="ui button green" id="runReportButton" href="/run_report/{{ report_name }}" style="margin-right: 40px;">
Manually run this report
</a>
<button class="ui button red" id="deleteAllReportsButton" data-href="/delete_all_reports/{{ report_name }}">
Delete all reports
</button>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we could add a Jest test for this as well please

</div>
{% endif %}
</div>
Expand All @@ -56,5 +59,14 @@ <h1 class="ui huge centered header">{{ titleised_report_name }} ({{ report_name
<div class="ui cancel button">Cancel</div>
</div>
</div>
<script type="application/javascript">
document.getElementById('deleteAllReportsButton').addEventListener('click', function(e) {
e.preventDefault();
var confirmed = confirm('Are you sure you wish to delete all reports?');
if (confirmed) {
window.location.href = this.getAttribute('data-href');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could take a long time - do we want to display a spinner or even a status update to the user?

}
});
</script>
</body>
</html>