<% 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; my $total; 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(':project.id{like}'); $where->param({'project.id' => "%$q%"}); $rows = $dbi->model($table)->select( [ {__MY__ => '*'}, {user => ['id']} ], where => $where, append => "order by project.id, user.id limit $offset, $count" )->all; } $total = $dbi->model($table)->select( 'count(*)', where => $where, )->value; } $rows //= []; $total //= 0; # Pager 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
% } else {
We couldn't find any users matching '<%= $q %>'
% } % } else { % if (@$rows) {
We've found <%= $total %> repository results
    % for my $project (@$rows) { <% my $user_id = $project->{'user.id'}; my $project_id = $project->{id}; my $rev = app->manager->default_branch($user_id, $project_id); my $desc = app->git->description(app->rep_info($user_id, $project_id)); my $branches = app->git->branches($self->app->rep_info($user_id, $project_id)); my $commit; if (@$branches) { $commit = app->git->get_commit(app->rep_info($user_id, $project_id), $rev); } %>
  • <%= $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) {
    % if ($pager->previous_page) {
  • «
  • % } else {
  • «
  • % } % for my $p (@pages) { % if ($p eq $pager->current_page) {
  • <%= $p %>
  • % } else {
  • <%= $p %>
  • % } % } % if ($pager->next_page) {
  • »
  • % } else {
  • »
  • % }
% }
%= include '/include/footer';