Merge pull request #5230 from solgenomics/topic/open_pollinated
[sgn.git] / lib / SGN / Controller / solGS / AJAX / solGS.pm
blob9d8a5278f755250054e0c8856f2962222212f257
2 =head1 NAME
4 SGN::Controller::solGS::AJAX::solGS - a REST controller class to provide the
5 backend for objects linked with solgs
7 =head1 AUTHOR
9 Isaak Yosief Tecle <iyt2@cornell.edu>
11 =cut
13 package SGN::Controller::solGS::AJAX::solGS;
15 use Moose;
18 BEGIN { extends 'Catalyst::Controller::REST' }
20 __PACKAGE__->config(
21 default => 'application/json',
22 stash_key => 'rest',
23 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
28 sub solgs_trait_search_autocomplete : Path('/solgs/ajax/trait/search') : ActionClass('REST') { }
30 sub solgs_trait_search_autocomplete_GET :Args(0) {
31 my ( $self, $c ) = @_;
33 my $term = $c->req->param('term');
35 $term =~ s/(^\s+|\s+)$//g;
36 $term =~ s/\s+/ /g;
38 my $traits = $c->controller('solGS::Search')->model($c)->search_trait($term);
40 $c->{stash}->{rest} = $traits;
45 sub solgs_population_search_autocomplete : Path('/solgs/ajax/population/search') : ActionClass('REST') { }
47 sub solgs_population_search_autocomplete_GET :Args() {
48 my ( $self, $c ) = @_;
50 my $term = $c->req->param('term');
51 $term =~ s/(^\s+|\s+)$//g;
52 $term =~ s/\s+/ /g;
54 my @response_list;
55 my $rs = $c->controller('solGS::Search')->model($c)->project_details_by_name($term);
57 while (my $row = $rs->next)
59 my $pop_id = $row->id;
60 my $page_type = $c->controller('solGS::Path')->page_type($c, $c->req->referer);
61 my $is_computation = $c->controller('solGS::Search')->check_saved_analysis_trial($c, $pop_id);
63 if ($page_type =~ /training_model/)
65 #filter out trials of analysis_type (with stored analyzed results) from search
66 #result of trials relevant to selection prediction.
67 if (!$is_computation)
69 push @response_list, $row->name;
72 else
74 #filter out trials of analysis_type (with stored analyzed results) and with out phenotype data from search
75 #result of trials relevant to training populations.
76 my $has_phenotype = $c->controller('solGS::Search')->model($c)->has_phenotype($pop_id);
77 if ($has_phenotype && !$is_computation)
79 push @response_list, $row->name;
84 $c->{stash}->{rest} = \@response_list;
88 sub begin : Private {
89 my ($self, $c) = @_;
91 $c->controller('solGS::Files')->get_solgs_dirs($c);
95 ###
97 ###