Browse files

Add ability to Search issues

  • Loading branch information...
1 parent 86021a7 commit 5b284f6adf4cf17ffb66b32a5afdb2f754d5ad5f @adamjleonard adamjleonard committed Oct 22, 2011
Showing with 61 additions and 11 deletions.
  1. +1 −0 Gemfile
  2. +2 −0 Gemfile.lock
  3. +7 −0 app/controllers/issues_controller.rb
  4. +17 −1 app/views/issues/index.html.haml
  5. +9 −10 config/database.yml
  6. +3 −0 config/routes.rb
  7. +22 −0 spec/requests/issues_spec.rb
View
1 Gemfile
@@ -20,6 +20,7 @@ gem "kaminari"
gem "thin"
gem "git"
gem "acts_as_list"
+gem "mysql2"
group :assets do
gem 'sass-rails', " ~> 3.1.0"
View
2 Gemfile.lock
@@ -128,6 +128,7 @@ GEM
treetop (~> 1.4.8)
mime-types (1.16)
multi_json (1.0.3)
+ mysql2 (0.3.7)
nokogiri (1.5.0)
orm_adapter (0.0.5)
polyglot (0.3.2)
@@ -258,6 +259,7 @@ DEPENDENCIES
jquery-rails
kaminari
launchy
+ mysql2
pygments.rb (= 0.2.3)
rails (= 3.1.0)
rails-footnotes (>= 3.7.5.rc4)
View
7 app/controllers/issues_controller.rb
@@ -78,6 +78,13 @@ def sort
render :nothing => true
end
+ def search
+ @project = Project.find(params['project'])
+ @issues = @project.issues.where("title LIKE ? OR content LIKE ?", "%#{params['terms']}%", "%#{params['terms']}%")
+
+ render :partial => 'issues'
+ end
+
protected
def issue
View
18 app/views/issues/index.html.haml
@@ -1,6 +1,10 @@
%div
- if can? current_user, :write_issue, @project
- .left= link_to 'New Issue', new_project_issue_path(@project), :remote => true, :class => "lbutton vm"
+ .left
+ = form_tag search_project_issues_path(@project), :method => :get, :remote => true do
+ = search_field_tag :issue_search, nil, { :placeholder => 'Search', :class => 'issue_search' }
+ = link_to 'New Issue', new_project_issue_path(@project), :remote => true, :class => "lbutton vm"
+
.right
= form_tag project_issues_path(@project), :method => :get do
.span-2
@@ -20,6 +24,18 @@
#issues-table-holder= render "issues"
%br
:javascript
+ $('.issue_search').keyup(function() {
+ var terms = $(this).val();
+ var project_id = 1;
+
+ if (terms.length >= 2) {
+ $.get($(this).parent().attr('action'), { 'terms': terms, project: project_id }, function(response) {
+ $('#issues-table').html(response);
+ setSortable();
+ });
+ }
+ });
+
$('.delete-issue').live('ajax:success', function() {
$(this).closest('tr').fadeOut(); });
View
19 config/database.yml
@@ -4,22 +4,21 @@
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
- adapter: sqlite3
- database: db/development.sqlite3
+ adapter: mysql2
+ database: gitlab_development
+ username: root
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
- adapter: sqlite3
- database: db/test.sqlite3
- pool: 5
- timeout: 5000
+ adapter: mysql2
+ database: gitlab_development
+ username: root
production:
- adapter: sqlite3
- database: db/production.sqlite3
- pool: 5
- timeout: 5000
+ adatper: mysql2
+ database: gitlab_test
+ username: root
View
3 config/routes.rb
@@ -47,6 +47,9 @@
collection do
post :sort
end
+ collection do
+ get :search
+ end
end
resources :notes, :only => [:create, :destroy]
end
View
22 spec/requests/issues_spec.rb
@@ -144,4 +144,26 @@
end
end
end
+
+ describe "Search issue", :js => true do
+ before do
+ ['foobar', 'foobar2', 'gitlab'].each do |title|
+ @issue = Factory :issue,
+ :author => @user,
+ :assignee => @user,
+ :project => project,
+ :title => title
+ @issue.save
+ end
+ end
+
+ it "should search and return the correct results" do
+ visit project_issues_path(project)
+ fill_in "issue_search", :with => "foobar"
+ page.should have_content 'foobar'
+ page.should have_content 'foobar2'
+ page.should_not have_content 'gitlab'
+ end
+ end
+
end

0 comments on commit 5b284f6

Please sign in to comment.