replace empty fixture with one that works.
[sgn.git] / lib / SGN / Controller / Search.pm
blobd6e0a4d76ede195aa5baef8e4c403a6d02366823
1 package SGN::Controller::Search;
2 use Moose;
3 use URI::FromHash 'uri';
4 use namespace::autoclean;
5 use Data::Dumper;
7 use CXGN::Search::CannedForms;
8 use CXGN::Page::Toolbar::SGN;
9 use CXGN::Glossary qw(get_definitions create_tooltips_from_text);
11 # this is suboptimal
12 use CatalystX::GlobalContext qw( $c );
14 BEGIN {extends 'Catalyst::Controller'; }
16 =head1 NAME
18 SGN::Controller::Search - SGN Search Controller
20 =head1 DESCRIPTION
22 SGN Search Controller. Most, but not all, search code interacts with this
23 controller. This controller defines the general search interface that used to
24 live at direct_search.pl, and links to all other kinds of search.
26 =cut
28 sub auto : Private {
29 $_[1]->stash->{template} = '/search/stub.mas';
32 =head1 PUBLIC ACTIONS
34 =cut
36 =head2 glossary
38 Public path: /search/glossary
40 Runs the glossary search.
42 =cut
44 sub glossary : Path('/search/glossary') :Args() {
45 my ( $self, $c, $term ) = @_;
46 my $response;
47 if($term){
48 my @defs = get_definitions($term);
49 unless (@defs){
50 $response = "<p>Your term was not found. <br> The term you searched for was $term.</p>";
51 } else {
52 $response = "<hr /><dl><dt>$term</dt>";
53 for my $d (@defs){
54 $response .= "<dd>$d</dd><br />";
56 $response .= "</dl>";
58 } else {
59 $response =<<DEFAULT;
60 <hr />
61 <h2>Glossary search</h2>
62 <form action="#" method='get' name='glossary'>
63 <b>Search the glossary by term:</b>
64 <input type = 'text' name = 'getTerm' size = '50' tabindex='0' />
65 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
66 <input type = 'submit' value = 'Lookup' /></form>
67 <script type="text/javascript" language="javascript">
68 document.glossary.getTerm.focus();
69 </script>
71 DEFAULT
74 $c->stash(
75 content => $response,
80 =head2 old_direct_search
82 Public path: /search/direct_search.pl
84 Redirects to the new search functionality.
86 =cut
88 sub old_direct_search : Path('/search/direct_search.pl') {
89 my ( $self, $c ) = @_;
91 my $term = $c->req->param('search');
93 $term =~ s/[{}\n\r;'"]//g;
95 # map the old direct_search param to the new scheme
96 $term = {
97 cvterm_name => 'qtl',
99 qtl => 'phenotypes/qtl',
100 marker => 'markers',
102 # expression
103 platform => 'expression/platform',
104 template => 'expression/template',
105 experiment => 'expression/experiment',
107 # transcripts
108 est_library => 'transcripts/est_library',
109 est => 'transcripts/est',
110 unigene => 'transcripts/unigene',
111 library => 'transcripts/est_library',
113 template_experiment_platform => 'expression',
115 bacs => 'genomic/clones',
117 phenotype_qtl_trait => 'phenotypes',
120 }->{$term} || $term;
121 $c->res->redirect('/search/'.$term, 301 );
124 =head2 search_index
126 Public path: /search/index.pl, /search/
128 Display a search index page.
130 =cut
132 sub search_index : Path('/search/index.pl') Path('/search') Args(0) {
133 my ( $self, $c ) = @_;
135 $c->stash->{template} = '/search/advanced_search.mas';
138 sub family_search : Path('/search/family') Args(0) {
139 $_[1]->stash->{content} = CXGN::Search::CannedForms->family_search_form();
142 sub marker_search : Path('/search/markers') Args(0) {
143 my ( $self, $c ) = @_;
144 my $dbh = $c->dbc->dbh;
145 my $mform = CXGN::Search::CannedForms::MarkerSearch->new($dbh);
146 $c->stash->{content} =
147 '<form action="/search/markers/markersearch.pl">'
148 . $mform->to_html()
149 . '</form>';
153 sub bac_search : Path('/search/genomic/clones') Args(0) {
154 $_[1]->stash->{content} = CXGN::Search::CannedForms->clone_search_form();
157 sub directory_search : Path('/search/directory') Args(0) {
158 $_[1]->stash->{content} = CXGN::Search::CannedForms->people_search_form();
161 #sub gene_search : Path('/search/loci') Args(0) {
162 # $_[1]->stash->{content} = CXGN::Search::CannedForms->gene_search_form();
165 sub images_search : Path('/search/images') Args(0) {
166 my $self = shift;
167 my $c = shift;
168 $c->stash->{template} = '/search/images.mas';
169 #$_[1]->stash->{content} = CXGN::Search::CannedForms->image_search_form(); ####DEPRECATED CGIBIN CODE
172 sub bulk_search : Path('/search/bulk') Args(0) {
173 my $self = shift;
174 my $c = shift;
176 if (!$c->user()) {
177 $c->res->redirect( uri( path => '/user/login', query => { goto_url => $c->req->uri->path_query } ) );
178 $c->detach();
181 $c->stash->{template} = '/search/bulk.mas';
184 =head1 AUTHOR
186 Converted to Catalyst by Jonathan "Duke" Leto, then heavily refactored
187 by Robert Buels
189 =head1 LICENSE
191 This library is free software. You can redistribute it and/or modify
192 it under the same terms as Perl itself.
194 =cut
196 __PACKAGE__->meta->make_immutable;