source: server/trunk/web/lib/Sophie/Controller/0Explorer.pm @ 421

Last change on this file since 421 was 277, checked in by nanardon, 13 years ago
  • use animated icons to notify ajax load
File size: 2.9 KB
Line 
1package Sophie::Controller::0Explorer;
2use Moose;
3use namespace::autoclean;
4use DBD::Pg qw(:async);
5use Sophie::Base::Async;
6
7BEGIN {extends 'Catalyst::Controller'; }
8
9=head1 NAME
10
11Sophie::Controller::0Explorer - Catalyst Controller
12
13=head1 DESCRIPTION
14
15Catalyst Controller.
16
17=head1 METHODS
18
19=cut
20
21
22=head2 index
23
24=cut
25
26sub dir :Local {
27    my ( $self, $c, @args ) = @_;
28    my $dir = join('/', map { "$_" } grep { $_ } @args);
29    $c->stash->{path} = $dir;
30    $c->stash->{explorerurl} = '/explorer' . ($dir ? "/$dir" : '');
31
32    my $rsdist = $c->forward('/search/distrib_search', [
33            $c->session->{__explorer}, 1 ]);
34    my %uniq;
35
36    my $query = Sophie::Base::Async->new(
37        $c->model('Base'),
38        timeout => 30,
39        build => sub { $_[0]
40            ->resultset('Files')
41            ->search(
42                {
43                    dirname => '/' . ($dir ? "$dir/" : ''),
44                    ($rsdist 
45                        ? (pkgid => { IN => $rsdist->get_column('pkgid')->as_query, },)
46                        : ()),
47                    ($c->req->param('filename')
48                        ? ( basename => { LIKE => $c->req->param('filename') . '%' } )
49                        : ()),
50                },
51                {
52                    #order_by => [ 'basename' ],
53                    #group_by => [ 'basename' ],
54                    select => [ 'basename' ],
55                }
56            )
57            ->get_column('basename')
58        },
59    );
60
61    if(my $sth = $query->wait_result) {
62        while (my $res = $sth->fetchrow_hashref()) {
63            $uniq{$res->{basename}} = 1;
64        }
65    } else {
66        $c->stash->{timeout} = 1;
67    }
68
69    $c->stash->{xmlrpc} = [ sort keys %uniq ]; 
70}
71
72sub file :Local {
73    my ( $self, $c, @args ) = @_;
74    my $basename = pop(@args);
75    my $dir = join('/', map { "$_" } grep { $_ } @args);
76    $c->stash->{path} = $dir;
77    $c->stash->{explorerurl} = '/explorer' . ($dir ? "/$dir" : '');
78
79    my $rsdist = $c->forward('/search/distrib_search', [
80            $c->session->{__explorer}, 1 ]);
81
82    my @col = qw(dirname basename md5 size pkgid count);
83    $c->stash->{xmlrpc} = [ 
84        map { {
85                $_->get_columns
86            } }
87        $c->model('Base')
88      ->resultset('Files')
89      ->search({
90              dirname => '/' . ($dir ? "$dir/" : ''), basename => $basename,
91              ($rsdist 
92                ? (pkgid => { IN => $rsdist->get_column('pkgid')->as_query, },)
93                : ())
94          },
95          { 
96              'select' => [ 'contents is NOT NULL as has_content', 'rpmfilesmode(mode) as perm', @col, '"group"',
97                  '"user"' ],
98              as => [ qw(has_content perm), @col, 'group', 'user' ],
99              order_by => [ 'pkgid' ],
100
101          },
102      )->all ];
103}
104
105=head1 AUTHOR
106
107Olivier Thauvin
108
109=head1 LICENSE
110
111This library is free software. You can redistribute it and/or modify
112it under the same terms as Perl itself.
113
114=cut
115
116__PACKAGE__->meta->make_immutable;
117
1181;
Note: See TracBrowser for help on using the repository browser.