Project

General

Profile

RE: Projects Tree View Plugin - Version 0.0.1 ยป show.rhtml

Andrew R Jackson, 2010-07-23 16:57

 
1
<div class="contextual">
2
  <% if User.current.allowed_to?(:add_subprojects, @project) %>
3
      <%= link_to l(:label_subproject_new), {:controller => 'projects', :action => 'add', :parent_id => @project}, :class => 'icon icon-add' %>
4
  <% end %>
5
</div>
6

    
7
<h2><%=l(:label_overview)%></h2>
8

    
9
<div class="splitcontentleft">
10
	<%= textilizable @project.description %>
11
	<ul>
12
	<% unless @project.homepage.blank? %><li><%=l(:field_homepage)%>: <%= link_to(h(@project.homepage), @project.homepage) %></li><% end %>
13
	</ul>
14
  <% if @subprojects.any? %>
15
    <% showHideOnclick = "onclick=\"showHide('#{@project.id}','#{@project.id}span')\"" %>
16
    <table class="list">
17
      <tbody>
18
        <tr class="open show parent subprojectRoot" id="<%= @project.id.to_s + "span" %>" >
19
          <td class="name" style="padding-left: 0em;">
20
            <span class="expander" <%=showHideOnclick%> >&nbsp; </span>
21
            <%= h("Sub Projects") %><span class="empty" <%=showHideOnclick%> >&nbsp;</span>
22
          </td>
23
        </tr>
24
<%
25
      # First, let's put the full project sub-tree into a nice array structure
26
	    projTree = [ @project ]
27
	    currIdx = 1
28
	    loop {
29
        currParent = projTree[currIdx - 1]
30
        break if(currParent.nil?)
31
        if(!currParent.children.empty?)
32
          sortedChildren = currParent.children.sort { |aa, bb| aa.name.downcase <=> bb.name.downcase }
33
	  sortedChildren.each_index { |ii|
34
            projTree[currIdx + ii,0] = sortedChildren[ii]
35
          }
36
        end
37
        currIdx += 1
38
      }
39

    
40
      # Next, loop over the sub-tree array elements and make the HTML rows
41
	    projTree.each_index { |ii|
42
        if(ii > 0)  # We'll skip the tree root
43
          rowid = classes = spanicon = openonclick = ""
44
          project = tmpProj = projTree[ii]
45
          # Getting the full ancestor of each project need only take a little iteration code
46
          ancestorIds = []
47
          (ii-1).downto(0) { |jj|
48
            if(tmpProj.parent_id == projTree[jj].id)  # We found the parent of tmpProj, next find ITS parent, etc
49
              ancestorIds << projTree[jj].id
50
              tmpProj = projTree[jj]
51
            end
52
          }
53
          # Let's only show the immediate subprojects (sub-sub projects will be hidden until user expands)
54
          if(project.parent_id == @project.id)
55
            classes += " show "
56
          else
57
            classes += " hide "
58
          end
59
          # Set up classes and such for the rows, depending on whether has children or not
60
          if(!project.children.empty?)
61
            projIdStr = project.id.to_s
62
            classes += " closed parent " + cycle("odd", "even")
63
            rowid = "id=\"#{projIdStr}span\""
64
            openonclick = "onclick=\"showHide('#{projIdStr}','#{projIdStr}span')\""
65
            spanicon = "<span #{openonclick} class=\"expander\">&nbsp; </span>"
66
          else
67
            classes += " closed child " + cycle("odd", "even")
68
          end
69
          classes += " #{ancestorIds.join(' ')} "
70
          baseurl = url_for(:controller => 'plugin_assets', :action => 'index')
71
          # Does this project have boards? If so, we'll provide a direct link to its Forums page
72
          if(!project.boards.empty?)
73
            forumsStr = "<a href=\"#{url_for({ :controller => 'projects', :action => 'show', :id => project})}/boards\"><span class=\"forumsLink\">" +
74
                        "<img alt=\"Forums\" title=\"Forums\" src=\"#{baseurl}/projects_tree_view/images/user_comment.png\"></span></a>"
75
          else
76
            forumsStr = ""
77
          end
78
          # Does this project have a wiki? If so, we'll provide a direct link to its main Wiki page
79
          if(project.wiki)
80
            wikiStr = "<a href=\"#{url_for({ :controller => 'projects', :action => 'show', :id => project})}/wiki\"><span class=\"wikiLink\">" +
81
                      "<img alt=\"Wiki\" title=\"Wiki\" src=\"#{baseurl}/projects_tree_view/images/page_white_wrench.png\"></span></a>"
82
          else
83
            wikiStr = ""
84
          end
85
%>
86
          <tr class="<%= classes %>" <%= rowid %> >
87
            <td class="name" style="padding-left: <%= 2*project.level %>em;">
88
              <%= spanicon %>
89
              <%= project.active? ? link_to(h(project.name), {:controller => 'projects', :action => 'show', :id => project}, :class => "project") : h(project.name) %>
90
              <span <%= openonclick %> class="empty <%=User.current.member_of?(project) ? 'my-project' : nil%>">&nbsp;</span>
91
              <%= forumsStr %><%= wikiStr %>
92
            </td>
93
          </tr>
94
<%
95
        end
96
      }
