# HG changeset patch
# User Chris Cannam
# Date 1297170847 0
# Node ID a6f87892f063080d7fd1dd48803112ba30c0a56e
# Parent abc11f2ead7214156fc719ff959f2f02519621da# Parent 05f9a2a9c753eb27deb355503dc8798f642f5ee2
Merge from branch "bug_67"
diff -r abc11f2ead72 -r a6f87892f063 app/controllers/projects_controller.rb
--- a/app/controllers/projects_controller.rb Mon Feb 07 14:21:07 2011 +0000
+++ b/app/controllers/projects_controller.rb Tue Feb 08 13:14:07 2011 +0000
@@ -46,19 +46,20 @@
include RepositoriesHelper
include ProjectsHelper
- # Lists visible projects
+ # Lists visible projects. Paginator is for top-level projects only
+ # (subprojects belong to them)
def index
respond_to do |format|
format.html {
- sort_init 'lft'
- sort_update %w(lft title created_on updated_on)
+ sort_init 'name'
+ sort_update %w(name lft created_on updated_on)
@limit = per_page_option
- @project_count = Project.visible.count
+ @project_count = Project.visible_roots.count
@project_pages = Paginator.new self, @project_count, @limit, params['page']
@offset ||= @project_pages.current.offset
- @projects = Project.visible.all(:offset => @offset, :limit => @limit, :order => sort_clause)
+ @projects = Project.visible_roots.all(:offset => @offset, :limit => @limit, :order => sort_clause)
if User.current.logged?
- @user_projects = User.current.projects.sort_by(&:lft)
+ @user_projects = User.current.projects.sort_by(&:name)
end
render :template => 'projects/index.rhtml', :layout => !request.xhr?
}
diff -r abc11f2ead72 -r a6f87892f063 app/helpers/projects_helper.rb
--- a/app/helpers/projects_helper.rb Mon Feb 07 14:21:07 2011 +0000
+++ b/app/helpers/projects_helper.rb Tue Feb 08 13:14:07 2011 +0000
@@ -163,74 +163,17 @@
s << "
"
s << ""
- s << sort_header_tag('lft', :caption => l("field_name"), :default_order => 'desc')
+ s << sort_header_tag('name', :caption => l("field_name"))
s << "" << l("label_managers") << " | "
s << sort_header_tag('created_on', :default_order => 'desc')
s << sort_header_tag('updated_on', :default_order => 'desc')
s << "
"
- ancestors = []
original_project = @project
- oddeven = 'even'
- level = 0
projects.each do |project|
-
- # set the project environment to please macros.
-
- @project = project
-
- if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
- level = level + 1
- else
- level = 0
- oddeven = cycle('odd','even')
- ancestors.pop
- while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
- ancestors.pop
- end
- end
-
- classes = (ancestors.empty? ? 'root' : 'child')
-
- s << ""
- s << "" << link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}");
- s << " "
- unless project.description.blank?
- s << ""
- s << textilizable(project.short_description, :project => project)
- s << " "
- end
-
- s << " | "
-
- u = project.users_by_role
- if u
- u.keys.each do |r|
- if r.allowed_to?(:edit_project)
- mgrs = []
- u[r].sort.each do |m|
- mgrs << link_to_user(m)
- end
- if mgrs.size < 3
- s << '' << mgrs.join(', ') << ''
- else
- s << mgrs.join(', ')
- end
- end
- end
- end
-
- s << " | "
- s << "" << format_date(project.created_on) << " | "
- s << "" << format_date(project.updated_on) << " | "
-
- s << "
"
-
- ancestors << project
+ s << render_project_in_table(project, cycle('odd', 'even'), 0)
end
s << "
"
@@ -241,6 +184,58 @@
end
+ def render_project_in_table(project, oddeven, level)
+
+ # set the project environment to please macros.
+ @project = project
+
+ classes = (level == 0 ? 'root' : 'child')
+
+ s = ""
+
+ s << ""
+ s << "" << link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}");
+ s << " "
+ unless project.description.blank?
+ s << ""
+ s << textilizable(project.short_description, :project => project)
+ s << " "
+ end
+
+ s << " | "
+
+ u = project.users_by_role
+ if u
+ u.keys.each do |r|
+ if r.allowed_to?(:edit_project)
+ mgrs = []
+ u[r].sort.each do |m|
+ mgrs << link_to_user(m)
+ end
+ if mgrs.size < 3
+ s << '' << mgrs.join(', ') << ''
+ else
+ s << mgrs.join(', ')
+ end
+ end
+ end
+ end
+
+ s << " | "
+ s << "" << format_date(project.created_on) << " | "
+ s << "" << format_date(project.updated_on) << " | "
+
+ s << "
"
+
+ project.children.each do |child|
+ s << render_project_in_table(child, oddeven, level + 1)
+ end
+
+ s
+ end
+
# Returns a set of options for a select field, grouped by project.
def version_options_for_select(versions, selected=nil)
diff -r abc11f2ead72 -r a6f87892f063 app/models/project.rb
--- a/app/models/project.rb Mon Feb 07 14:21:07 2011 +0000
+++ b/app/models/project.rb Tue Feb 08 13:14:07 2011 +0000
@@ -83,6 +83,7 @@
named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
named_scope :all_public, { :conditions => { :is_public => true } }
named_scope :visible, lambda { { :conditions => Project.visible_by(User.current) } }
+ named_scope :visible_roots, lambda { { :conditions => Project.root_visible_by(User.current) } }
def identifier=(identifier)
super unless identifier_frozen?
@@ -114,6 +115,10 @@
end
end
+ def self.root_visible_by(user=nil)
+ return "#{Project.table_name}.parent_id IS NULL AND " + visible_by(user)
+ end
+
def self.allowed_to_condition(user, permission, options={})
statements = []
base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"