about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-10-13 12:01:18 -0500
committerFrederick Muriuki Muriithi2025-10-13 13:13:57 -0500
commiteecc17d9c7b79a31eed40ed72df9dc06eec9056d (patch)
tree97e69cff4ad4c88a93c422b421e8ccba89d261a9
parentc348539518374a29b778084e96ba9af546f33cd3 (diff)
downloadgn-uploader-eecc17d9c7b79a31eed40ed72df9dc06eec9056d.tar.gz
Publications: Enable editing publication details.
-rw-r--r--uploader/publications/views.py40
-rw-r--r--uploader/static/js/pubmed.js2
-rw-r--r--uploader/templates/publications/edit-publication.html194
-rw-r--r--uploader/templates/publications/view-publication.html4
4 files changed, 238 insertions, 2 deletions
diff --git a/uploader/publications/views.py b/uploader/publications/views.py
index a88f754..23efa2e 100644
--- a/uploader/publications/views.py
+++ b/uploader/publications/views.py
@@ -14,6 +14,7 @@ from flask import (
 from uploader.authorisation import require_login
 
 from .models import (
+    update_publications,
     fetch_publication_by_id,
     create_new_publications,
     fetch_publication_phenotypes)
@@ -102,3 +103,42 @@ def create_publication():
     flash("Publication creation failed!", "alert alert-danger")
     app.logger.debug("Failed to create the new publication.", exc_info=True)
     return redirect(url_for("publications.create_publication"))
+
+
+@pubbp.route("/edit/<int:publication_id>", methods=["GET", "POST"])
+@require_login
+def edit_publication(publication_id: int):
+    """Edit a publication's details."""
+    with database_connection(app.config["SQL_URI"]) as conn:
+        if request.method == "GET":
+            return render_template(
+                "publications/edit-publication.html",
+                publication=fetch_publication_by_id(conn, publication_id),
+                linked_phenotypes=tuple(fetch_publication_phenotypes(
+                    conn, publication_id)),
+                publication_id=publication_id)
+
+        form = request.form
+        _pub = update_publications(conn, ({
+            "publication_id": publication_id,
+            "pubmed_id": form.get("pubmed-id") or None,
+            "abstract": form.get("publication-abstract").encode("utf8") or None,
+            "authors": form.get("publication-authors").encode("utf8"),
+            "title":  form.get("publication-title").encode("utf8") or None,
+            "journal": form.get("publication-journal").encode("utf8") or None,
+            "volume": form.get("publication-volume").encode("utf8") or None,
+            "pages": form.get("publication-pages").encode("utf8") or None,
+            "month": (form.get("publication-month") or "").encode("utf8").capitalize() or None,
+            "year": form.get("publication-year").encode("utf8") or None
+        },))
+
+        if not _pub:
+            flash("There was an error updating the publication details.",
+                  "alert-danger")
+            return redirect(url_for(
+                "publications.edit_publication", publication_id=publication_id))
+
+        flash("Successfully updated the publication details.",
+              "alert-success")
+        return redirect(url_for(
+            "publications.view_publication", publication_id=publication_id))
diff --git a/uploader/static/js/pubmed.js b/uploader/static/js/pubmed.js
index 9afd4c3..f425f49 100644
--- a/uploader/static/js/pubmed.js
+++ b/uploader/static/js/pubmed.js
@@ -22,7 +22,7 @@ var extract_details = (pubmed_id, details) => {
         "journal": details[pubmed_id].fulljournalname,
         "volume": details[pubmed_id].volume,
         "pages": details[pubmed_id].pages,
-        "month": _date.length > 1 ? months[_date[1].toLowerCase()] : "jan",
+        "month": _date.length > 1 ? (months[_date[1].toLowerCase()] || "January") : "January",
         "year": _date[0],
     };
 };
