-
Notifications
You must be signed in to change notification settings - Fork 82
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
ceallen
wants to merge
8
commits into
master
Choose a base branch
from
123-delete-all-button-on-report-listing-screen
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1a4d069
First crack
ceallen e1183d3
Remove unused code
ceallen fe78135
remove diff
ceallen 540ef0e
newline
ceallen 705207b
flake8 again
ceallen 9d38088
Redirect to front page if successful
ceallen 9360482
Missing delete_all_for_report_name serialization function
ceallen a4c884e
added spinner
ceallen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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): | ||
""" | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 redirect("/") | ||
except Exception: | ||
error_info = traceback.format_exc() | ||
return jsonify({"status": "error", "error": error_info}), 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
@@ -56,5 +59,74 @@ <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) { | ||
// 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'; | ||
}); | ||
} | ||
}); | ||
</script> | ||
<!-- Spinner --> | ||
<div id="spinner" style="display: none;"> | ||
<div class="loader"></div> | ||
</div> | ||
|
||
<!-- CSS for the spinner --> | ||
<style> | ||
#spinner { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
position: absolute; | ||
z-index: 9999; | ||
width: 100%; | ||
height: 100%; | ||
overflow: auto; | ||
top: 0: | ||
left: 0; | ||
} | ||
|
||
.loader { | ||
border: 16px solid #f3f3f3; | ||
border-radius: 50%; | ||
border-top: 16px solid #3498db; | ||
width: 120px; | ||
height: 120px; | ||
-webkit-animation: spin 2s linear infinite; /* Safari */ | ||
animation: spin 2s linear infinite; | ||
margin: auto; | ||
} | ||
|
||
/* Safari */ | ||
@-webkit-keyframes spin { | ||
0% { -webkit-transform: rotate(0deg); } | ||
100% { -webkit-transform: rotate(360deg); } | ||
} | ||
|
||
@keyframes spin { | ||
0% { transform: rotate(0deg); } | ||
100% { transform: rotate(360deg); } | ||
} | ||
</style> | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a test please