]> source.dussan.org Git - redmine.git/commitdiff
Include subprojects on the issue list, calendar and gantt by default.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 28 Feb 2008 21:57:03 +0000 (21:57 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 28 Feb 2008 21:57:03 +0000 (21:57 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1178 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/projects_controller.rb
app/models/issue.rb
app/models/query.rb
app/views/projects/calendar.rhtml
app/views/projects/gantt.rhtml
app/views/queries/_filters.rhtml

index 39eb33b996191105cda0e915edaa087b5cefdf2f..adb49114ccdbb9d1b2dfd51dc5dc70f113155254 100644 (file)
@@ -87,9 +87,15 @@ class ProjectsController < ApplicationController
     @members_by_role = @project.members.find(:all, :include => [:user, :role], :order => 'position').group_by {|m| m.role}
     @subprojects = @project.active_children
     @news = @project.news.find(:all, :limit => 5, :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
-    @trackers = @project.trackers
-    @open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
-    @total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
+    @trackers = @project.rolled_up_trackers
+    Issue.visible_by(User.current) do
+      @open_issues_by_tracker = Issue.count(:group => :tracker,
+                                            :include => [:project, :status, :tracker],
+                                            :conditions => ["(#{Project.table_name}.id=? OR #{Project.table_name}.parent_id=?) and #{IssueStatus.table_name}.is_closed=?", @project.id, @project.id, false])
+      @total_issues_by_tracker = Issue.count(:group => :tracker,
+                                            :include => [:project, :status, :tracker],
+                                            :conditions => ["#{Project.table_name}.id=? OR #{Project.table_name}.parent_id=?", @project.id, @project.id])
+    end
     TimeEntry.visible_by(User.current) do
       @total_hours = TimeEntry.sum(:hours, 
                                    :include => :project,
@@ -307,9 +313,9 @@ class ProjectsController < ApplicationController
     @year ||= Date.today.year
     @month ||= Date.today.month    
     @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month)
-    
+    @with_subprojects = params[:with_subprojects].nil? ? true : (params[:with_subprojects] == '1')
     events = []
-    @project.issues_with_subprojects(params[:with_subprojects]) do
+    @project.issues_with_subprojects(@with_subprojects) do
       events += Issue.find(:all, 
                            :include => [:tracker, :status, :assigned_to, :priority, :project], 
                            :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?)) AND #{Issue.table_name}.tracker_id IN (#{@selected_tracker_ids.join(',')})", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt]
@@ -350,9 +356,10 @@ class ProjectsController < ApplicationController
     
     @date_from = Date.civil(@year_from, @month_from, 1)
     @date_to = (@date_from >> @months) - 1
+    @with_subprojects = params[:with_subprojects].nil? ? true : (params[:with_subprojects] == '1')
     
     @events = []
-    @project.issues_with_subprojects(params[:with_subprojects]) do
+    @project.issues_with_subprojects(@with_subprojects) do
       @events += Issue.find(:all, 
                            :order => "start_date, due_date",
                            :include => [:tracker, :status, :assigned_to, :priority, :project], 
index 6b9b3bd1c5b82025b497902a0fb2e7f7358feb16..9d7f6eaaf89cfd42a890e4ae0dfa014c50ae66e2 100644 (file)
@@ -231,4 +231,10 @@ class Issue < ActiveRecord::Base
   def soonest_start
     @soonest_start ||= relations_to.collect{|relation| relation.successor_soonest_start}.compact.min
   end
+  
+  def self.visible_by(usr)
+    with_scope(:find => { :conditions => Project.visible_by(usr) }) do
+      yield
+    end
+  end
 end
index a4103c08a8b46cb72d17ee2d257084db5ba038a0..73828f739530b8b2e8fc284056153563537eed53 100644 (file)
@@ -83,7 +83,7 @@ class Query < ActiveRecord::Base
   @@operators_by_filter_type = { :list => [ "=", "!" ],
                                  :list_status => [ "o", "=", "!", "c", "*" ],
                                  :list_optional => [ "=", "!", "!*", "*" ],
-                                 :list_one_or_more => [ "*", "=" ],
+                                 :list_subprojects => [ "*", "!*", "=" ],
                                  :date => [ "<t+", ">t+", "t+", "t", "w", ">t-", "<t-", "t-" ],
                                  :date_past => [ ">t-", "<t-", "t-", "t", "w" ],
                                  :string => [ "=", "~", "!", "!~" ],
@@ -163,7 +163,7 @@ class Query < ActiveRecord::Base
       @available_filters["category_id"] = { :type => :list_optional, :order => 6, :values => @project.issue_categories.collect{|s| [s.name, s.id.to_s] } }
       @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => @project.versions.sort.collect{|s| [s.name, s.id.to_s] } }
       unless @project.active_children.empty?
-        @available_filters["subproject_id"] = { :type => :list_one_or_more, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } }
+        @available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => @project.active_children.collect{|s| [s.name, s.id.to_s] } }
       end
       @project.all_custom_fields.select(&:is_filter?).each do |field|
         case field.field_format
@@ -259,16 +259,18 @@ class Query < ActiveRecord::Base
   def statement
     # project/subprojects clause
     clause = ''
-    if project && has_filter?("subproject_id")
-      subproject_ids = []
-      if operator_for("subproject_id") == "="
-        subproject_ids = values_for("subproject_id").each(&:to_i)
+    if project && !@project.active_children.empty?
+      ids = [project.id]
+      if has_filter?("subproject_id") && operator_for("subproject_id") == "="
+        # include the selected subprojects
+        ids += values_for("subproject_id").each(&:to_i)
       else
-        subproject_ids = project.active_children.collect{|p| p.id}
+        # include all the subprojects unless 'none' is selected
+        ids += project.active_children.collect{|p| p.id} unless has_filter?("subproject_id") && operator_for("subproject_id") == "!*"
       end
-      clause << "#{Issue.table_name}.project_id IN (%d,%s)" % [project.id, subproject_ids.join(",")] if project
+      clause << "#{Issue.table_name}.project_id IN (%s)" % ids.join(',')
     elsif project
-      clause << "#{Issue.table_name}.project_id=%d" % project.id
+      clause << "#{Issue.table_name}.project_id = %d" % project.id
     else
       clause << Project.visible_by(User.current)
     end
index a2af3e2bbb96437357ce3834ef8281a270368aef..743721cb3f039f9bbf3f2f421dd083350d621bf0 100644 (file)
       <label><%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %> <%= tracker.name %></label><br />
     <% end %>
     <% if @project.active_children.any? %>
-    <br /><label><%= check_box_tag "with_subprojects", 1, params[:with_subprojects] %> <%=l(:label_subproject_plural)%></label>
+    <br /><label><%= check_box_tag 'with_subprojects', 1, @with_subprojects %> <%=l(:label_subproject_plural)%></label>
+    <%= hidden_field_tag 'with_subprojects', 0 %>
     <% end %>
-    <p><%= submit_tag l(:button_apply), :class => 'button-small' %></p>
+    <p><%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %></p>
     <% end %>
 <% end %>
 
index ece77669941f255b38e032bfdfc12fdff8a843ac..2979bce2b951e4ad2f999890038afe1d3eb0cb3f 100644 (file)
@@ -235,7 +235,8 @@ if Date.today >= @date_from and Date.today <= @date_to %>
       <label><%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s) %> <%= tracker.name %></label><br />
     <% end %>
     <% if @project.active_children.any? %>
-    <br /><label><%= check_box_tag "with_subprojects", 1, params[:with_subprojects] %> <%=l(:label_subproject_plural)%></label>
+    <br /><label><%= check_box_tag 'with_subprojects', 1, @with_subprojects %> <%=l(:label_subproject_plural)%></label>
+    <%= hidden_field_tag 'with_subprojects', 0 %>
     <% end %>
     <p><%= submit_tag l(:button_apply), :class => 'button-small' %></p>
     <% end %>
index bc60bd5ebf81c956037ca935e8ab9dff5c3079b0..2465818d8929d6371f1a5d2adcaed81627f0869c 100644 (file)
@@ -75,7 +75,7 @@ function toggle_multi_select(field) {
     <td valign="top">    
     <div id="div_values_<%= field %>" style="display:none;">
     <% case options[:type]
-    when :list, :list_optional, :list_status, :list_one_or_more %>
+    when :list, :list_optional, :list_status, :list_subprojects %>
         <select <%= "multiple=true" if query.values_for(field) and query.values_for(field).length > 1 %> name="values[<%= field %>][]" id="values_<%= field %>" class="select-small" style="vertical-align: top;">
         <%= options_for_select options[:values], query.values_for(field) %>        
         </select>