aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-04-19 11:29:19 +0300
committerFrederick Muriuki Muriithi2023-04-19 11:30:15 +0300
commitbfe557dc1e537dc78a82a30817ecf2ca3004d978 (patch)
tree29245328de967cead92457fff79be9262945f63f
parent1e5986939963b73cc9030764140f893f0bbb5b57 (diff)
downloadgenenetwork2-bfe557dc1e537dc78a82a30817ecf2ca3004d978.tar.gz
oauth2: phenotypes: Enable search from user input.
-rw-r--r--wqflask/wqflask/oauth2/data.py21
-rw-r--r--wqflask/wqflask/static/new/javascript/auth/search_phenotypes.js13
-rw-r--r--wqflask/wqflask/templates/oauth2/data-list-phenotype.html2
3 files changed, 30 insertions, 6 deletions
diff --git a/wqflask/wqflask/oauth2/data.py b/wqflask/wqflask/oauth2/data.py
index 5026a6d1..d7be85f0 100644
--- a/wqflask/wqflask/oauth2/data.py
+++ b/wqflask/wqflask/oauth2/data.py
@@ -76,6 +76,7 @@ def __search_phenotypes__(query, template, **kwargs):
selected_traits=selected_traits, search_results=search_results,
search_endpoint=urljoin(
app.config["GN_SERVER_URL"], "oauth2/data/search"),
+ gn_server_url = app.config["GN_SERVER_URL"],
results_endpoint=urljoin(
app.config["GN_SERVER_URL"],
f"oauth2/data/search/phenotype/{job_id}"),
@@ -124,6 +125,26 @@ def json_search_mrna() -> Response:
__handle_error__,
lambda datasets: jsonify(datasets))
+@data.route("/phenotype/search", methods=["POST"])
+def json_search_phenotypes() -> Response:
+ """Search for phenotypes."""
+ form = request.json
+ def __handle_error__(err):
+ error = process_error(err)
+ return jsonify(error), error["status_code"]
+
+ return oauth2_get(
+ "oauth2/data/search",
+ json={
+ "dataset_type": "phenotype",
+ "species_name": form["species_name"],
+ "query": form.get("query", ""),
+ "per_page": int(form.get("per_page", 50)),
+ "page": int(form.get("page", 1)),
+ "gn3_server_uri": app.config["GN_SERVER_URL"],
+ "selected_traits": form.get("selected_traits", [])
+ }).either(__handle_error__, jsonify)
+
@data.route("/<string:species_name>/<string:dataset_type>/list",
methods=["GET", "POST"])
def list_data_by_species_and_dataset(
diff --git a/wqflask/wqflask/static/new/javascript/auth/search_phenotypes.js b/wqflask/wqflask/static/new/javascript/auth/search_phenotypes.js
index 7cccbb3a..98396924 100644
--- a/wqflask/wqflask/static/new/javascript/auth/search_phenotypes.js
+++ b/wqflask/wqflask/static/new/javascript/auth/search_phenotypes.js
@@ -96,7 +96,8 @@ function display_search_results(data, textStatus, jqXHR) {
* @param {UUID}: The job id to fetch data for
*/
function fetch_search_results(job_id, success, error=default_error_fn) {
- endpoint = $("#frm-search-traits").attr("data-search-results-endpoint");
+ host = $("#frm-search-traits").attr("data-gn-server-url");
+ endpoint = host + "oauth2/data/search/phenotype/" + job_id
$("#txt-search").prop("disabled", true);
$.ajax(
endpoint,
@@ -113,22 +114,24 @@ function fetch_search_results(job_id, success, error=default_error_fn) {
function search_phenotypes() {
query = document.getElementById("txt-query").value;
selected = JSON.parse(document.getElementById(
- "tbl-link-phenotypes").getAttribute("data-traitss"));
+ "tbl-link-phenotypes").getAttribute("data-traits"));
species_name = document.getElementById("txt-species-name").value
per_page = document.getElementById("txt-per-page").value
search_table = new TableDataSource(
"#tbl-phenotypes", "data-traits", search_checkbox);
+ endpoint = "/oauth2/data/phenotype/search"
$.ajax(
- "/oauth2/data/search",
+ endpoint,
{
- "method": "GET",
+ "method": "POST",
"contentType": "application/json; charset=utf-8",
"dataType": "json",
"data": JSON.stringify({
"query": query,
"species_name": species_name,
"dataset_type": "phenotype",
- "per_page": per_page
+ "per_page": per_page,
+ "selected_traits": selected
}),
"error": default_error_fn,
"success": (data, textStatus, jqXHR) => {
diff --git a/wqflask/wqflask/templates/oauth2/data-list-phenotype.html b/wqflask/wqflask/templates/oauth2/data-list-phenotype.html
index 9838a38d..8329e023 100644
--- a/wqflask/wqflask/templates/oauth2/data-list-phenotype.html
+++ b/wqflask/wqflask/templates/oauth2/data-list-phenotype.html
@@ -110,7 +110,7 @@
<form id="frm-search-traits"
action="#"
method="POST"
- data-search-results-endpoint="{{results_endpoint}}">
+ data-gn-server-url="{{gn_server_url}}">
{%if dataset_type == "mrna"%}
<legend>mRNA: Search</legend>
{%else%}