aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-04-06 04:13:26 +0300
committerFrederick Muriuki Muriithi2023-04-06 04:13:26 +0300
commit52340397fc263b5c629b53147fce4d3927a1e62f (patch)
tree3af3d7b49ad227e9005a1490ba5bba202f7754a1
parenta8af2d89b380da71b8df658ff60178fe51288bb2 (diff)
downloadgenenetwork2-52340397fc263b5c629b53147fce4d3927a1e62f.tar.gz
oauth2: UI - Enable auto-selection of datasets to be linked
When a user selects a dataset in the search table, automatically add it to the link table and remove it from the search table.
-rw-r--r--wqflask/wqflask/templates/oauth2/data-list-genotype.html81
1 files changed, 79 insertions, 2 deletions
diff --git a/wqflask/wqflask/templates/oauth2/data-list-genotype.html b/wqflask/wqflask/templates/oauth2/data-list-genotype.html
index fd39a86a..3ef810ec 100644
--- a/wqflask/wqflask/templates/oauth2/data-list-genotype.html
+++ b/wqflask/wqflask/templates/oauth2/data-list-genotype.html
@@ -152,6 +152,75 @@
{%block js%}
<script language="javascript" type="text/javascript">
+ function link_checkbox(dataset) {
+ cell = $("<td>");
+ check = $('<input type="checkbox" class="checkbox checkbox-selected" ' +
+ 'name="selected_datasets" checked="checked">');
+ check.val(JSON.stringify(dataset));
+ cell.append(check);
+ return cell;
+ }
+
+ function table_cell(value) {
+ cell = $("<td>");
+ cell.html(value);
+ return cell;
+ }
+
+ function render_table(table_id, data_attr_name) {
+ $(table_id + " tbody tr").remove();
+ table_data = JSON.parse($(table_id).attr(data_attr_name));
+ if(table_data.length < 1) {
+ row = $("<tr>")
+ cell = $('<td colspan="100%" align="center">');
+ cell.append(
+ $('<span class="glyphicon glyphicon-info-sign text-info">'));
+ cell.append("&nbsp;");
+ cell.append("No genotype datasets remaining.");
+ row.append(cell);
+ $(table_id + " tbody").append(row);
+ }
+ table_data.forEach(function(dataset) {
+ row = $("<tr>")
+ row.append(link_checkbox(dataset));
+ row.append(table_cell(dataset.InbredSetName));
+ row.append(table_cell(dataset.dataset_name));
+ row.append(table_cell(dataset.dataset_fullname));
+ row.append(table_cell(dataset.dataset_shortname));
+ $(table_id + " tbody").append(row);
+ });
+ }
+
+ function in_array(dataset, datasets) {
+ found = datasets.filter(function(dst) {
+ return (dst.SpeciesId == dataset.SpeciesId &&
+ dst.InbredSetId == dataset.InbredSetId &&
+ dst.GenoFreezeId == dataset.GenoFreezeId);
+ });
+ return found.length > 0;
+ }
+
+ function remove_from_table_data(dataset, table_id, data_attr_name) {
+ without_dataset = JSON.parse($(table_id).attr(data_attr_name)).filter(
+ function(dst) {
+ return !(dst.SpeciesId == dataset.SpeciesId &&
+ dst.InbredSetId == dataset.InbredSetId &&
+ dst.GenoFreezeId == dataset.GenoFreezeId);
+ });
+ $(table_id).attr(data_attr_name, JSON.stringify(without_dataset));
+ }
+
+ 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;
+ if(num_groups > 0 && num_selected > 0) {
+ $("#frm-link-genotypes input[type='submit']").prop("disabled", false);
+ } else {
+ $("#frm-link-genotypes input[type='submit']").prop("disabled", true);
+ }
+ }
+
$(document).ready(function() {
$("#frm-search-traits").submit(function(event) {
event.preventDefault();
@@ -163,11 +232,19 @@
selected = JSON.parse(
$("#tbl-link-genotypes").attr("data-selected-datasets"));
this_item = JSON.parse(this.value);
- selected.push(this_item);
+ if(!in_array(this_item, selected)) {
+ selected.push(this_item);
+ }
$("#tbl-link-genotypes").attr(
- "data-selected-datasets", JSON.stringify(selected));
+ "data-selected-datasets",
+ JSON.stringify(Array.from(selected)));
/* Remove from source table */
+ remove_from_table_data(
+ this_item, "#tbl-genotypes", "data-datasets");
/* Re-render tables */
+ render_table("#tbl-link-genotypes", "data-selected-datasets");
+ render_table("#tbl-genotypes", "data-datasets");
+ toggle_link_button();
}
});
});