Showing 2 changed files with 102 additions and 4 deletions
+97 -1
templates/auto/_search.html.ep
... ...
@@ -1 +1,97 @@
1
-aaaa
1
+<%
2
+  my $type = param('type');
3
+  my $type_exists = $type ? 1 : 0;
4
+  $type ||= 'repositories';
5
+  my $q = param('q');
6
+  my $q_exists = defined $q ? 1 : 0;
7
+  
8
+  # DBI
9
+  my $dbi = app->dbi;
10
+  
11
+  my $users;
12
+  my $projects;
13
+  if ($q_exists) {
14
+    if ($type eq 'users') {
15
+      $users = $dbi->model('user')->select(
16
+        where => [
17
+          ':id{like}',
18
+          {id => "%$q%"}
19
+        ],
20
+        append => 'order by id'
21
+      )->all;
22
+    } 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'
29
+      )->all;
30
+    }
31
+  }
32
+  $users ||= [];
33
+  $projects ||= [];
34
+%>
35
+% layout 'common';
36
+  
37
+  %= include '/include/header', title => 'Gitprep';
38
+  <!-- Index page -->
39
+  <div class="container" style="min-heigth:500px">
40
+    <div class="row">
41
+      <div class="span2">
42
+        <h3 style="font-size:19px;display:inline-block;margin-top:5px;margin-bottom:0;padding-bottom:0;padding-top:0">Search</h3>
43
+      </div>
44
+      <div class="span10" style="height:30px">
45
+        <form action="<%= url_for %>">
46
+          <%= text_field 'q', style => "width:600px;margin-top:10px;margin-right:3px" %>
47
+          <input class="btn" type="submit" value="Search">
48
+          % if ($type_exists) {
49
+            %= hidden_field type => $type;
50
+          % }
51
+        </form>
52
+      </div>
53
+    </div>
54
+  </div>
55
+  <hr>
56
+  <div class="container" style="min-heigth:500px">
57
+    <div class="row">
58
+      <div class="span2">
59
+        <ul class="nav nav-tabs nav-stacked">
60
+          <li>
61
+            <a href="<%= url_with->query([type => 'repositories']) %>">Repositories</a>
62
+          </li>
63
+          <li>
64
+            <a href="<%= url_with->query([type => 'users']) %>">Users</a>
65
+          </li>
66
+        </ul>
67
+      </div>
68
+      <div class="span10">
69
+        % if ($type eq 'users') {
70
+          % if (@$users) {
71
+            % for my $user (@$users) {
72
+              <div>
73
+                <%= $user->{id} %>
74
+              </div>
75
+            % }
76
+          % } else {
77
+            <div class="well">
78
+              <b>We couldn't find any users matching '<%= $q %>'</b>
79
+            </div>
80
+          % }
81
+        % } else {
82
+          % if (@$projects) {
83
+            % for my $project (@$projects) {
84
+              <div>
85
+                <%= $project->{name} %>
86
+              </div>
87
+            % }
88
+          % } else {
89
+            <div class="well">
90
+              <b>We couldn't find any repositories matching '<%= $q %>'</b>
91
+            </div>
92
+          % }
93
+        % }
94
+      </div>
95
+    </div>
96
+  </div>
97
+  %= include '/include/footer';
+5 -3
templates/include/header.html.ep
... ...
@@ -7,9 +7,11 @@
7 7
     <div class="span6">
8 8
       <div style="margin-top:5px">
9 9
         <h3 style="display:inline-block"><a href="<%= url_for('/') %>">GitPrep</a></h3>
10
-        <form action="<%= url_for('/_search') %>" style="display:inline-block;margin-left:15px">
11
-          <%= text_field 'q', style => 'display:inline-block', placeholder => 'Search' %>
12
-        </form>
10
+        % if ((url_for->path->parts->[0] || '') ne '_search') {
11
+          <form action="<%= url_for('/_search') %>" style="display:inline-block;margin-left:15px">
12
+            <%= text_field 'q', style => 'display:inline-block', placeholder => 'Search' %>
13
+          </form>
14
+        % }
13 15
       </div>
14 16
     </div>
15 17
     <div class="span6 text-right">