From bfe557dc1e537dc78a82a30817ecf2ca3004d978 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 19 Apr 2023 11:29:19 +0300 Subject: oauth2: phenotypes: Enable search from user input. --- wqflask/wqflask/oauth2/data.py | 21 +++++++++++++++++++++ .../static/new/javascript/auth/search_phenotypes.js | 13 ++++++++----- .../templates/oauth2/data-list-phenotype.html | 2 +- 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("///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 @@
+ data-gn-server-url="{{gn_server_url}}"> {%if dataset_type == "mrna"%} mRNA: Search {%else%} -- cgit v1.2.3