aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-03-20 16:01:45 +0300
committerFrederick Muriuki Muriithi2023-03-20 16:07:23 +0300
commit6e45510c3ee685a960db594aef70661220bebe60 (patch)
tree107b4a7468e71537ea25d8fb81bd882961f26979 /wqflask
parentd48be5b240e9394955972a4e6aefe97d490b41fb (diff)
downloadgenenetwork2-6e45510c3ee685a960db594aef70661220bebe60.tar.gz
oauth2: Load menu and populate dropdown
In order to enable searching through the existing datasets for linking with the auth system, we need a way to filter the data. In this commit, I load the menu and load it onto a dropdown box as a proof of concept to give an idea of some of the filters I can use down the road to fetch the data. This commit breaks the data-linking code. I will need to rework the data-linking code entirely to get it working again.
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/oauth2/data.py36
-rw-r--r--wqflask/wqflask/templates/oauth2/data-list.html200
2 files changed, 149 insertions, 87 deletions
diff --git a/wqflask/wqflask/oauth2/data.py b/wqflask/wqflask/oauth2/data.py
index 8005a2a0..0cd110f6 100644
--- a/wqflask/wqflask/oauth2/data.py
+++ b/wqflask/wqflask/oauth2/data.py
@@ -23,15 +23,47 @@ def list_data():
**{key:val for key,val in kwargs.items()
if key not in ("groups", "data_items", "user_privileges")})
+ def __process_menus__(mns):
+ return {
+ species_id: {
+ "display_name": display_name,
+ "family": family,
+ "groups": {
+ group_id: {
+ "group_name": group_name,
+ "family": family,
+ "types": {
+ type_id: {
+ "menu_value": type_menu_value,
+ "menu_heading": type_menu_heading,
+ "datasets": tuple(
+ dict(zip(("accession_id", "dataset_id",
+ "dataset_fullname"),
+ dataset_row))
+ for dataset_row in mns["datasets"][
+ species_id][group_id][type_id])
+ }
+ for type_id, type_menu_value, type_menu_heading
+ in mns["types"][species_id][group_id]
+ }
+ }
+ for group_id, group_name, family in mns["groups"][species_id]
+ }
+ }
+ for species_id, display_name, family in mns["species"]}
+
groups = oauth2_get("oauth2/group/list").either(
lambda err: {"groups_error": process_error(err)},
lambda grp: {"groups": grp})
roles = oauth2_get("oauth2/user/roles").either(
lambda err: {"roles_error": process_error(err)},
lambda roles: {"roles": roles})
+ menus = oauth2_get("menu/generate/json").either(
+ lambda err: {"menus_error": process_error(err)},
+ lambda mns: {"menus": __process_menus__(mns)})
if request.method == "GET":
- return __render__(**{**groups, **roles})
+ return __render__(**{**groups, **roles, **menus})
dataset_type = request.form["dataset_type"]
offset = int(request.form.get("offset", 0)) + (
@@ -47,7 +79,7 @@ def list_data():
lambda err: {"data_items_error": process_error(err)},
lambda data: {"data_items": data})
return __render__(**{
- **groups, **roles, **data_items, "dataset_type": dataset_type,
+ **groups, **roles, **menus, **data_items, "dataset_type": dataset_type,
"offset": offset
})
diff --git a/wqflask/wqflask/templates/oauth2/data-list.html b/wqflask/wqflask/templates/oauth2/data-list.html
index 6d0ae427..019e2346 100644
--- a/wqflask/wqflask/templates/oauth2/data-list.html
+++ b/wqflask/wqflask/templates/oauth2/data-list.html
@@ -12,23 +12,46 @@
<div class="row">
<form method="POST" action="{{url_for('oauth2.data.list_data')}}">
<legend>Dataset Type</legend>
+ <input type="hidden" name="offset" value="0" />
+ <input type="hidden" name="menus" value="{{menus | tojson}}" />
+ <div class="form-group">
+ <label for="select-menu">Dataset</label>
+ <select id="select-menu" name="dataset">
+ {%for species_id, species_data in menus.items()%}
+ <optgroup label="{{species_data.display_name}}">
+ {%for group_id, group_data in species_data["groups"].items()%}
+ <optgroup label=" {{group_data.group_name}}">
+ {%for type_id, type_data in group_data["types"].items()%}
+ <optgroup label="{{type_data.menu_heading}}">
+ {%for dataset in type_data["datasets"]%}
+ <option value="{{dataset.dataset_id}}">
+ {{dataset.dataset_fullname}}
+ </option>
+ {%endfor%}
+ </optgroup>
+ {%endfor%}
+ </optgroup>
+ {%endfor%}
+ </optgroup>
+ {%endfor%}
+ </select>
+ </div>
<div class="form-group">
- <input type="hidden" name="offset" value="0" />
<label for="dataset_type" class="form-label">Dataset Type</label>
<select name="dataset_type" required="required">
<option value="">Select dataset type</option>
<option value="mrna"
{%if dataset_type=="mrna"%}
- selected="selected"
+ selected="selected"
{%endif%}>mRNA Assay Datasets</option>
- <option value="genotype"
- {%if dataset_type=="genotype"%}
- selected="selected"
- {%endif%}>Genotype Datasets</option>
- <option value="phenotype"
- {%if dataset_type=="phenotype"%}
- selected="selected"
- {%endif%}>Phenotype/Publish Datasets</option>
+ <option value="genotype"
+ {%if dataset_type=="genotype"%}
+ selected="selected"
+ {%endif%}>Genotype Datasets</option>
+ <option value="phenotype"
+ {%if dataset_type=="phenotype"%}
+ selected="selected"
+ {%endif%}>Phenotype/Publish Datasets</option>
</select>
</div>
<input type="submit" value="Fetch Unlinked Data" class="btn btn-primary" />
@@ -39,87 +62,94 @@
{%if data_items_error is defined%}
{{display_error("Data Error", data_items_error)}}
{%else%}
- <div class="row">
- <table class="table">
- <caption>Link Data to Group</caption>
+ <div class="row">
+ <form method="POST" action="{{url_for('oauth2.data.link_data')}}">
+ <legend>Link Data to Group</legend>
+ <input type="hidden" name="offset" value="{{offset or 0}}" />
+ <input type="hidden" name="dataset_type" value="{{dataset_type}}" />
- <thead>
- <tr>
- {%if dataset_type == "phenotype"%}
- <th>Trait ID</th>
- <th>Data Group</th>
- {%endif%}
- <th>Dataset Name</th>
- <th>Dataset Full Name</th>
- <th>Group</th>
- <th>Link</th>
- </tr>
- </thead>
+ <div class="form-group">
+ <label for="select-group-id">Group</label>
+ <select name="group_id" required="required">
+ <option value="">Select group</option>
+ {%for group in groups%}
+ <option value="{{group.group_id}}">{{group.group_name}}</option>
+ {%endfor%}
+ </select>
+ </div>
- <tbody>
- {%for data_item in data_items%}
- <tr>
- <form method="POST" action="{{url_for('oauth2.data.link_data')}}">
- <input type="hidden" name="offset" value="{{offset or 0}}" />
- <input type="hidden" name="dataset_id" value="{{data_item.Id}}" />
- <input type="hidden" name="dataset_type" value="{{dataset_type}}" />
- {%if dataset_type == "phenotype"%}
- <td>
- <a href="/show_trait?trait_id={{data_item.Id}}&dataset={{data_item.dataset_name}}"
- title="Trait Page">
- {{data_item.Id}}
- </a>
- </td>
- <td>{{data_item.InbredSetName}}</td>
- {%endif%}
- <td>
- <a href="https://gn1.genenetwork.org/webqtl/main.py?FormID=sharinginfo&GN_AccessionId={{data_item.accession_id}}&InfoPageName={{data_item.dataset_name}}"
- title="Link to information on dataset '{{data_item.dataset_fullname}}'"
- target="_blank">
- {{data_item.dataset_name}}
- </a>
- </td>
- <td>{{data_item.dataset_fullname}}</td>
- <td>
- <select name="group_id" required="required">
- <option value="">Select group</option>
- {%for group in groups%}
- <option value="{{group.group_id}}">{{group.group_name}}</option>
- {%endfor%}
- </select>
- </td>
- <td>
- <input type="submit" value="Link" class="btn btn-info" />
- </td>
- </form>
- </tr>
- {%else%}
- <tr>
- <td colspan="4">
- <span class="glyphicon glyphicon-info-sign text-danger">
- </span>
- &nbsp;
- <strong class="text-info">No available data to link</strong>
- </td>
- </tr>
- {%endfor%}
- </tbody>
- </table>
+ <table class="table">
+ <caption>Link Data to Group</caption>
- <form method="POST" action="{{url_for('oauth2.data.list_data')}}">
- <input type="hidden" name="dataset_type" value="{{dataset_type}}" />
- <input type="hidden" name="offset" value="{{offset or 0}}" />
- <div class="form-group" style="margin: auto;width: 50%;">
- {%if offset != 0%}
- <input type="submit" name="offset_submit" value="Previous" class="btn btn-warning" />
+ <thead>
+ <tr>
+ <th>Select</th>
+ {%if dataset_type == "phenotype"%}
+ <th>Trait ID</th>
+ <th>Data Group</th>
{%endif%}
- {%if data_items | length == 100:%}
- <input type="submit" name="offset_submit" value="Next" class="btn btn-warning" />
+ <th>Dataset Name</th>
+ <th>Dataset Full Name</th>
+ <th>Link</th>
+ </tr>
+ </thead>
+
+ <tbody>
+ {%for data_item in data_items%}
+ <tr>
+ <td>
+ <input type="checkbox" value="{{data_item.Id}}"
+ name="dataset_ids" />
+ </td>
+ {%if dataset_type == "phenotype"%}
+ <td>
+ <a href="/show_trait?trait_id={{data_item.Id}}&dataset={{data_item.dataset_name}}"
+ title="Trait Page">
+ {{data_item.Id}}
+ </a>
+ </td>
+ <td>{{data_item.InbredSetName}}</td>
{%endif%}
- </div>
- </form>
+ <td>
+ <a href="https://gn1.genenetwork.org/webqtl/main.py?FormID=sharinginfo&GN_AccessionId={{data_item.accession_id}}&InfoPageName={{data_item.dataset_name}}"
+ title="Link to information on dataset '{{data_item.dataset_fullname}}'"
+ target="_blank">
+ {{data_item.dataset_name}}
+ </a>
+ </td>
+ <td>{{data_item.dataset_fullname}}</td>
+ <td>
+ <input type="submit" value="Link" class="btn btn-info" />
+ </td>
+ </tr>
+ {%else%}
+ <tr>
+ <td colspan="4">
+ <span class="glyphicon glyphicon-info-sign text-danger">
+ </span>
+ &nbsp;
+ <strong class="text-info">No available data to link</strong>
+ </td>
+ </tr>
+ {%endfor%}
+ </tbody>
+ </table>
+ </form>
+
+ <form method="POST" action="{{url_for('oauth2.data.list_data')}}">
+ <input type="hidden" name="dataset_type" value="{{dataset_type}}" />
+ <input type="hidden" name="offset" value="{{offset or 0}}" />
+ <div class="form-group" style="margin: auto;width: 50%;">
+ {%if offset != 0%}
+ <input type="submit" name="offset_submit" value="Previous" class="btn btn-warning" />
+ {%endif%}
+ {%if data_items | length == 100:%}
+ <input type="submit" name="offset_submit" value="Next" class="btn btn-warning" />
+ {%endif%}
</div>
- {%endif%}
+ </form>
+ </div>
+ {%endif%}
{%endif%}
</div>