... | ... |
@@ -23,3 +23,9 @@ requires 'Test::MockModule', '== 0.05'; |
23 | 23 |
requires 'Digest::SHA', '== 5.84'; |
24 | 24 |
requires 'Text::Markdown::Hoedown', '== 1.01'; |
25 | 25 |
requires 'parent', '== 0.228'; |
26 |
+requires 'Data::Page', '== 2.02'; |
|
27 |
+requires 'Class::Accessor::Chained', '== 0.01'; |
|
28 |
+requires 'Class::Accessor', '== 0.34'; |
|
29 |
+requires 'Test::Exception', '== 0.32'; |
|
30 |
+requires 'Sub::Uplevel', '== 0.24'; |
|
31 |
+requires 'Data::Page::Navigation', '== 0.06'; |
... | ... |
@@ -1,36 +1,56 @@ |
1 | 1 |
<% |
2 |
+ use Data::Page (); |
|
3 |
+ use Data::Page::Navigation (); |
|
4 |
+ |
|
5 |
+ # Parameters |
|
2 | 6 |
my $type = param('type'); |
7 |
+ my $q = param('q'); |
|
8 |
+ my $page = param('page'); |
|
9 |
+ |
|
3 | 10 |
my $type_exists = $type ? 1 : 0; |
4 | 11 |
$type ||= 'repositories'; |
5 |
- my $q = param('q'); |
|
6 | 12 |
my $q_exists = defined $q ? 1 : 0; |
7 | 13 |
|
8 | 14 |
# DBI |
9 | 15 |
my $dbi = app->dbi; |
10 |
- |
|
11 |
- my $users; |
|
12 |
- my $projects; |
|
16 |
+ |
|
17 |
+ # Limit |
|
18 |
+ $page ||= 1; |
|
19 |
+ my $count = 20; |
|
20 |
+ my $offset = ($page - 1) * $count; |
|
21 |
+ |
|
22 |
+ my $rows; |
|
23 |
+ my $tabel; |
|
24 |
+ my $table; |
|
25 |
+ my $where = $dbi->where; |
|
13 | 26 |
if ($q_exists) { |
14 | 27 |
if ($type eq 'users') { |
15 |
- $users = $dbi->model('user')->select( |
|
16 |
- where => [ |
|
17 |
- ':id{like}', |
|
18 |
- {id => "%$q%"} |
|
19 |
- ], |
|
20 |
- append => 'order by id' |
|
28 |
+ $table = 'user'; |
|
29 |
+ $where->clause(':id{like}'); |
|
30 |
+ $where->param({id => "%$q%"}); |
|
31 |
+ $rows = $dbi->model($table)->select( |
|
32 |
+ where => $where, |
|
33 |
+ append => "order by id limit $offset, $count" |
|
21 | 34 |
)->all; |
22 | 35 |
} elsif ($type eq 'repositories') { |
23 |
- $projects = $dbi->model('project')->select( |
|
24 |
- where => [ |
|
25 |
- ':name{like}', |
|
26 |
- {name => "%$q%"} |
|
27 |
- ], |
|
28 |
- append => 'order by name, user_id' |
|
36 |
+ $table = 'project'; |
|
37 |
+ $where->clause(':name{like}'); |
|
38 |
+ $where->param({name => "%$q%"}); |
|
39 |
+ $rows = $dbi->model($table)->select( |
|
40 |
+ where => $where, |
|
41 |
+ append => "order by name, user_id limit $offset, $count" |
|
29 | 42 |
)->all; |
30 | 43 |
} |
31 | 44 |
} |
32 |
- $users ||= []; |
|
33 |
- $projects ||= []; |
|
45 |
+ $rows ||= []; |
|
46 |
+ |
|
47 |
+ # Pager |
|
48 |
+ my $total = $dbi->model($table)->select( |
|
49 |
+ 'count(*)', |
|
50 |
+ where => $where, |
|
51 |
+ )->value; |
|
52 |
+ my $pager = Data::Page->new($total, $count, $page); |
|
53 |
+ my @pages = $pager->pages_in_navigation(10); |
|
34 | 54 |
%> |
35 | 55 |
% layout 'common', title => 'Search'; |
36 | 56 |
|
... | ... |
@@ -67,8 +87,11 @@ |
67 | 87 |
</div> |
68 | 88 |
<div class="span10"> |
69 | 89 |
% if ($type eq 'users') { |
70 |
- % if (@$users) { |
|
71 |
- % for my $user (@$users) { |
|
90 |
+ % if (@$rows) { |
|
91 |
+ <div style="font-size:18px;padding-bottom:10px;margin-bottom:10px;border-bottom:1px solid #EEEEEE"> |
|
92 |
+ <b>We've found <%= $total %> user results</b> |
|
93 |
+ </div> |
|
94 |
+ % for my $user (@$rows) { |
|
72 | 95 |
% my $user = $user->{id}; |
73 | 96 |
<div> |
74 | 97 |
<div> |
... | ... |
@@ -83,8 +106,11 @@ |
83 | 106 |
</div> |
84 | 107 |
% } |
85 | 108 |
% } else { |
86 |
- % if (@$projects) { |
|
87 |
- % for my $project (@$projects) { |
|
109 |
+ % if (@$rows) { |
|
110 |
+ <div style="font-size:18px;padding-bottom:10px;margin-bottom:10px;border-bottom:1px solid #EEEEEE"> |
|
111 |
+ <b>We've found <%= $total %> repository results</b> |
|
112 |
+ </div> |
|
113 |
+ % for my $project (@$rows) { |
|
88 | 114 |
% my $user = $project->{user_id}; |
89 | 115 |
% my $project = $project->{name}; |
90 | 116 |
% my $rev = app->manager->default_branch($user, $project); |
... | ... |
@@ -118,6 +144,30 @@ |
118 | 144 |
</div> |
119 | 145 |
% } |
120 | 146 |
% } |
147 |
+ |
|
148 |
+ % if (@$rows && $pager->last_page != 1) { |
|
149 |
+ <div class="pagination"> |
|
150 |
+ <ul> |
|
151 |
+ % if ($pager->previous_page) { |
|
152 |
+ <li><a href="<%= url_with->query([page => $pager->previous_page]) %>">«</a></li> |
|
153 |
+ % } else { |
|
154 |
+ <li class="disabled"><a href="#">«</a></li> |
|
155 |
+ % } |
|
156 |
+ % for my $p (@pages) { |
|
157 |
+ % if ($p eq $pager->current_page) { |
|
158 |
+ <li class="active"><a href="#"><%= $p %></a></li> |
|
159 |
+ % } else { |
|
160 |
+ <li><a href="<%= url_with->query([page => $p]) %>"><%= $p %></a></li> |
|
161 |
+ % } |
|
162 |
+ % } |
|
163 |
+ % if ($pager->next_page) { |
|
164 |
+ <li><a href="<%= url_with->query([page => $pager->next_page]) %>">»</a></li> |
|
165 |
+ % } else { |
|
166 |
+ <li class="disabled"><a href="#">»</a></li> |
|
167 |
+ % } |
|
168 |
+ </ul> |
|
169 |
+ </div> |
|
170 |
+ % } |
|
121 | 171 |
</div> |
122 | 172 |
</div> |
123 | 173 |
</div> |