8 $ajaxRequestString => ""
12 <& /util/import_css.mas, paths => ['tools/GraphicalFiltering.css'] &>
14 <& '/page/page_title.mas', title => "Graphical Filtering" &>
16 <& '/util/import_javascript.mas', classes => [ 'jquery', 'jqueryui', 'CXGN.List', 'd3.d3v4Min', 'brapi.BrAPI', 'brapi.GraphicalFilter' ] &>
18 <div id="select_div" class="row" hidden="true">
19 <!-- form for selecting a list -->
20 <p>Choose a list of <!--plant, plots, or -->trials to filter.</p>
21 <form class="tc-form">
22 <div class="form-group">
24 <div id="filter_list_select_container" class="select_container col-md-6">
25 <select disabled class="form-control input-sm" id="filter_list_select">
26 <option selected="selected">Loading...</option>
29 <div id="type_list_select_container" class="select_container col-md-3">
30 <select disabled class="form-control input-sm" id="type_list_select">
31 <option selected disabled value="">Select Type</option>
32 <option value="plot">Plots</option>
33 <option value="plant">Plants</option>
36 <div class="checkbox col-md-3">
38 <input type="checkbox" id="accession_group"> Group By Accession
44 <!-- spinner to show during ajax call -->
47 <img hidden="true" id="results-loading-spinner" src="/img/wheel.gif" alt="loading">
51 <!-- div in which to draw filters -->
52 <div id="filter_div" class="row"></div>
53 <!-- div with table of filtered results and an option to save the output as a list -->
54 <div id="filtered_results_wrap" hidden="true" class="row dataTables_wrapper">
55 <&| /page/info_section.mas, title => 'Filtered Results', collapsible=>0, collapsed=>0 &>
56 <table id="filtered_results" width="100%" class="table table-hover table-striped dataTable no-footer" role="grid" style="width: 100%;"></table>
58 <&| /page/info_section.mas, title => 'Save Results as List', collapsible=>1, collapsed=>1 &>
59 <form id="new-list-form">
60 <label>List Name: </label> <input name="name" class="form-control" type="text">
61 <button type="submit" class="btn btn-primary">Create</button>
70 var currentGFilter = null;
71 var list = new CXGN.List();
73 $('#accession_group').change(function(){$('#type_list_select').trigger("change");})
75 $('#type_list_select').change(function(){
76 var list_id = $("#filter_list_select").val(),
77 unit = $("#type_list_select").val(),
78 group = $('#accession_group').is(":checked"),
79 brapi = BrAPI("/brapi/v1");
81 var list_contents = list.transform2Ids(list_id),
82 list_type = list.getListType(list_id);
86 alert("not yet implimented");
90 brapi.phenotypes_search({
91 "studyDbIds": list_contents,
92 "observationLevel": unit,
100 function updateGFilter(group,brapi_node){
101 if (currentGFilter!=null){
102 $("#filtered_results").DataTable().destroy();
103 $("#filtered_results").html("");
105 $('#filtered_results_wrap').hide();
106 $('#filter_div').hide();
107 $('#results-loading-spinner').show();
108 brapi_node.all(function(){
109 $('#filtered_results_wrap').show();
110 $('#filter_div').show();
111 $('#results-loading-spinner').hide();
113 currentGFilter = GraphicalFilter(
116 group? groupCols : obsCols,
117 group? ["Accession"] : ["Study","Unit","Accession"],
118 group? groupByAccession : undefined
120 currentGFilter.draw("#filter_div","#filtered_results");
123 $(document).ready(function(){
125 // set up and show the list select div.
126 $('#select_div').show();
129 var filter_list_select_html = list.listSelect('filter', ['trials'/*,'plots','plants'*/], 'Choose a List:');
130 $('#filter_list_select_container').html(filter_list_select_html);
131 $('#filter_list_select>option:first-of-type').prop('disabled', true);
133 $('#filter_list_select').change(function(){
134 $(this).prop('disabled', true);
135 var list_id = $(this).val();
136 var list_type = list.getListType(list_id);
137 $(this).prop('disabled', false);
138 $('#type_list_select').prop('disabled', false);
141 $('#type_list_select').prop('val', "");
144 $('#type_list_select').val("plot").trigger("change");
145 $('#type_list_select').prop('disabled', true);
148 $('#type_list_select').val("plant").trigger("change");
149 $('#type_list_select').prop('disabled', true);
155 function obsTraits(d) { // traits/values
157 d.observations.forEach(function(obs){
158 traits[obs.observationVariableName] = obs.value;
162 function obsCols(d){ // header columns accessor
165 'Unit':d.observationUnitName,
166 'Accession':d.germplasmName,
169 function groupCols(d) {
171 'Accession':d.germplasmName
174 function groupByAccession(d) {
175 return d.germplasmDbId
178 // set up the form for saving results as a list
179 $('#new-list-form').submit(function () {
180 if (!window.gfiltering.data){
181 alert("Can't create a list from nothing.")
185 var form = d3.map($(this).serializeArray(),function(d){return d.name;});
186 var list = new CXGN.List();
187 var newListID = list.newList(form.get("name").value);
188 if (!newListID) throw "List creation failed.";
189 list.setListType(newListID,"plots");
190 var data = currentGFilter.data.filter(currentGFilter.root.getFilter());
191 var count = list.addBulk(newListID,data.map(function(d){return d.observationUnitName}));
192 if (!count) throw "Added nothing to list or addition failed.";
193 alert("List \""+form.get("name").value+"\" created with "+count+" entries.")
196 setTimeout(function(){throw err;});