Mercurial > hg > soundsoftware-site
changeset 68:60c0a4e08e09 luisf
Feature #35: The projects page now is separated in "My Projects" and "Other Projects".
author | luisf |
---|---|
date | Mon, 06 Dec 2010 17:50:43 +0000 |
parents | 29d087fde142 |
children | dc22c3eb3c81 |
files | app/helpers/projects_helper.rb app/views/projects/index.rhtml config/locales/en.yml |
diffstat | 3 files changed, 102 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/app/helpers/projects_helper.rb Mon Dec 06 13:48:52 2010 +0000 +++ b/app/helpers/projects_helper.rb Mon Dec 06 17:50:43 2010 +0000 @@ -83,6 +83,94 @@ s end + + # Renders a tree of projects where the current user belongs + # as a nested set of unordered lists + # The given collection may be a subset of the whole project tree + # (eg. some intermediate nodes are private and can not be seen) + def render_my_project_hierarchy(projects) + s = '' + + if projects.any? + ancestors = [] + original_project = @project + projects.each do |project| + # set the project environment to please macros. + + @project = project + + if User.current.member_of?(project): + + if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) + s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n" + else + ancestors.pop + s << "</li>" + while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) + ancestors.pop + s << "</ul></li>\n" + end + end + + classes = (ancestors.empty? ? 'root' : 'child') + s << "<li class='#{classes}'><div class='#{classes}'>" + + link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}") + s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank? + s << "</div>\n" + ancestors << project + end + end + s << ("</li></ul>\n" * ancestors.size) + @project = original_project + end + s + end + + # Renders a tree of projects where the current DOES NOT belong + # as a nested set of unordered lists + # The given collection may be a subset of the whole project tree + # (eg. some intermediate nodes are private and can not be seen) + def render_other_project_hierarchy(projects) + s = '' + + if projects.any? + ancestors = [] + original_project = @project + projects.each do |project| + # set the project environment to please macros. + + @project = project + + if not User.current.member_of?(project): + + if (ancestors.empty? || project.is_descendant_of?(ancestors.last)) + s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n" + else + ancestors.pop + s << "</li>" + while (ancestors.any? && !project.is_descendant_of?(ancestors.last)) + ancestors.pop + s << "</ul></li>\n" + end + end + + classes = (ancestors.empty? ? 'root' : 'child') + s << "<li class='#{classes}'><div class='#{classes}'>" + + link_to_project(project, {}, :class => "project #{User.current.member_of?(project) ? 'my-project' : nil}") + s << "<div class='wiki description'>#{textilizable(project.short_description, :project => project)}</div>" unless project.description.blank? + s << "</div>\n" + ancestors << project + end + end + + s << ("</li></ul>\n" * ancestors.size) + @project = original_project + end + s + end + + + # Returns a set of options for a select field, grouped by project. def version_options_for_select(versions, selected=nil) grouped = Hash.new {|h,k| h[k] = []}
--- a/app/views/projects/index.rhtml Mon Dec 06 13:48:52 2010 +0000 +++ b/app/views/projects/index.rhtml Mon Dec 06 17:50:43 2010 +0000 @@ -9,9 +9,12 @@ <%= link_to l(:label_overall_activity), { :controller => 'activities', :action => 'index' }%> </div> -<h2><%=l(:label_project_plural)%></h2> +<h2><%=l(:label_my_project_plural)%></h2> +<%= render_my_project_hierarchy(@projects)%> -<%= render_project_hierarchy(@projects)%> + +<h2><%=l(:label_other_project_plural)%></h2> +<%= render_other_project_hierarchy(@projects)%> <% if User.current.logged? %> <p style="text-align:right;"> @@ -19,6 +22,13 @@ </p> <% end %> + + + + + + + <% other_formats_links do |f| %> <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %> <% end %>
--- a/config/locales/en.yml Mon Dec 06 13:48:52 2010 +0000 +++ b/config/locales/en.yml Mon Dec 06 17:50:43 2010 +0000 @@ -436,6 +436,8 @@ label_project: Project label_project_new: New project label_project_plural: Projects + label_my_project_plural: My Projects + label_other_project_plural: Other Projects label_x_projects: zero: no projects one: 1 project