2 package SGN
::Controller
::AJAX
::Search
::Trial
;
7 use CXGN
::Trial
::Search
;
10 BEGIN { extends
'Catalyst::Controller::REST'; }
13 default => 'application/json',
15 map => { 'application/json' => 'JSON' },
18 sub search
: Path
('/ajax/search/trials') Args
(0) {
23 my $location_id = $c->req->param('location_id');
24 if ($location_id && $location_id ne 'not_provided'){
25 #print STDERR "location id: " . $location_id . "\n";
26 push @location_ids, $location_id;
29 my $checkbox_select_name = $c->req->param('select_checkbox_name');
30 my $field_trials_only = $c->req->param('field_trials_only') || 1;
31 my $trial_design_list = $c->req->param('trial_design') ?
[$c->req->param('trial_design')] : [];
33 my $sp_person_id = $c->user() ?
$c->user->get_object()->get_sp_person_id() : undef;
34 my $schema = $c->dbic_schema("Bio::Chado::Schema", undef, $sp_person_id);
36 my $trial_search = CXGN
::Trial
::Search
->new({
38 location_id_list
=>\
@location_ids,
39 field_trials_only
=>$field_trials_only,
40 trial_design_list
=>$trial_design_list
42 my ($data, $total_count) = $trial_search->search();
44 my %selected_columns = ('plot_name'=>1, 'plot_id'=>1, 'block_number'=>1, 'plot_number'=>1, 'rep_number'=>1, 'row_number'=>1, 'col_number'=>1, 'accession_name'=>1, 'is_a_control'=>1);
45 my $selected_columns_json = encode_json \
%selected_columns;
47 my $folder_string = '';
48 if ($_->{folder_name
}){
49 $folder_string = "<a href=\"/folder/$_->{folder_id}\">$_->{folder_name}</a>";
52 if ($checkbox_select_name){
53 push @res, "<input type='checkbox' name='$checkbox_select_name' value='$_->{trial_id}'>";
56 "<a href=\"/breeders_toolbox/trial/$_->{trial_id}\">$_->{trial_name}</a>",
58 "<a href=\"/breeders/program/$_->{breeding_program_id}\">$_->{breeding_program_name}</a>",
64 $_->{project_planting_date
},
65 $_->{project_harvest_date
},
66 "<a class='btn btn-sm btn-default' href='/breeders/trial/$_->{trial_id}/download/layout?format=csv&dataLevel=plots&selected_columns=$selected_columns_json'>Download Plot Layout</a>"
70 #print STDERR Dumper \@result;
72 $c->stash->{rest
} = { data
=> \
@result };