change_roadmap_issues_to_tree_structure.patch

Mizuki ISHIKAWA, 2018-11-08 02:40

Download (4.88 KB)

View differences:

app/controllers/versions_controller.rb
27 27

  
28 28
  helper :custom_fields
29 29
  helper :projects
30
  helper :issues
30 31

  
31 32
  def index
32 33
    respond_to do |format|
......
50 51
            includes(:project, :tracker).
51 52
            preload(:status, :priority, :fixed_version).
52 53
            where(:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)).
53
            order("#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id")
54
            order("#{Issue.table_name}.root_id, #{Issue.table_name}.lft, #{Issue.table_name}.id")
54 55
          @issues_by_version = issues.group_by(&:fixed_version)
55 56
        end
56 57
        @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
......
67 68
        @issues = @version.fixed_issues.visible.
68 69
          includes(:status, :tracker, :priority).
69 70
          preload(:project).
70
          reorder("#{Tracker.table_name}.position, #{Issue.table_name}.id").
71
          reorder("#{Issue.table_name}.root_id, #{Issue.table_name}.lft, #{Issue.table_name}.id").
71 72
          to_a
72 73
      }
73 74
      format.api
app/views/versions/index.html.erb
26 26
      <%= form_tag({}, :data => {:cm_url => issues_context_menu_path}) do -%>
27 27
        <table class="list related-issues">
28 28
        <caption><%= l(:label_related_issues) %></caption>
29
        <% issues.each do |issue| -%>
30
          <tr class="hascontextmenu">
29
        <% issue_list(issues) do |issue, level| -%>
30
          <tr class="issue hascontextmenu<%= " idnt idnt-#{level}" if level > 0 %>">
31 31
            <td class="checkbox"><%= check_box_tag 'ids[]', issue.id, false, :id => nil %></td>
32 32
            <td class="subject"><%= link_to_issue(issue, :project => (@project != issue.project)) %></td>
33 33
            <td class="buttons"><%= link_to_context_menu %></td>
app/views/versions/show.html.erb
40 40
<%= form_tag({}, :data => {:cm_url => issues_context_menu_path}) do -%>
41 41
  <table class="list related-issues">
42 42
  <caption><%= l(:label_related_issues) %></caption>
43
  <%- @issues.each do |issue| -%>
44
    <tr class="issue hascontextmenu">
43
  <% issue_list(@issues) do |issue, level| -%>
44
    <tr class="issue hascontextmenu<%= " idnt idnt-#{level}" if level > 0 %>">
45 45
      <td class="checkbox"><%= check_box_tag 'ids[]', issue.id, false, :id => nil %></td>
46 46
      <td class="subject"><%= link_to_issue(issue, :project => (@project != issue.project)) %></td>
47 47
      <td class="buttons"><%= link_to_context_menu %></td>
test/functional/versions_controller_test.rb
69 69
    assert_select 'a.issue.tracker-3'
70 70
  end
71 71

  
72
  def test_index_issues_should_be_tree_structure
73
    parent_issue_id = nil
74
    (1..3).each do |i|
75
      issue = Issue.generate!(:project_id => 1, :fixed_version_id => 3, :parent_id => parent_issue_id, :tracker_id => i)
76
      parent_issue_id = issue.id
77
    end
78
    get :index, :params => {:project_id => 1}
79
    assert_response :success
80
    assert_select 'tr a.issue.tracker-1'
81
    assert_select 'tr.idnt.idnt-1 a.issue.tracker-2'
82
    assert_select 'tr.idnt.idnt-2 a.issue.tracker-3'
83
  end
84

  
72 85
  def test_index_showing_subprojects_versions
73 86
    @subproject_version = Version.create!(:project => Project.find(3), :name => "Subproject version")
74 87
    get :index, :params => {:project_id => 1, :with_subprojects => 1}
......
150 163
    end
151 164
  end
152 165

  
166
  def test_show_issues_should_be_tree_structure
167
    parent_issue_id = nil
168
    (1..3).each do |i|
169
      issue = Issue.generate!(:project_id => 1, :fixed_version_id => 3, :parent_id => parent_issue_id, :tracker_id => i)
170
      parent_issue_id = issue.id
171
    end
172
    get :show, :params => {:id => 3}
173
    assert_response :success
174
    assert_select 'tr a.issue.tracker-1'
175
    assert_select 'tr.idnt.idnt-1 a.issue.tracker-2'
176
    assert_select 'tr.idnt.idnt-2 a.issue.tracker-3'
177
  end
178

  
153 179
  def test_new
154 180
    @request.session[:user_id] = 2
155 181
    get :new, :params => {:project_id => '1'}