1 | package Sophie::Controller::0Explorer; |
---|
2 | use Moose; |
---|
3 | use namespace::autoclean; |
---|
4 | |
---|
5 | BEGIN {extends 'Catalyst::Controller'; } |
---|
6 | |
---|
7 | =head1 NAME |
---|
8 | |
---|
9 | Sophie::Controller::0Explorer - Catalyst Controller |
---|
10 | |
---|
11 | =head1 DESCRIPTION |
---|
12 | |
---|
13 | Catalyst Controller. |
---|
14 | |
---|
15 | =head1 METHODS |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | |
---|
20 | =head2 index |
---|
21 | |
---|
22 | =cut |
---|
23 | |
---|
24 | sub dir :Local { |
---|
25 | my ( $self, $c, @args ) = @_; |
---|
26 | my $dir = join('/', map { "$_" } grep { $_ } @args); |
---|
27 | $c->stash->{path} = $dir; |
---|
28 | $c->stash->{explorerurl} = '/explorer' . ($dir ? "/$dir" : ''); |
---|
29 | |
---|
30 | my $rsdist = $c->forward('/search/distrib_search', [ $c->session->{__explorer} ]); |
---|
31 | $c->stash->{xmlrpc} = [ $c->model('Base') |
---|
32 | ->resultset('Files') |
---|
33 | ->search( |
---|
34 | { |
---|
35 | dirname => '/' . ($dir ? "$dir/" : ''), |
---|
36 | pkgid => { IN => $rsdist->get_column('pkgid')->as_query, }, |
---|
37 | }, |
---|
38 | { |
---|
39 | order_by => [ 'basename' ], |
---|
40 | group_by => [ 'basename' ], |
---|
41 | select => [ 'basename' ], |
---|
42 | } |
---|
43 | )->get_column('basename')->all ]; |
---|
44 | } |
---|
45 | |
---|
46 | sub file :Local { |
---|
47 | my ( $self, $c, @args ) = @_; |
---|
48 | my $basename = pop(@args); |
---|
49 | my $dir = join('/', map { "$_" } grep { $_ } @args); |
---|
50 | $c->stash->{path} = $dir; |
---|
51 | $c->stash->{explorerurl} = '/explorer' . ($dir ? "/$dir" : ''); |
---|
52 | |
---|
53 | my $rsdist = $c->forward('/search/distrib_search', [ $c->session->{__explorer} ]); |
---|
54 | |
---|
55 | $c->stash->{xmlrpc} = [ |
---|
56 | map { { pkgid => $_->get_column('pkgid') } } |
---|
57 | $c->model('Base') |
---|
58 | ->resultset('Files') |
---|
59 | ->search({ |
---|
60 | dirname => '/' . ($dir ? "$dir/" : ''), basename => $basename, |
---|
61 | pkgid => { IN => $rsdist->get_column('pkgid')->as_query, }, |
---|
62 | }, |
---|
63 | { |
---|
64 | 'select' => [ |
---|
65 | 'contents IS NULL as has_contents', 'pkgid' |
---|
66 | ], |
---|
67 | as => [ qw(has_content pkgid) ], |
---|
68 | order_by => 'pkgid' |
---|
69 | } |
---|
70 | )->all ]; |
---|
71 | } |
---|
72 | |
---|
73 | =head1 AUTHOR |
---|
74 | |
---|
75 | Olivier Thauvin |
---|
76 | |
---|
77 | =head1 LICENSE |
---|
78 | |
---|
79 | This library is free software. You can redistribute it and/or modify |
---|
80 | it under the same terms as Perl itself. |
---|
81 | |
---|
82 | =cut |
---|
83 | |
---|
84 | __PACKAGE__->meta->make_immutable; |
---|
85 | |
---|
86 | 1; |
---|