4 <& /util/import_javascript.mas, classes => [ 'brapi.Table' ] &>
6 <& /page/page_title.mas, title=>"Germplasm Search and Exchange" &>
8 <h4>Database Select</h4>
9 <select name="brapi_home_url_select" id="brapi_home_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>
21 <h4>Germplasm Search</h4>
23 <div id="brapi_germplasm_search_home_div" class="well">
25 <input name="brapi_germplasm_search_germplasmName" id="brapi_germplasm_search_germplasmname" class="form-control" type="text" placeholder="GermplasmName(s) e.g. TMEB419,TMEB529" />
26 <input name="brapi_germplasm_search_accessionNumber" id="brapi_germplasm_search_accessionNumber" class="form-control" type="text" placeholder="AccessionNumber" />
27 <input name="brapi_germplasm_search_germplasmGenus" id="brapi_germplasm_search_germplasmGenus" class="form-control" type="text" placeholder="GermplasmGenus" />
28 <input name="brapi_germplasm_search_germplasmSpecies" id="brapi_germplasm_search_germplasmSpecies" class="form-control" type="text" placeholder="GermplasmSpecies" />
29 <input name="brapi_germplasm_search_germplasmDbId" id="brapi_germplasm_search_germplasmDbId" class="form-control" type="text" placeholder="GermplasmDbId" />
30 <input name="brapi_germplasm_search_germplasmPUI" id="brapi_germplasm_search_germplasmPUI" class="form-control" type="text" placeholder="GermplasmPUI" />
31 <select name="brapi_germplasm_search_matchMethod" id="brapi_germplasm_search_matchMethod" class="form-control" />
32 <option value="exact">Exact</option>
33 <option value="wildcard">Wildcard. Wildcard allows % or * for multiple characters and ? for single characters.</option>
36 <button class="btn btn-primary" name="brapi_germplasm_search_submit" id="brapi_germplasm_search_submit">Search</button>
40 <div id="brapi_germplasm_search_result_div">
42 <div id="brapi_germplasm_search_result_div_collection">
45 <div class="modal fade" id="brapi_germplasm_saved_message_modal" name="brapi_germplasm_saved_message_modal" tabindex="-1" role="dialog" aria-labelledby="brapiGermplasmSearchSavedDialog">
46 <div class="modal-dialog" role="document">
47 <div class="modal-content">
48 <div class="modal-header" style="text-align: center">
49 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
50 <h4 class="modal-title" id="brapiGermplasmSearchSavedDialog">BrAPI Germplasm Exchange</h4>
52 <div class="modal-body">
53 <div class="container-fluid">
54 <div id="brapi_germplasm_saved_message"></div>
57 <div class="modal-footer">
58 <button id="close_brapi_germplasm_saved_message_modal" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
68 var allowed_organism_results = [];
70 jQuery(document).ready(function() {
72 var selected_results = [];
73 var selected_organism_results = [];
75 jQuery("#brapi_germplasm_search_submit").click(function() {
76 var germplasmNames = jQuery("#brapi_germplasm_search_germplasmname").val();
78 germplasmNames = germplasmNames.split(',');
82 var accessionNumbers = jQuery("#brapi_germplasm_search_accessionNumber").val();
83 if (accessionNumbers){
84 accessionNumbers = accessionNumbers.split(',');
86 accessionNumbers = [];
88 var genusNames = jQuery("#brapi_germplasm_search_germplasmGenus").val();
90 genusNames = genusNames.split(',');
94 var subtaxaNames = jQuery("#brapi_germplasm_search_germplasmSubTaxa").val();
96 subtaxaNames = subtaxaNames.split(',');
100 var speciesNames = jQuery("#brapi_germplasm_search_germplasmSpecies").val();
102 speciesNames = speciesNames.split(',');
106 var germplasmDbIds = jQuery("#brapi_germplasm_search_germplasmDbId").val();
108 germplasmDbIds = germplasmDbIds.split(',');
112 var germplasmPUIs = jQuery("#brapi_germplasm_search_germplasmPUI").val();
114 germplasmPUIs = germplasmPUIs.split(',');
118 var search_query_data = {
119 'germplasmNames' : germplasmNames,
120 'accessionNumbers' : accessionNumbers,
121 'germplasmGenus' : genusNames,
122 'germplasmSubTaxa' : subtaxaNames,
123 'germplasmSpecies' : speciesNames,
124 'germplasmDbIds' : germplasmDbIds,
125 'germplasmPUIs' : germplasmPUIs,
126 'matchMethod' : jQuery("#brapi_germplasm_search_matchMethod").val(),
128 return_url = jQuery('#brapi_home_url_select').val()+'/brapi/v1/germplasm-search';
130 'url': jQuery('#brapi_home_url_select').val()+'/brapi/v1/germplasm-search',
132 'beforeSend': function(){
133 jQuery('#working_modal').modal('show');
135 'data': search_query_data,
136 'success': function(response) {
137 //console.log(response);
138 brapi_create_paginated_table(response.result.data, response.metadata.pagination, 'brapi_germplasm_search_result_div', return_url, { "germplasmName": ["germplasmPUI", ""] }, search_query_data, ['germplasmName','commonCropName','genus','species','accessionNumber','germplasmPUI','synonyms'], 'germplasmName', ['species']);
139 jQuery('#working_modal').modal('hide');
141 error: function(response) {
142 jQuery('#working_modal').modal('hide');
143 alert('An error occurred');
148 jQuery(document).on('click', '#brapi_table_select_submit_brapi_germplasm_search_result_div', function(){
149 jQuery.each(jQuery('input[name="brapi_table_select_'+return_url+'"]:checked'), function(){
150 if (jQuery.inArray(jQuery(this).val(), selected_results) == -1){
151 selected_results.push(jQuery(this).val());
153 if (jQuery.inArray(jQuery(this).data("species"), selected_organism_results) == -1){
154 selected_organism_results.push(jQuery(this).data("species"));
157 console.log(selected_results);
158 console.log(selected_organism_results);
161 'url': '/ajax/accession_list/verify',
163 'beforeSend': function(){
164 jQuery('#working_modal').modal('show');
167 'accession_list' : JSON.stringify(selected_results),
168 'organism_list' : JSON.stringify(selected_organism_results),
169 'do_fuzzy_search' : 'true'
171 'success': function(response){
173 alert(response.error);
174 jQuery('#working_modal').modal('hide');
177 console.log(response);
179 var html = '<h3>How Selected Organisms Compare to This Database:</h3>';
180 html = html + '<table class="table table-bordered"><thead><tr><th>Species</th><th>Status</th><th>Possible Matches</th></tr></thead><tbody>';
181 for (var i=0; i<response.found_organisms.length; i++){
182 html = html + '<tr><td>' + response.found_organisms[i].unique_name + '</td><td class="bg-success">Exact Species Found in This Database</td><td>Exact Match</td></tr>';
183 allowed_organism_results.push(response.found_organisms[i].unique_name);
185 for (var i=0; i<response.fuzzy_organisms.length; i++){
186 html = html + '<tr><td>' + response.fuzzy_organisms[i].name + '</td><td class="bg-danger">Possible Species Matches Found in This Database, but Not Exact Match. Please Contact Us to Add Your Organism, or change Your Species to Match Our Species Name!</td>';
187 html = html + '<td><select class="form-control">'
188 for (var j=0; j<response.fuzzy_organisms[i].matches.length; j++){
189 html = html + '<option value="'+response.fuzzy_organisms[i].matches[j].name+'">'+response.fuzzy_organisms[i].matches[j].name+'</option>'
191 html = html + '</select></td></tr>';
193 for (var i=0; i<response.absent_organisms.length; i++){
194 html = html + '<tr><td>' + response.absent_organisms[i] + '</td><td class="bg-danger">Please Contact Us to Add Your Organism, or change Your Species to Match Our Species Name!</td><td>No Match</td></tr>';
196 html = html + '</tbody></table>';
198 html = html + '<h3>How Selected GermplasmNames Compare to This Database:</h3>';
199 html = html + '<table class="table table-bordered"><thead><tr><th>Select</th><th>GermplasmName</th><th>Status</th><th>Possible Matches</th></tr></thead><tbody>';
200 for (var i=0; i<response.found.length; i++){
201 html = html + '<tr><td><input type="checkbox" name="brapi_germplasm_search_collection_select" disabled/></td><td>' + response.found[i].unique_name + '</td><td class="bg-success">Exact GermplasmName Found in This Database</td><td>Exact Match</td></tr>';
203 for (var i=0; i<response.fuzzy.length; i++){
204 html = html + '<tr><td><input type="checkbox" name="brapi_germplasm_search_collection_select" value="' + response.fuzzy[i].name + '"/></td><td>' + response.fuzzy[i].name + '</td><td class="bg-info">Possible GermplasmName Matches Found in This Database</td>';
205 html = html + '<td><select class="form-control">'
206 for (var j=0; j<response.fuzzy[i].matches.length; j++){
207 html = html + '<option value="'+response.fuzzy[i].matches[j].name+'">'+response.fuzzy[i].matches[j].name+'</option>'
209 html = html + '</select></td></tr>';
211 for (var i=0; i<response.absent.length; i++){
212 html = html + '<tr><td><input type="checkbox" name="brapi_germplasm_search_collection_select" value="' + response.absent[i] + '"/></td><td>' + response.absent[i] + '</td><td class="bg-warning">GermplasmName Not Found in This Database</td><td>No Match</td></tr>';
214 html = html + '</tbody></table><button class="btn btn-primary" name="brapi_germplasm_search_submit_final" id="brapi_germplasm_search_submit_final">Save in Database</button>';
215 jQuery('#working_modal').modal('hide');
216 jQuery('#brapi_germplasm_search_result_div_collection').html(html);
218 'error': function(response){
219 jQuery('#working_modal').modal('hide');
220 alert('An error occurred in fuzzy search!');
225 jQuery(document).on('click', '#brapi_germplasm_search_submit_final', function(){
226 jQuery('#working_modal').modal('show');
227 var selected_to_save = [];
228 jQuery.each(jQuery('input[name="brapi_germplasm_search_collection_select"]:checked'), function(){
229 if (jQuery.inArray(jQuery(this).val(), selected_to_save) == -1){
230 selected_to_save.push(jQuery(this).val());
233 console.log(selected_to_save);
235 var num_requests = selected_to_save.length;
237 for (var i=0; i<num_requests; i++){
240 'url': jQuery('#brapi_home_url_select').val()+'/brapi/v1/germplasm-search?matchMethod=exact&germplasmName='+selected_to_save[i],
241 'success': function(response){
242 //console.log(response);
243 if (jQuery.inArray(response.result.data[0].species, allowed_organism_results) == -1){
244 alert('Will Skip '+response.result.data[0].germplasmName+' because the species '+response.result.data[0].species+' is not in this database!');
246 to_save.push(response.result.data[0]);
248 if (request == num_requests){
249 perform_save(to_save);
253 'error': function(response){
254 alert('An error occurred getting details to save!');
263 function perform_save(to_save){
264 console.log(to_save);
266 'url': '/ajax/accession_list/add',
269 'full_info' : JSON.stringify(to_save),
270 'allowed_organisms' : JSON.stringify(allowed_organism_results)
272 'success': function(response){
273 console.log(response);
275 alert(response.error);
276 jQuery('#working_modal').modal('hide');
279 if(response.success){
280 var html = 'The following stocks were added!<br/>';
281 for (var i=0; i<response.added.length; i++){
282 html = html + '<a href="/stock/'+response.added[i][0]+'/view">'+response.added[i][1]+'</a><br/>';
284 jQuery('#brapi_germplasm_saved_message').html(html);
285 jQuery('#brapi_germplasm_saved_message_modal').modal('show');
287 jQuery('#working_modal').modal('hide');
289 'error': function(response){
290 alert('An error occurred in fuzzy search!');
291 jQuery('#working_modal').modal('hide');