97
%>
98
	  </tbody>
99
	</table>
100
  <% end %>
101
	<% @project.custom_values.each do |custom_value| %>
102
	<% if !custom_value.value.empty? %>
103
	   <li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
104
	<% end %>
105
	<% end %>
106

    
107
  <% if User.current.allowed_to?(:view_issues, @project) %>
108
  <div class="box">
109
    <h3 class="icon22 icon22-tracker"><%=l(:label_issue_tracking)%></h3>
110
    <ul>
111
    <% for tracker in @trackers %>
112
      <li><%= link_to tracker.name, :controller => 'issues', :action => 'index', :project_id => @project,
113
                                                :set_filter => 1,
114
                                                "tracker_id" => tracker.id %>:
115
					<%= l(:label_x_open_issues_abbr_on_total, :count => @open_issues_by_tracker[tracker].to_i,
116
																										:total => @total_issues_by_tracker[tracker].to_i) %>
117
			</li>
118
    <% end %>
119
    </ul>
120
    <p><%= link_to l(:label_issue_view_all), :controller => 'issues', :action => 'index', :project_id => @project, :set_filter => 1 %></p>
121
  </div>
122
  <% end %>
123
  <%= call_hook(:view_projects_show_left, :project => @project) %>
124
</div>
125

    
126
<div class="splitcontentright">
127
<% if users_by_role_implemented %>
128
	<% if @members_by_role.any? %>
129
	  <div class="box">
130
		<h3 class="icon22 icon22-users"><%=l(:label_member_plural)%></h3>
131
		<p><% @members_by_role.keys.sort.each do |role| %>
132
		<%= role.name %>:
133
		<%= @members_by_role[role].collect(&:user).sort.collect{|u| link_to_user u}.join(", ") %>
134
		<br />
135
		<% end %></p>
136
	  </div>
137
	<% end %>
138
<% else %>
139
	<% if @users_by_role.any? %>
140
	  <div class="box">
141
		<h3 class="icon22 icon22-users"><%=l(:label_member_plural)%></h3>
142
		<p><% @users_by_role.keys.sort.each do |role| %>
143
		<%=h role %>: <%= @users_by_role[role].sort.collect{|u| link_to_user u}.join(", ") %><br />
144
		<% end %></p>
145
	  </div>
146
	<% end %>
147
<% end %>
148

    
149
  <% if @news.any? && authorize_for('news', 'index') %>
150
  <div class="box">
151
    <h3><%=l(:label_news_latest)%></h3>
152
    <%= render :partial => 'news/news', :collection => @news %>
153
    <p><%= link_to l(:label_news_view_all), :controller => 'news', :action => 'index', :project_id => @project %></p>
154
  </div>
155
  <% end %>
156
  <%= call_hook(:view_projects_show_right, :project => @project) %>
157
</div>
158

    
159
<% content_for :sidebar do %>
160
    <% planning_links = []
161
      planning_links << link_to_if_authorized(l(:label_calendar), :controller => 'issues', :action => 'calendar', :project_id => @project)
162
      planning_links << link_to_if_authorized(l(:label_gantt), :controller => 'issues', :action => 'gantt', :project_id => @project)
163
      planning_links.compact!
164
      unless planning_links.empty? %>
165
    <h3><%= l(:label_planning) %></h3>
166
    <p><%= planning_links.join(' | ') %></p>
167
    <% end %>
168

    
169
    <% if @total_hours && User.current.allowed_to?(:view_time_entries, @project) %>
170
    <h3><%= l(:label_spent_time) %></h3>
171
    <p><span class="icon icon-time"><%= l_hours(@total_hours) %></span></p>
172
    <p><%= link_to(l(:label_details), {:controller => 'timelog', :action => 'details', :project_id => @project}) %> |
173
    <%= link_to(l(:label_report), {:controller => 'timelog', :action => 'report', :project_id => @project}) %></p>
174
    <% end %>
175
<% end %>
176

    
177
<% content_for :header_tags do %>
178
<%= auto_discovery_link_tag(:atom, {:action => 'activity', :id => @project, :format => 'atom', :key => User.current.rss_key}) %>
179
<% end %>
180

    
181
<% html_title(l(:label_overview)) -%>
    (1-1/1)