Commit 5b284f6adf4cf17ffb66b32a5afdb2f754d5ad5f
1 parent
86021a7d
Exists in
master
and in
4 other branches
Add ability to Search issues
Showing
7 changed files
with
61 additions
and
11 deletions
Show diff stats
Gemfile
Gemfile.lock
... | ... | @@ -128,6 +128,7 @@ GEM |
128 | 128 | treetop (~> 1.4.8) |
129 | 129 | mime-types (1.16) |
130 | 130 | multi_json (1.0.3) |
131 | + mysql2 (0.3.7) | |
131 | 132 | nokogiri (1.5.0) |
132 | 133 | orm_adapter (0.0.5) |
133 | 134 | polyglot (0.3.2) |
... | ... | @@ -258,6 +259,7 @@ DEPENDENCIES |
258 | 259 | jquery-rails |
259 | 260 | kaminari |
260 | 261 | launchy |
262 | + mysql2 | |
261 | 263 | pygments.rb (= 0.2.3) |
262 | 264 | rails (= 3.1.0) |
263 | 265 | rails-footnotes (>= 3.7.5.rc4) | ... | ... |
app/controllers/issues_controller.rb
... | ... | @@ -78,6 +78,13 @@ class IssuesController < ApplicationController |
78 | 78 | render :nothing => true |
79 | 79 | end |
80 | 80 | |
81 | + def search | |
82 | + @project = Project.find(params['project']) | |
83 | + @issues = @project.issues.where("title LIKE ? OR content LIKE ?", "%#{params['terms']}%", "%#{params['terms']}%") | |
84 | + | |
85 | + render :partial => 'issues' | |
86 | + end | |
87 | + | |
81 | 88 | protected |
82 | 89 | |
83 | 90 | def issue | ... | ... |
app/views/issues/index.html.haml
1 | 1 | %div |
2 | 2 | - if can? current_user, :write_issue, @project |
3 | - .left= link_to 'New Issue', new_project_issue_path(@project), :remote => true, :class => "lbutton vm" | |
3 | + .left | |
4 | + = form_tag search_project_issues_path(@project), :method => :get, :remote => true do | |
5 | + = search_field_tag :issue_search, nil, { :placeholder => 'Search', :class => 'issue_search' } | |
6 | + = link_to 'New Issue', new_project_issue_path(@project), :remote => true, :class => "lbutton vm" | |
7 | + | |
4 | 8 | .right |
5 | 9 | = form_tag project_issues_path(@project), :method => :get do |
6 | 10 | .span-2 |
... | ... | @@ -20,6 +24,18 @@ |
20 | 24 | #issues-table-holder= render "issues" |
21 | 25 | %br |
22 | 26 | :javascript |
27 | + $('.issue_search').keyup(function() { | |
28 | + var terms = $(this).val(); | |
29 | + var project_id = 1; | |
30 | + | |
31 | + if (terms.length >= 2) { | |
32 | + $.get($(this).parent().attr('action'), { 'terms': terms, project: project_id }, function(response) { | |
33 | + $('#issues-table').html(response); | |
34 | + setSortable(); | |
35 | + }); | |
36 | + } | |
37 | + }); | |
38 | + | |
23 | 39 | $('.delete-issue').live('ajax:success', function() { |
24 | 40 | $(this).closest('tr').fadeOut(); }); |
25 | 41 | ... | ... |
config/database.yml
... | ... | @@ -4,8 +4,9 @@ |
4 | 4 | # Ensure the SQLite 3 gem is defined in your Gemfile |
5 | 5 | # gem 'sqlite3' |
6 | 6 | development: |
7 | - adapter: sqlite3 | |
8 | - database: db/development.sqlite3 | |
7 | + adapter: mysql2 | |
8 | + database: gitlab_development | |
9 | + username: root | |
9 | 10 | pool: 5 |
10 | 11 | timeout: 5000 |
11 | 12 | |
... | ... | @@ -13,13 +14,11 @@ development: |
13 | 14 | # re-generated from your development database when you run "rake". |
14 | 15 | # Do not set this db to the same as development or production. |
15 | 16 | test: |
16 | - adapter: sqlite3 | |
17 | - database: db/test.sqlite3 | |
18 | - pool: 5 | |
19 | - timeout: 5000 | |
17 | + adapter: mysql2 | |
18 | + database: gitlab_development | |
19 | + username: root | |
20 | 20 | |
21 | 21 | production: |
22 | - adapter: sqlite3 | |
23 | - database: db/production.sqlite3 | |
24 | - pool: 5 | |
25 | - timeout: 5000 | |
22 | + adatper: mysql2 | |
23 | + database: gitlab_test | |
24 | + username: root | ... | ... |
config/routes.rb
spec/requests/issues_spec.rb
... | ... | @@ -144,4 +144,26 @@ describe "Issues" do |
144 | 144 | end |
145 | 145 | end |
146 | 146 | end |
147 | + | |
148 | + describe "Search issue", :js => true do | |
149 | + before do | |
150 | + ['foobar', 'foobar2', 'gitlab'].each do |title| | |
151 | + @issue = Factory :issue, | |
152 | + :author => @user, | |
153 | + :assignee => @user, | |
154 | + :project => project, | |
155 | + :title => title | |
156 | + @issue.save | |
157 | + end | |
158 | + end | |
159 | + | |
160 | + it "should search and return the correct results" do | |
161 | + visit project_issues_path(project) | |
162 | + fill_in "issue_search", :with => "foobar" | |
163 | + page.should have_content 'foobar' | |
164 | + page.should have_content 'foobar2' | |
165 | + page.should_not have_content 'gitlab' | |
166 | + end | |
167 | + end | |
168 | + | |
147 | 169 | end | ... | ... |