remove variable attribute section for traits.
[sgn.git] / mason / brapiclient / phenotyping_handhelds.mas
blobc31ca603976ddbfaab0dc9db332c20071c61004c
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     <option value="https://www.crop-diversity.org/mgis">crop-diversity.org</option>
19 </select>
21 <br/><br/>
23 <div id="brapi_phenotyping_handhelds_layout_div" class="well">
25     <h3>Get Trial Layout(s)</h3>
27     <select name="brapi_phenotyping_handhelds_layout_format" id="brapi_phenotyping_handhelds_layout_format" class="form-control" />
28         <option value="json">JSON</option>
29         <option value="csv">CSV</option>
30         <option value="tsv">TSV</option>
31         <option value="xls">Excel (xls)</option>
32     </select>
34     <div id="brapi_phenotyping_handhelds_studies_div">
35     </div>
37     <div id="brapi_phenotyping_handhelds_layout_results_div">
38     </div>
40 </div>
42 <div id="brapi_phenotyping_handhelds_traits_div" class="well">
44     <h3>Get Observation Variables</h3>
46     <div id="brapi_phenotyping_handhelds_traits_div">
47     </div>
49     <div id="brapi_phenotyping_handhelds_traits_results_div">
50     </div>
52 </div>
54 <div id="brapi_phenotyping_handhelds_upload_div" class="well">
56     <h3>Upload Phenotypes Using POST brapi/v1/studies/studyId/observationunits?observationLevel=observationLevel</h3>
58     <h4>Not yet implemented</h4>
60     <h3>Upload Phenotypes Using POST brapi/v1/studies/studyId/table</h3>
62     <h4>Not yet implemented</h4>
64 </div>
66 <script>
68 var selected_results = [];
69 var studies_return_url;
70 var traits_return_url;
72 jQuery(document).ready(function() {
74     brapi_phenotyping_handhelds_get_studies(jQuery('#brapi_phenotyping_handhelds_url_select').val());
75     brapi_phenotyping_handhelds_get_traits(jQuery('#brapi_phenotyping_handhelds_url_select').val());
77     jQuery('#brapi_phenotyping_handhelds_url_select').change(function(){
78         brapi_phenotyping_handhelds_get_studies(jQuery('#brapi_phenotyping_handhelds_url_select').val());
79         brapi_phenotyping_handhelds_get_traits(jQuery('#brapi_phenotyping_handhelds_url_select').val());
80     });
82     jQuery(document).on('click', '#brapi_table_select_submit_brapi_phenotyping_handhelds_studies_div', function(){
83         jQuery.each(jQuery('input[name="brapi_table_select_'+studies_return_url+'"]:checked'), function(){
84             if (jQuery.inArray(jQuery(this).val(), selected_results) == -1){
85                 selected_results.push(jQuery(this).val());
86             }
87         });
88         console.log(selected_results);
89         var format = jQuery('#brapi_phenotyping_handhelds_layout_format').val();
90         var url = jQuery('#brapi_phenotyping_handhelds_url_select').val();
92         for (var i=0; i<selected_results.length; i++){
93             var return_url = url+'/brapi/v1/studies/'+selected_results[i]+'/layout?format='+format;
94             jQuery.ajax( {
95                 'url': return_url,
96                 'beforeSend': function(){
97                     jQuery('#working_modal').modal('show');
98                 },
99                 'success': function(response) {
100                     //console.log(response);
101                     if (response.metadata.datafiles.length > 0){
102                         var html = "<h4>Download Layout File(s) From Here: <br/>";
103                         for (var j=0; j<response.metadata.datafiles.length; j++){
104                             html = html + "<a href='"+response.metadata.datafiles[j]+"'>"+response.metadata.datafiles[j]+"</a><br/>";
105                         }
106                         jQuery('#brapi_phenotyping_handhelds_layout_results_div').html(html);
107                     } else {
108                         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', []);
109                     }
110                     jQuery('#working_modal').modal('hide');
111                 },
112                 error: function(response) {
113                     jQuery('#working_modal').modal('hide');
114                     alert('An error occurred');
115                 }
116             });
117         }
118     });
122 function brapi_phenotyping_handhelds_get_studies(url) {
123     studies_return_url = url+'/brapi/v1/studies-search';
124     jQuery.ajax( {
125         'url': url+'/brapi/v1/studies-search',
126         'beforeSend': function(){
127             jQuery('#working_modal').modal('show');
128         },
129         'success': function(response) {
130             //console.log(response);
131             brapi_create_paginated_table(response.result.data, response.metadata.pagination, 'brapi_phenotyping_handhelds_studies_div', studies_return_url, undefined, {}, ['studyName','trialName','programName','locationName'], 'studyDbId', []);
132             jQuery('#working_modal').modal('hide');
133         },
134         error: function(response) {
135             jQuery('#working_modal').modal('hide');
136             alert('An error occurred');
137         }
138     });
141 function brapi_phenotyping_handhelds_get_traits(url) {
142     traits_return_url = url+'/brapi/v1/variables';
143     jQuery.ajax( {
144         'url': url+'/brapi/v1/variables',
145         'beforeSend': function(){
146             jQuery('#working_modal').modal('show');
147         },
148         'success': function(response) {
149             //console.log(response);
150             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', []);
151             jQuery('#working_modal').modal('hide');
152         },
153         error: function(response) {
154             jQuery('#working_modal').modal('hide');
155             alert('An error occurred');
156         }
157     });
160 </script>