Project

General

Profile

Defect #7114 ยป show_projects_having_a_descendant_with_issue_tracking.patch

Jean-Philippe Lang, 2010-12-16 11:16

View differences:

test/unit/lib/redmine/helpers/gantt_test.rb (copie de travail)
159 159
                               :start_date => Date.yesterday,
160 160
                               :due_date => 1.week.from_now.to_date)
161 161
      @project.issues << @issue
162

  
163
      @response.body = @gantt.subjects
164 162
    end
165 163

  
166 164
    context "project" do
167
      should "be rendered" do
165
      should "be rendered" do
166
        @response.body = @gantt.subjects
168 167
        assert_select "div.project-name a", /#{@project.name}/
169 168
      end
170 169

  
171
      should "have an indent of 4" do
170
      should "have an indent of 4" do
171
        @response.body = @gantt.subjects
172 172
        assert_select "div.project-name[style*=left:4px]"
173
      end
174
      
175
      context "with descendants" do
176
        setup do
177
          @child = Project.generate!
178
          @child.set_parent!(@project)
179
          @child.enabled_module_names = ['issue_tracking']
180
          @grandchild = Project.generate!
181
          @grandchild.set_parent!(@child)
182
          @grandchild.enabled_module_names = ['issue_tracking']
183
        end
184
        
185
        context ":html format" do
186
          should "render descendants" do
187
            @gantt.subjects
188
            
