2 package SGN
::Controller
::AJAX
::Trials
;
6 use CXGN
::BreedersToolbox
::Projects
;
7 use CXGN
::Trial
::Folder
;
10 use File
::Path
qw(make_path);
11 use File
::Spec
::Functions qw
/ catfile catdir/;
12 use SGN
::Model
::Cvterm
;
14 BEGIN { extends
'Catalyst::Controller::REST'; }
17 default => 'application/json',
19 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
23 sub get_trials
: Path
('/ajax/breeders/get_trials') Args
(0) {
27 my $p = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $c->dbic_schema("Bio::Chado::Schema") } );
29 my $projects = $p->get_breeding_programs();
32 foreach my $project (@
$projects) {
33 my $trials = $p->get_trials_by_breeding_program($project->[0]);
34 $data{$project->[1]} = $trials;
38 $c->stash->{rest
} = \
%data;
41 sub get_trials_with_folders
: Path
('/ajax/breeders/get_trials_with_folders') Args
(0) {
45 my $schema = $c->dbic_schema("Bio::Chado::Schema");
46 my $p = CXGN
::BreedersToolbox
::Projects
->new( { schema
=> $schema } );
48 my $projects = $p->get_breeding_programs();
51 foreach my $project (@
$projects) {
52 my $folder = CXGN
::Trial
::Folder
->new( { bcs_schema
=> $schema, folder_id
=> $project->[0] });
53 $html .= $folder->get_jstree_html('breeding_program');
56 my $dir = catdir
($c->site_cluster_shared_dir, "folder");
57 eval { make_path
($dir) };
59 print "Couldn't create $dir: $@";
61 my $filename = $dir."/entire_jstree_html.txt";
64 open $OUTFILE, '>', $filename or die "Error opening $filename: $!";
65 print { $OUTFILE } $html or croak
"Cannot write to $filename: $!";
66 close $OUTFILE or croak
"Cannot close $filename: $!";
68 $c->stash->{rest
} = { status
=> 1 };
71 sub get_trials_with_folders_cached
: Path
('/ajax/breeders/get_trials_with_folders_cached') Args
(0) {
75 my $dir = catdir
($c->site_cluster_shared_dir, "folder");
76 my $filename = $dir."/entire_jstree_html.txt";
78 open(my $fh, '<', $filename) or die "cannot open file $filename";
86 $c->stash->{rest
} = { html
=> $html };
89 sub trial_autocomplete
: Local
: ActionClass
('REST') { }
91 sub trial_autocomplete_GET
:Args
(0) {
94 my $term = $c->req->param('term');
96 $term =~ s/(^\s+|\s+)$//g;
99 my $trial_design_cvterm_id = SGN
::Model
::Cvterm
->get_cvterm_row($c->dbic_schema("Bio::Chado::Schema"), "design", "project_property")->cvterm_id();
101 my $q = "select distinct(name) from project join projectprop using(project_id) where project.name ilike ? and projectprop.type_id = ? ORDER BY name";
102 my $sth = $c->dbc->dbh->prepare($q);
103 $sth->execute('%'.$term.'%', $trial_design_cvterm_id);
104 while (my ($project_name) = $sth->fetchrow_array) {
105 push @response_list, $project_name;
107 print STDERR Dumper \
@response_list;
109 $c->{stash
}->{rest
} = \
@response_list;