about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-17 12:46:31 -0500
committerFrederick Muriuki Muriithi2024-09-17 12:47:58 -0500
commit7e54ea61c374e15df31c41c1ca87a001acd85242 (patch)
tree7fa48f39cbb99671dc31aa0033bb3e0cc11e2695
parent879fbc4d6086860e2de76a4f74509a1bb8642af5 (diff)
downloadgn-uploader-7e54ea61c374e15df31c41c1ca87a001acd85242.tar.gz
UI Improvements: Enumerate data in tables.
-rw-r--r--uploader/datautils.py7
-rw-r--r--uploader/population/views.py4
-rw-r--r--uploader/samples/views.py6
-rw-r--r--uploader/species/views.py4
-rw-r--r--uploader/templates/populations/list-populations.html2
-rw-r--r--uploader/templates/samples/list-samples.html2
-rw-r--r--uploader/templates/species/list-species.html2
7 files changed, 21 insertions, 6 deletions
diff --git a/uploader/datautils.py b/uploader/datautils.py
index b95a9e0..2c2a3dc 100644
--- a/uploader/datautils.py
+++ b/uploader/datautils.py
@@ -1,7 +1,14 @@
 """Generic data utilities: Rename module."""
 import math
+from typing import Sequence
 from functools import reduce
 
+def enumerate_sequence(seq: Sequence[dict]) -> Sequence[dict]:
+    """Enumerate sequence beginning at 1"""
+    return tuple({**item, "sequence_number": seqno}
+                 for seqno, item in enumerate(seq, start=1))
+
+
 def order_by_family(items: tuple[dict, ...],
                     family_key: str = "Family",
                     order_key: str = "FamilyOrderId") -> list:
diff --git a/uploader/population/views.py b/uploader/population/views.py
index 5136ee0..39a5762 100644
--- a/uploader/population/views.py
+++ b/uploader/population/views.py
@@ -19,6 +19,7 @@ from uploader.ui import make_template_renderer
 from uploader.authorisation import require_login
 from uploader.genotypes.views import genotypesbp
 from uploader.db_utils import database_connection
+from uploader.datautils import enumerate_sequence
 from uploader.species.models import (all_species,
                                      species_by_id,
                                      order_species_by_family)
@@ -64,7 +65,8 @@ def list_species_populations(species_id: int):
         return render_template(
             "populations/list-populations.html",
             species=species,
-            populations=populations_by_species(conn, species_id),
+            populations=enumerate_sequence(populations_by_species(
+                conn, species_id)),
             activelink="list-populations")
 
 
diff --git a/uploader/samples/views.py b/uploader/samples/views.py
index 4332c21..fd3c601 100644
--- a/uploader/samples/views.py
+++ b/uploader/samples/views.py
@@ -19,9 +19,9 @@ from flask import (
 
 from uploader import jobs
 from uploader.files import save_file
-from uploader.datautils import order_by_family
 from uploader.authorisation import require_login
 from uploader.input_validation import is_integer_input
+from uploader.datautils import order_by_family, enumerate_sequence
 from uploader.db_utils import (
     with_db_connection,
     database_connection,
@@ -107,8 +107,8 @@ def list_samples(species_id: int, population_id: int):
                 "species.populations.samples.select_population",
                 species_id=species_id))
 
-        all_samples = samples_by_species_and_population(
-            conn, species_id, population_id)
+        all_samples = enumerate_sequence(samples_by_species_and_population(
+            conn, species_id, population_id))
         total_samples = len(all_samples)
         offset = int(request.args.get("from") or 0)
         if offset < 0:
diff --git a/uploader/species/views.py b/uploader/species/views.py
index 55b0dd3..08d3728 100644
--- a/uploader/species/views.py
+++ b/uploader/species/views.py
@@ -8,11 +8,11 @@ from flask import (flash,
                    current_app as app)
 
 from uploader.population import popbp
-from uploader.datautils import order_by_family
 from uploader.ui import make_template_renderer
 from uploader.db_utils import database_connection
 from uploader.oauth2.client import oauth2_get, oauth2_post
 from uploader.authorisation import require_login, require_token
+from uploader.datautils import order_by_family, enumerate_sequence
 
 from .models import (all_species,
                      save_species,
@@ -31,7 +31,7 @@ def list_species():
     """List and display all the species in the database."""
     with database_connection(app.config["SQL_URI"]) as conn:
         return render_template("species/list-species.html",
-                               allspecies=all_species(conn))
+                               allspecies=enumerate_sequence(all_species(conn)))
 
 @speciesbp.route("/<int:species_id>", methods=["GET"])
 @require_login
diff --git a/uploader/templates/populations/list-populations.html b/uploader/templates/populations/list-populations.html
index c83c18c..7c7145f 100644
--- a/uploader/templates/populations/list-populations.html
+++ b/uploader/templates/populations/list-populations.html
@@ -51,6 +51,7 @@
     <caption>Populations for {{species.FullName}}</caption>
     <thead>
       <tr>
+        <th>#</th>
         <th>Name</th>
         <th>Full Name</th>
         <th>Description</th>
@@ -60,6 +61,7 @@
     <tbody>
       {%for population in populations%}
       <tr>
+        <td>{{population["sequence_number"]}}</td>
         <td>
           <a href="{{url_for('species.populations.view_population',
                    species_id=species.SpeciesId,
diff --git a/uploader/templates/samples/list-samples.html b/uploader/templates/samples/list-samples.html
index f82d72e..13e5cec 100644
--- a/uploader/templates/samples/list-samples.html
+++ b/uploader/templates/samples/list-samples.html
@@ -73,6 +73,7 @@
   <table class="table">
     <thead>
       <tr>
+        <th>#</th>
         <th>Name</th>
         <th>Auxilliary Name</th>
         <th>Symbol</th>
@@ -83,6 +84,7 @@
     <tbody>
       {%for sample in samples%}
       <tr>
+        <td>{{sample.sequence_number}}</td>
         <td>{{sample.Name}}</td>
         <td>{{sample.Name2}}</td>
         <td>{{sample.Symbol or "-"}}</td>
diff --git a/uploader/templates/species/list-species.html b/uploader/templates/species/list-species.html
index d3dae7f..85c9d40 100644
--- a/uploader/templates/species/list-species.html
+++ b/uploader/templates/species/list-species.html
@@ -29,6 +29,7 @@
     <caption>Available Species</caption>
     <thead>
       <tr>
+        <th>#</td>
         <th title="A common, layman's name for the species.">Common Name</th>
         <th title="The scientific name for the species">Organism Name</th>
         <th title="An identifier for the species in the NCBI taxonomy database">
@@ -42,6 +43,7 @@
     <tbody>
       {%for species in allspecies%}
       <tr>
+        <td>{{species["sequence_number"]}}</td>
         <td>{{species["SpeciesName"]}}</td>
         <td>
           <a href="{{url_for('species.view_species',