Skip to content

Commit

Permalink
Added a select menu to filter issues related to the appli or a specif…
Browse files Browse the repository at this point in the history
…ic instance in applis/show (closes #14)
  • Loading branch information
jbbarth committed Feb 20, 2010
1 parent ee44faa commit 528cee9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
11 changes: 10 additions & 1 deletion app/controllers/applis_controller.rb
Expand Up @@ -27,7 +27,16 @@ def index
end

def show
c = ARCondition.new(["#{IssueElement.table_name}.appli_id = ?", @appli.id])
table = IssueElement.table_name
c = ARCondition.new(["#{table}.appli_id = ?", @appli.id])

case params[:filter].to_s
when "Appli"
c << ["#{table}.element_type = ?", "Appli"]
when /^Instance:(\d+)$/
c << ["#{table}.element_type = ? and #{table}.element_id = ?", "Instance", $1]
end

sort_init([['id', 'desc']])
sort_update({'id' => "#{Issue.table_name}.id"})
@issue_count = Issue.count(:joins => :issue_elements, :conditions => c.conditions)
Expand Down
9 changes: 9 additions & 0 deletions app/helpers/applis_helper.rb
Expand Up @@ -58,6 +58,15 @@ def applis_status_options_for_select(selected, datacenter)
end
options_for_select(options, selected)
end

def appli_instances_options_for_select(appli, selected=nil)
options = [['', '']]
options << [ appli.name, "Appli" ]
appli.instances.sort_by(&:name).each do |instance|
options << [ "&nbsp;&nbsp;&#187; #{instance.name}", "Instance:#{instance.id}" ] if instance.active?
end
options_for_select_without_escape(options, selected)
end
end

module ActionView
Expand Down
9 changes: 9 additions & 0 deletions app/views/applis/show.html.erb
Expand Up @@ -25,6 +25,15 @@

<div class="splitcontentright">

<div class="contextual">
<% form_tag({}, :method => :get) do %>
<%= select_tag 'filter',
appli_instances_options_for_select(@appli, params[:filter]),
:class => "small",
:onchange => "this.form.submit(); return false;" %>
<% end %>
</div>

<h3><%= l(:label_related_issues) %></h3>
<%= render :partial => 'datacenter_plugin/issues_list_simple', :locals => {:issues => @issues} %>
<% if @issues.any? %>
Expand Down
20 changes: 19 additions & 1 deletion test/functional/applis_controller_test.rb
Expand Up @@ -32,8 +32,26 @@ def test_index
end

def test_show
get :show, :id => Appli.first, :project_id => 1
get :show, :id => 2, :project_id => 1
assert_template 'show'
#Appli(2) has Instance(4)
#Issue(2) linked to Appli(2)
#Issue(3) linked to Instance(4)
assert_tag :tr, :attributes => {:id => 'issue-2'}
assert_tag :tr, :attributes => {:id => 'issue-3'}
end

def test_show_filter_does_not_interfer_if_incorrect
params = {:id => 2, :project_id => 1, :filter => 'dummy'}
get :show, params.merge(:filter => 'dummy')
assert_tag :tr, :attributes => {:id => 'issue-2'}
assert_tag :tr, :attributes => {:id => 'issue-3'}
get :show, params.merge(:filter => 'Appli')
assert_tag :tr, :attributes => {:id => 'issue-2'}
assert_no_tag :tr, :attributes => {:id => 'issue-3'}
get :show, params.merge(:filter => 'Instance:4')
assert_no_tag :tr, :attributes => {:id => 'issue-2'}
assert_tag :tr, :attributes => {:id => 'issue-3'}
end

def test_cannot_show_appli_from_other_project
Expand Down

0 comments on commit 528cee9

Please sign in to comment.