From 23d346cfc7dae6f8e34d01ab7476d1536346b9b6 Mon Sep 17 00:00:00 2001 From: Chris Weyl Date: Tue, 30 Mar 2010 19:58:47 -0700 Subject: [PATCH] Massive reorg/cleanups. Move /packages/ to /, as it's really the only page that... matters. Drop extra, unused controllers, as well as some unused template files, etc. Move sidebar widgets over into markup, in an attempt to be more consistent :) --- lib/Fedora/App/Updates/Controller/Package.pm | 86 ----------- lib/Fedora/App/Updates/Controller/Packages.pm | 59 -------- lib/Fedora/App/Updates/Controller/REST.pm | 136 ++++++++++-------- lib/Fedora/App/Updates/Controller/Root.pm | 105 +++++--------- .../App/Updates/Schema/ResultSet/Packages.pm | 13 +- root/lib/site/sidebar | 25 +--- root/src/index.tt2 | 135 +++++++++++++++-- root/src/message.tt2 | 16 --- root/src/packages.tt2 | 129 ----------------- root/src/welcome.tt2 | 9 -- t/controller_Package.t | 10 -- t/controller_Packages.t | 10 -- 12 files changed, 244 insertions(+), 489 deletions(-) delete mode 100644 lib/Fedora/App/Updates/Controller/Package.pm delete mode 100644 lib/Fedora/App/Updates/Controller/Packages.pm delete mode 100644 root/src/message.tt2 delete mode 100644 root/src/packages.tt2 delete mode 100644 root/src/welcome.tt2 delete mode 100644 t/controller_Package.t delete mode 100644 t/controller_Packages.t diff --git a/lib/Fedora/App/Updates/Controller/Package.pm b/lib/Fedora/App/Updates/Controller/Package.pm deleted file mode 100644 index cc79771..0000000 --- a/lib/Fedora/App/Updates/Controller/Package.pm +++ /dev/null @@ -1,86 +0,0 @@ -package Fedora::App::Updates::Controller::Package; - -use strict; -use warnings; -use parent 'Catalyst::Controller'; - -=head1 NAME - -Fedora::App::Updates::Controller::Package - Catalyst Controller - -=head1 DESCRIPTION - -Catalyst Controller. - -=head1 METHODS - -=cut - - -=head2 index - -=cut - -sub index :Path :Args(0) { - my ( $self, $c ) = @_; - - $c->response->body('Matched Fedora::App::Updates::Controller::Package in Package.'); -} - -=head2 get_package - -Private action. - -=cut - -sub get_package : Chained('/') PathPart('package') CaptureArgs(1) { - my ($self, $c, $name) = @_; - - my $package = $c - ->model('Updates::Packages') - ->find({ name => $name }) - ; - - $c->stash->{package} = $package; - return; -} - -=head2 package_show - -=cut - -sub package_show : Chained('get_package') PathPart('') Args(0) { - my ($self, $c) = @_; - - # ... -} - -=head1 AUTHOR - -Chris Weyl - -=head1 LICENCE AND COPYRIGHT - -Copyright (c) 2008, Chris Weyl - -This library is free software; you can redistribute it and/or modify it under -the terms of the GNU Lesser General Public License as published by the Free -Software Foundation; either version 2.1 of the License, or (at your option) -any later version. - -This library is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -OR A PARTICULAR PURPOSE. - -See the GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with this library; if not, write to the - - Free Software Foundation, Inc., - 59 Temple Place, Suite 330, - Boston, MA 02111-1307 USA - -=cut - -1; diff --git a/lib/Fedora/App/Updates/Controller/Packages.pm b/lib/Fedora/App/Updates/Controller/Packages.pm deleted file mode 100644 index 80038c3..0000000 --- a/lib/Fedora/App/Updates/Controller/Packages.pm +++ /dev/null @@ -1,59 +0,0 @@ -package Fedora::App::Updates::Controller::Packages; - -use strict; -use warnings; -use parent 'Catalyst::Controller'; - -=head1 NAME - -Fedora::App::Updates::Controller::Packages - Catalyst Controller - -=head1 DESCRIPTION - -Catalyst Controller. - -=head1 METHODS - -=cut - - -=head2 index - -=cut - -sub index :Path :Args(0) { - my ( $self, $c ) = @_; - - $c->response->body('Matched Fedora::App::Updates::Controller::Packages in Packages.'); -} - - -=head1 AUTHOR - -Chris Weyl - -=head1 LICENCE AND COPYRIGHT - -Copyright (c) 2008, Chris Weyl - -This library is free software; you can redistribute it and/or modify it under -the terms of the GNU Lesser General Public License as published by the Free -Software Foundation; either version 2.1 of the License, or (at your option) -any later version. - -This library is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -OR A PARTICULAR PURPOSE. - -See the GNU Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with this library; if not, write to the - - Free Software Foundation, Inc., - 59 Temple Place, Suite 330, - Boston, MA 02111-1307 USA - -=cut - -1; diff --git a/lib/Fedora/App/Updates/Controller/REST.pm b/lib/Fedora/App/Updates/Controller/REST.pm index db53c6d..3907504 100644 --- a/lib/Fedora/App/Updates/Controller/REST.pm +++ b/lib/Fedora/App/Updates/Controller/REST.pm @@ -1,36 +1,14 @@ package Fedora::App::Updates::Controller::REST; -use strict; -use warnings; +use Moose; +use namespace::autoclean; -use parent 'Catalyst::Controller::REST'; +BEGIN { extends 'Catalyst::Controller::REST' } use DBIx::Class::ResultClass::HashRefInflator; -=head1 NAME - -Fedora::App::Updates::Controller::REST - Catalyst Controller - -=head1 DESCRIPTION - -RESTful Catalyst Controller. - -=head1 HELPERS - -=head2 status_partial_content - -Returns a "206 Partial Content" response. Takes an "entity" to serialize. - -Dojo uses this for requesting chunks of information.. - -Example: - - $self->status_partial_content( - $c, - entity => { ... }, - ); - -=cut +##############################################################3 +# Helpers sub status_partial_content { my $self = shift; @@ -43,6 +21,9 @@ sub status_partial_content { return 1; } +# take a DBIC::ResultSet and "explode" it out into an arrayref of hashrefs +# (hashrefs being just the raw rows). + sub _explode { my ($self, $rs) = @_; @@ -51,11 +32,28 @@ sub _explode { return [ $rs->all ]; } -=head1 METHODS +sub handle_partial_request { + my ($self, $c, $rs, $transform_sub) = @_; -=head2 packages + return unless my $range = $c->req->header('Range'); -=cut + my $total = $rs->count; + + # break out our start and end ranges... + # we do sometimes see 'items=0-' + $range =~ s/items=//; + my ($from, $to) = split /-/, $range; + $to = $total unless $to && $to < $total; + + # now, touch up our result set... + $rs = $rs->search(undef, { rows => $to - $from + 1, offset => $from }); + + $c->res->header('Content-Range' => "items $from-$to/$total"); + return $self->status_partial_content($c, entity => $transform_sub->($rs)); +} + +##############################################################3 +# Actions sub package_names : Local ActionClass('REST') { } @@ -64,7 +62,7 @@ sub package_names_GET { my $like = $c->req->params->{name} || '%'; $like =~ s/\*/%/g; - + my $rs = $c->model('Updates::Packages'); my @names = $rs ->search( @@ -84,7 +82,7 @@ sub package_names_GET { warn "to: $to"; $to = $total - 1 unless $to && $to < $total; - my @partial = @names[$from..$to]; + my @partial = @names[$from..$to]; # make sure $to = $from + actual number of items $to = $from + scalar @partial; @@ -110,7 +108,7 @@ sub packages_GET { # FIXME need search bits here my $search = $self->query_to_dbic($c); - my $rs = $c->model('Updates::Packages')->search($search, { order_by => 'name' }); + my $rs = $c->model('Updates::Packages')->search($search, { order_by => 'me.name' }); my $transform_sub = sub { shift->all_versions }; return $self->handle_partial_request($c, $rs, $transform_sub) @@ -130,58 +128,76 @@ sub query_to_dbic { # if we're a wildcard search... $name =~ s/\*/%/g; - return { name => { LIKE => $name } }; + return { 'me.name' => { LIKE => $name } }; } - return { name => $name }; + return { 'me.name' => $name }; } -sub handle_partial_request { - my ($self, $c, $rs, $transform_sub) = @_; +__PACKAGE__->meta->make_immutable; - return unless my $range = $c->req->header('Range'); +__END__ - my $total = $rs->count; +=head1 NAME - # break out our start and end ranges... - # we do sometimes see 'items=0-' - $range =~ s/items=//; - my ($from, $to) = split /-/, $range; - $to = $total unless $to && $to < $total; +Fedora::App::Updates::Controller::REST - Catalyst Controller - # now, touch up our result set... - $rs = $rs->search(undef, { rows => $to - $from + 1, offset => $from }); +=head1 DESCRIPTION + +RESTful Catalyst Controller. + +=head1 HELPERS + +=head2 status_partial_content + +Returns a "206 Partial Content" response. Takes an "entity" to serialize. + +Dojo uses this for requesting chunks of information. + +Example: + + $self->status_partial_content( + $c, + entity => { ... }, + ); + +=head2 _explode + +Take a L and "explode" it out into a collection of +hashrefs, using L. + +=head1 PATH ACTIONS + +=head2 package_names + + +=head2 packages - $c->res->header('Content-Range' => "items $from-$to/$total"); - return $self->status_partial_content($c, entity => $transform_sub->($rs)); -} =head1 AUTHOR -Chris Weyl +Chris Weyl =head1 LICENCE AND COPYRIGHT Copyright (c) 2008, Chris Weyl This library is free software; you can redistribute it and/or modify it under -the terms of the GNU Lesser General Public License as published by the Free -Software Foundation; either version 2.1 of the License, or (at your option) +the terms of the GNU Lesser General Public License as published by the Free +Software Foundation; either version 2.1 of the License, or (at your option) any later version. -This library is distributed in the hope that it will be useful, but WITHOUT +This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS OR A PARTICULAR PURPOSE. -See the GNU Lesser General Public License for more details. +See the GNU Lesser General Public License for more details. -You should have received a copy of the GNU Lesser General Public License -along with this library; if not, write to the +You should have received a copy of the GNU Lesser General Public License +along with this library; if not, write to the - Free Software Foundation, Inc., - 59 Temple Place, Suite 330, + Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA =cut - -1; diff --git a/lib/Fedora/App/Updates/Controller/Root.pm b/lib/Fedora/App/Updates/Controller/Root.pm index c14d04b..28093ef 100644 --- a/lib/Fedora/App/Updates/Controller/Root.pm +++ b/lib/Fedora/App/Updates/Controller/Root.pm @@ -1,9 +1,5 @@ package Fedora::App::Updates::Controller::Root; -#use strict; -#use warnings; -#use parent 'Catalyst::Controller'; - use Moose; BEGIN { extends 'Catalyst::Controller' } @@ -13,97 +9,65 @@ BEGIN { extends 'Catalyst::Controller' } # __PACKAGE__->config->{namespace} = ''; -=head1 NAME - -Fedora::App::Updates::Controller::Root - Root Controller for Fedora::App::Updates - -=head1 DESCRIPTION - -[enter your description here] - -=head1 METHODS - -=cut - -=head2 index - -=cut - sub index : Path Args(0) { my ( $self, $c ) = @_; - # Hello World - #$c->response->body( $c->welcome_message ); + # get our list of dists to display + my @dists = $c + ->model('Updates::Dist') + ->search(undef, { order_by => 'shortname DESC' }) + ->get_column('shortname') + ->all + ; + $c->stash->{dists} = \@dists; + + return; } sub default : Path { - my ( $self, $c ) = @_; - $c->response->body( 'Page not found' ); + my ($self, $c) = @_; + + $c->response->body('Page not found'); $c->response->status(404); } -use Fedora::App::Updates::Form::Search; - -has search_form => ( - is => 'ro', - isa => 'Fedora::App::Updates::Form::Search', - lazy => 1, - clearer => 'clear_search_form', - default => sub { Fedora::App::Updates::Form::Search->new }, -); - sub packages : Path('packages') Args(0) { my ($self, $c) = @_; - # setup our packages resultset - my $packages = $c->stash->{packages} = $c - ->model('Updates::Packages') - ->search( - { name => { like => 'perl%' } }, - { order_by => 'name', rows => 40}, - ) - ; + # forward to /, redirect from old path... + $c->res->redirect($c->uri_for('/'), 301); + $c->detach; - # let's try out this pager thingie, hmm? - my $page = $c->request->param('page'); - $page = 1 if (not defined $page) || ($page !~ /^\d+$/); + return; +} - $c->stash->{packages} = $packages = $c->stash->{packages}->page($page); - $c->stash->{pager} = $packages->pager; +sub end : ActionClass('RenderView') {} - # get our list of dists to display - my @dists = $c - ->model('Updates::Dist') - ->search(undef, { order_by => 'shortname DESC' }) - ->get_column('shortname') - ->all - ; - $c->stash->{dists} = \@dists; +__PACKAGE__->meta->make_immutable; - my @dist_ids = $c - ->model('Updates::Dist') - ->search(undef, { order_by => 'shortname DESC' }) - ->get_column('id') - ->all - ; - $c->stash->{dist_ids} = \@dist_ids; +__END__ - $c->stash->{search_form} = $self->search_form; +=head1 NAME - return; -} +Fedora::App::Updates::Controller::Root - Root Controller for Fedora::App::Updates -=head2 end +=head1 METHODS -Attempt to render a view, if needed. +=head2 index -=cut +The main -- and only -- real public path. -sub end : ActionClass('RenderView') {} +=index2 packages + +Redirect to the index action -- formerly an active public path. + +=head2 end + +Attempt to render a view, if needed. =head1 AUTHOR -Chris Weyl +Chris Weyl =head1 LICENCE AND COPYRIGHT @@ -129,4 +93,3 @@ along with this library; if not, write to the =cut -1; diff --git a/lib/Fedora/App/Updates/Schema/ResultSet/Packages.pm b/lib/Fedora/App/Updates/Schema/ResultSet/Packages.pm index 853d0c5..32e1095 100644 --- a/lib/Fedora/App/Updates/Schema/ResultSet/Packages.pm +++ b/lib/Fedora/App/Updates/Schema/ResultSet/Packages.pm @@ -24,8 +24,9 @@ sub all_versions { my ($self) = @_; my @rows = (); + my $rs = $self->search(undef, { prefetch => { versions => 'dist' } }); - while (my $row = $self->next) { + for my $row ($rs->all) { # FIXME this should all be refactored out into a Result class method @@ -35,18 +36,14 @@ sub all_versions { owner => $row->owner_id, }; - my $versions_rs = $row->search_related( - 'versions', undef, { prefetch => [ 'dist' ] }, - ); - #$data->{$_->dist->shortname} = $_->current while $_ = $versions_rs->next; - while (my $v = $versions_rs->next) { + for my $v ($row->versions->all) { #my $sn = $v->dist->shortname; my ($sn, $c, $class) = ($v->dist->shortname, $v->current, $v->update_class); - $data->{$sn} = $v->current; - $data->{"$sn-class"} = $v->update_class; + $data->{$sn} = $c; # $v->current; + $data->{"$sn-class"} = $class; # $v->update_class; $data->{"$sn-html"} = qq{$c}; } diff --git a/root/lib/site/sidebar b/root/lib/site/sidebar index bc9a567..508259f 100644 --- a/root/lib/site/sidebar +++ b/root/lib/site/sidebar @@ -3,35 +3,24 @@ + +