enable_to_filtering_versions_on_project_setting_versions_trunk_r15361.patch

Takenori TAKAKI, 2016-04-25 03:46

Download (6.47 KB)

View differences:

app/controllers/projects_controller.rb
160 160
    @issue_custom_fields = IssueCustomField.sorted.to_a
161 161
    @issue_category ||= IssueCategory.new
162 162
    @member ||= @project.members.new
163
    @versions ||= @project.shared_versions(params[:version])
164
    @version_status = params[:version] && params[:version][:status]
165
    @version_name = params[:version] && params[:version][:name]
163 166
    @trackers = Tracker.sorted.to_a
164 167
    @wiki ||= @project.wiki || Wiki.new(:project => @project)
165 168
  end
app/helpers/projects_helper.rb
100 100
    l("label_version_sharing_#{sharing}")
101 101
  end
102 102

  
103
  def version_status_check_group(checked_status)
104
    checked_status ||= Version::VERSION_STATUSES
105
    content = "<label for='version[status]'>#{l(:field_status)}:</label>"
106
    Version::VERSION_STATUSES.each do |s|
107
      content += check_box_tag('version[status][]', s, checked_status.include?(s), :id => "version_status_#{s}", :onchange => "this.form.submit(); return false;")
108
      content += content_tag('label', l("version_status_#{s}"), :for => "version_status_#{s}")
109
    end
110
    content.html_safe
111
  end
112

  
103 113
  def render_boards_tree(boards, parent=nil, level=0, &block)
104 114
    selection = boards.select {|b| b.parent == parent}
105 115
    return '' if selection.empty?
app/models/project.rb
453 453
  end
454 454

  
455 455
  # Returns a scope of the Versions used by the project
456
  def shared_versions
456
  def shared_versions(conditions = nil)
457 457
    if new_record?
458 458
      Version.
459 459
        joins(:project).
......
473 473
                    " OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" +
474 474
                  "))")
475 475
      end
476
      if conditions.is_a?(Hash) && conditions.any?
477
        @shared_versions = @shared_versions.where("#{Version.table_name}.status IN (?)", conditions[:status]) if conditions[:status].is_a?(Array)
478
        @shared_versions = @shared_versions.where("#{Version.table_name}.name LIKE ?", "%#{conditions[:name]}%") if conditions[:name].present?
479
      end
480
      @shared_versions
476 481
    end
477 482
  end
478 483

  
app/views/projects/settings/_versions.html.erb
1
<% if @project.shared_versions.any? %>
1
<%= form_tag(settings_project_path(:tab => 'versions'), :method => :get) do %>
2
  <fieldset><legend><%= l(:label_filter_plural) %></legend>
3
  <%= version_status_check_group(@version_status) %>
4
  <label for='version[name]'><%= l(:label_version) %>:</label>
5
  <%= text_field_tag 'version[name]', @version_name, :size => 30 %>
6
  <%= submit_tag l(:button_apply), :class => "small", :name => nil %>
7
  <%= link_to l(:button_clear), settings_project_path(:tab => 'versions'), :class => 'icon icon-reload' %>
8
  </fieldset>
9
<% end %>
10
&nbsp;
11

  
12
<% if @versions && @versions.any? %>
2 13
<table class="list versions">
3 14
  <thead><tr>
4 15
    <th><%= l(:label_version) %></th>
......
10 21
    <th style="width:15%"></th>
11 22
    </tr></thead>
12 23
  <tbody>
13
<% for version in @project.shared_versions.sort %>
24
<% for version in @versions.sort %>
14 25
    <tr class="version <%= cycle 'odd', 'even' %> <%=h version.status %> <%= 'shared' if version.project != @project %>">
15 26
    <td class="name"><%= link_to_version version %></td>
16 27
    <td class="date"><%= format_date(version.effective_date) %></td>
test/functional/projects_controller_test.rb
423 423
    assert_template 'settings'
424 424
  end
425 425

  
426
  def test_settings_with_version_parameters_should_assigns_matched_versions
427
    @request.session[:user_id] = 2 # manager
428
    version_parameters = {:status => ['open']}
429
    get :settings, :id => 1, :version => version_parameters
430
    assert_response :success
431
    assert_template 'settings'
432
    assert assigns(:versions)
433
    assert_equal Project.find(1).shared_versions(version_parameters), assigns(:versions)
434
  end
435

  
426 436
  def test_settings_of_subproject
427 437
    @request.session[:user_id] = 2
428 438
    get :settings, :id => 'private-child'
test/unit/project_test.rb
633 633
    assert_include v, Project.new.shared_versions
634 634
  end
635 635

  
636
   def test_shared_versions_with_status_conditions_should_returns_filterd_versions
637
     p = Project.find(5)
638
     Version.update_all(:status => 'closed')
639
     open_version = Version.create!(:name => 'open version', :project => p, :status => 'open')
640
     locked_version = Version.create!(:name => 'locked version', :project => p, :status => 'locked')
641

  
642
     versions = p.shared_versions(:status => ['open', 'locked'])
643
     assert_equal 2, versions.size
644
     assert_include open_version, versions
645
     assert_include locked_version, versions
646
   end
647

  
648
   def test_shared_versions_with_name_conditions_should_returns_filterd_versions
649
     p = Project.find(5)
650
     Version.update_all(:name => 'unmatch versoin')
651
     open_version = Version.create!(:name => 'version first open', :project => p, :status => 'open')
652
     locked_version = Version.create!(:name => 'second version locked', :project => p, :status => 'locked')
653
     closed_version = Version.create!(:name => 'last closed version', :project => p, :status => 'closed')
654

  
655
     versions = p.shared_versions(:name => 'version')
656
     assert_equal 3, versions.size
657
     assert_include open_version, versions
658
     assert_include locked_version, versions
659
     assert_include locked_version, versions
660
   end
661

  
636 662
  def test_next_identifier
637 663
    ProjectCustomField.delete_all
638 664
    Project.create!(:name => 'last', :identifier => 'p2008040')