fix test with new description field.
[sgn.git] / mason / breeders_toolbox / download.mas
blobc6269121bd855bef680efd75e7da2356dbdd707c
1 <%args>
2 $seedlot_maintenance_enabled => 0
3 </%args>
5 <& /util/import_javascript.mas, classes => [ 'jqueryui', 'jquery.cookie', 'CXGN.BreederSearch', 'CXGN.List', 'CXGN.BreedersToolbox.HTMLSelect', 'spin_min', 'ladda_min' ] &>
7 <& /page/page_title.mas, title=>"Download Using Lists" &>
9 <div class="container-fluid">
11 <div class="well">
12 Choose a list for each parameter and click "Download".
13 </div>
15 <div class="well well-sm">
16 <h4>Download Phenotypes Using Lists</h4><p>Select Parameters:</p>
17 <form id="download_form" action="/breeders/download_action" method="POST" >
18 <table class="table table-bordered" >
19   <thead>
20   <tr>
21     <th>
22       Accessions
23     </th>
24     <th>
25       Trials
26     </th>
27     <th>
28       Traits
29     </th>
30     <th>
31         Options
32     </th>
33     <th>
34       Action
35     </th>
36   </tr>
37   </thead>
38   <tbody>
39   <tr>
40     <td>
41       <div id="accession_list">
42       </div>
43     </td>
44     <td>
45       <div id="trial_list">
46       </div>
47     </td>
48     <td>
49       <div id="trait_list">
50       </div>
51    </td>
52     <td>
53     <b>Format:</b><br/>
54     <select class="form-control" id="format" name="format">
55         <option value=".csv">CSV</option>
56         <option value=".xlsx">XLSX</option>
57         <option value="html">HTML</option>
58     </select>
59     <br/>
60     <b>Data Level:</b><br/>
61     <select class="form-control" id="phenotype_datalevel" name="phenotype_datalevel">
62         <option value="all">All</option>
63         <option value="plot">Plot</option>
64         <option value="plant">Plant</option>
65     </select>
66     <br/>
67     <b>Timestamp:</b><br/>
68     <select class="form-control" id="timestamp" name="timestamp">
69         <option value="0">No</option>
70         <option value="1">Yes</option>
71     </select>
72     <br/>
73     <b>Exclude Phenotype Outliers:</b><br/>
74     <select class="form-control" id="exclude_phenotype_outlier" name="exclude_phenotype_outlier">
75         <option value="0">No</option>
76         <option value="1">Yes</option>
77     </select>
78     </td>
79     <td>
80       <button class="btn btn-primary" type="button" id="phenotype">Download</button>
81       <input type="hidden" id="phenotype_download_token" name="phenotype_download_token"/>
82     </td>
83   </tr>
84   </tbody>
85   </table>
86 </form>
87 </div>
89 <div class="well well-sm">
90 <h4>Inspect Datasets</h4>
91 <table class="table table-bordered" >
92   <thead>
93   <tr>
94     <th>
95       Datasets
96     </th>
97   </tr>
98   </thead>
99   <tbody>
100   <tr>
101     <td>
102       <div id="phenotype_download_dataset_list">
103       </div>
104     </td>
105   </tr>
106   </tbody>
107   </table>
108 </div>
110 <div class="well well-sm">
111 <h4>Download Metadata</h4><p>Select Parameters:</p>
112 <form id="download_metadata_form" action="/breeders/download_action" method="POST" >
113 <table class="table table-bordered" >
114   <thead>
115   <tr>
116     <th>
117       Trials
118     </th>
119     <th>
120         Options
121     </th>
122     <th>
123       Action
124     </th>
125   </tr>
126   </thead>
127   <tbody>
128   <tr>
129     <td>
130       <div id="trial_metadata_list">
131       </div>
132     </td>
133     <td>
134     <b>Format:</b><br/>
135     <select class="form-control" id="metadata_format" name="metadata_format">
136         <option value=".xlsx">XLSX</option>
137         <option value=".csv">CSV</option>
138         <option value="html">HTML</option>
139     </select>
140     <br/>
141     <div id="datalevel" style="display:none">
142       <select class="form-control" id="metadata_datalevel" name="metadata_datalevel">
143           <option value="metadata">Metadata</option>
144       </select>
145     </div>
146     </td>
147     <td>
148       <button class="btn btn-primary" type="button" id="metadata">Download</button>
149       <input type="hidden" id="metadata_download_token" name="metadata_download_token"/>
150     </td>
151   </tr>
152   </tbody>
153   </table>
154 </form>
155 </div>
157 <script>
158 $(document).ready(function() {
160     var lo = new CXGN.List();
162     $('#accession_list').html(lo.listSelect('accession_list', [ 'accessions' ], 'select', undefined, undefined));
163     $('#trial_list').html(lo.listSelect('trial_list', [ 'trials' ], 'select', undefined, undefined ));
164     $('#trait_list').html(lo.listSelect('trait_list', [ 'traits' ], 'select', undefined, undefined  ));
165     $('#trial_metadata_list').html(lo.listSelect('trial_metadata_list', ['trials'], 'select', undefined, undefined));
167     get_select_box('datasets', 'phenotype_download_dataset_list');
169     $('#metadata').click(function() { 
170       var trial_list_id = $('#trial_metadata_list_list_select').val();
171       var trial_validation = 1;
172       if (trial_list_id) { trial_validation = lo.validate(trial_list_id, 'trials', true).then( 
173          function(r) {
174             if (r.missing.length != 0) {
175                alert("The following lists did not pass validation: "+r.missing.join(", ")+". Please correct the list(s) and try again");
176             }
177             else {
178                
180 //      var ladda = Ladda.create(this);
181 //      ladda.start();
182 //      var token = new Date().getTime(); //use the current timestamp as the token name and value
183 //      manage_dl_with_cookie(token, ladda);
184 //      jQuery('#metadata_download_token').val(token);
185                jQuery('#download_metadata_form').submit();
186             }
187         });
188       } });
190     $('#phenotype').click(function() {
192       var accession_list_id = $('#accession_list_list_select').val();
193       var trial_list_id = $('#trial_list_list_select').val();
194       var trait_list_id = $('#trait_list_list_select').val();
196       var lists = new Array();
197       var types = new Array();
199       if (accession_list_id) {
200          lists.push(accession_list_id);
201          types.push('accessions');
202          //alert("ACC LIST ID = "+accession_list_id);
203       }
204       if (trial_list_id) {
205           lists.push(trial_list_id);
206           types.push('trials');
207       }
209       if (trait_list_id) {
210           lists.push(trait_list_id);
211           types.push('traits');
212       }
214       jQuery('#working_modal').modal('show');
216       validateLists(lists, types).then(function(r) {
217          console.log('validation results: '+JSON.stringify(r));
218          var names_str = '';
219          for (var n=0; n < r.invalid_lists.length; n++) {
220             names_str += r.invalid_lists[n][1];
221          }
222          if(names_str.length > 0) {
223             alert('Some lists ('+names_str+') are not valid, please check.');
224             jQuery('#working_modal').modal('hide');
225          }
226          else { 
227             download_phenotypes(this);
228             jQuery('#working_modal').modal('hide');
229          
230          }},
231     
232          function(e) { alert(e);     jQuery('#working_modal').modal('hide');
234          );
236       });
238         
239       
241 //alert("The following lists did not pass validation: "+problem_lists.join(", ")+". Please correct the list(s) and try again");
242 //       return;
243 //      
244   
249 function download_phenotypes() {
250     //alert("NOW DOWNLOADING!");
251     //var ladda = Ladda.create(data);
252      // ladda.start();
253       var token = new Date().getTime(); //use the current timestamp as the token name and value
254      // manage_dl_with_cookie(token, ladda);
255       jQuery('#phenotype_download_token').val(token);
256       jQuery('#download_form').submit();
261 </script>
265 <!-- DOWNLOAD ACCESSION PROPERTIES -->
267 <div class="well well-sm">
268   <form id="download_accession_properties" action="/breeders/download_accession_properties_action" method="POST">
269     <table class="table"  cellpadding="10">
270       <thead>
271         <tr><td colspan="2"><h4>Download Accession Properties</h4><p>Select parameters:</p></tr>
272         <tr>
273           <th>Accessions</th>
274           <th>Format</th>
275           <th>Action</th>
276         </tr>
277       </thead>
278       <tbody>
279       <tr>
280         <td>
281           <div id="accession_list5"></div>
282         </td>
283         <td>
284           <select class="form-control" id="accession_properties_format" name="file_format">
285               <option value=".xlsx">XLSX</option>
286               <option value=".csv">CSV</option>
287           </select>
288         </td>
289         <td>
290           <button class="btn btn-primary" type="button" id="accession_properties_download">Download</button>
291           <input type="hidden" id="accession_properties_download_token" name="accession_properties_download_token"/>
292         </td>
293       </tr>
294       </tbody>
295   </table>
296 </form>
297 </div>
300 <script>
301 $(document).ready(function() {
303     var lo = new CXGN.List();
305     $('#accession_list5').html(lo.listSelect('accession_properties_accession_list', [ 'accessions' ], 'select', undefined, undefined));
307     $('#accession_properties_download').click(function() {
309         var accession_list_id = $('#accession_properties_accession_list_list_select').val();
310         if (!accession_list_id) {
311             alert("You need to select an accession list!");
312             return;
313         }
316         if (accession_list_id) {
317               jQuery('#working_modal').modal('show');
318               lo.validate(accession_list_id, 'accessions', true).then(
319               function(r) {
320                  if (r.valid != 1) { 
321                     alert("The accession list did not pass validation. Please correct the list and try again");
322                     jQuery('#working_modal').modal('hide');
323                  }
324                  else { 
325                     //var ladda = Ladda.create(this);
326                     //ladda.start();
327                     //var token = new Date().getTime(); //use the current timestamp as the token name and value
328                     //manage_dl_with_cookie(token, ladda);
329                     //jQuery('#accession_properties_download_token').val(token);
330                     jQuery('#download_accession_properties').submit();
331                     jQuery('#working_modal').modal('hide');
332                 }
333             });
334         }
335     });
338 </script>
340 <!-- END OF DOWNLOAD ACCESSION PROPERTIES -->
346 <!-- start of code for pedigree download -->
348 <div class="well well-sm">
349 <form id="download_pedigree" action="/breeders/download_pedigree_action" method="POST">
350 <table class="table"  cellpadding="10">
351   <thead>
352   <tr><td colspan="2"><h4>Download Pedigrees </h4><p>Select parameter:</p></tr>
353   <tr>
354     <th>
355       Accessions
356     </th>
357     <th>
358       Query
359     </th>
360     <th>
361       Format
362     </th>
363     <th>
364       Action
365     </th>
366   </tr>
367   </thead>
368   <tbody>
369   <tr>
370     <td>
371       <div id="accession_list4">
372       </div>
373     </td>
374     <td>
375       <div style="width: 175px">
376         <p><strong>Depth:</strong></p>
377         <div class="radio">
378           <label><input type="radio" id="ped_format_parents" name="ped_format" value="parents_only" checked>Only One Generation</label>
379         </div>
380         <div class="radio">
381           <label><input type="radio" id="ped_format_full" name="ped_format" value="full">All Generations</label>
382         </div>
383         <p><strong>Include:</strong></p>
384         <div class="radio">
385           <label><input type="radio" id="include_ancestors" name="ped_include" value="ancestors" checked>Only Ancestors</label>
386         </div>
387         <div class="radio">
388           <label><input type="radio" id="include_ancestors_descendants" name="ped_include" value="ancestors_descendants">Ancestors and Descendants</label>
389         </div>
390       </div>
391     </td>
392     <td>
393       <select class="form-control" id="pedigree_file_format" name="file_format">
394         <option value=".txt">Plain Text</option>
395         <option value=".helium">Helium Format</option>
396       </select>
397     </td>
398     <td>
399       <button class="btn btn-primary" type="button" id="pedigree">Download</button>
400       <input type="hidden" id="pedigree_download_token" name="pedigree_download_token"/>
401     </td>
402   </tr>
403   </tbody>
404   </table>
405 </form>
406 </div>
409 <script>
410 $(document).ready(function() {
412     var lo = new CXGN.List();
414     $('#accession_list4').html(lo.listSelect('pedigree_accession_list', [ 'accessions' ], 'select', undefined, undefined));
416     $('#pedigree').click(function() {
418         var accession_list_id = $('#pedigree_accession_list_list_select').val();
419         if (!accession_list_id) {
420             alert("You need to select an accession list!");
421             return;
422         }
424         if (accession_list_id) {
425            accession_validation = lo.validate(accession_list_id, 'accessions', true).then(
426              function(r) { 
427                  if(r.valid != 1) {
428                    alert("The accession list did not pass validation. Please correct the list and try again");
429                  }
430                  else { 
431                     //var ladda = Ladda.create(this);
432                     //ladda.start();
433                     //var token = new Date().getTime(); //use the current timestamp as the token name and value
434                     //manage_dl_with_cookie(token, ladda);
435                     //jQuery('#pedigree_download_token').val(token);
436                     jQuery('#working_modal').modal('show');
437                     var http = new XMLHttpRequest();
438                     http.open('POST', '/breeders/download_pedigree_action', true);
439                     http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
440                     http.onreadystatechange = () => {
441                       if( http.readyState == 4 ) {
442                         jQuery('#working_modal').modal('hide');
443                         if ( http.status == 200) {
444                           var blob = new Blob([http.response], { type : 'plain/text' });
445                           var fileName = http.getResponseHeader("FileName");
446                           var link = document.createElement('a');
447                           link.href = window.URL.createObjectURL(blob);
448                           link.download = fileName;
449                           link.click();
450                         }
451                       }
452                     }
453                     http.send(jQuery("#download_pedigree").serialize());
454                  }
455              });
456         } });
459 </script>
461 <!-- end of code for pedigree download -->
465 <!-- start of code for download seedlot matinenance events -->
467 % if ( $seedlot_maintenance_enabled ) {
469 <div class="well well-sm">
470   <form id="download_seedlot_maintenance_events" action="/breeders/download_seedlot_maintenance_events_action" method="POST">
471       <table class="table"  cellpadding="10">
472         <thead>
473           <tr><td colspan="2"><h4>Download Seedlot Maintenance Events</h4><p>Select parameters:</p></tr>
474           <tr>
475             <th>Seedlots</th>
476             <th>Format</th>
477             <th>Action</th>
478           </tr>
479         </thead>
480         <tbody>
481         <tr>
482           <td>
483             <div id="seedlot_list1"></div>
484           </td>
485           <td>
486             <select class="form-control" id="seedlot_maintenance_events_format" name="file_format">
487                 <option value=".xlsx">XLSX</option>
488             </select>
489           </td>
490           <td>
491             <button class="btn btn-primary" type="button" id="seedlot_maintenance_events_download">Download</button>
492             <input type="hidden" id="seedlot_maintenance_events_download_token" name="seedlot_maintenance_events_download_token"/>
493           </td>
494         </tr>
495         </tbody>
496     </table>
497   </form>
498 </div>
500 <script>
501 $(document).ready(function() {
503     var lo = new CXGN.List();
505     $('#seedlot_list1').html(lo.listSelect('seedlot_maintenance_events_list', [ 'seedlots' ], 'select', undefined, undefined));
507     $('#seedlot_maintenance_events_download').click(function() {
509         var seedlot_list_id = $('#seedlot_maintenance_events_list_list_select').val();
510         if (!seedlot_list_id) {
511             alert("You need to select a seedlot list!");
512             return;
513         }
515         var seedlot_validation = 1;
516         if (seedlot_list_id) {
517             seedlot_validation = lo.validate(seedlot_list_id, 'seedlots', true);
518         }
520         if (seedlot_validation != 1) {
521             alert("The seedlot list did not pass validation. Please correct the list and try again");
522             return;
523         }
525         var ladda = Ladda.create(this);
526         ladda.start();
527         var token = new Date().getTime(); //use the current timestamp as the token name and value
528         manage_dl_with_cookie(token, ladda);
529         jQuery('#seedlot_maintenance_events_download_token').val(token);
530         jQuery('#download_seedlot_maintenance_events').submit();
532     });
535 </script>
537 % }
539 <!-- end of code for seedlot maintenance event download -->
542 <div class="well well-sm">
543 <form id="download_gbs" action="/breeders/download_gbs_action" method="POST">
544 <table class="table"  cellpadding="10">
545   <thead>
546   <tr><td colspan="2"><h4>Download Genotypes </h4><p>Select parameter:</p></tr>
547   <tr>
548     <th>
549       Accessions
550     </th>
551     <th>
552       Genotyping Protocol
553     </th>
554     <th>
555       Action
556     </th>
557   </tr>
558   </thead>
559   <tbody>
560   <tr>
561     <td>
562       <div id="accession_list2">
563       </div>
564     </td>
565     <td>
566       <div id="protocol_list">
567       </div>
568     </td>
569     <td>
570       <button class="btn btn-primary" type="button" id="genotype">Download</button>
571       <input type="hidden" id="gbs_download_token" name="gbs_download_token"/>
572     </td>
573   </tr>
574   </tbody>
575   </table>
576 </form>
577 </div>
579 <script>
580   $(document).ready(function() {
582       var lo = new CXGN.List();
584       $('#accession_list2').html(lo.listSelect('genotype_accession_list', [ 'accessions' ], 'select', undefined, undefined));
585       get_select_box("genotyping_protocol", "protocol_list");
587       $('#genotype').click(function() {
589       var accession_list_id = $('#genotype_accession_list_list_select').val();
590       var protocol_list_id = $('#protocol_list').val();
592       var accession_validation = 1;
593       if (accession_list_id) {
594   accession_validation = lo.validate(accession_list_id, 'accessions', true).then(
595      function(r) { 
596          if (!( accession_list_id || protocol_list_id) ) {
597              alert("You need to select a list of accessions and a protocol !");
598          }
599          else if(r.valid != 1)  { 
600              alert("The accession list could not be validated. Please correct the list(s) and try again");
601          }
602   else  {
603   
605       //var ladda = Ladda.create(this);
606       //ladda.start();
607       //var token = new Date().getTime(); //use the current timestamp as the token name and value
608       //manage_dl_with_cookie(token, ladda);
609       //jQuery('#gbs_download_token').val(token);
610       jQuery('#download_gbs').submit();
611    }
612   }, function(e) { alert('An error occurred.'); });
613   }
615   });
616   });
617 </script>
619 <div class="well well-sm">
620 <form id="gbs_qc" action="/breeders/gbs_qc_action" method="POST">
621 <table class="table" cellpadding="10">
622   <thead>
623   <tr><td colspan="3"><h4>Genotyping QC</h4><p>Select parameter:</p></tr>
624   <tr>
625     <th>
626       Trials
627     </th>
628     <th>
629       Accessions
630     </th>
631     <th>
632       Genotyping Protocol
633     </th>
634     <th>
635       Action
636     </th>
637   </tr>
638   </thead>
639   <tbody>
640   <tr>
641     <td>
642       <div id="trial_list3">
643       </div>
644     </td>
645     <td>
646       <div id="accession_list3">
647       </div>
648     </td>
649     <td>
650       <div id="protocol_list2">
651       </div>
652     </td>
653     <td>
654       <button class="btn btn-primary" type="button" id="genotype_qc">Download</button>
655       <input type="hidden" id="qc_download_token" name="qc_download_token"/>
656     </td>
657   </tr>
658   </tbody>
659   </table>
660 </form>
661 </div>
663 </div>
665 <script>
666   $(document).ready(function() {
668       var lo = new CXGN.List();
670       $('#accession_list3').html(lo.listSelect('genotype_qc_accession_list', [ 'accessions' ], 'select', undefined, undefined));
671       $('#trial_list3').html(lo.listSelect('genotype_trial_list', [ 'trials' ], 'select', undefined, undefined ));
672       get_select_box("genotyping_protocol", "protocol_list2", {'id':'protocol_list2_select', 'name':'protocol_list2_select'});
674       $('#genotype_qc').click(function() {
676         $('#working').dialog( {
677                 height: 100,
678                 width:  300,
679                 modal: true,
680                 autoOpen: false,
681                 closeOnEscape: true,
682                 draggable: true,
683                 resizable: true,
684                 open: function() { $(this).closest('.ui-dialog').find('.ui-dialog-titlebar-close').hide(); },
685                 title: 'Downloading genotype...'
686                 });
688       var lists = new Array();
689   
690       var accession_list_id = $('#genotype_qc_accession_list_list_select').val();
691       var trial_list_id = $('#genotype_trial_list_list_select').val();
693       
694       if (! (accession_list_id || trial_list_id) ) {
695         alert("You need to select an accession or a trial, or both!");
696         return;
697       }
699       var lists = new Array();
700       var types = new Array();
702   if (accession_list_id) {
703   lists.push(accession_list_id);
704   types.push('accessions');
705   }
707   if(trial_list_id) {
708   lists.push(trial_list_id);
709   types.push('trials');
710   }
712   
713       validateLists(lists, types).then(function(r) {
714          console.log('validation results: '+JSON.stringify(r));
715          var names_str = '';
716          for (var n=0; n < r.invalid_lists.length; n++) {
717             names_str += r.invalid_lists[n][1];
718          }
719          if(names_str.length > 0) {
720             alert('Some lists ('+names_str+') are not valid, please check.');
721             jQuery('#working_modal').modal('hide');
722          }
723          else { 
724            //      var ladda = Ladda.create(this);
725 //         ladda.start();
726 //         var token = new Date().getTime(); //use the current timestamp as the token name and value
727 //          manage_dl_with_cookie(token, ladda);
728 //          jQuery('#qc_download_token').val(token);
729             jQuery('#gbs_qc').submit();
730    
731             jQuery('#working_modal').modal('hide');
732          
733         }
735       });
738     });
740   });
741 </script>