From b1ea0b3c01f6d68834957a5f88b04329651802cc Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 13 Aug 2012 01:38:00 -0400 Subject: [PATCH 1/3] Allow filtering by issues with no assigned milestone Closes #1222 --- app/controllers/issues_controller.rb | 6 +++++- app/helpers/issues_helper.rb | 6 ++++++ app/views/issues/index.html.haml | 2 +- spec/requests/issues_spec.rb | 32 ++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index a7958b1e..e7396be2 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -145,9 +145,13 @@ class IssuesController < ApplicationController end @issues = @issues.where(assignee_id: params[:assignee_id]) if params[:assignee_id].present? - @issues = @issues.where(milestone_id: params[:milestone_id]) if params[:milestone_id].present? @issues = @issues.tagged_with(params[:label_name]) if params[:label_name].present? @issues = @issues.includes(:author, :project).order("updated_at") + + # Filter by specific milestone_id (or lack thereof)? + if params[:milestone_id].present? + @issues = @issues.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id])) + end @issues end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 177ba0c2..53ceec47 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -36,4 +36,10 @@ module IssuesHelper def issue_tags @project.issues.tag_counts_on(:labels).map(&:name) end + + # Returns a fake Milestone-like object that can be used in a + # select_tag to allow filtering by issues with no assigned milestone + def unassigned_milestone + OpenStruct.new(id: 0, title: 'Unspecified') + end end diff --git a/app/views/issues/index.html.haml b/app/views/issues/index.html.haml index f3c743f7..5ce097f5 100644 --- a/app/views/issues/index.html.haml +++ b/app/views/issues/index.html.haml @@ -50,7 +50,7 @@ = form_tag project_issues_path(@project), method: :get, class: :right do = select_tag(:label_name, options_for_select(issue_tags, params[:label_name]), prompt: "Labels") = select_tag(:assignee_id, options_from_collection_for_select(@project.users.all, "id", "name", params[:assignee_id]), prompt: "Assignee") - = select_tag(:milestone_id, options_from_collection_for_select(@project.milestones.order("id desc").all, "id", "title", params[:milestone_id]), prompt: "Milestone") + = select_tag(:milestone_id, options_from_collection_for_select([unassigned_milestone] + @project.milestones.order("id desc").all, "id", "title", params[:milestone_id]), prompt: "Milestone") = hidden_field_tag :f, params[:f] .clearfix diff --git a/spec/requests/issues_spec.rb b/spec/requests/issues_spec.rb index 24c21db8..1acac7d9 100644 --- a/spec/requests/issues_spec.rb +++ b/spec/requests/issues_spec.rb @@ -89,4 +89,36 @@ describe "Issues" do page.should have_content 'gitlab' end end + + describe "Filter issue" do + before do + ['foobar', 'barbaz', 'gitlab'].each do |title| + @issue = Factory :issue, + author: @user, + assignee: @user, + project: project, + title: title + end + + @issue = Issue.first + @issue.milestone = Factory(:milestone, project: project) + @issue.save + end + + it "should allow filtering by issues with no specified milestone" do + visit project_issues_path(project, milestone_id: '0') + + page.should_not have_content 'foobar' + page.should have_content 'barbaz' + page.should have_content 'gitlab' + end + + it "should allow filtering by a specified milestone" do + visit project_issues_path(project, milestone_id: @issue.milestone.id) + + page.should have_content 'foobar' + page.should_not have_content 'barbaz' + page.should_not have_content 'gitlab' + end + end end From 5a90d044f7fddf28b4dc3cd541315bce862f2866 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Mon, 13 Aug 2012 20:49:18 -0400 Subject: [PATCH 2/3] Allow filtering by issues with no assigned... assignee Continues #1222 --- app/controllers/issues_controller.rb | 7 ++++++- app/helpers/issues_helper.rb | 4 ++++ app/views/issues/index.html.haml | 2 +- spec/requests/issues_spec.rb | 17 +++++++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index e7396be2..889a7d98 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -144,14 +144,19 @@ class IssuesController < ApplicationController else @project.issues.opened end - @issues = @issues.where(assignee_id: params[:assignee_id]) if params[:assignee_id].present? @issues = @issues.tagged_with(params[:label_name]) if params[:label_name].present? @issues = @issues.includes(:author, :project).order("updated_at") + # Filter by specific assignee_id (or lack thereof)? + if params[:assignee_id].present? + @issues = @issues.where(assignee_id: (params[:assignee_id] == '0' ? nil : params[:assignee_id])) + end + # Filter by specific milestone_id (or lack thereof)? if params[:milestone_id].present? @issues = @issues.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id])) end + @issues end diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 53ceec47..452611fe 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -42,4 +42,8 @@ module IssuesHelper def unassigned_milestone OpenStruct.new(id: 0, title: 'Unspecified') end + + def unassigned_issue + OpenStruct.new(id: 0, name: 'Unassigned') + end end diff --git a/app/views/issues/index.html.haml b/app/views/issues/index.html.haml index 5ce097f5..fbc2fe7d 100644 --- a/app/views/issues/index.html.haml +++ b/app/views/issues/index.html.haml @@ -49,7 +49,7 @@ .right = form_tag project_issues_path(@project), method: :get, class: :right do = select_tag(:label_name, options_for_select(issue_tags, params[:label_name]), prompt: "Labels") - = select_tag(:assignee_id, options_from_collection_for_select(@project.users.all, "id", "name", params[:assignee_id]), prompt: "Assignee") + = select_tag(:assignee_id, options_from_collection_for_select([unassigned_issue] + @project.users.all, "id", "name", params[:assignee_id]), prompt: "Assignee") = select_tag(:milestone_id, options_from_collection_for_select([unassigned_milestone] + @project.milestones.order("id desc").all, "id", "title", params[:milestone_id]), prompt: "Milestone") = hidden_field_tag :f, params[:f] .clearfix diff --git a/spec/requests/issues_spec.rb b/spec/requests/issues_spec.rb index 1acac7d9..15ee5d17 100644 --- a/spec/requests/issues_spec.rb +++ b/spec/requests/issues_spec.rb @@ -102,6 +102,7 @@ describe "Issues" do @issue = Issue.first @issue.milestone = Factory(:milestone, project: project) + @issue.assignee = nil @issue.save end @@ -120,5 +121,21 @@ describe "Issues" do page.should_not have_content 'barbaz' page.should_not have_content 'gitlab' end + + it "should allow filtering by issues with no specified assignee" do + visit project_issues_path(project, assignee_id: '0') + + page.should have_content 'foobar' + page.should_not have_content 'barbaz' + page.should_not have_content 'gitlab' + end + + it "should allow filtering by a specified assignee" do + visit project_issues_path(project, assignee_id: @user.id) + + page.should_not have_content 'foobar' + page.should have_content 'barbaz' + page.should have_content 'gitlab' + end end end From feee3838e14c90bc73b97cfa8be3760e52605531 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 16 Aug 2012 18:13:22 -0400 Subject: [PATCH 3/3] Combine unassigned_issue and unassigned_milestone into unassigned_filter --- app/helpers/issues_helper.rb | 13 +++++-------- app/views/issues/index.html.haml | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 452611fe..d4d6c2d4 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -37,13 +37,10 @@ module IssuesHelper @project.issues.tag_counts_on(:labels).map(&:name) end - # Returns a fake Milestone-like object that can be used in a - # select_tag to allow filtering by issues with no assigned milestone - def unassigned_milestone - OpenStruct.new(id: 0, title: 'Unspecified') - end - - def unassigned_issue - OpenStruct.new(id: 0, name: 'Unassigned') + # Returns an OpenStruct object suitable for use by options_from_collection_for_select + # to allow filtering issues by an unassigned User or Milestone + def unassigned_filter + # Milestone uses :title, Issue uses :name + OpenStruct.new(id: 0, title: 'Unspecified', name: 'Unassigned') end end diff --git a/app/views/issues/index.html.haml b/app/views/issues/index.html.haml index fbc2fe7d..8876d24d 100644 --- a/app/views/issues/index.html.haml +++ b/app/views/issues/index.html.haml @@ -49,8 +49,8 @@ .right = form_tag project_issues_path(@project), method: :get, class: :right do = select_tag(:label_name, options_for_select(issue_tags, params[:label_name]), prompt: "Labels") - = select_tag(:assignee_id, options_from_collection_for_select([unassigned_issue] + @project.users.all, "id", "name", params[:assignee_id]), prompt: "Assignee") - = select_tag(:milestone_id, options_from_collection_for_select([unassigned_milestone] + @project.milestones.order("id desc").all, "id", "title", params[:milestone_id]), prompt: "Milestone") + = select_tag(:assignee_id, options_from_collection_for_select([unassigned_filter] + @project.users.all, "id", "name", params[:assignee_id]), prompt: "Assignee") + = select_tag(:milestone_id, options_from_collection_for_select([unassigned_filter] + @project.milestones.order("id desc").all, "id", "title", params[:milestone_id]), prompt: "Milestone") = hidden_field_tag :f, params[:f] .clearfix