about summary refs log tree commit diff
path: root/uploader/templates
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-03-18 13:11:41 -0500
committerFrederick Muriuki Muriithi2025-03-18 13:11:41 -0500
commita675d462d2771f9e6c497c2385c985c2a6bb8806 (patch)
treecbeb1e7a1f341840565b472c076e051e870d46df /uploader/templates
parenta4b32dee1b1b638ab60c56df27ace221d6a77c3a (diff)
downloadgn-uploader-a675d462d2771f9e6c497c2385c985c2a6bb8806.tar.gz
Enable downloading of dataset's phenotype's data.
Diffstat (limited to 'uploader/templates')
-rw-r--r--uploader/templates/phenotypes/view-dataset.html45
1 files changed, 44 insertions, 1 deletions
diff --git a/uploader/templates/phenotypes/view-dataset.html b/uploader/templates/phenotypes/view-dataset.html
index 10fd428..fa1044b 100644
--- a/uploader/templates/phenotypes/view-dataset.html
+++ b/uploader/templates/phenotypes/view-dataset.html
@@ -89,7 +89,12 @@
 {%block javascript%}
 <script type="text/javascript">
   $(function() {
+      var species_id = {{species.SpeciesId}};
+      var population_id = {{population.Id}};
+      var dataset_id = {{dataset.Id}};
+      var dataset_name = "{{dataset.Name}}";
       var data = {{phenotypes | tojson}};
+
       var dtPhenotypesList = buildDataTable(
           "#tbl-phenotypes-list",
           data,
@@ -143,7 +148,45 @@
                           {
                               text: "Bulk Edit (Download Data)",
                               action: (event, dt, node, config) => {
-                                  alert("Not implemented yet!");
+                                  var phenoids = [];
+                                  var selected = dt.rows({selected: true, page: "all"}).data();
+                                  for(var idx = 0; idx < selected.length; idx++) {
+                                      phenoids.push({
+                                          phenotype_id: selected[idx].Id,
+                                          xref_id: selected[idx].xref_id
+                                      });
+                                  }
+                                  if(phenoids.length == 0) {
+                                      alert("No record selected. Nothing to do!");
+                                      return false;
+                                  }
+                                  $.ajax(
+                                      (`/species/${species_id}/populations/` +
+                                       `${population_id}/phenotypes/datasets/` +
+                                       `${dataset_id}/download`),
+                                      {
+                                          method: "POST",
+                                          data: JSON.stringify(phenoids),
+                                          xhrFields: {
+                                              responseType: "blob"
+                                          },
+                                          success: (data, textStatus, jqXHR) => {
+                                              var link = document.createElement("a");
+                                              uri = window.URL.createObjectURL(data);
+                                              link.href = uri;
+                                              link.download = `${dataset_name}_data.tsv`;
+
+                                              document.body.appendChild(link);
+                                              link.click();
+                                              window.URL.revokeObjectURL(uri);
+                                              link.remove();
+                                          },
+                                          error: (jQXHR, textStatus, errorThrown) => {
+                                              console.log("Experienced an error: ", textStatus);
+                                              console.log("The ERROR: ", errorThrown);
+                                          },
+                                          contentType: "application/json"
+                                      });
                               },
                               className: "btn btn-info",
                               titleAttr: "Click to download data for editing."