improve search page
|
1 |
<% |
add search feature
|
2 |
use Data::Page (); |
3 |
use Data::Page::Navigation (); |
|
4 |
|
|
5 |
# Parameters |
|
improve search page
|
6 |
my $type = param('type'); |
add search feature
|
7 |
my $q = param('q'); |
8 |
my $page = param('page'); |
|
9 |
|
|
improve search page
|
10 |
my $type_exists = $type ? 1 : 0; |
11 |
$type ||= 'repositories'; |
|
12 |
my $q_exists = defined $q ? 1 : 0; |
|
13 |
|
|
14 |
# DBI |
|
15 |
my $dbi = app->dbi; |
|
add search feature
|
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; |
|
fix search page error bug
|
26 |
my $total; |
improve search page
|
27 |
if ($q_exists) { |
28 |
if ($type eq 'users') { |
|
add search feature
|
29 |
$table = 'user'; |
30 |
$where->clause(':id{like}'); |
|
31 |
$where->param({id => "%$q%"}); |
|
32 |
$rows = $dbi->model($table)->select( |
|
33 |
where => $where, |
|
34 |
append => "order by id limit $offset, $count" |
|
improve search page
|
35 |
)->all; |
36 |
} elsif ($type eq 'repositories') { |
|
add search feature
|
37 |
$table = 'project'; |
fix search page error bug
|
38 |
$where->clause(':project.id{like}'); |
39 |
$where->param({'project.id' => "%$q%"}); |
|
add search feature
|
40 |
$rows = $dbi->model($table)->select( |
fix search page error bug
|
41 |
[ |
42 |
{__MY__ => '*'}, |
|
fix _search page bug
|
43 |
{user => ['id']} |
fix search page error bug
|
44 |
], |
add search feature
|
45 |
where => $where, |
fix _search page bug
|
46 |
append => "order by project.id, user.id limit $offset, $count" |
improve search page
|
47 |
)->all; |
48 |
} |
|
fix search page error bug
|
49 | |
50 |
$total = $dbi->model($table)->select( |
|
51 |
'count(*)', |
|
52 |
where => $where, |
|
53 |
)->value; |
|
improve search page
|
54 |
} |
fix search page error bug
|
55 |
$rows //= []; |
56 |
$total //= 0; |
|
add search feature
|
57 | |
58 |
# Pager |
|
59 |
my $pager = Data::Page->new($total, $count, $page); |
|
60 |
my @pages = $pager->pages_in_navigation(10); |
|
improve search page
|
61 |
%> |
improve search page design
|
62 |
% layout 'common', title => 'Search'; |
improve search page
|
63 |
|
64 |
%= include '/include/header', title => 'Gitprep'; |
|
65 |
<!-- Index page --> |
|
improve search page design
|
66 |
<div class="container"> |
67 |
<div class="search-top"> |
|
68 |
<div>Search</div> |
|
69 |
<form action="<%= url_for %>"> |
|
70 |
<%= text_field 'q', style => "width:600px;margin-top:10px;margin-right:3px" %> |
|
71 |
<input class="btn" type="submit" value="Search"> |
|
72 |
% if ($type_exists) { |
|
73 |
%= hidden_field type => $type; |
|
74 |
% } |
|
75 |
</form> |
|
improve search page
|
76 |
</div> |
77 |
</div> |
|
improve search page design
|
78 |
<div class="container"> |
79 |
<div class="search-result"> |
|
80 |
<div class="left"> |
|
81 |
<ul> |
|
82 |
<li class="<%= $type eq 'repositories' ? 'active' : '' %>"> |
|
improve search page
|
83 |
<a href="<%= url_with->query([type => 'repositories']) %>">Repositories</a> |
84 |
</li> |
|
improve search page design
|
85 |
<li class="<%= $type eq 'users' ? 'active' : '' %>"> |
improve search page
|
86 |
<a href="<%= url_with->query([type => 'users']) %>">Users</a> |
87 |
</li> |
|
88 |
</ul> |
|
89 |
</div> |
|
improve search page design
|
90 |
<div class="right"> |
improve search page
|
91 |
% if ($type eq 'users') { |
add search feature
|
92 |
% if (@$rows) { |
improve search page design
|
93 |
<div> |
94 |
We've found <%= $total %> user results |
|
add search feature
|
95 |
</div> |
improve search page design
|
96 |
<ul> |
97 |
% for my $user (@$rows) { |
|
fix search page error bug
|
98 |
% my $user_id = $user->{id}; |
improve search page design
|
99 |
<li> |
100 |
<div> |
|
fix search page error bug
|
101 |
<a style="font-size:19px" href="<%= url_for("/$user_id") %>"><%= $user_id %></a> |
improve search page design
|
102 |
</div> |
103 |
</li> |
|
104 |
% } |
|
105 |
</ul> |
|
improve search page
|
106 |
% } else { |
improve search page design
|
107 |
<div> |
108 |
We couldn't find any users matching '<%= $q %>' |
|
improve search page
|
109 |
</div> |
110 |
% } |
|
111 |
% } else { |
|
add search feature
|
112 |
% if (@$rows) { |
improve search page design
|
113 |
<div> |
114 |
We've found <%= $total %> repository results |
|
add search feature
|
115 |
</div> |
improve search page design
|
116 |
<ul> |
117 |
% for my $project (@$rows) { |
|
118 |
<% |
|
fix _search page bug
|
119 |
my $user_id = $project->{'user.id'}; |
fix search page error bug
|
120 |
my $project_id = $project->{id}; |
121 |
my $rev = app->manager->default_branch($user_id, $project_id); |
|
122 |
my $desc = app->git->description(app->rep_info($user_id, $project_id)); |
|
123 |
my $branches = app->git->branches($self->app->rep_info($user_id, $project_id)); |
|
improve search page design
|
124 |
my $commit; |
125 |
if (@$branches) { |
|
fix search page error bug
|
126 |
$commit = app->git->get_commit(app->rep_info($user_id, $project_id), $rev); |
improve search page design
|
127 |
} |
128 |
%> |
|
129 |
|
|
130 |
<li> |
|
131 |
<div> |
|
fix search page error bug
|
132 |
<a style="font-size:19px" href="<%= url_for("/$user_id/$project_id") %>"><%= $user_id %>/<%= $project_id %></a> |
improve search page design
|
133 |
</div> |
134 |
<div> |
|
135 |
<%= $desc %> |
|
136 |
</div> |
|
137 |
<div class="text-gray" style="font-size:13px;"> |
|
138 |
% if ($commit) { |
|
139 |
<span title="<%= $commit->{age_string_datetime_local} %>"><%= $commit->{age_string} %> |
|
140 |
% } else { |
|
141 |
<span >Repositry is not yet created. |
|
142 |
% } |
|
143 |
</div> |
|
144 |
</li> |
|
improve search page design
|
145 |
% } |
improve search page design
|
146 |
</ul> |
improve search page
|
147 |
% } else { |
improve search page design
|
148 |
<div> |
149 |
We couldn't find any repositories matching '<%= $q %>' |
|
improve search page
|
150 |
</div> |
151 |
% } |
|
152 |
% } |
|
add search feature
|
153 | |
154 |
% if (@$rows && $pager->last_page != 1) { |
|
improve search page design
|
155 |
<div class="pagination-num"> |
add search feature
|
156 |
<ul> |
157 |
% if ($pager->previous_page) { |
|
158 |
<li><a href="<%= url_with->query([page => $pager->previous_page]) %>">«</a></li> |
|
159 |
% } else { |
|
160 |
<li class="disabled"><a href="#">«</a></li> |
|
161 |
% } |
|
162 |
% for my $p (@pages) { |
|
163 |
% if ($p eq $pager->current_page) { |
|
164 |
<li class="active"><a href="#"><%= $p %></a></li> |
|
165 |
% } else { |
|
166 |
<li><a href="<%= url_with->query([page => $p]) %>"><%= $p %></a></li> |
|
167 |
% } |
|
168 |
% } |
|
169 |
% if ($pager->next_page) { |
|
170 |
<li><a href="<%= url_with->query([page => $pager->next_page]) %>">»</a></li> |
|
171 |
% } else { |
|
172 |
<li class="disabled"><a href="#">»</a></li> |
|
173 |
% } |
|
174 |
</ul> |
|
175 |
</div> |
|
176 |
% } |
|
improve search page
|
177 |
</div> |
178 |
</div> |
|
179 |
</div> |
|
180 |
%= include '/include/footer'; |