message dialog and js
[sgn.git] / mason / search / stocks_graphicalfiltering.mas
blob1d566e1786b6770902900489fcf5a355bc94fb70
1 <%args>
2 </%args>
4 <& /util/import_css.mas, paths => ['tools/GraphicalFiltering.css'] &>
6 <& /util/import_javascript.mas, classes => [ 'CXGN.List', 'd3.d3v4Min', 'brapi.BrAPI', 'brapi.GraphicalFilter' ] &>
8 <&| /page/info_section.mas, id=>"stock_search_graphical_filter", title => 'Graphical Filter Accessions By Traits (Includes all Search Criteria From Above Search Form)', collapsible=>1, collapsed=>1&>
10 <div class="well well-sm">
12 <div class="panel panel-default">
13     <div class="panel-body">
14         <div id="stock_search_graphical_filter_div" style="margin:1em">
15         [LOADING...]
16         </div>
17     </div>
18 </div>
20 <br/>
22 <div class="panel panel-default">
23     <div class="panel-body">
24         <div style="overflow:scroll">
25             <table id="stock_search_graphical_filter_results_div" >
26             </table>
27         </div>
28     </div>
29 </div>
31 <br/>
33 <&| /page/info_section.mas, title => 'Copy Filtered Accessions to a List', collapsible=>1, collapsed=>0, subtitle=>'<i>Copy the accession names in table to a new or exisiting list</i>'&>
34 <div style="text-align:right" id="graphical_filter_results_to_list_menu"></div>
35 <div id="graphical_filter_result_names" style="display: none;"></div>
36 </&>
39 </div>
41 </&>
43 <script>
45 jQuery(document).ready(function () {
47 });
49 var currentGFilter = null;
50 function loadBrAPIData(server,parameters,success){
51       var auth_token;
52       var require_login = "<%  $c->get_conf('brapi_require_login') %>";
53       if (require_login === '1'){
54           auth_token = "<%  CXGN::Login->new($c->dbc->dbh)->get_login_cookie() %>";
55           if (!auth_token){ alert("Login required to display graphical filtering"); }
56       }
58     var data = {
59         "pageSize" : 10000000,
60         "includeObservations" : "true",
61     };
62     d3.entries(parameters).forEach(function(entry){
63         data[entry.key] = data[entry.key]||entry.value;
64     });
65     
66     var brapi_Data = BrAPI("/brapi/v2",'v2.0',auth_token).search_observationunits(data);
68     if (currentGFilter!=null){
69         $("#stock_search_graphical_filter_results_div").DataTable().destroy();
70         $("#stock_search_graphical_filter_results_div").html("");
71       }
73     currentGFilter = GraphicalFilter(
74         brapi_Data,
75         function(d) { // traits/values
76           var traits = {}
77           d.observations.forEach(function(obs){
78             traits[obs.observationVariableName] = obs.value;
79           });
80           return traits;
81         },
82         function(d) {
83           return {
84             'Accession':d.germplasmName
85           }
86         },
87         ["Accession"],
88         function(d) {
89           return d.germplasmDbId
90         }
91       );
93     currentGFilter.draw("#stock_search_graphical_filter_div","#stock_search_graphical_filter_results_div");
95     jQuery('#stock_search_graphical_filter_results_div').on( 'draw.dt', function () {
97         var names = [];
98         var data = $("#stock_search_graphical_filter_results_div").DataTable().context[0].aoData;
99         var displayed_rows = $("#stock_search_graphical_filter_results_div").DataTable().context[0].aiDisplay;
100         var names = [];
101         for (var i =0; i< displayed_rows.length; i++){
102             var displayed_index = displayed_rows[i];
103             names.push(data[displayed_index].nTr.firstChild.innerText+'\n');
104         }
105         jQuery('#graphical_filter_result_names').html(names);
106         addToListMenu('graphical_filter_results_to_list_menu', 'graphical_filter_result_names', {
107             listType: 'accessions'
108         });
109     });
112 </script>