Updated display of issues to adhere to the "view_own_costs" paradigm

git-svn-id: https://dev.finn.de/svn/cockpit/trunk@359 7926756e-e54e-46e6-9721-ed318f58905e
pull/6827/head
hjust 15 years ago
parent 7f357a39b8
commit 4e0d1fac1f
  1. 18
      app/views/hooks/_view_issues_show_details_bottom.rhtml
  2. 2
      app/views/issues/show.rhtml
  3. 48
      lib/issues_controller_patch.rb

@ -33,19 +33,27 @@ end
<tr>
<td><b><%= l(:label_cost_object) %>:</b></td>
<td><% if @issue.cost_object.nil? %>-<%else%><%= link_to h(@issue.cost_object.subject), {:controller => "cost_objects", :action => "show", :id => @issue.cost_object} %><% end %></td>
<% if User.current.allowed_to?(:view_cost_entries, @project) %>
<% if User.current.allowed_to?(:view_cost_entries, @project, :for => User.current) %>
<td><b><%= l(:label_spent_units) %>:</b></td>
<td>
<%= summarized_cost_entries(@issue.cost_entries) %>
<%= summarized_cost_entries(@cost_entries) %>
</td>
<% end %>
</tr>
<% if User.current.allowed_to?(:view_unit_price, @project) && User.current.allowed_to?(:view_all_rates, @project)%>
<% unless @overall_costs.nil? %>
<%
if @material_costs.nil?
label = :field_labor_costs
elsif @labor_costs.nil?
label = :field_material_costs
else
label = :field_overall_costs
end %>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><b><%= l(:label_overall_costs) %>:</b></td>
<td><% if @issue.overall_costs > 0 %><%= link_to number_to_currency(@issue.overall_costs), {:controller => 'costlog', :action => 'details', :project_id => @issue.project, :issue_id => @issue}, :class => 'icon icon-money' %><% else %>-<%end%></td>
<td><b><%= l(label) %>:</b></td>
<td><%= number_to_currency(@overall_costs) %></td>
</tr>
<% end %>
<% end %>

@ -35,7 +35,7 @@
</tr>
<tr>
<th class="category"><%=l(:field_category)%>:</th><td><%=h @issue.category ? @issue.category.name : "-" %></td>
<% if User.current.allowed_to?(:view_time_entries, @project) %>
<% if User.current.allowed_to?(:view_time_entries, @project, :for => User.current) %>
<th class="spent-time"><%=l(:label_spent_time)%>:</th>
<td class="spent-hours"><%= @issue.spent_hours > 0 ? (link_to l_hours(@issue.spent_hours), {:controller => 'timelog', :action => 'details', :project_id => @project, :issue_id => @issue}) : "-" %></td>
<% end %>

@ -0,0 +1,48 @@
module IssuesControllerPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
# Same as typing in the class
base.class_eval do
unless instance_methods.include? "show_without_entries"
alias_method_chain :show, :entries
end
end
end
module InstanceMethods
# Authorize the user for the requested action
def show_with_entries
@cost_entries = []
CostEntry.visible_by(User.current) do
@cost_entries += CostEntry.all(:include => [:user, :project], :conditions => {:issue_id => @issue.id})
end
cost_entries_with_rate = @cost_entries.select{|c| c.costs_visible_by?(User.current)}
@material_costs = cost_entries_with_rate.blank? ? nil : cost_entries_with_rate.collect(&:real_costs).sum
@time_entries = []
TimeEntry.visible_by(User.current) do
@time_entries += TimeEntry.all(:include => [:user, :project], :conditions => {:issue_id => @issue.id})
end
time_entries_with_rate = @time_entries.select{|c| c.costs_visible_by?(User.current)}
@labor_costs = time_entries_with_rate.blank? ? nil : time_entries_with_rate.collect(&:real_costs).sum
unless @material_costs.nil? && @labor_costs.nil?:
@overall_costs = 0
@overall_costs += @material_costs unless @material_costs.nil?
@overall_costs += @labor_costs unless @labor_costs.nil?
else
@overall_costs = nil
end
show_without_entries
end
end
end
Loading…
Cancel
Save