Merge pull request #1247 from tsigo/feature/no_milestone_filter

Allow filtering issues that have no milestone or assignee
This commit is contained in:
Dmitriy Zaporozhets 2012-08-16 22:33:56 -07:00
commit 4ce034ca65
4 changed files with 69 additions and 4 deletions

View file

@ -144,10 +144,19 @@ class IssuesController < ApplicationController
else @project.issues.opened else @project.issues.opened
end 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.tagged_with(params[:label_name]) if params[:label_name].present?
@issues = @issues.includes(:author, :project).order("updated_at") @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 @issues
end end

View file

@ -36,4 +36,11 @@ module IssuesHelper
def issue_tags def issue_tags
@project.issues.tag_counts_on(:labels).map(&:name) @project.issues.tag_counts_on(:labels).map(&:name)
end end
# Returns an OpenStruct object suitable for use by <tt>options_from_collection_for_select</tt>
# 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 end

View file

@ -49,8 +49,8 @@
.right .right
= form_tag project_issues_path(@project), method: :get, class: :right do = 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(: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_filter] + @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_filter] + @project.milestones.order("id desc").all, "id", "title", params[:milestone_id]), prompt: "Milestone")
= hidden_field_tag :f, params[:f] = hidden_field_tag :f, params[:f]
.clearfix .clearfix

View file

@ -89,4 +89,53 @@ describe "Issues" do
page.should have_content 'gitlab' page.should have_content 'gitlab'
end end
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.assignee = nil
@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
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 end