From 5b284f6adf4cf17ffb66b32a5afdb2f754d5ad5f Mon Sep 17 00:00:00 2001 From: Adam Leonard Date: Sat, 22 Oct 2011 00:06:38 -0400 Subject: [PATCH] Add ability to Search issues --- Gemfile | 1 + Gemfile.lock | 2 ++ app/controllers/issues_controller.rb | 7 +++++++ app/views/issues/index.html.haml | 18 +++++++++++++++++- config/database.yml | 19 +++++++++---------- config/routes.rb | 3 +++ spec/requests/issues_spec.rb | 22 ++++++++++++++++++++++ 7 files changed, 61 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index 77a00659..ad15fc83 100644 --- a/Gemfile +++ b/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" diff --git a/Gemfile.lock b/Gemfile.lock index 5ba34459..a881b05e 100644 --- a/Gemfile.lock +++ b/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) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index cf8e1ebe..7b8c7cb5 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -78,6 +78,13 @@ class IssuesController < ApplicationController 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 diff --git a/app/views/issues/index.html.haml b/app/views/issues/index.html.haml index 6f4548a8..53c4fe66 100644 --- a/app/views/issues/index.html.haml +++ b/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(); }); diff --git a/config/database.yml b/config/database.yml index 51a4dd45..59e1f12c 100644 --- a/config/database.yml +++ b/config/database.yml @@ -4,8 +4,9 @@ # 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 @@ -13,13 +14,11 @@ development: # 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 diff --git a/config/routes.rb b/config/routes.rb index 8a40a8fe..57879224 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -47,6 +47,9 @@ Gitlab::Application.routes.draw do collection do post :sort end + collection do + get :search + end end resources :notes, :only => [:create, :destroy] end diff --git a/spec/requests/issues_spec.rb b/spec/requests/issues_spec.rb index 79fdf5ef..d3582d16 100644 --- a/spec/requests/issues_spec.rb +++ b/spec/requests/issues_spec.rb @@ -144,4 +144,26 @@ describe "Issues" do 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