From 04d4846eadff4c553440b9b1a7e2689ca5a36403 Mon Sep 17 00:00:00 2001 From: mueller Date: Tue, 26 Oct 2010 16:02:45 -0400 Subject: [PATCH] fixing and adapting test for ajax image function --- lib/SGN/Controller/#Feature.pm# | 220 ++++++++++++++++++++++++++++++++++++++++ t/image/ajax.t | 15 +-- 2 files changed, 228 insertions(+), 7 deletions(-) create mode 100644 lib/SGN/Controller/#Feature.pm# diff --git a/lib/SGN/Controller/#Feature.pm# b/lib/SGN/Controller/#Feature.pm# new file mode 100644 index 000000000..4737e7b5a --- /dev/null +++ b/lib/SGN/Controller/#Feature.pm# @@ -0,0 +1,220 @@ +package SGN::Controller::Feature; + +=head1 NAME + +SGN::Controller::Feature - Catalyst controller for pages dealing with features + +=cut + +use Moose; +use namespace::autoclean; + +use HTML::FormFu; +use URI::FromHash 'uri'; +use YAML::Any; +use SGN::View::Feature qw/feature_link/; + +has 'schema' => ( +is => 'rw', +isa => 'DBIx::Class::Schema', +required => 0, +); + +has 'default_page_size' => ( +is => 'ro', +default => 20, +); + + +BEGIN { extends 'Catalyst::Controller' } +with 'Catalyst::Component::ApplicationAttribute'; + +sub delegate_component +{ + my ($self, $c, $matching_features) = @_; + my $feature = $matching_features->next; + my @children = $feature->child_features; + my @parents = $feature->parent_features; + my $type_name = $feature->type->name; + my $template = "/feature/dhandler"; + + $c->stash->{feature} = $feature; + $c->stash->{children} = \@children; + $c->stash->{parents} = \@parents; + + if ($c->view('Mason')->component_exists("/feature/$type_name.mas")) { + $template = "/feature/$type_name.mas"; + $c->stash->{type} = $type_name; + } + $c->stash->{template} = $template; +} + +sub validate +{ + my ($self, $c,$matching_features,$key, $val) = @_; + my $count = $matching_features->count; +# EVIL HACK: We need a disambiguation process +# $c->throw( message => "too many features where $key='$val'") if $count > 1; + $c->throw( message => "feature with $key = '$val' not found") if $count < 1; +} + +sub view_name :Path('/feature/view/name') Args(1) { + my ( $self, $c, $feature_name ) = @_; + $self->schema( $c->dbic_schema('Bio::Chado::Schema','sgn_chado') ); + $self->_view_feature($c, 'name', $feature_name); +} + +sub _validate_pair { + my ($self,$c,$key,$value) = @_; + $c->throw( message => "$value is not a valid value for $key" ) + if ($key =~ m/_id$/ and $value !~ m/\d+/); +} + +sub _view_feature { + my ($self, $c, $key, $value) = @_; + + $self->_validate_pair($c,$key,$value); + my $matching_features = $self->schema + ->resultset('Sequence::Feature') + ->search({ $key => $value }); + + $self->validate($c, $matching_features, $key => $value); + $self->delegate_component($c, $matching_features); +} + +sub view_id :Path('/feature/view/id') Args(1) { + my ( $self, $c, $feature_id ) = @_; + $self->schema( $c->dbic_schema('Bio::Chado::Schema','sgn_chado') ); + $self->_view_feature($c, 'feature_id', $feature_id); +} + +sub search :Path('/feature/search') Args(0) { + my ( $self, $c ) = @_; + $self->schema( $c->dbic_schema('Bio::Chado::Schema','sgn_chado') ); + + my $req = $c->req; + my $form = $self->_build_form; + + $form->process( $req ); + + my $results; + if( $form->submitted_and_valid ) { + $results = $self->_make_feature_search_rs( $c, $form ); + } + + $c->forward_to_mason_view( + '/feature/search.mas', + form => $form, + results => $results, + pagination_link_maker => sub { + return uri( query => { %{$form->params}, page => shift } ); + }, + ); +} + + +sub _build_form { + my ($self) = @_; + + my $form = HTML::FormFu->new(Load(<