diff --git a/uploader/templates/publications/edit-publication.html b/uploader/templates/publications/edit-publication.html
new file mode 100644
index 0000000..540ecf1
--- /dev/null
+++ b/uploader/templates/publications/edit-publication.html
@@ -0,0 +1,194 @@
+{%extends "publications/base.html"%}
+{%from "flash_messages.html" import flash_all_messages%}
+
+{%block title%}View Publication{%endblock%}
+
+{%block pagetitle%}View Publication{%endblock%}
+
+
+{%block contents%}
+{{flash_all_messages()}}
+
+<div class="row">
+  <form id="frm-create-publication"
+        method="POST"
+        action="{{url_for('publications.edit_publication', publication_id=publication_id, **request.args)}}"
+        class="form-horizontal">
+
+    <div class="row mb-3">
+      <label for="txt-pubmed-id" class="col-sm-2 col-form-label">
+        PubMed ID</label>
+      <div class="col-sm-10">
+        <div class="input-group">
+          <input type="text"
+                 id="txt-pubmed-id"
+                 name="pubmed-id"
+                 value="{{publication.PubMed_ID or ''}}"
+                 class="form-control" />
+          <div class="input-group-text">
+            <button class="btn btn-outline-primary"
+                    id="btn-search-pubmed-id">search</button>
+          </div>
+        </div>
+        <span id="search-pubmed-id-error"
+              class="form-text text-muted text-danger visually-hidden">
+        </span>
+        <span class="form-text text-muted">This is the publication's ID on
+          <a href="https://pubmed.ncbi.nlm.nih.gov/"
+             title="Link to NCBI's PubMed service">NCBI's Pubmed Service</a>
+        </span>
+      </div>
+    </div>
+
+    <div class="row mb-3">
+      <label for="txt-publication-title" class="col-sm-2 col-form-label">
+        Title</label>
+      <div class="col-sm-10">
+        <input type="text"
+               id="txt-publication-title"
+               name="publication-title"
+               value="{{publication.Title}}"
+               class="form-control" />
+        <span class="form-text text-muted">Provide the publication's title here.</span>
+      </div>
+    </div>
+
+    <div class="row mb-3">
+      <label for="txt-publication-authors" class="col-sm-2 col-form-label">
+        Authors</label>
+      <div class="col-sm-10">
+        <input type="text"
+               id="txt-publication-authors"
+               name="publication-authors"
+               value="{{publication.Authors}}"
+               required="required"
+               class="form-control" />
+        <span class="form-text text-muted">
+          A publication <strong>MUST</strong> have an author. You <em>must</em>
+          provide a value for the authors field.
+        </span>
+      </div>
+    </div>
+
+    <div class="row mb-3">
+      <label for="txt-publication-journal" class="col-sm-2 col-form-label">
+        Journal</label>
+      <div class="col-sm-10">
+        <input type="text"
+               id="txt-publication-journal"
+               name="publication-journal"
+               value="{{publication.Journal}}"
+               class="form-control" />
+        <span class="form-text text-muted">Provide the name journal where the
+          publication was done, here.</span>
+      </div>
+    </div>
+
+    <div class="row mb-3">
+      <label for="select-publication-month"
+             class="col-sm-2 col-form-label">
+        Month</label>
+      <div class="col-sm-4">
+        <select class="form-control"
+                id="select-publication-month"
+                name="publication-month">
+          <option value="">Select a month</option>
+          {%for month in ("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"):%}
+          <option value="{{month}}"
+                  {%if publication.Month | lower == month %}
+                  selected="selected"
+                  {%endif%}>
+            {{month | title}}
+          </option>
+          {%endfor%}
+        </select>
+        <span class="form-text text-muted">Month of publication</span>
+      </div>
+
+      <label for="txt-publication-year"
+             class="col-sm-2 col-form-label">
+        Year</label>
+      <div class="col-sm-4">
+        <input type="number"
+               id="txt-publication-year"
+               name="publication-year"
+               value="{{publication.Year}}"
+               class="form-control"
+               min="1960" />
+        <span class="form-text text-muted">Year of publication</span>
+      </div>
+    </div>
+
+    <div class="row mb-3">
+      <label for="txt-publication-volume"
+             class="col-sm-2 col-form-label">
+        Volume</label>
+      <div class="col-sm-4">
+        <input type="text"
+               id="txt-publication-volume"
+               name="publication-volume"
+               value="{{publication.Volume}}"
+               class="form-control">
+        <span class="form-text text-muted">Journal volume</span>
+      </div>
+
+      <label for="txt-publication-pages"
+             class="col-sm-2 col-form-label">
+        Pages</label>
+      <div class="col-sm-4">
+        <input type="text"
+               id="txt-publication-pages"
+               name="publication-pages"
+               value="{{publication.Pages}}"
+               class="form-control" />
+        <span class="form-text text-muted">Journal pages for the publication</span>
+      </div>
+    </div>
+
+    <div class="row mb-3">
+      <label for="txt-abstract" class="col-sm-2 col-form-label">Abstract</label>
+      <div class="col-sm-10">
+        <textarea id="txt-publication-abstract"
+                  name="publication-abstract"
+                  class="form-control"
+                  rows="7">{{publication.Abstract or ""}}</textarea>
+      </div>
+    </div>
+
+    <div class="row mb-3">
+      <div class="col-sm-2"></div>
+      <div class="col-sm-8">
+        <input type="submit" class="btn btn-primary" value="Save" />
+        <input type="reset" class="btn btn-danger" />
+      </div>
+    </div>
+
+</form>
+</div>
+
+{%endblock%}
+
+
+{%block javascript%}
+<script type="text/javascript" src="/static/js/pubmed.js"></script>
+<script type="text/javascript">
+  $(function() {
+      $("#btn-search-pubmed-id").on("click", (event) => {
+          event.preventDefault();
+          var search_button = event.target;
+          var pubmed_id = $("#txt-pubmed-id").val().trim();
+          remove_class($("#txt-pubmed-id").parent(), "has-error");
+          if(pubmed_id == "") {
+              add_class($("#txt-pubmed-id").parent(), "has-error");
+              return false;
+          }
+
+          search_button.disabled = true;
+          // Fetch publication details
+          fetch_publication_details(pubmed_id,
+                                    [() => {search_button.disabled = false;}]);
+          return false;
+      });
+  });
+</script>
+{%endblock%}
diff --git a/uploader/templates/publications/view-publication.html b/uploader/templates/publications/view-publication.html
index 388547a..4de5da8 100644
--- a/uploader/templates/publications/view-publication.html
+++ b/uploader/templates/publications/view-publication.html
@@ -58,10 +58,12 @@
 </div>
 
 <div class="row">
+  <a href="{{url_for('publications.edit_publication', publication_id=publication.Id)}}"
+     title="Edit details for this publication."
+     class="btn btn-primary">Edit</a>
   <form id="frm-edit-delete-publication" method="POST" action="#">
     <input type="hidden" name="publication_id" value="{{publication.Id}}" />
     <div class="form-group">
-      <input type="submit" value="edit" class="btn btn-primary not-implemented" />
       {%if linked_phenotypes | length == 0%}
       <input type="submit" value="delete" class="btn btn-danger not-implemented" />
       {%endif%}