changeset 69:dc22c3eb3c81 luisf

Feature #35: - Does not show the label "My Projects" if the user does not have any projects. - If the user is not signed in only shows the default Projects list.
author luisf
date Mon, 06 Dec 2010 18:12:52 +0000
parents 60c0a4e08e09
children 35c1d1c098e6
files app/helpers/projects_helper.rb app/views/projects/index.rhtml
diffstat 2 files changed, 32 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/app/helpers/projects_helper.rb	Mon Dec 06 17:50:43 2010 +0000
+++ b/app/helpers/projects_helper.rb	Mon Dec 06 18:12:52 2010 +0000
@@ -90,6 +90,11 @@
   # (eg. some intermediate nodes are private and can not be seen)
   def render_my_project_hierarchy(projects)
     s = ''
+
+    a = ''
+
+    # Flag to tell if user has any projects
+    t = FALSE
     
     if projects.any?
       ancestors = []
@@ -101,6 +106,8 @@
 
         if User.current.member_of?(project):
 
+          t = TRUE
+
           if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
             s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
           else
@@ -123,7 +130,17 @@
         s << ("</li></ul>\n" * ancestors.size)
         @project = original_project
     end
-    s
+
+    if t == TRUE
+      a << "<h2>"
+      a <<  l("label_my_project_plural")
+      a << "</h2>"
+      a << s
+    else
+      a = s
+    end
+    
+    a
   end
 
   # Renders a tree of projects where the current DOES NOT belong
@@ -166,6 +183,8 @@
       s << ("</li></ul>\n" * ancestors.size)
       @project = original_project
     end
+
+
     s
   end
 
--- a/app/views/projects/index.rhtml	Mon Dec 06 17:50:43 2010 +0000
+++ b/app/views/projects/index.rhtml	Mon Dec 06 18:12:52 2010 +0000
@@ -9,12 +9,20 @@
     <%= link_to l(:label_overall_activity), { :controller => 'activities', :action => 'index' }%>
 </div>
 
-<h2><%=l(:label_my_project_plural)%></h2>
-<%= render_my_project_hierarchy(@projects)%>
+<% if User.current.logged? %>
+  
+  <%= render_my_project_hierarchy(@projects)%>
 
+  <h2><%=l(:label_other_project_plural)%></h2>
+  <%= render_other_project_hierarchy(@projects)%>
 
-<h2><%=l(:label_other_project_plural)%></h2>
-<%= render_other_project_hierarchy(@projects)%>
+<% else %>
+
+  <h2><%=l(:label_project_plural)%></h2>
+  <%= render_project_hierarchy(@projects)%>
+<% end %>
+
+
 
 <% if User.current.logged? %>
 <p style="text-align:right;">
@@ -23,12 +31,6 @@
 <% end %>
 
 
-
-
-
-
-
-
 <% other_formats_links do |f| %>
 	<%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
 <% end %>