<% use Data::Page (); use Data::Page::Navigation (); # Parameters my $type = param('type'); my $q = param('q'); my $page = param('page'); my $type_exists = $type ? 1 : 0; $type ||= 'repositories'; my $q_exists = defined $q ? 1 : 0; # DBI my $dbi = app->dbi; # Limit $page ||= 1; my $count = 20; my $offset = ($page - 1) * $count; my $rows; my $tabel; my $table; my $where = $dbi->where; if ($q_exists) { if ($type eq 'users') { $table = 'user'; $where->clause(':id{like}'); $where->param({id => "%$q%"}); $rows = $dbi->model($table)->select( where => $where, append => "order by id limit $offset, $count" )->all; } elsif ($type eq 'repositories') { $table = 'project'; $where->clause(':name{like}'); $where->param({name => "%$q%"}); $rows = $dbi->model($table)->select( where => $where, append => "order by name, user_id limit $offset, $count" )->all; } } $rows ||= []; # Pager my $total = $dbi->model($table)->select( 'count(*)', where => $where, )->value; my $pager = Data::Page->new($total, $count, $page); my @pages = $pager->pages_in_navigation(10); %> % layout 'common', title => 'Search'; %= include '/include/header', title => 'Gitprep';

Search

<%= text_field 'q', style => "width:600px;margin-top:10px;margin-right:3px" %> % if ($type_exists) { %= hidden_field type => $type; % }

% if ($type eq 'users') { % if (@$rows) {
We've found <%= $total %> user results
% for my $user (@$rows) { % my $user = $user->{id};
"><%= $user %>

% } % } else {
We couldn't find any users matching '<%= $q %>'
% } % } else { % if (@$rows) {
We've found <%= $total %> repository results
% for my $project (@$rows) { % my $user = $project->{user_id}; % my $project = $project->{name}; % my $rev = app->manager->default_branch($user, $project); % my $desc = app->git->description($user, $project); % my $branches = app->git->branches($user, $project); % my $commit; % if (@$branches) { % $commit = app->git->get_commit($user, $project, $rev); % }
"><%= $user %>/<%= $project %>
<%= $desc %>
% if ($commit) { <%= $commit->{age_string} %> % } else { Repositry is not yet created. % }

% } % } else {
We couldn't find any repositories matching '<%= $q %>'
% } % } % if (@$rows && $pager->last_page != 1) { % }
%= include '/include/footer';