Commit 92f6de03 authored by Adam Leonard's avatar Adam Leonard

If terms are removed show all results for current status

parent 09558634
...@@ -79,8 +79,17 @@ class IssuesController < ApplicationController ...@@ -79,8 +79,17 @@ class IssuesController < ApplicationController
end end
def search def search
terms = params['terms']
@project = Project.find(params['project']) @project = Project.find(params['project'])
@issues = @project.issues.where("title LIKE ? OR content LIKE ?", "%#{params['terms']}%", "%#{params['terms']}%") @issues = case params[:status].to_i
when 1 then @project.issues
when 2 then @project.issues.closed
when 3 then @project.issues.opened.assigned(current_user)
else @project.issues.opened
end
@issues = @issues.where("title LIKE ? OR content LIKE ?", "%#{terms}%", "%#{terms}%") unless terms.blank?
render :partial => 'issues' render :partial => 'issues'
end end
......
...@@ -2,38 +2,45 @@ ...@@ -2,38 +2,45 @@
- if can? current_user, :write_issue, @project - if can? current_user, :write_issue, @project
.left .left
= form_tag search_project_issues_path(@project), :method => :get, :remote => true do = form_tag search_project_issues_path(@project), :method => :get, :remote => true do
= hidden_field_tag :project_id, @project.id, { :id => 'project_id' }
= search_field_tag :issue_search, nil, { :placeholder => 'Search', :class => 'issue_search' } = 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" = link_to 'New Issue', new_project_issue_path(@project), :remote => true, :class => "lbutton vm"
.right .right
= form_tag project_issues_path(@project), :method => :get do = form_tag project_issues_path(@project), :method => :get do
.span-2 .span-2
= radio_button_tag :f, 0, (params[:f] || "0") == "0", :onclick => "this.form.submit()", :id => "open_issues" = radio_button_tag :f, 0, (params[:f] || "0") == "0", :onclick => "this.form.submit()", :id => "open_issues", :class => "status"
= label_tag "open_issues","Open" = label_tag "open_issues","Open"
.span-2 .span-2
= radio_button_tag :f, 2, params[:f] == "2", :onclick => "this.form.submit()", :id => "closed_issues" = radio_button_tag :f, 2, params[:f] == "2", :onclick => "this.form.submit()", :id => "closed_issues", :class => "status"
= label_tag "closed_issues","Closed" = label_tag "closed_issues","Closed"
.span-2 .span-2
= radio_button_tag :f, 3, params[:f] == "3", :onclick => "this.form.submit()", :id => "my_issues" = radio_button_tag :f, 3, params[:f] == "3", :onclick => "this.form.submit()", :id => "my_issues", :class => "status"
= label_tag "my_issues","To Me" = label_tag "my_issues","To Me"
.span-2 .span-2
= radio_button_tag :f, 1, params[:f] == "1", :onclick => "this.form.submit()", :id => "all_issues" = radio_button_tag :f, 1, params[:f] == "1", :onclick => "this.form.submit()", :id => "all_issues", :class => "status"
= label_tag "all_issues","All" = label_tag "all_issues","All"
#issues-table-holder= render "issues" #issues-table-holder= render "issues"
%br %br
:javascript :javascript
var href = $('.issue_search').parent().attr('action');
var last_terms = '';
$('.issue_search').keyup(function() { $('.issue_search').keyup(function() {
var terms = $(this).val(); var terms = $(this).val();
var project_id = 1; var project_id = $('#project_id').val();
var status = $('.status:checked').val();
if (terms != last_terms) {
last_terms = terms;
if (terms.length >= 2) { if (terms.length >= 2 || terms.length == 0) {
$.get($(this).parent().attr('action'), { 'terms': terms, project: project_id }, function(response) { $.get(href, { 'status': status, 'terms': terms, project: project_id }, function(response) {
$('#issues-table').html(response); $('#issues-table').html(response);
setSortable(); setSortable();
}); });
} }
}
}); });
$('.delete-issue').live('ajax:success', function() { $('.delete-issue').live('ajax:success', function() {
......
...@@ -157,13 +157,38 @@ describe "Issues" do ...@@ -157,13 +157,38 @@ describe "Issues" do
end end
end end
it "should search and return the correct results" do it "should be able to search on different statuses" do
@issue = Issue.first
@issue.closed = true
@issue.save
visit project_issues_path(project) visit project_issues_path(project)
fill_in "issue_search", :with => "foobar" choose 'closed_issues'
fill_in 'issue_search', :with => 'foobar'
page.should have_content 'foobar' page.should have_content 'foobar'
page.should have_content 'foobar2' page.should_not have_content 'foobar2'
page.should_not have_content 'gitlab' page.should_not have_content 'gitlab'
end end
it "should search for term 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
it "should return all results if term has been cleared" do
visit project_issues_path(project)
fill_in "issue_search", :with => "foobar"
# Because fill_in, :with => "" triggers nothing we need to trigger a keyup event
page.execute_script("$('.issue_search').val('').keyup();");
page.should have_content 'foobar'
page.should have_content 'foobar2'
page.should have_content 'gitlab'
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment