aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wqflask/wqflask/oauth2/data.py71
-rw-r--r--wqflask/wqflask/static/new/javascript/auth/search.js9
-rw-r--r--wqflask/wqflask/static/new/javascript/auth/search_genotypes.js93
-rw-r--r--wqflask/wqflask/static/new/javascript/auth/search_phenotypes.js11
-rw-r--r--wqflask/wqflask/templates/oauth2/data-list-genotype.html20
5 files changed, 152 insertions, 52 deletions
diff --git a/wqflask/wqflask/oauth2/data.py b/wqflask/wqflask/oauth2/data.py
index 8b8f4f20..56ba5cb1 100644
--- a/wqflask/wqflask/oauth2/data.py
+++ b/wqflask/wqflask/oauth2/data.py
@@ -11,6 +11,8 @@ from flask import (
current_app as app)
from jobs import jobs
+
+from . import client
from .ui import render_ui
from .request_utils import process_error
from .client import oauth2_get, oauth2_post
@@ -20,7 +22,7 @@ data = Blueprint("data", __name__)
def __search_mrna__(query, template, **kwargs):
species_name = kwargs["species_name"]
search_uri = urljoin(app.config["GN_SERVER_URL"], "oauth2/data/search")
- datasets = oauth2_get(
+ datasets = client.post(
"oauth2/data/search",
json = {
"query": query,
@@ -41,22 +43,23 @@ def __selected_datasets__():
return request.args.get("selected",
request.form.get("selected", []))
-def __search_genotypes__(query, template, **kwargs):
- species_name = kwargs["species_name"]
- search_uri = urljoin(app.config["GN_SERVER_URL"], "oauth2/data/search")
- datasets = oauth2_get(
- "oauth2/data/search",
- json = {
- "query": query,
- "dataset_type": "genotype",
- "species_name": species_name,
- "selected": __selected_datasets__()
- }).either(
- lambda err: {"datasets_error": process_error(err)},
- lambda datasets: {"datasets": datasets})
- return render_ui(template, search_uri=search_uri, **datasets, **kwargs)
-
-def __search_phenotypes__(query, template, **kwargs):
+# def __search_genotypes__(query, template, **kwargs):
+# species_name = kwargs["species_name"]
+# search_uri = urljoin(app.config["GN_SERVER_URL"], "oauth2/data/search")
+# datasets = oauth2_get(
+# "oauth2/data/search",
+# json = {
+# "query": query,
+# "dataset_type": "genotype",
+# "species_name": species_name,
+# "selected": __selected_datasets__()
+# }).either(
+# lambda err: {"datasets_error": process_error(err)},
+# lambda datasets: {"datasets": datasets})
+# return render_ui(template, search_uri=search_uri, **datasets, **kwargs)
+
+def __search_data_xapian__(query, template, dataset_type, **kwargs):
+ """Search data using xapian search."""
page = int(request.args.get("page", 1))
per_page = int(request.args.get("per_page", 50))
selected_traits = request.form.getlist("selected_traits")
@@ -72,10 +75,10 @@ def __search_phenotypes__(query, template, **kwargs):
gn_server_url = app.config["GN_SERVER_URL"],
results_endpoint=urljoin(
app.config["GN_SERVER_URL"],
- f"oauth2/data/search/phenotype/{job_id}"),
+ f"oauth2/data/search/results/{job_id}"),
**kwargs)
- return oauth2_get("oauth2/data/search", json={
- "dataset_type": "phenotype",
+ return client.post("oauth2/data/search", json={
+ "dataset_type": dataset_type,
"species_name": kwargs["species_name"],
"per_page": per_page,
"page": page,
@@ -84,19 +87,37 @@ def __search_phenotypes__(query, template, **kwargs):
lambda err: __search_error__(process_error(err)),
__search_success__)
+def __search_genotypes__(query, template, **kwargs):
+ return __search_data_xapian__(
+ query, template, "genotype", **{
+ key: value for key, value in kwargs.items()
+ if key not in ("dataset_type",)
+ })
+
+def __search_phenotypes__(query, template, **kwargs):
+ return __search_data_xapian__(
+ query, template, "phenotype", **{
+ key: value for key, value in kwargs.items()
+ if key not in ("dataset_type",)
+ })
+
@data.route("/genotype/search", methods=["POST"])
def json_search_genotypes() -> Response:
+ form = request.json
def __handle_error__(err):
error = process_error(err)
return jsonify(error), error["status_code"]
-
- return oauth2_get(
+
+ return client.post(
"oauth2/data/search",
json = {
- "query": request.json["query"],
+ "query": form.get("query", ""),
"dataset_type": "genotype",
- "species_name": request.json["species_name"],
- "selected": __selected_datasets__()
+ "species_name": form["species_name"],
+ "selected_traits": form.get("selected_traits", []),
+ "per_page": int(form.get("per_page", 50)),
+ "page": int(form.get("page", 1)),
+ "gn3_server_uri": app.config["GN_SERVER_URL"]
}).either(
__handle_error__,
lambda datasets: jsonify(datasets))
diff --git a/wqflask/wqflask/static/new/javascript/auth/search.js b/wqflask/wqflask/static/new/javascript/auth/search.js
index d094cebf..299d09c7 100644
--- a/wqflask/wqflask/static/new/javascript/auth/search.js
+++ b/wqflask/wqflask/static/new/javascript/auth/search.js
@@ -170,3 +170,12 @@ function table_cell(value) {
cell.html(value);
return cell;
}
+
+/**
+ * Default error function: print out debug messages
+ */
+function default_error_fn(jqXHR, textStatus, errorThrown) {
+ console.debug("XHR:", jqXHR);
+ console.debug("STATUS:", textStatus);
+ console.debug("ERROR:", errorThrown);
+}
diff --git a/wqflask/wqflask/static/new/javascript/auth/search_genotypes.js b/wqflask/wqflask/static/new/javascript/auth/search_genotypes.js
index 8d571c53..cbdf215c 100644
--- a/wqflask/wqflask/static/new/javascript/auth/search_genotypes.js
+++ b/wqflask/wqflask/static/new/javascript/auth/search_genotypes.js
@@ -1,7 +1,17 @@
+search_table = new TableDataSource(
+ "#tbl-genotypes", "data-traits", (trait) => {
+ return build_checkbox(trait, "search_traits", "checkbox-search");
+ });
+link_table = new TableDataSource(
+ "#tbl-link-genotypes", "data-traits", (trait) => {
+ return build_checkbox(
+ trait, "selected", "checkbox-selected", checked=true);
+ });
+
function toggle_link_button() {
num_groups = $("#frm-link-genotypes select option").length - 1;
num_selected = JSON.parse(
- $("#tbl-link-genotypes").attr("data-selected-datasets")).length;
+ $("#tbl-link-genotypes").attr("data-traits")).length;
if(num_groups > 0 && num_selected > 0) {
$("#frm-link-genotypes input[type='submit']").prop("disabled", false);
} else {
@@ -9,14 +19,61 @@ function toggle_link_button() {
}
}
+function render_geno_table(table_data_source) {
+ table_id = table_data_source.table_id.selector;
+ data_attr_name = table_data_source.data_attribute_name;
+ $(table_id + " tbody tr").remove();
+ table_data = JSON.parse($(table_id).attr(data_attr_name)).sort((t1, t2) => {
+ return (t1.name > t2.name ? 1 : (t1.name < t2.name ? -1 : 0))
+ });
+ console.debug("WOULD RENDER THE TABLE!!!")
+}
+
+function display_search_results(data, textStatus, jqXHR) {
+ if(data.status == "queued" || data.status == "started") {
+ setTimeout(() => {
+ fetch_search_results(data.job_id, display_search_results);
+ }, 250);
+ return;
+ }
+ if(data.status == "completed") {
+ $("#tbl-genotypes").attr(
+ "data-traits", JSON.stringify(data.search_results));
+ console.debug("THE SEARCH RESULTS: ", data.search_results);
+ // Remove this reference to global variable
+ render_geno_table(search_table);
+ }
+ $("#txt-search").prop("disabled", false);
+}
+
+/**
+ * Fetch the search results
+ * @param {UUID}: The job id to fetch data for
+ */
+function fetch_search_results(job_id, success, error=default_error_fn) {
+ host = $("#frm-search").attr("data-gn-server-url");
+ endpoint = host + "oauth2/data/search/results/" + job_id
+ $("#txt-search").prop("disabled", true);
+ $.ajax(
+ endpoint,
+ {
+ "method": "GET",
+ "contentType": "application/json; charset=utf-8",
+ "dataType": "json",
+ "error": error,
+ "success": success
+ }
+ );
+}
+
function search_genotypes() {
query = document.getElementById("txt-query").value;
selected = JSON.parse(document.getElementById(
- "tbl-link-genotypes").getAttribute("data-selected-datasets"));
+ "tbl-link-genotypes").getAttribute("data-traits"));
species_name = document.getElementById("txt-species-name").value
search_endpoint = "/oauth2/data/genotype/search"
search_table = new TableDataSource(
- "#tbl-genotypes", "data-datasets", search_checkbox);
+ "#tbl-genotypes", "data-traits", search_checkbox);
$.ajax(
search_endpoint,
{
@@ -29,6 +86,7 @@ function search_genotypes() {
"dataset_type": "genotype",
"species_name": species_name}),
"error": function(jqXHR, textStatus, errorThrown) {
+ console.debug("**************************************")
data = jqXHR.responseJSON
elt = document.getElementById("search-error").setAttribute(
"style", "display: block;");
@@ -36,18 +94,27 @@ function search_genotypes() {
data.error + " (" + data.status_code + "): " +
data.error_description);
document.getElementById("tbl-genotypes").setAttribute(
- "data-datasets", JSON.stringify([]));
+ "data-traits", JSON.stringify([]));
render_table(search_table);
+ console.debug("**************************************")
},
- "success": function(data, textStatus, jqXHR) {
+ "success": (data, textStatus, jqXHR) => {
+ console.debug("++++++++++++++++++++++++++++++++++++++")
+ fetch_search_results(data.job_id, display_search_results)
+ console.debug("++++++++++++++++++++++++++++++++++++++")
+ }
+ });
+}
+
+/*
+ function(data, textStatus, jqXHR) {
document.getElementById("search-error").setAttribute(
"style", "display: none;");
document.getElementById("tbl-genotypes").setAttribute(
"data-datasets", JSON.stringify(data));
render_table(search_table);
- }
- });
-}
+ }
+*/
/**
* Return function to check whether `dataset` is in array of `datasets`.
@@ -64,9 +131,9 @@ function make_filter(trait) {
$(document).ready(function() {
let search_table = new TableDataSource(
- "#tbl-genotypes", "data-datasets", search_checkbox);
+ "#tbl-genotypes", "data-traits", search_checkbox);
let link_table = new TableDataSource(
- "#tbl-link-genotypes", "data-selected-datasets", link_checkbox);
+ "#tbl-link-genotypes", "data-traits", link_checkbox);
$("#frm-search-traits").submit(function(event) {
event.preventDefault();
@@ -92,4 +159,10 @@ $(document).ready(function() {
toggle_link_button();
}
});
+
+ setTimeout(() => {
+ fetch_search_results(
+ $("#tbl-genotypes").attr("data-initial-job-id"),
+ display_search_results);
+ }, 500);
});
diff --git a/wqflask/wqflask/static/new/javascript/auth/search_phenotypes.js b/wqflask/wqflask/static/new/javascript/auth/search_phenotypes.js
index 556a7467..7efcf851 100644
--- a/wqflask/wqflask/static/new/javascript/auth/search_phenotypes.js
+++ b/wqflask/wqflask/static/new/javascript/auth/search_phenotypes.js
@@ -26,15 +26,6 @@ function toggle_link_button() {
}
/**
- * Default error function: print out debug messages
- */
-function default_error_fn(jqXHR, textStatus, errorThrown) {
- console.debug("XHR:", jqXHR);
- console.debug("STATUS:", textStatus);
- console.debug("ERROR:", errorThrown);
-}
-
-/**
* Render the table(s) for the phenotype traits
* @param {TableDataSource} The table to render
*/
@@ -97,7 +88,7 @@ function display_search_results(data, textStatus, jqXHR) {
*/
function fetch_search_results(job_id, success, error=default_error_fn) {
host = $("#frm-search-traits").attr("data-gn-server-url");
- endpoint = host + "oauth2/data/search/phenotype/" + job_id
+ endpoint = host + "oauth2/data/search/results/" + job_id
$("#txt-search").prop("disabled", true);
$.ajax(
endpoint,
diff --git a/wqflask/wqflask/templates/oauth2/data-list-genotype.html b/wqflask/wqflask/templates/oauth2/data-list-genotype.html
index c780a583..e7854fdb 100644
--- a/wqflask/wqflask/templates/oauth2/data-list-genotype.html
+++ b/wqflask/wqflask/templates/oauth2/data-list-genotype.html
@@ -43,7 +43,7 @@
<div class="form-group">
<table id="tbl-link-genotypes"
class="table-hover table-striped cell-border dataTable no-footer"
- data-selected-datasets='{{selected_datasets | list | tojson}}'>
+ data-traits="[]">
<thead>
<tr>
<th>Deselect</th>
@@ -92,8 +92,9 @@
<div class="row">
<span id="search-messages" class="alert-danger" style="display:none"></span>
<form id="frm-search"
- action="{{search_uri}}"
- method="POST">
+ action="#"
+ method="POST"
+ data-gn-server-url="{{gn_server_url}}">
<legend>Search: Genotype</legend>
<input type="hidden" value="{{species_name}}" name="species"
id="txt-species-name" />
@@ -103,9 +104,12 @@
id="txt-per-page" />
<div class="form-group">
- <label for="txt-query">Dataset Search String</label>
- <input type="text" id="txt-query" name="query" class="form-control"
- value="{{query}}"/>
+ <label for="txt-query">Search</label>
+ <div class="input-group">
+ <span class="input-group-addon">species:{{species_name}} AND </span>
+ <input type="text" id="txt-query" name="query" class="form-control"
+ value="{{query}}"/>
+ </div>
</div>
</form>
</div>
@@ -118,7 +122,9 @@
</div>
<table id="tbl-genotypes"
class="table-hover table-striped cell-border dataTable no-footer"
- data-datasets='{{datasets | list | tojson}}'>
+ data-traits='{{traits | list | tojson}}'
+ data-initial-job-id="{{search_results.job_id}}"
+ data-initial-command-id="{{search_results.command_id}}">
<thead>
<tr>
<th>Select</th>