1 package SGN
::Controller
::Root
;
3 use namespace
::autoclean
;
5 use Scalar
::Util
'weaken';
6 use CatalystX
::GlobalContext
();
9 use CXGN
::People
::Person
;
11 BEGIN { extends
'Catalyst::Controller' }
14 # Sets the actions in this controller to be registered with no prefix
15 # so they function identically to actions created in MyApp.pm
17 __PACKAGE__
->config(namespace
=> '');
21 SGN::Controller::Root - Root Controller for SGN
25 Web application to run the SGN web site.
35 sub index :Path
:Args
(0) {
36 my ( $self, $c ) = @_;
38 if ($c->config->{homepage_display_phenotype_uploads
}){
41 my $schema = $c->dbic_schema('Bio::Chado::Schema', 'sgn_chado');
42 my $q = "SELECT file_id, m.create_date, p.sp_person_id, p.username, basename, dirname, filetype, project_id, project.name FROM nd_experiment_project JOIN project USING(project_id) JOIN nd_experiment_phenotype USING(nd_experiment_id) JOIN phenome.nd_experiment_md_files ON (nd_experiment_phenotype.nd_experiment_id=nd_experiment_md_files.nd_experiment_id) LEFT JOIN metadata.md_files using(file_id) LEFT JOIN metadata.md_metadata as m using(metadata_id) LEFT JOIN sgn_people.sp_person as p ON (p.sp_person_id=m.create_person_id) WHERE m.obsolete = 0 and NOT (metadata.md_files.filetype='generated from plot from plant phenotypes') and NOT (metadata.md_files.filetype='direct phenotyping')";
43 my $h = $schema->storage()->dbh()->prepare($q);
46 while (my ($file_id, $create_date, $person_id, $username, $basename, $dirname, $filetype, $project_id, $project_name) = $h->fetchrow_array()) {
47 $file_info{$file_id}->{project_ids
}->{$project_id} = $project_name;
48 $file_info{$file_id}->{metadata
} = [$file_id, $create_date, $person_id, $username, $basename, $dirname, $filetype, $project_id];
50 foreach (sort {$b <=> $a} keys %file_info){
51 push @file_array, $file_info{$_};
53 #print STDERR Dumper \@file_array;
54 $c->stash->{phenotype_files
} = \
@file_array;
58 $c->stash->{template
} = '/index.mas';
59 $c->stash->{schema
} = $c->dbic_schema('SGN::Schema');
60 $c->stash->{static_content_path
} = $c->config->{static_content_path
};
65 Attempt to find index.pl pages, and prints standard 404 error page if
66 nothing could be found.
71 my ( $self, $c ) = @_;
73 return 1 if $c->forward('/redirects/find_redirect');
80 Render a bare mason component, with no autohandler wrapping.
81 Currently used for GBrowse integration (GBrowse makes a subrequest for
82 the mason header and footer).
86 sub bare_mason
:Path
('bare_mason') {
87 my ( $self, $c, @args ) = @_;
89 # figure out our template path
90 my $t = File
::Spec
->catfile( @args );
91 $t .= '.mas' unless $t =~ m
|\
.[^/\\\
.]+$|;
92 $c->stash->{template
} = $t;
94 # TODO: check that it exists
96 $c->forward('View::BareMason');
99 =head1 PRIVATE ACTIONS
103 Attempt to render a view, if needed.
107 sub render
: ActionClass
('RenderView') { }
109 my ( $self, $c ) = @_;
111 return if @
{$c->error};
113 # don't try to render a default view if this was handled by a CGI
114 $c->forward('render') unless $c->req->path =~ /\.pl$/;
116 # enforce a default text/html content type regardless of whether
117 # we tried to render a default view
118 $c->res->content_type('text/html') unless $c->res->content_type;
120 if( $c->res->content_type eq 'text/html' ) {
121 # insert any additional header html collected during rendering
122 $c->forward('insert_collected_html');
124 # tell caches our responses vary depending on the Cookie header
125 $c->res->headers->push_header('Vary', 'Cookie');
127 $c->log->debug("skipping JS pack insertion for page with content type ".$c->res->content_type)
133 sub insert_collected_html
:Private
{
134 my ( $self, $c ) = @_;
136 $c->forward('/js/resolve_javascript_classes');
138 my $b = $c->res->body;
139 my $inserted_head_pre = $b && $b =~ s{<!-- \s* INSERT_HEAD_PRE_HTML \s* --> }{ $self->_make_head_pre_html( $c ) }ex;
140 my $inserted_head_post = $b && $b =~ s{<!-- \s* INSERT_HEAD_POST_HTML \s* -->}{ $self->_make_head_post_html( $c ) }ex;
141 if( $inserted_head_pre || $inserted_head_post ) {
144 # we have changed the size of the body. remove the
145 # content-length and let catalyst recalculate the content-length
147 $c->res->headers->remove_header('content-length');
149 delete $c->stash->{$_} for qw( add_head_html add_css_files add_js_classes );
153 sub _make_head_pre_html
{
154 my ( $self, $c ) = @_;
155 return join "\n", @
{ $c->stash->{head_pre_html
} || [] };
158 sub _make_head_post_html
{
159 my ( $self, $c ) = @_;
161 my $head_post_html = join "\n", (
162 @
{ $c->stash->{add_head_html
} || [] },
164 qq{<link rel
="stylesheet" type
="text/css" href
="$_" />}
165 } @
{ $c->stash->{css_uris
} || [] }
168 qq{<script src
="$_" type
="text/javascript"></script
>}
169 } @
{ $c->stash->{js_uris
} || [] }
173 return $head_post_html;
178 Run for every request to the site.
184 CatalystX
::GlobalContext
->set_context( $c );
186 weaken
$c->stash->{c
};
187 $c->assets->set_base_uri($c->config->{main_production_site_url
});
189 # gluecode for logins
191 unless( $c->config->{'disable_login'} ) {
192 my $dbh = $c->dbc->dbh;
193 if ( my $sp_person_id = CXGN
::Login
->new( $dbh )->has_session ) {
195 my $sp_person = CXGN
::People
::Person
->new( $dbh, $sp_person_id);
198 username
=> $sp_person->get_username(),
199 password
=> $sp_person->get_password(),
209 ############# helper methods ##########
211 sub _find_cgi_action
{
212 my ($self,$c,$path) = @_;
215 my $cgi = $c->controller('CGI')
218 my $index_action = $cgi->cgi_action_for( $path )
221 $c->log->debug("found CGI index action '$index_action'") if $c->debug;
223 return $index_action;
228 Robert Buels, Jonathan "Duke" Leto
232 This library is free software. You can redistribute it and/or modify
233 it under the same terms as Perl itself.
237 __PACKAGE__
->meta->make_immutable;