parent
c71594f71c
commit
4d424a9a39
@ -1,24 +0,0 @@ |
||||
<% if not project.nil? and project.module_enabled? :costs_module %> |
||||
<% |
||||
cost_objects_any = false |
||||
possible_cost_objects = issues.inject(issues.first.project.cost_objects) do |intersect, issue| |
||||
cost_objects_any |= issue.project.cost_objects.any? |
||||
issue.project.cost_objects & intersect |
||||
end |
||||
%> |
||||
<li class="folder"> |
||||
<a href="#" class="submenu"><%= l(:label_cost_object) %></a> |
||||
<ul> |
||||
<% unless possible_cost_objects.empty? -%> |
||||
<% possible_cost_objects.each do |co| -%> |
||||
<li> |
||||
<%= context_menu_link co.subject, {:controller => '/issues', :action => 'bulk_edit', :ids => issues.collect(&:id), 'cost_object_id' => co, :back_url => back}, :method => :post, |
||||
:selected => (@issue && co == @issue.cost_object), :disabled => !can[:edit] %> |
||||
</li> |
||||
<% end -%> |
||||
<% else -%> |
||||
<li><%= l(cost_objects_any ? :notice_cost_object_conflict : :notice_no_cost_objects_available)%></li> |
||||
<% end -%> |
||||
</ul> |
||||
</li> |
||||
<% end %> |
@ -0,0 +1,24 @@ |
||||
<% if not project.nil? and project.module_enabled? :costs_module %> |
||||
<% |
||||
cost_objects_any = false |
||||
possible_cost_objects = work_packages.inject(work_packages.first.project.cost_objects) do |intersect, work_package| |
||||
cost_objects_any |= work_package.project.cost_objects.any? |
||||
work_package.project.cost_objects & intersect |
||||
end |
||||
%> |
||||
<li class="folder"> |
||||
<a href="#" class="submenu"><%= l(:label_cost_object) %></a> |
||||
<ul> |
||||
<% unless possible_cost_objects.empty? -%> |
||||
<% possible_cost_objects.each do |co| -%> |
||||
<li> |
||||
<%= context_menu_link co.subject, {:controller => '/work_packages', :action => 'bulk_edit', :ids => work_packages.collect(&:id), 'cost_object_id' => co, :back_url => back}, :method => :post, |
||||
:selected => (@work_package && co == @work_package.cost_object), :disabled => !can[:edit] %> |
||||
</li> |
||||
<% end -%> |
||||
<% else -%> |
||||
<li><%= l(cost_objects_any ? :notice_cost_object_conflict : :notice_no_cost_objects_available)%></li> |
||||
<% end -%> |
||||
</ul> |
||||
</li> |
||||
<% end %> |
@ -1,11 +1,11 @@ |
||||
<% if @project.module_enabled? :costs_module && @issue%> |
||||
<% if @project.module_enabled? :costs_module && @work_package%> |
||||
<%# Only render this partial, if the plugin is enabled for the current project %> |
||||
<style> |
||||
<%# disables core's spent-time as it is not displayed if the user has just the view_own_time_entries permission %> |
||||
.spent-time { display: none } |
||||
</style> |
||||
|
||||
<% attributes_array = cost_issues_attributes(@issue) %> |
||||
<% attributes_array = cost_work_packages_attributes(@work_package) %> |
||||
<% (0..(attributes_array.size - 1)).step(2) do |i| %> |
||||
<tr> |
||||
<th> |
@ -1,19 +0,0 @@ |
||||
<% content_for :action_menu_main do %> |
||||
<%= li_unless_nil(link_to_if_authorized(l(:button_update), { :controller => '/issues', |
||||
:action => 'edit', |
||||
:id => @issue }, |
||||
:class => 'edit icon icon-edit', |
||||
:accesskey => accesskey(:edit))) %> |
||||
<%= li_unless_nil(watcher_link(@issue, |
||||
User.current, |
||||
{ :class => 'watcher_link', |
||||
:replace => User.current.allowed_to?(:view_issue_watchers, @project) ? ['#watchers', '.watcher_link'] : ['.watcher_link'] })) %> |
||||
<% end %> |
||||
<% content_for :action_menu_more do %> |
||||
<%= li_unless_nil(link_to_if_authorized l(:button_log_time), {:controller => '/timelog', :action => 'new', :issue_id => @issue}, :class => 'icon icon-time-add') %> |
||||
<%= li_unless_nil(link_to_if_authorized l(:button_log_costs), {:controller => '/costlog', :action => 'new', :issue_id => @issue}, :class => 'icon icon-pieces') %> |
||||
<%= li_unless_nil(link_to_if_authorized l(:button_duplicate), {:controller => '/issues', :action => 'new', :project_id => @project, :copy_from => @issue }, :class => 'icon icon-duplicate') %> |
||||
<%= li_unless_nil(link_to_if_authorized l(:button_copy), {:controller => '/issue_moves', :action => 'new', :id => @issue, :copy_options => {:copy => 't'}}, :class => 'icon icon-copy') %> |
||||
<%= li_unless_nil(link_to_if_authorized l(:button_move), {:controller => '/issue_moves', :action => 'new', :id => @issue}, :class => 'icon icon-move') %> |
||||
<%= li_unless_nil(link_to_if_authorized l(:button_delete), {:controller => '/issues', :action => 'destroy', :id => @issue}, :confirm => (@issue.leaf? ? l(:text_are_you_sure) : l(:text_are_you_sure_with_children)), :method => :post, :class => 'icon icon-del') %> |
||||
<% end %> |
@ -0,0 +1,19 @@ |
||||
<% content_for :action_menu_main do %> |
||||
<%= li_unless_nil(link_to_if_authorized(l(:button_update), { :controller => '/work_packages', |
||||
:action => 'edit', |
||||
:id => @work_package }, |
||||
:class => 'edit icon icon-edit', |
||||
:accesskey => accesskey(:edit))) %> |
||||
<%= li_unless_nil(watcher_link(@work_package, |
||||
User.current, |
||||
{ :class => 'watcher_link', |
||||
:replace => User.current.allowed_to?(:view_work_package_watchers, @project) ? ['#watchers', '.watcher_link'] : ['.watcher_link'] })) %> |
||||
<% end %> |
||||
<% content_for :action_menu_more do %> |
||||
<%= li_unless_nil(link_to_if_authorized l(:button_log_time), {:controller => '/timelog', :action => 'new', :work_package_id => @work_package}, :class => 'icon icon-time-add') %> |
||||
<%= li_unless_nil(link_to_if_authorized l(:button_log_costs), {:controller => '/costlog', :action => 'new', :work_package_id => @work_package}, :class => 'icon icon-pieces') %> |
||||
<%= li_unless_nil(link_to_if_authorized l(:button_duplicate), {:controller => '/work_packages', :action => 'new', :project_id => @project, :copy_from => @work_package }, :class => 'icon icon-duplicate') %> |
||||
<%= li_unless_nil(link_to_if_authorized l(:button_copy), {:controller => '/work_package_moves', :action => 'new', :id => @work_package, :copy_options => {:copy => 't'}}, :class => 'icon icon-copy') %> |
||||
<%= li_unless_nil(link_to_if_authorized l(:button_move), {:controller => '/work_package_moves', :action => 'new', :id => @work_package}, :class => 'icon icon-move') %> |
||||
<%= li_unless_nil(link_to_if_authorized l(:button_delete), {:controller => '/work_packages', :action => 'destroy', :id => @work_package}, :confirm => (@work_package.leaf? ? l(:text_are_you_sure) : l(:text_are_you_sure_with_children)), :method => :post, :class => 'icon icon-del') %> |
||||
<% end %> |
@ -1,7 +1,7 @@ |
||||
<h2><%= l(:label_confirmation) %></h2> |
||||
|
||||
<%= form_tag do %> |
||||
<%= @issues.collect {|i| hidden_field_tag 'ids[]', i.id } %> |
||||
<%= @work_packages.collect {|i| hidden_field_tag 'ids[]', i.id } %> |
||||
<div class="box"> |
||||
<p><strong><%= |
||||
if @hours > 0 && !@entries.blank? |
@ -1,21 +0,0 @@ |
||||
require_dependency 'issue' |
||||
|
||||
class CostsIssueObserver < ActiveRecord::Observer |
||||
unloadable |
||||
observe :issue |
||||
|
||||
def after_update(issue) |
||||
if issue.project_id_changed? |
||||
# TODO: This only works with the global cost_rates |
||||
CostEntry.update_all({:project_id => issue.project_id}, {:work_package_id => issue.id}) |
||||
end |
||||
end |
||||
|
||||
def before_update(issue) |
||||
# FIXME: remove this method once controller_issues_move_before_save is in 0.9-stable |
||||
if issue.project_id_changed? && issue.cost_object_id && !issue.project.cost_object_ids.include?(issue.cost_object_id) |
||||
issue.cost_object = nil |
||||
end |
||||
# true |
||||
end |
||||
end |
@ -1,27 +0,0 @@ |
||||
require 'issue' |
||||
|
||||
module OpenProject::Costs::Patches::IssuePatch |
||||
def self.included(base) # :nodoc: |
||||
base.extend(ClassMethods) |
||||
|
||||
base.send(:include, InstanceMethods) |
||||
|
||||
# Same as typing in the class |
||||
base.class_eval do |
||||
unloadable |
||||
|
||||
belongs_to :cost_object, :inverse_of => :work_packages |
||||
has_many :cost_entries, :foreign_key => :work_package_id, :dependent => :delete_all |
||||
end |
||||
end |
||||
|
||||
module ClassMethods |
||||
|
||||
end |
||||
|
||||
module InstanceMethods |
||||
|
||||
end |
||||
end |
||||
|
||||
Issue.send(:include, OpenProject::Costs::Patches::IssuePatch) |
@ -1,77 +0,0 @@ |
||||
require_dependency 'issues_controller' |
||||
|
||||
module OpenProject::Costs::Patches::IssuesControllerPatch |
||||
def self.included(base) # :nodoc: |
||||
base.send(:include, InstanceMethods) |
||||
|
||||
base.class_eval do |
||||
alias_method_chain :show, :entries |
||||
alias_method_chain :destroy, :entries |
||||
|
||||
helper :issues |
||||
end |
||||
|
||||
end |
||||
|
||||
module InstanceMethods |
||||
# Authorize the user for the requested action |
||||
def show_with_entries |
||||
@cost_entries = @issue.cost_entries.visible(User.current, @issue.project) |
||||
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 = @issue.time_entries.visible(User.current, @issue.project) |
||||
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 |
||||
|
||||
def destroy_with_entries |
||||
@entries = CostEntry.all(:conditions => ['work_package_id IN (?)', @issues]) |
||||
@hours = TimeEntry.sum(:hours, :conditions => ['work_package_id IN (?)', @issues]).to_f |
||||
unless @entries.blank? && @hours == 0 |
||||
case params[:todo] |
||||
when 'destroy' |
||||
# nothing to do |
||||
when 'nullify' |
||||
TimeEntry.update_all('work_package_id = NULL', ['work_package_id IN (?)', @issues]) |
||||
CostEntry.update_all('work_package_id = NULL', ['work_package_id IN (?)', @issues]) |
||||
when 'reassign' |
||||
reassign_to = @project.work_packages.find_by_id(params[:reassign_to_id]) |
||||
if reassign_to.nil? |
||||
flash.now[:error] = l(:error_issue_not_found_in_project) |
||||
return |
||||
else |
||||
TimeEntry.update_all("work_package_id = #{reassign_to.id}", ['work_package_id IN (?)', @issues]) |
||||
CostEntry.update_all("work_package_id = #{reassign_to.id}", ['work_package_id IN (?)', @issues]) |
||||
end |
||||
else |
||||
# display the destroy form if it's a user request |
||||
return unless api_request? |
||||
end |
||||
end |
||||
@issues.each do |issue| |
||||
begin |
||||
issue.reload.destroy |
||||
rescue ::ActiveRecord::RecordNotFound # raised by #reload if issue no longer exists |
||||
# nothing to do, issue was already deleted (eg. by a parent) |
||||
end |
||||
end |
||||
respond_to do |format| |
||||
format.html { redirect_to :action => 'index', :project_id => @project } |
||||
format.api { head :ok } |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
IssuesController.send(:include, OpenProject::Costs::Patches::IssuesControllerPatch) |
@ -1,89 +0,0 @@ |
||||
require_dependency 'issues_helper' |
||||
|
||||
module OpenProject::Costs::Patches::IssuesHelperPatch |
||||
def self.included(base) # :nodoc: |
||||
base.send(:include, InstanceMethods) |
||||
|
||||
# Same as typing in the class |
||||
base.class_eval do |
||||
def summarized_cost_entries(cost_entries, create_link=true) |
||||
last_cost_type = "" |
||||
|
||||
return "-" if cost_entries.blank? |
||||
result = cost_entries.sort_by(&:id).inject(Hash.new) do |result, entry| |
||||
if entry.cost_type == last_cost_type |
||||
result[last_cost_type][:units] += entry.units |
||||
else |
||||
last_cost_type = entry.cost_type |
||||
|
||||
result[last_cost_type] = {} |
||||
result[last_cost_type][:units] = entry.units |
||||
result[last_cost_type][:unit] = entry.cost_type.unit |
||||
result[last_cost_type][:unit_plural] = entry.cost_type.unit_plural |
||||
end |
||||
result |
||||
end |
||||
|
||||
str_array = [] |
||||
result.each do |k, v| |
||||
txt = pluralize(v[:units], v[:unit], v[:unit_plural]) |
||||
if create_link |
||||
# TODO why does this have project_id, issue_id and cost_type_id params? |
||||
str_array << link_to(txt, { :controller => '/costlog', |
||||
:action => 'index', |
||||
:project_id => @work_package.project, |
||||
:work_package_id => @work_package, |
||||
:cost_type_id => k }, |
||||
{ :title => k.name }) |
||||
else |
||||
str_array << "<span title=\"#{h(k.name)}\">#{txt}</span>" |
||||
end |
||||
end |
||||
str_array.join(", ").html_safe |
||||
end |
||||
|
||||
def cost_issues_attributes(work_package) |
||||
attributes = [] |
||||
|
||||
object_value = if work_package.cost_object.nil? |
||||
"-" |
||||
else |
||||
link_to_cost_object(work_package.cost_object) |
||||
end |
||||
|
||||
attributes << [CostObject.model_name.human, object_value] |
||||
|
||||
if User.current.allowed_to?(:view_time_entries, @project) || |
||||
User.current.allowed_to?(:view_own_time_entries, @project) |
||||
|
||||
#TODO: put inside controller or model |
||||
summed_hours = @time_entries.sum(&:hours) |
||||
|
||||
value = summed_hours > 0 ? |
||||
link_to(l_hours(summed_hours), issue_time_entries_path(work_package)) : "-" |
||||
|
||||
attributes << [Issue.human_attribute_name(:spent_hours), value] |
||||
end |
||||
|
||||
unless @overall_costs.nil? |
||||
attributes << [Issue.human_attribute_name(:overall_costs), number_to_currency(@overall_costs)] |
||||
end |
||||
|
||||
|
||||
if User.current.allowed_to?(:view_cost_entries, @project) || |
||||
User.current.allowed_to?(:view_own_cost_entries, @project) |
||||
|
||||
attributes << [Issue.human_attribute_name(:spent_units), summarized_cost_entries(@cost_entries)] |
||||
end |
||||
|
||||
attributes |
||||
end |
||||
end |
||||
end |
||||
|
||||
module InstanceMethods |
||||
|
||||
end |
||||
end |
||||
|
||||
IssuesHelper.send(:include, OpenProject::Costs::Patches::IssuesHelperPatch) |
@ -0,0 +1,21 @@ |
||||
require_dependency 'work_package' |
||||
|
||||
class CostsWorkPackageObserver < ActiveRecord::Observer |
||||
unloadable |
||||
observe :work_package |
||||
|
||||
def after_update(work_package) |
||||
if work_package.project_id_changed? |
||||
# TODO: This only works with the global cost_rates |
||||
CostEntry.update_all({:project_id => work_package.project_id}, {:work_package_id => work_package.id}) |
||||
end |
||||
end |
||||
|
||||
def before_update(work_package) |
||||
# FIXME: remove this method once controller_work_packages_move_before_save is in 0.9-stable |
||||
if work_package.project_id_changed? && work_package.cost_object_id && !work_package.project.cost_object_ids.include?(work_package.cost_object_id) |
||||
work_package.cost_object = nil |
||||
end |
||||
# true |
||||
end |
||||
end |
Loading…
Reference in new issue