From d04b7cb89b3fbaa1689f8f6525a2740eda7c3be3 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 18 Dec 2025 10:54:27 -0600 Subject: Provide new streamlined UI for publications. --- uploader/publications/views.py | 29 ++- uploader/route_utils.py | 20 +- uploader/static/css/theme.css | 5 + .../templates/phenotypes/sui-view-dataset.html | 8 - uploader/templates/publications/sui-base.html | 9 + .../publications/sui-create-publication.html | 200 ++++++++++++++++++++ .../publications/sui-delete-publication.html | 95 ++++++++++ .../publications/sui-edit-publication.html | 203 +++++++++++++++++++++ uploader/templates/publications/sui-index.html | 109 +++++++++++ .../publications/sui-view-publication.html | 80 ++++++++ uploader/templates/sui-index.html | 200 ++++++++++++-------- 11 files changed, 851 insertions(+), 107 deletions(-) create mode 100644 uploader/templates/publications/sui-base.html create mode 100644 uploader/templates/publications/sui-create-publication.html create mode 100644 uploader/templates/publications/sui-delete-publication.html create mode 100644 uploader/templates/publications/sui-edit-publication.html create mode 100644 uploader/templates/publications/sui-index.html create mode 100644 uploader/templates/publications/sui-view-publication.html diff --git a/uploader/publications/views.py b/uploader/publications/views.py index 4ec832f..f0ec95a 100644 --- a/uploader/publications/views.py +++ b/uploader/publications/views.py @@ -10,6 +10,8 @@ from flask import ( render_template, current_app as app) +from uploader.sui import sui_template + from uploader.flask_extensions import url_for from uploader.authorisation import require_login from uploader.route_utils import redirect_to_next @@ -30,7 +32,7 @@ pubbp = Blueprint("publications", __name__) @require_login def index(): """Index page for publications.""" - return render_template("publications/index.html") + return render_template(sui_template("publications/index.html")) @pubbp.route("/list", methods=["GET"]) @@ -72,7 +74,7 @@ def view_publication(publication_id: int): return redirect(url_for('publications.index')) return render_template( - "publications/view-publication.html", + sui_template("publications/view-publication.html"), publication=publication, linked_phenotypes=tuple(fetch_publication_phenotypes( conn, publication_id))) @@ -82,13 +84,21 @@ def view_publication(publication_id: int): @require_login def create_publication(): """Create a new publication.""" + _get_args = { + key: request.args[key] + for key in ("species_id", "population_id", "dataset_id", "return_to") + if bool(request.args.get(key)) + } + if request.method == "GET": - return render_template("publications/create-publication.html") + return render_template( + sui_template("publications/create-publication.html"), + get_args=_get_args) form = request.form authors = form.get("publication-authors").encode("utf8") if authors is None or authors == "": flash("The publication's author(s) MUST be provided!", "alert alert-danger") - return redirect(url_for("publications.create", **request.args)) + return redirect(url_for("publications.create")) with database_connection(app.config["SQL_URI"]) as conn: publications = create_new_publications(conn, ({ @@ -106,7 +116,7 @@ def create_publication(): return redirect(url_for( request.args.get("return_to") or "publications.view_publication", publication_id=publications[0]["publication_id"], - **request.args)) + **_get_args)) flash("Publication creation failed!", "alert alert-danger") app.logger.debug("Failed to create the new publication.", exc_info=True) @@ -120,7 +130,7 @@ def edit_publication(publication_id: int): with database_connection(app.config["SQL_URI"]) as conn: if request.method == "GET": return render_template( - "publications/edit-publication.html", + sui_template("publications/edit-publication.html"), publication=fetch_publication_by_id(conn, publication_id), linked_phenotypes=tuple(fetch_publication_phenotypes( conn, publication_id)), @@ -171,15 +181,16 @@ def delete_publication(publication_id: int): flash("Cannot delete publication with linked phenotypes!", "alert-warning") return redirect(url_for( - "publications.view_publication", publication_id=publication_id)) + sui_template("publications.view_publication"), + publication_id=publication_id)) if request.method == "GET": return render_template( - "publications/delete-publication.html", + sui_template("publications/delete-publication.html"), publication=publication, linked_phenotypes=linked_phenotypes, publication_id=publication_id) delete_publications(conn, (publication,)) flash("Deleted the publication successfully.", "alert-success") - return render_template("publications/delete-publication-success.html") + return redirect(url_for("publications.index")) diff --git a/uploader/route_utils.py b/uploader/route_utils.py index 4449475..fa63233 100644 --- a/uploader/route_utils.py +++ b/uploader/route_utils.py @@ -56,15 +56,17 @@ def generic_select_population( def redirect_to_next(default: dict): """Redirect to the next uri if specified, else redirect to default.""" assert "uri" in default, "You must provide at least the 'uri' value." - try: - next_page = base64_decode_to_dict(request.args.get("next")) - _uri = next_page["uri"] - next_page.pop("uri") - return redirect(url_for(_uri, **next_page)) - except (TypeError, JSONDecodeError) as _err: - logger.debug("We could not decode the next value '%s'", - next_page, - exc_info=True) + _next = request.args.get("next") + if bool(_next): + try: + next_page = base64_decode_to_dict(_next) + _uri = next_page["uri"] + next_page.pop("uri") + return redirect(url_for(_uri, **next_page)) + except (TypeError, JSONDecodeError) as _err: + logger.debug("We could not decode the next value '%s'", + next_page, + exc_info=True) return redirect(url_for( default["uri"], diff --git a/uploader/static/css/theme.css b/uploader/static/css/theme.css index 99b7af3..bdac745 100644 --- a/uploader/static/css/theme.css +++ b/uploader/static/css/theme.css @@ -83,3 +83,8 @@ table.dataTable tbody tr.selected td { padding-bottom: 0.2em; border-bottom: solid gray 1px; } + + +.breadcrumb-item { + text-transform: Capitalize; +} diff --git a/uploader/templates/phenotypes/sui-view-dataset.html b/uploader/templates/phenotypes/sui-view-dataset.html index 6a26004..f858c4e 100644 --- a/uploader/templates/phenotypes/sui-view-dataset.html +++ b/uploader/templates/phenotypes/sui-view-dataset.html @@ -53,14 +53,6 @@ title="Add a bunch of phenotypes" class="btn btn-primary">Add phenotypes - -