189
            assert @gantt.subjects.match(/#{@child.name}/)
190
            assert @gantt.subjects.match(/#{@grandchild.name}/)
191
          end
192
          
193
          should "render projects having a descendant with issue tracking enabled" do
194
            @project.enabled_module_names = []
195
            @child.enabled_module_names = []
196
            @response.body = @gantt.subjects
197
            
198
            assert @gantt.subjects.match(/#{@project.name}/)
199
            assert @gantt.subjects.match(/#{@child.name}/)
200
            assert @gantt.subjects.match(/#{@grandchild.name}/)
201
          end
202
          
203
          should "not render projects not having a descendant with issue tracking enabled" do
204
            @project.enabled_module_names = []
205
            @child.enabled_module_names = []
206
            @grandchild.enabled_module_names = []
207
            @response.body = @gantt.subjects
208
            
209
            assert !@gantt.subjects.match(/#{@project.name}/)
210
          end
211
        end
173 212
      end
174 213
    end
175 214

  
176 215
    context "version" do
177
      should "be rendered" do
216
      should "be rendered" do
217
        @response.body = @gantt.subjects
178 218
        assert_select "div.version-name a", /#{@version.name}/
179 219
      end
180 220

  
181
      should "be indented 24 (one level)" do
221
      should "be indented 24 (one level)" do
222
        @response.body = @gantt.subjects
182 223
        assert_select "div.version-name[style*=left:24px]"
183 224
      end
184 225
    end
185 226

  
186 227
    context "issue" do
187
      should "be rendered" do
228
      should "be rendered" do
229
        @response.body = @gantt.subjects
188 230
        assert_select "div.issue-subject", /#{@issue.subject}/
189 231
      end
190 232

  
191
      should "be indented 44 (two levels)" do
233
      should "be indented 44 (two levels)" do
234
        @response.body = @gantt.subjects
192 235
        assert_select "div.issue-subject[style*=left:44px]"
193 236
      end
194 237
    end
app/models/project.rb (copie de travail)
513 513
      enabled_modules.each {|mod| mod.destroy unless module_names.include?(mod.name)}
514 514
      # add new modules
515 515
      module_names.reject {|name| module_enabled?(name)}.each {|name| enabled_modules << EnabledModule.new(:name => name)}
516
      enabled_modules.reload
516 517
    else
517 518
      enabled_modules.clear
518 519
    end
lib/redmine/helpers/gantt.rb (copie de travail)
104 104
        rows = if @project
105 105
          number_of_rows_on_project(@project)
106 106
        else
107
          Project.roots.visible.has_module('issue_tracking').inject(0) do |total, project|
107
          Project.roots.visible.inject(0) do |total, project|
108 108
            total += number_of_rows_on_project(project)
109 109
          end
110 110
        end
......
115 115
      # Returns the number of rows that will be used to list a project on
116 116
      # the Gantt chart.  This will recurse for each subproject.
117 117
      def number_of_rows_on_project(project)
118
        unless project.module_enabled?('issue_tracking') || 
119
          (!project.leaf? && project.descendants.visible.has_module('issue_tracking').exists?)
120
          return 0
121
        end
122
        
118 123
        # Remove the project requirement for Versions because it will
119 124
        # restrict issues to only be on the current project.  This
120 125
        # ends up missing issues which are assigned to shared versions.
......
122 127

  
123 128
        # One Root project
124 129
        count = 1
125
        # Issues without a Version
126
        count += project.issues.for_gantt.without_version.with_query(@query).count
130
        
131
        if project.module_enabled?('issue_tracking')
132
          # Issues without a Version
133
          count += project.issues.for_gantt.without_version.with_query(@query).count
127 134

  
128
        # Versions
129
        count += project.versions.count
135
          # Versions
136
          count += project.versions.count
130 137

  
131
        # Issues on the Versions
132
        project.versions.each do |version|
133
          count += version.fixed_issues.for_gantt.with_query(@query).count
138
          # Issues on the Versions
139
          project.versions.each do |version|
140
            count += version.fixed_issues.for_gantt.with_query(@query).count
141
          end
134 142
        end
135 143

  
136 144
        # Subprojects
137
        project.children.visible.has_module('issue_tracking').each do |subproject|
145
        project.children.visible.each do |subproject|
138 146
          count += number_of_rows_on_project(subproject)
139
        end
147
        end unless project.leaf?
140 148

  
141 149
        count
142 150
      end
......
163 171
        if @project
164 172
          render_project(@project, options)
165 173
        else
166
          Project.roots.visible.has_module('issue_tracking').each do |project|
174
          Project.roots.visible.each do |project|
167 175
            render_project(project, options)
168 176
            break if abort?
169 177
          end
......
176 184
      end
177 185

  
178 186
      def render_project(project, options={})
187
        unless project.module_enabled?('issue_tracking') || 
188
          (!project.leaf? && project.descendants.visible.has_module('issue_tracking').exists?)
189
          return
190
        end
191
          
179 192
        options[:top] = 0 unless options.key? :top
180 193
        options[:indent_increment] = 20 unless options.key? :indent_increment
181 194
        options[:top_increment] = 20 unless options.key? :top_increment
......
188 201
        @number_of_rows += 1
189 202
        return if abort?
190 203
        
191
        # Second, Issues without a version
192
        issues = project.issues.for_gantt.without_version.with_query(@query).all(:limit => current_limit)
193
        sort_issues!(issues)
194
        if issues
195
          render_issues(issues, options)
196
          return if abort?
197
        end
204
        if project.module_enabled?('issue_tracking')
205
          # Second, Issues without a version
206
          issues = project.issues.for_gantt.without_version.with_query(@query).all(:limit => current_limit)
207
          sort_issues!(issues)
208
          if issues
209
            render_issues(issues, options)
210
            return if abort?
211
          end
198 212

  
199
        # Third, Versions
200
        project.versions.sort.each do |version|
201
          render_version(version, options)
202
          return if abort?
213
          # Third, Versions
214
          project.versions.sort.each do |version|
215
            render_version(version, options)
216
            return if abort?
217
          end
203 218
        end
204

  
219
        
205 220
        # Fourth, subprojects
206
        project.children.visible.has_module('issue_tracking').each do |project|
221
        project.children.visible.each do |project|
207 222
          render_project(project, options)
208 223
          return if abort?
209 224
        end unless project.leaf?
    (1-1/1)