11 <& '/page/page_title.mas', title => "Compare trials" &>
13 <& /util/import_css.mas, paths => ['tools/trial_comparison.css'] &>
15 <& '/util/import_javascript.mas', classes => [ 'jquery', 'jqueryui', 'popup', 'CXGN.List', 'CXGN.Login', 'd3.d3v4Min','brapi.BrAPI','brapi.StudyComparison'] &>
18 #tc-grid, #tc-histogram{
21 #tc-grid svg, #tc-histogram svg{
28 <center class = "col-md-offset-2 col-md-8">
29 <form class="tc-form">
30 <div class="form-group">
31 <label for="trials_list_select">Choose a list of trials:</label>
32 <div id="trials_list_select_container">
33 <select disabled class="form-control input-sm" id="trials_list_select">
34 <option selected="selected">Loading...</option>
37 <img hidden id="trials-loading-spinner" src="/img/wheel.gif" alt="loading">
39 <div class="form-group">
40 <label>Choose Observation Level</label>
41 <select class="form-control input-sm" id="unit_select">
42 <option selected value="plot">Plot</option>
43 <option value="plant">Plant</option>
46 <div class="form-group">
47 <label>Choose a trait to compare:</label>
48 <select disabled class="form-control input-sm" id="trait_select">
49 <option selected="selected" value=""> </option>
52 <img hidden id="results-loading-spinner" src="/img/wheel.gif" alt="loading">
57 <div id="result_div" class="row">
59 <div hidden="true" id="tc-grid" class="col-lg-6 col-md-6 col-sm-12"></div>
60 <div hidden="true" id="tc-histogram" class="col-lg-6 col-md-6 col-sm-12"></div>
70 $(document).ready(function(){
72 list = new CXGN.List();
73 var select_html = list.listSelect('trials', ['trials'], ' ', undefined, undefined);
74 $('#trials_list_select_container').html(select_html);
75 if (d3.select('#trials_list_select').selectAll("option").size()<2){
76 d3.select('#trials_list_select').html("<option>No trial lists! (Create one using the wizard.)</option>");
78 $('#trials_list_select').change(call_change);
81 $('#trials_list_select').html('<option selected="selected">You must be logged in to use lists.</option>');
85 function call_change(){
86 $("#trials-loading-spinner").show();
88 $("#tc-histogram").hide();
89 $('#trait_select').attr("disabled",true).html('<option selected="selected" disabled value=""> </option>');
90 var trial_list_id = $('#trials_list_select').val();
91 if (trial_list_id === "") {
92 $("#trials-loading-spinner").hide();
95 setTimeout(function(){ //use setTimeout to pull sync call list.getListData out of event listener thread.
96 var item_data = list.getListData(trial_list_id);
97 // var items = item_data.elements;
98 // console.log("items: ",items);
99 var ids = list.transform2Ids(trial_list_id, item_data);
100 console.log("ids: ",ids);
103 var require_login = "<% $c->get_conf('brapi_require_login') %>";
104 if (require_login === '1'){
105 auth_token = "<% CXGN::Login->new($c->dbc->dbh)->get_login_cookie() %>";
106 if (!auth_token){ alert("Login required to display graphical filtering"); }
108 BrAPI("/brapi/v2",'v2.0',auth_token)
109 .search_observationunits({
111 "observationLevels": [{'levelName': $('#unit_select').val() }],
112 "includeObservations" : "true",
113 "pageSize" : 10000000})
115 $('#unit_select').change(call_change);
119 function createSComp(data){
120 $("#trials-loading-spinner").hide();
121 $('#trait_select').attr("disabled",false);
122 var scomp = StudyComparison().links(function(dbId){
123 return "/stock/"+dbId+"/view";
125 var sharedVars = scomp.loadData(data);
126 console.log("vars",sharedVars);
128 var varOpts = d3.select("#trait_select")
129 .selectAll("option:not([disabled])")
131 varOpts.exit().remove();
132 varOpts.enter().append("option").merge(varOpts)
133 .attr("value",function(d){return d})
134 .text(function(d){return d})
138 $("#trait_select").change(function(){
139 $("#tc-grid").show();
140 $("#tc-histogram").show();
141 scomp.setVariable($("#trait_select").val());
142 scomp.graphGrid("#tc-grid");
143 scomp.multiHist("#tc-histogram");