From 41dad95e13fc18532a139a6dfb3d16eb72362403 Mon Sep 17 00:00:00 2001 From: bellerbrock Date: Wed, 21 Sep 2022 12:08:07 -0400 Subject: [PATCH] add openWindowWithPost function and convert wizard downloads from GET to POST --- js/source/modules/wizard-downloads.js | 110 ++++++++++++++++++++++++++++------ 1 file changed, 93 insertions(+), 17 deletions(-) diff --git a/js/source/modules/wizard-downloads.js b/js/source/modules/wizard-downloads.js index 2e87c211c..55cf28682 100644 --- a/js/source/modules/wizard-downloads.js +++ b/js/source/modules/wizard-downloads.js @@ -10,6 +10,27 @@ import "../legacy/CXGN/Dataset.js"; * @param {type} wizard wizard to link to * @returns {Object} */ + +function openWindowWithPost(url, data) { + var form = document.createElement("form"); + form.target = "_blank"; + form.method = "POST"; + form.action = url; + form.style.display = "none"; + + for (var key in data) { + var input = document.createElement("input"); + input.type = "hidden"; + input.name = key; + input.value = data[key]; + form.appendChild(input); + } + + document.body.appendChild(form); + form.submit(); + document.body.removeChild(form); +} + export function WizardDownloads(main_id,wizard){ var main = d3.select(main_id); var datasets = new CXGN.Dataset(); @@ -57,8 +78,21 @@ export function WizardDownloads(main_id,wizard){ d3.select(this).attr("disabled",null); return; } - var url = document.location.origin+`/breeders/download_gbs_action/?ids=${accession_ids.join(",")}&protocol_id=${protocol_id}&format=accession_ids&chromosome_number=${chromosome_number}&start_position=${start_position}&end_position=${end_position}&trial_ids=${trial_ids.join(",")}&download_format=${download_format}&compute_from_parents=${compute_from_parents}&marker_set_list_id=${marker_set_list_id}&include_duplicate_genotypes=${include_duplicate_genotypes}`; - window.open(url,'_blank'); + var url = document.location.origin+'/breeders/download_gbs_action'; + openWindowWithPost(url, { + ids: accession_ids.join(","), + protocol_id: protocol_id, + format: accession_ids, + chromosome_number: chromosome_number, + start_position: start_position, + end_position: end_position, + trial_ids: trial_ids.join(","), + download_format: download_format, + compute_from_parents: compute_from_parents, + marker_set_list_id: marker_set_list_id, + include_duplicate_genotypes: include_duplicate_genotypes, + }); + // window.open(url,'_blank'); }); main.selectAll(".wizard-download-genetic-relationship-matrix") .attr("disabled",!!accessions.length&&protocols.length<=1?null:true) @@ -72,8 +106,19 @@ export function WizardDownloads(main_id,wizard){ var marker_filter = d3.select(".wizard-download-genotypes-grm-marker-filter").node().value; var individuals_filter = d3.select(".wizard-download-genotypes-grm-individuals-filter").node().value; var compute_from_parents = d3.select(".wizard-download-genotypes-parents-compute").property("checked"); - var url = document.location.origin+`/breeders/download_grm_action/?ids=${accession_ids.join(",")}&protocol_id=${protocol_id}&format=accession_ids&trial_ids=${trial_ids.join(",")}&download_format=${download_format}&compute_from_parents=${compute_from_parents}&minor_allele_frequency=${maf}&marker_filter=${marker_filter}&individuals_filter=${individuals_filter}`; - window.open(url,'_blank'); + var url = document.location.origin+'/breeders/download_grm_action'; + openWindowWithPost(url, { + ids: accession_ids.join(","), + protocol_id: protocol_id, + format: accession_ids, + trial_ids: trial_ids.join(","), + download_format: download_format, + compute_from_parents: compute_from_parents, + minor_allele_frequency: maf, + marker_filter: marker_filter, + individuals_filter: individuals_filter, + }); + // window.open(url,'_blank'); }); main.selectAll(".wizard-download-gwas") .attr("disabled",!!traits.length&&accessions.length&&protocols.length<=1?null:true) @@ -88,8 +133,20 @@ export function WizardDownloads(main_id,wizard){ var download_format = d3.select(".wizard-download-genotypes-gwas-format").node().value; var repeated_measurements = d3.select(".wizard-download-genotypes-gwas-repeated-measurements").node().value; var compute_from_parents = d3.select(".wizard-download-genotypes-parents-compute").property("checked"); - var url = document.location.origin+`/breeders/download_gwas_action/?ids=${accession_ids.join(",")}&protocol_id=${protocol_id}&format=accession_ids&trait_ids=${trait_ids.join(",")}&compute_from_parents=${compute_from_parents}&minor_allele_frequency=${maf}&marker_filter=${marker_filter}&individuals_filter=${individuals_filter}&download_format=${download_format}&traits_are_repeated_measurements=${repeated_measurements}`; - window.open(url,'_blank'); + var url = document.location.origin+'/breeders/download_gwas_action'; + openWindowWithPost(url, { + ids: accession_ids.join(","), + protocol_id: protocol_id, + format: accession_ids, + trait_ids: trait_ids.join(","), + compute_from_parents: compute_from_parents, + minor_allele_frequency: maf, + marker_filter: marker_filter, + individuals_filter: individuals_filter, + download_format: download_format, + traits_are_repeated_measurements: repeated_measurements, + }); + // window.open(url,'_blank'); }); // Download Trial Metadata var trials = categories.indexOf("trials")!=-1 ? selections["trials"] : []; @@ -100,8 +157,13 @@ export function WizardDownloads(main_id,wizard){ .on("click",()=>{ var t_ids = JSON.stringify(trials.map(d=>d.id)); var format = d3.select(".wizard-download-tmetadata-format").node().value; - var url = document.location.origin+`/breeders/trials/phenotype/download?trial_list=${t_ids}&format=${format}&dataLevel=metadata`; - window.open(url,'_blank'); + var url = document.location.origin+'/breeders/trials/phenotype/download'; + openWindowWithPost(url, { + trial_list: t_ids, + format: format, + dataLevel: 'metadata' + }); + // window.open(url,'_blank'); }); // Download Trial Phenotypes @@ -138,15 +200,29 @@ export function WizardDownloads(main_id,wizard){ var min = d3.select(".wizard-download-phenotypes-min").node().value; var max = d3.select(".wizard-download-phenotypes-max").node().value; - var url = document.location.origin+ - `/breeders/trials/phenotype/download?trial_list=${trial_ids}`+ - `&speed=${speed}&format=${format}&trait_list=${trait_ids}&trait_component_list=${comp_ids}`+ - `&accession_list=${accession_ids}&plot_list=${plot_ids}&plant_list=${plant_ids}&location_list=${location_ids}`+ - `&year_list=${year_ids}&dataLevel=${level}&phenotype_min_value=${min}&phenotype_max_value=${max}`+ - `×tamp=${timestamp}&entry_numbers=${entry_numbers}&trait_contains=${names}`+ - `&include_row_and_column_numbers=1&exclude_phenotype_outlier=${outliers}`+ - `&include_pedigree_parents=0`; - window.open(url,'_blank'); + var url = document.location.origin+'/breeders/trials/phenotype/download'; + openWindowWithPost(url, { + trial_list: trial_ids, + speed: speed, + format: format, + trait_list: trait_ids, + trait_component_list: comp_ids, + accession_list: accession_ids, + plot_list: plot_ids, + plant_list: plant_ids, + location_list: location_ids, + year_list: year_ids, + dataLevel: level, + phenotype_min_value: min, + phenotype_max_value: max, + timestamp: timestamp, + entry_numbers: entry_numbers, + trait_contains: names, + include_row_and_column_numbers: 1, + exclude_phenotype_outlier: outliers, + include_pedigree_parents: 0, + }); + // window.open(url,'_blank'); }); }); -- 2.11.4.GIT