Changeset 53


Ignore:
Timestamp:
11/30/10 02:02:14 (14 years ago)
Author:
nanardon
Message:
  • factorize code
  • add some view in distrib/
Location:
server/trunk/web
Files:
5 added
4 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/lib/Sophie/Controller/Distrib.pm

    r50 r53  
    7878} 
    7979 
     80sub distrib_rs : Private { 
     81    my ( $self, $c, $distrib ) = @_; 
     82    return $c->model('Base')->resultset('Distribution') 
     83        ->search( 
     84            { 
     85                $distrib->{distribution} 
     86                    ? (name => $distrib->{distribution}) 
     87                    : () 
     88            } 
     89        )->search_related('Release', 
     90            { 
     91                $distrib->{release} 
     92                    ? (version => $distrib->{release}) 
     93                    : () 
     94            } 
     95        )->search_related('Arch', 
     96            { 
     97                $distrib->{arch} 
     98                    ? (arch => $distrib->{arch}) 
     99                    : () 
     100            } 
     101        )->search_related('Medias', 
     102            { 
     103                ($distrib->{media} ? (label => $distrib->{media}) : ()), 
     104                ($distrib->{media_group} 
     105                    ? (group_label => $distrib->{media_group}) 
     106                    : ()), 
     107            } 
     108        ); 
     109} 
     110 
     111sub exists : XMLRPC { 
     112    my ( $self, $c, $d ) = @_; 
     113 
     114    my $rs = $c->forward('distrib_rs', [ $d ]); 
     115 
     116    if ($rs->search({}, { rows => 1 })->next) { 
     117        $c->stash->{xmlrpc} = 1; 
     118    } else { 
     119        $c->stash->{xmlrpc} = 0; 
     120    } 
     121} 
    80122 
    81123=head2 index 
     
    96138    my ( $self, $c, $distribution ) = @_; 
    97139    $c->stash->{dist}{distribution} = $distribution; 
     140    if (!$c->forward('exists', [ $c->stash->{dist} ])) { 
     141        $c->go('/404/index'); 
     142    } 
    98143    $c->forward('list', [ $c->stash->{dist} ] ); 
    99144} 
     
    127172} 
    128173 
    129 sub rpms :XMLRPC { 
    130     my ( $self, $c, $distribution, $release, $arch ) = @_; 
    131  
    132     if (ref $distribution) { 
    133         ($distribution, $release, $arch) = ( 
    134             $distribution->{distribution}, 
    135             $distribution->{release}, 
    136             $distribution->{arch}, 
    137         ); 
    138     } 
    139      
     174sub anyrpms :XMLRPC { 
     175    my ( $self, $c, $distribution, $release, $arch ) = @_; 
     176 
     177    if (!ref $distribution) { 
     178        $distribution = { 
     179            distribution => $distribution, 
     180            release => $release, 
     181            arch => $arch, 
     182        } 
     183    } 
     184 
    140185    @{$c->stash->{rpm}} = map { 
    141186            {  
     
    144189            } 
    145190        } 
    146         $c->model('Base') 
    147         ->resultset('Distribution')->search({ name => $distribution }) 
    148         ->search_related('Release', { version => $release }) 
    149         ->search_related('Arch',    { arch => $arch }) 
    150         ->search_related('Medias') 
     191        $c->forward('distrib_rs', [ $distribution ]) 
     192        ->search_related('MediasPaths') 
     193        ->search_related('Paths') 
     194        ->search_related('Rpmfiles') 
     195        ->all; 
     196 
     197    $c->stash->{xmlrpc} = $c->stash->{rpm}; 
     198} 
     199 
     200sub rpms :XMLRPC { 
     201    my ( $self, $c, $distribution, $release, $arch ) = @_; 
     202 
     203    if (!ref $distribution) { 
     204        $distribution = { 
     205            distribution => $distribution, 
     206            release => $release, 
     207            arch => $arch, 
     208        } 
     209    } 
     210 
     211    $c->stash->{rpm} = [ map { 
     212            {  
     213              pkgid => $_->pkgid, 
     214              filename => $_->filename, 
     215            } 
     216        } 
     217        $c->forward('distrib_rs', [ $distribution ]) 
    151218        ->search_related('MediasPaths') 
    152219        ->search_related('Paths') 
     
    155222                IN => $c->model('Base')->resultset('Rpms') 
    156223                ->search({ issrc => 'false' })->get_column('pkgid') ->as_query } 
    157         } )->all; 
     224        } )->all ]; 
    158225 
    159226    $c->stash->{xmlrpc} = $c->stash->{rpm}; 
     
    163230    my ( $self, $c, $distribution, $release, $arch ) = @_; 
    164231 
    165     if (ref $distribution) { 
    166         ($distribution, $release, $arch) = ( 
    167             $distribution->{distribution}, 
    168             $distribution->{release}, 
    169             $distribution->{arch}, 
    170         ); 
     232    if (!ref $distribution) { 
     233        $distribution = { 
     234            distribution => $distribution, 
     235            release => $release, 
     236            arch => $arch, 
     237        } 
    171238    } 
    172239 
     
    177244            } 
    178245        } 
    179         $c->model('Base') 
    180         ->resultset('Distribution')->search({ name => $distribution }) 
    181         ->search_related('Release', { version => $release }) 
    182         ->search_related('Arch',    { arch => $arch }) 
    183         ->search_related('Medias') 
     246        $c->forward('distrib_rs', [ $distribution ]) 
    184247        ->search_related('MediasPaths') 
    185248        ->search_related('Paths') 
     
    193256} 
    194257 
     258sub rpms_name :XMLRPC { 
     259    my ( $self, $c, $distribution, $release, $arch ) = @_; 
     260 
     261    if (!ref $distribution) { 
     262        $distribution = { 
     263            distribution => $distribution, 
     264            release => $release, 
     265            arch => $arch, 
     266        } 
     267    } 
     268 
     269    $c->stash->{xmlrpc} = [ 
     270        $c->model('Base')->resultset('Rpms')->search( 
     271            { pkgid => { 
     272                IN => 
     273        $c->forward('distrib_rs', [ $distribution ]) 
     274        ->search_related('MediasPaths') 
     275        ->search_related('Paths') 
     276        ->search_related('Rpmfiles')->get_column('pkgid')->as_query 
     277        } }, 
     278        { group_by => [ qw(name) ], order_by => [ qw(name) ] } 
     279        )->get_column('name')->all ]; 
     280} 
     281 
    195282sub list_rpms :Chained('distrib_view') PathPart('rpms') { 
    196283    my ( $self, $c ) = @_; 
     
    224311} 
    225312 
    226 sub media_rpms : XMLRPC { 
    227     my ( $self, $c, $distribution, $release, $arch, $media ) = @_; 
    228      
    229     if (ref $distribution) { 
    230         ($distribution, $release, $arch, $media) = ( 
    231             $distribution->{distribution}, 
    232             $distribution->{release}, 
    233             $distribution->{arch}, 
    234             $release, 
    235         ); 
    236     } 
    237      
    238     @{$c->stash->{rpm}} = map { 
    239             {  
    240               pkgid => $_->pkgid, 
    241               filename => $_->filename, 
    242             } 
    243         } 
    244         $c->model('Base') 
    245         ->resultset('Distribution')->search({ name => $distribution }) 
    246         ->search_related('Release', { version => $release }) 
    247         ->search_related('Arch',    { arch => $arch }) 
    248         ->search_related('Medias', { label => $media }) 
    249         ->search_related('MediasPaths') 
    250         ->search_related('Paths') 
    251         ->search_related('Rpmfiles')->all; 
    252  
    253     $c->stash->{xmlrpc} = $c->stash->{rpm}; 
    254 } 
    255  
    256313sub _media_list_rpms :Chained('distrib_view') PathPart('media') CaptureArgs(1) { 
    257314    my ( $self, $c, $media ) = @_; 
    258     $c->stash->{media} = $media; 
     315    $c->stash->{dist}{media} = $media; 
    259316} 
    260317 
    261318sub media_list_rpms :Chained('_media_list_rpms') PathPart('') { 
    262319    my ( $self, $c ) = @_; 
    263     $c->forward('media_rpms', [ $c->stash->{dist}, $c->stash->{media} ]); 
     320    $c->forward('anyrpms', [ $c->stash->{dist} ]); 
    264321} 
    265322 
  • server/trunk/web/lib/Sophie/Controller/Search.pm

    r51 r53  
    6666    my ( $self, $c, $searchspec ) = @_; 
    6767 
    68     return $c->model('Base')->resultset('Distribution') 
    69         ->search( 
    70             { 
    71                 $searchspec->{distribution} 
    72                     ? (name => $searchspec->{distribution}) 
    73                     : () 
    74             } 
    75         )->search_related('Release', 
    76             { 
    77                 $searchspec->{release} 
    78                     ? (version => $searchspec->{release}) 
    79                     : () 
    80             } 
    81         )->search_related('Arch', 
    82             { 
    83                 $searchspec->{arch} 
    84                     ? (arch => $searchspec->{arch}) 
    85                     : () 
    86             } 
    87         )->search_related('Medias', 
    88             { 
    89                 ($searchspec->{media} ? (label => $searchspec->{media}) : ()), 
    90                 ($searchspec->{media_group} 
    91                     ? (group_label => $searchspec->{media_group})  
    92                     : ()), 
    93             } 
    94         )->search_related('MediasPaths') 
     68    return $c->forward('/distrib/distrib_rs', [ $searchspec ]) 
     69        ->search_related('MediasPaths') 
    9570        ->search_related('Paths') 
    9671        ->search_related('Rpmfiles'); 
  • server/trunk/web/root/templates/html/distrib/distrib.html

    r21 r53  
    1 <ol> 
    2 [% FOREACH media = xmlrpc %] 
    3 <li><a href="[% c.uri_for('/', c.req.path, 'media', media) %]">[% media %]</a></li> 
    4 [% END %] 
    5 </ol> 
     1<!-- $Id$ --> 
     2 
     3[% INCLUDE 'distrib/distrib.tt' %] 
  • server/trunk/web/t/controller_Distrib.t

    r21 r53  
    99my $release = 'cooker'; 
    1010my $arch = 'i586'; 
     11my $media = 'main-release'; 
    1112 
    1213BEGIN { use_ok 'Catalyst::Test', 'Sophie' } 
     
    3031ok( request("/distrib/$distribution/$release")->is_success, 'Request should succeed' ); 
    3132ok( request("/distrib/$distribution/$release/$arch")->is_success, 'Request should succeed' ); 
     33ok( request("/distrib/$distribution/$release/$arch/media")->is_success, 'Request should succeed' ); 
    3234done_testing(); 
Note: See TracChangeset for help on using the changeset viewer.