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
| @@ -20,6 +20,7 @@ gem "kaminari" | @@ -20,6 +20,7 @@ gem "kaminari" | ||
| 20 | gem "thin" | 20 | gem "thin" |
| 21 | gem "git" | 21 | gem "git" |
| 22 | gem "acts_as_list" | 22 | gem "acts_as_list" |
| 23 | +gem "mysql2" | ||
| 23 | 24 | ||
| 24 | group :assets do | 25 | group :assets do |
| 25 | gem 'sass-rails', " ~> 3.1.0" | 26 | gem 'sass-rails', " ~> 3.1.0" |
Gemfile.lock
| @@ -128,6 +128,7 @@ GEM | @@ -128,6 +128,7 @@ GEM | ||
| 128 | treetop (~> 1.4.8) | 128 | treetop (~> 1.4.8) |
| 129 | mime-types (1.16) | 129 | mime-types (1.16) |
| 130 | multi_json (1.0.3) | 130 | multi_json (1.0.3) |
| 131 | + mysql2 (0.3.7) | ||
| 131 | nokogiri (1.5.0) | 132 | nokogiri (1.5.0) |
| 132 | orm_adapter (0.0.5) | 133 | orm_adapter (0.0.5) |
| 133 | polyglot (0.3.2) | 134 | polyglot (0.3.2) |
| @@ -258,6 +259,7 @@ DEPENDENCIES | @@ -258,6 +259,7 @@ DEPENDENCIES | ||
| 258 | jquery-rails | 259 | jquery-rails |
| 259 | kaminari | 260 | kaminari |
| 260 | launchy | 261 | launchy |
| 262 | + mysql2 | ||
| 261 | pygments.rb (= 0.2.3) | 263 | pygments.rb (= 0.2.3) |
| 262 | rails (= 3.1.0) | 264 | rails (= 3.1.0) |
| 263 | rails-footnotes (>= 3.7.5.rc4) | 265 | rails-footnotes (>= 3.7.5.rc4) |
app/controllers/issues_controller.rb
| @@ -78,6 +78,13 @@ class IssuesController < ApplicationController | @@ -78,6 +78,13 @@ class IssuesController < ApplicationController | ||
| 78 | render :nothing => true | 78 | render :nothing => true |
| 79 | end | 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 | protected | 88 | protected |
| 82 | 89 | ||
| 83 | def issue | 90 | def issue |
app/views/issues/index.html.haml
| 1 | %div | 1 | %div |
| 2 | - if can? current_user, :write_issue, @project | 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 | .right | 8 | .right |
| 5 | = form_tag project_issues_path(@project), :method => :get do | 9 | = form_tag project_issues_path(@project), :method => :get do |
| 6 | .span-2 | 10 | .span-2 |
| @@ -20,6 +24,18 @@ | @@ -20,6 +24,18 @@ | ||
| 20 | #issues-table-holder= render "issues" | 24 | #issues-table-holder= render "issues" |
| 21 | %br | 25 | %br |
| 22 | :javascript | 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 | $('.delete-issue').live('ajax:success', function() { | 39 | $('.delete-issue').live('ajax:success', function() { |
| 24 | $(this).closest('tr').fadeOut(); }); | 40 | $(this).closest('tr').fadeOut(); }); |
| 25 | 41 |
config/database.yml
| @@ -4,8 +4,9 @@ | @@ -4,8 +4,9 @@ | ||
| 4 | # Ensure the SQLite 3 gem is defined in your Gemfile | 4 | # Ensure the SQLite 3 gem is defined in your Gemfile |
| 5 | # gem 'sqlite3' | 5 | # gem 'sqlite3' |
| 6 | development: | 6 | development: |
| 7 | - adapter: sqlite3 | ||
| 8 | - database: db/development.sqlite3 | 7 | + adapter: mysql2 |
| 8 | + database: gitlab_development | ||
| 9 | + username: root | ||
| 9 | pool: 5 | 10 | pool: 5 |
| 10 | timeout: 5000 | 11 | timeout: 5000 |
| 11 | 12 | ||
| @@ -13,13 +14,11 @@ development: | @@ -13,13 +14,11 @@ development: | ||
| 13 | # re-generated from your development database when you run "rake". | 14 | # re-generated from your development database when you run "rake". |
| 14 | # Do not set this db to the same as development or production. | 15 | # Do not set this db to the same as development or production. |
| 15 | test: | 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 | production: | 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
| @@ -47,6 +47,9 @@ Gitlab::Application.routes.draw do | @@ -47,6 +47,9 @@ Gitlab::Application.routes.draw do | ||
| 47 | collection do | 47 | collection do |
| 48 | post :sort | 48 | post :sort |
| 49 | end | 49 | end |
| 50 | + collection do | ||
| 51 | + get :search | ||
| 52 | + end | ||
| 50 | end | 53 | end |
| 51 | resources :notes, :only => [:create, :destroy] | 54 | resources :notes, :only => [:create, :destroy] |
| 52 | end | 55 | end |
spec/requests/issues_spec.rb
| @@ -144,4 +144,26 @@ describe "Issues" do | @@ -144,4 +144,26 @@ describe "Issues" do | ||
| 144 | end | 144 | end |
| 145 | end | 145 | end |
| 146 | end | 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 | end | 169 | end |