Showing 2 changed files with 39 additions and 17 deletions
+24 -17
templates/auto/_search.html.ep
... ...
@@ -23,6 +23,7 @@
23 23
   my $tabel;
24 24
   my $table;
25 25
   my $where = $dbi->where;
26
+  my $total;
26 27
   if ($q_exists) {
27 28
     if ($type eq 'users') {
28 29
       $table = 'user';
... ...
@@ -34,21 +35,27 @@
34 35
       )->all;
35 36
     } elsif ($type eq 'repositories') {
36 37
       $table = 'project';
37
-      $where->clause(':name{like}');
38
-      $where->param({name => "%$q%"});
38
+      $where->clause(':project.id{like}');
39
+      $where->param({'project.id' => "%$q%"});
39 40
       $rows = $dbi->model($table)->select(
41
+        [
42
+          {__MY__ => '*'},
43
+          {__user => ['id']}
44
+        ],
40 45
         where => $where,
41
-        append => "order by name, user_id limit $offset, $count"
46
+        append => "order by project.id, __user.id limit $offset, $count"
42 47
       )->all;
43 48
     }
49
+
50
+    $total = $dbi->model($table)->select(
51
+      'count(*)',
52
+      where => $where,
53
+    )->value;
44 54
   }
45
-  $rows ||= [];
55
+  $rows //= [];
56
+  $total //= 0;
46 57
 
47 58
   # Pager
48
-  my $total = $dbi->model($table)->select(
49
-    'count(*)',
50
-    where => $where,
51
-  )->value;
52 59
   my $pager = Data::Page->new($total, $count, $page);
53 60
   my @pages = $pager->pages_in_navigation(10);
54 61
 %>
... ...
@@ -88,10 +95,10 @@
88 95
             </div>
89 96
             <ul>
90 97
               % for my $user (@$rows) {
91
-                % my $user = $user->{id};
98
+                % my $user_id = $user->{id};
92 99
                 <li>
93 100
                   <div>
94
-                    <a style="font-size:19px" href="<%= url_for("/$user") %>"><%= $user %></a>
101
+                    <a style="font-size:19px" href="<%= url_for("/$user_id") %>"><%= $user_id %></a>
95 102
                   </div>
96 103
                 </li>
97 104
               % }
... ...
@@ -109,20 +116,20 @@
109 116
             <ul>
110 117
               % for my $project (@$rows) {
111 118
                 <%
112
-                  my $user = $project->{user_id};
113
-                  my $project = $project->{name};
114
-                  my $rev = app->manager->default_branch($user, $project);
115
-                  my $desc = app->git->description(app->rep_info($user, $project));
116
-                  my $branches = app->git->branches($self->app->rep_info($user, $project));
119
+                  my $user_id = $project->{'__user.id'};
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));
117 124
                   my $commit;
118 125
                   if (@$branches) {
119
-                    $commit = app->git->get_commit(app->rep_info($user, $project), $rev);
126
+                    $commit = app->git->get_commit(app->rep_info($user_id, $project_id), $rev);
120 127
                   }
121 128
                 %>
122 129
                 
123 130
                 <li>
124 131
                   <div>
125
-                    <a style="font-size:19px" href="<%= url_for("/$user/$project") %>"><%= $user %>/<%= $project %></a>
132
+                    <a style="font-size:19px" href="<%= url_for("/$user_id/$project_id") %>"><%= $user_id %>/<%= $project_id %></a>
126 133
                   </div>
127 134
                   <div>
128 135
                     <%= $desc %>
+15
xt/basic.t
... ...
@@ -429,3 +429,18 @@ note 'Compare page';
429 429
   $t->content_like(qr/branch change/);
430 430
   $t->content_like(qr#http://foo5branch change#);
431 431
 }
432
+
433
+note 'Search page';
434
+{
435
+  # Page access (branch name)
436
+  $t->get_ok("/_search");
437
+  $t->content_like(qr/Search/);
438
+
439
+  # Page access (branch name)
440
+  $t->get_ok("/_search?q=foo&type=repositories");
441
+  $t->content_like(qr/Search/);
442
+
443
+  # Page access (branch name)
444
+  $t->get_ok("/_search?q=foo&type=users");
445
+  $t->content_like(qr/Search/);
446
+}