graphical filtering of accession search
[sgn.git] / mason / brapiclient / phenotyping_handhelds.mas
blob07ee62432fea24d2835182cd37baec77c7c5f56b
1 <%args>
2 </%args>
4 <& /util/import_javascript.mas, classes => [ 'brapi.Table' ] &>
6 <& /page/page_title.mas, title=>"Phenotyping Handhelds" &>
8 <h4>Database Select</h4>
9 <select name="brapi_phenotyping_handhelds_url_select" id="brapi_phenotyping_handhelds_url_select" class="form-control" />
10     <option value="">local</option>
11     <option value="https://cassbase.org">cassbase.org</option>
12     <option value="https://cassavabase.org">cassavabase.org</option>
13     <option value="https://musabase.org">musabase.org</option>
14     <option value="https://sweetpotatobase.org">sweetpotatobase.org</option>
15     <option value="https://yambase.org">yambase.org</option>
16     <option value="https://fernbase.org">fernbase.org</option>
17     <option value="https://solgenomics.net">solgenomics.net</option>
18 </select>
20 <br/><br/>
22 <div id="brapi_phenotyping_handhelds_layout_div" class="well">
24     <h3>Get Trial Layout(s)</h3>
26     <select name="brapi_phenotyping_handhelds_layout_format" id="brapi_phenotyping_handhelds_layout_format" class="form-control" />
27         <option value="json">JSON</option>
28         <option value="csv">CSV</option>
29         <option value="tsv">TSV</option>
30         <option value="xls">Excel (xls)</option>
31     </select>
33     <div id="brapi_phenotyping_handhelds_studies_div">
34     </div>
36     <div id="brapi_phenotyping_handhelds_layout_results_div">
37     </div>
39 </div>
41 <div id="brapi_phenotyping_handhelds_traits_div" class="well">
43     <h3>Get Observation Variables</h3>
45     <div id="brapi_phenotyping_handhelds_traits_div">
46     </div>
48     <div id="brapi_phenotyping_handhelds_traits_results_div">
49     </div>
51 </div>
53 <div id="brapi_phenotyping_handhelds_upload_div" class="well">
55     <h3>Upload Phenotypes Using POST brapi/v1/studies/studyId/observationunits?observationLevel=observationLevel</h3>
57     <h4>Not yet implemented</h4>
59     <h3>Upload Phenotypes Using POST brapi/v1/studies/studyId/table</h3>
61     <h4>Not yet implemented</h4>
63 </div>
65 <script>
67 var selected_results = [];
68 var studies_return_url;
69 var traits_return_url;
71 jQuery(document).ready(function() {
73     brapi_phenotyping_handhelds_get_studies(jQuery('#brapi_phenotyping_handhelds_url_select').val());
74     brapi_phenotyping_handhelds_get_traits(jQuery('#brapi_phenotyping_handhelds_url_select').val());
76     jQuery('#brapi_phenotyping_handhelds_url_select').change(function(){
77         brapi_phenotyping_handhelds_get_studies(jQuery('#brapi_phenotyping_handhelds_url_select').val());
78         brapi_phenotyping_handhelds_get_traits(jQuery('#brapi_phenotyping_handhelds_url_select').val());
79     });
81     jQuery(document).on('click', '#brapi_table_select_submit_brapi_phenotyping_handhelds_studies_div', function(){
82         jQuery.each(jQuery('input[name="brapi_table_select_'+studies_return_url+'"]:checked'), function(){
83             if (jQuery.inArray(jQuery(this).val(), selected_results) == -1){
84                 selected_results.push(jQuery(this).val());
85             }
86         });
87         console.log(selected_results);
88         var format = jQuery('#brapi_phenotyping_handhelds_layout_format').val();
89         var url = jQuery('#brapi_phenotyping_handhelds_url_select').val();
91         for (var i=0; i<selected_results.length; i++){
92             var return_url = url+'/brapi/v1/studies/'+selected_results[i]+'/layout?format='+format;
93             jQuery.ajax( {
94                 'url': return_url,
95                 'beforeSend': function(){
96                     jQuery('#working_modal').modal('show');
97                 },
98                 'success': function(response) {
99                     //console.log(response);
100                     if (response.metadata.datafiles.length > 0){
101                         var html = "<h4>Download Layout File(s) From Here: <br/>";
102                         for (var j=0; j<response.metadata.datafiles.length; j++){
103                             html = html + "<a href='"+response.metadata.datafiles[j]+"'>"+response.metadata.datafiles[j]+"</a><br/>";
104                         }
105                         jQuery('#brapi_phenotyping_handhelds_layout_results_div').html(html);
106                     } else {
107                         brapi_create_paginated_table(response.result.data, response.metadata.pagination, 'brapi_phenotyping_handhelds_layout_results_div', return_url, undefined, {}, ['observationUnitName','replicate','germplasmName','blockNumber', 'X', 'Y', 'entryType', 'additionalInfo'], 'observationUnitName', []);
108                     }
109                     jQuery('#working_modal').modal('hide');
110                 },
111                 error: function(response) {
112                     jQuery('#working_modal').modal('hide');
113                     alert('An error occurred');
114                 }
115             });
116         }
117     });
121 function brapi_phenotyping_handhelds_get_studies(url) {
122     studies_return_url = url+'/brapi/v1/studies-search';
123     jQuery.ajax( {
124         'url': url+'/brapi/v1/studies-search',
125         'beforeSend': function(){
126             jQuery('#working_modal').modal('show');
127         },
128         'success': function(response) {
129             //console.log(response);
130             brapi_create_paginated_table(response.result.data, response.metadata.pagination, 'brapi_phenotyping_handhelds_studies_div', studies_return_url, undefined, {}, ['studyName','trialName','programName','locationName'], 'studyDbId', []);
131             jQuery('#working_modal').modal('hide');
132         },
133         error: function(response) {
134             jQuery('#working_modal').modal('hide');
135             alert('An error occurred');
136         }
137     });
140 function brapi_phenotyping_handhelds_get_traits(url) {
141     traits_return_url = url+'/brapi/v1/variables';
142     jQuery.ajax( {
143         'url': url+'/brapi/v1/variables',
144         'beforeSend': function(){
145             jQuery('#working_modal').modal('show');
146         },
147         'success': function(response) {
148             //console.log(response);
149             brapi_create_paginated_table(response.result.data, response.metadata.pagination, 'brapi_phenotyping_handhelds_traits_div', traits_return_url, undefined, {}, ['observationVariableDbId','name','ontologyName','trait','method','scale'], 'name', []);
150             jQuery('#working_modal').modal('hide');
151         },
152         error: function(response) {
153             jQuery('#working_modal').modal('hide');
154             alert('An error occurred');
155         }
156     });
159 </script>