From 83c396761145f6cee69207c145add31848d0c6ef Mon Sep 17 00:00:00 2001 From: Florian Kraft Date: Tue, 17 Mar 2015 11:11:16 +0100 Subject: [PATCH 1/3] fix too small cost current rate input in project settings --- .../costs/_summarized_cost_entries.css.sass | 4 +- app/assets/stylesheets/costs/costs.css.sass | 3 +- app/assets/stylesheets/costs/settings.sass | 23 ++++++++++ ...ojects_settings_members_table_row.html.erb | 28 ++++++----- app/views/hourly_rates/edit.html.erb | 46 +++++++++---------- 5 files changed, 67 insertions(+), 37 deletions(-) create mode 100644 app/assets/stylesheets/costs/settings.sass diff --git a/app/assets/stylesheets/costs/_summarized_cost_entries.css.sass b/app/assets/stylesheets/costs/_summarized_cost_entries.css.sass index ad6d4e0ca8..2ac0367dcc 100644 --- a/app/assets/stylesheets/costs/_summarized_cost_entries.css.sass +++ b/app/assets/stylesheets/costs/_summarized_cost_entries.css.sass @@ -1,7 +1,7 @@ /*-- copyright * OpenProject Costs Plugin * - * Copyright (C) 2009 - 2014 the OpenProject Foundation (OPF) + * Copyright (C) 2009 - 2015 the OpenProject Foundation (OPF) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -11,7 +11,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/app/assets/stylesheets/costs/costs.css.sass b/app/assets/stylesheets/costs/costs.css.sass index d385c9f5c6..140338e657 100644 --- a/app/assets/stylesheets/costs/costs.css.sass +++ b/app/assets/stylesheets/costs/costs.css.sass @@ -1,7 +1,7 @@ /*-- copyright * OpenProject Costs Plugin * - * Copyright (C) 2009 - 2014 the OpenProject Foundation (OPF) + * Copyright (C) 2009 - 2015 the OpenProject Foundation (OPF) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -20,3 +20,4 @@ @import costs/costs_legacy @import costs/summarized_cost_entries +@import costs/settings diff --git a/app/assets/stylesheets/costs/settings.sass b/app/assets/stylesheets/costs/settings.sass new file mode 100644 index 0000000000..486b9d11dd --- /dev/null +++ b/app/assets/stylesheets/costs/settings.sass @@ -0,0 +1,23 @@ +/*-- copyright + * OpenProject Costs Plugin + * + * Copyright (C) 2009 - 2015 the OpenProject Foundation (OPF) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +table.list.members + .form--text-field.-tiny + min-width: 60px diff --git a/app/views/hooks/costs/_view_projects_settings_members_table_row.html.erb b/app/views/hooks/costs/_view_projects_settings_members_table_row.html.erb index 8c8d142e5d..f5c1cfe248 100644 --- a/app/views/hooks/costs/_view_projects_settings_members_table_row.html.erb +++ b/app/views/hooks/costs/_view_projects_settings_members_table_row.html.erb @@ -40,17 +40,23 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. <% if allow_edit %> - <%= remote_form_for :rate, :url => { :controller => '/hourly_rates', :action => 'set_rate', :id => member.user, :project_id => project}, :method => :posts do |f| %> - - - <%= f.text_field :rate, :value => "", :name => :rate, :size => 7, :id => "rate_text_field_for_#{member.user.id}" %> - - <%= Setting.plugin_openproject_costs['costs_currency'] %> - - - <%= icon_wrapper('icon icon-save1', I18n.t(:button_save)) %> - - + <%= remote_form_for :rate, :url => { :controller => '/hourly_rates', :action => 'set_rate', :id => member.user, :project_id => project}, :method => :post, html: { class: 'form' } do |f| %> +
+ +
+
+ <%= f.text_field :rate, :value => "", :name => :rate, :size => 7, :id => "rate_text_field_for_#{member.user.id}", class: 'form--text-field -tiny' %> +
+
+ + <%= Setting.plugin_openproject_costs['costs_currency'] %> + +
+ +
+
<% end %> <% else %> diff --git a/app/views/hourly_rates/edit.html.erb b/app/views/hourly_rates/edit.html.erb index 77d8c4295b..4d0ced0e5f 100644 --- a/app/views/hourly_rates/edit.html.erb +++ b/app/views/hourly_rates/edit.html.erb @@ -34,27 +34,27 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. <% end -%> <%= labelled_tabular_form_for @user, :url => {:action => 'update', :project_id => @project}, :method => :put do |f| %> -<%= back_url_hidden_field_tag %> -<%= error_messages_for 'user' %> -<%- @rates.each do |rate| -%> - <%- @rate = rate -%> - <%= error_messages_for 'rate' %> -<%- end -%> - - - - - - - - <%- @rates.each_with_index do |rate, index| -%> - <%= render :partial => 'rate', :object => rate, :locals => {:index => index, :classes => cycle('odd', 'even')} %> - <%- end -%> - -
<%= Rate.human_attribute_name(:valid_from) %><%= Rate.model_name.human %>
-
- - <%= link_to_function l(:button_add_rate), "addRate($('add_rate_date'))", {:class => "button icon icon-add"} %> -
-
<%= submit_tag l(:button_save), class: 'button -highlight' %>
+ <%= back_url_hidden_field_tag %> + <%= error_messages_for 'user' %> + <%- @rates.each do |rate| -%> + <%- @rate = rate -%> + <%= error_messages_for 'rate' %> + <%- end -%> + + + + + + + + <%- @rates.each_with_index do |rate, index| -%> + <%= render :partial => 'rate', :object => rate, :locals => {:index => index, :classes => cycle('odd', 'even')} %> + <%- end -%> + +
<%= Rate.human_attribute_name(:valid_from) %><%= Rate.model_name.human %>
+
+ + <%= link_to_function l(:button_add_rate), "addRate($('add_rate_date'))", {:class => "button icon icon-add"} %> +
+
<%= submit_tag l(:button_save), class: 'button -highlight' %>
<% end %> From 7dcd5b19da2786c53e045df36888f23af2b9dd3b Mon Sep 17 00:00:00 2001 From: Jens Ulferts Date: Mon, 23 Mar 2015 18:32:37 +0100 Subject: [PATCH 2/3] adapt unit cost log to core style --- app/assets/javascripts/costs/editinplace.js | 16 ++-- app/views/costlog/edit.html.erb | 96 +++++++++++++-------- 2 files changed, 71 insertions(+), 41 deletions(-) diff --git a/app/assets/javascripts/costs/editinplace.js b/app/assets/javascripts/costs/editinplace.js index 54e20d23b1..9e75845922 100644 --- a/app/assets/javascripts/costs/editinplace.js +++ b/app/assets/javascripts/costs/editinplace.js @@ -46,19 +46,23 @@ function edit(obj, name, obj_value) { var obj_value = typeof(obj_value) != 'undefined' ? obj_value : obj.innerHTML; var parsed = getCurrencyValue(obj_value); var value = parsed[0]; - var currency = parsed[1] + var currency = parsed[1]; - var span_in = '' - var text = ' '+currency; - var button = ' '; - var span_end = ''; + var button = ' '; + var span = ''; + span += ' '; + span += ''; - new Insertion.After(obj, span_in+text+button+span_end); + var affix = '' + currency + ''; + + new Insertion.After(obj, button + span + affix); Event.observe(obj.id+'_cancel', 'click', function(){cleanUp(obj)}); } function cleanUp(obj){ Element.remove(obj.id+'_editor'); + Element.remove(obj.id+'_affix'); + Element.remove(obj.id+'_cancel'); Element.show(obj); } diff --git a/app/views/costlog/edit.html.erb b/app/views/costlog/edit.html.erb index 5df11e6260..910baf0f78 100644 --- a/app/views/costlog/edit.html.erb +++ b/app/views/costlog/edit.html.erb @@ -34,44 +34,70 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. <%= back_url_hidden_field_tag %>
-

<%= f.text_field :work_package_id, :size => 6, :required => true %> <%= h("#{@cost_entry.work_package.to_s}") if @cost_entry.work_package%>

-

<%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('cost_entry_spent_on') %>

- <% if User.current.allowed_to? :log_costs, @project %> -

<%= f.select :user_id, user_collection_for_select_options, :required => true %>

- <% else %> - <%= f.hidden_field :user_id, :value => User.current.id %> - <% end %> -

<%= f.select :cost_type_id, cost_types_collection_for_select_options, :required => true %>

-

- - <%= f.text_field :units, :size => 6, :required => true %> - - <%= (@cost_entry.units == 1 ? @cost_entry.cost_type.unit : @cost_entry.cost_type.unit_plural) if @cost_entry.cost_type %> - - - <%= observe_field( "cost_entry_cost_type_id", :url => {:controller => :cost_objects, :action => :update_material_budget_item, :project_id => @cost_entry.project}, :with => "'cost_type_id=' + encodeURIComponent(value) + '&units=' + encodeURIComponent(document.getElementById('cost_entry_units').value) + '&fixed_date=' + encodeURIComponent(document.getElementById('cost_entry_spent_on').value) + '&element_id=cost_entry'") %> - <%= observe_field( "cost_entry_units", :frequency => 1, :url => {:controller => :cost_objects, :action => :update_material_budget_item, :project_id => @cost_entry.project}, :with => "'cost_type_id=' + encodeURIComponent(document.getElementById('cost_entry_cost_type_id').value) + '&units=' + encodeURIComponent(value) + '&fixed_date=' + encodeURIComponent(document.getElementById('cost_entry_spent_on').value) + '&element_id=cost_entry'") %> - <%= observe_field( "cost_entry_spent_on", :frequency => 1, :url => {:controller => :cost_objects, :action => :update_material_budget_item, :project_id => @cost_entry.project}, :with => "'cost_type_id=' + encodeURIComponent(document.getElementById('cost_entry_cost_type_id').value) + '&units=' + encodeURIComponent(document.getElementById('cost_entry_units').value) + '&fixed_date=' + encodeURIComponent(value) + '&element_id=cost_entry'") %> -

-

- - <% if User.current.allowed_to? :view_cost_rates, @cost_entry.project %> - - <%= number_to_currency(@cost_entry.calculated_costs) %> - - <%= update_page_tag do |page| - page << "makeEditable('cost_entry_costs', 'cost_entry[overridden_costs]');" - page << "edit($('cost_entry_costs'), 'cost_entry[overridden_costs]', '#{number_to_currency(@cost_entry.overridden_costs)}');" if @cost_entry.overridden_costs - end %> +

+ <%= f.text_field :work_package_id, :size => 6, :required => true %> + + <% if @cost_entry.work_package %> +
+ <%= h("#{@cost_entry.work_package.to_s}") %> +
+ <% end %> +
+
+ <%= f.text_field :spent_on, :size => 10, :required => true %> + <%= calendar_for('cost_entry_spent_on') %> +
+ <% if User.current.allowed_to? :log_costs, @project %> +
+ <%= f.select :user_id, user_collection_for_select_options, :required => true %> +
<% else %> - - " size="7" name="cost_entry[overridden_costs]" id="cost_entry_costs_edit"/> <%= Setting.plugin_openproject_costs['costs_currency'] %> - -
<%= l(:help_override_rate) %> + <%= f.hidden_field :user_id, :value => User.current.id %> <% end %> +
+ <%= f.select :cost_type_id, cost_types_collection_for_select_options, :required => true %>

+
+
+ <%= f.label :units %> + <% suffix = @cost_entry.cost_type.nil? ? '' : (@cost_entry.units == 1 ? @cost_entry.cost_type.unit : @cost_entry.cost_type.unit_plural) %> + + <%= f.text_field :units, size: 6, required: true, no_label: true %> + <% if @cost_entry.cost_type %> + + <%= h(@cost_entry.units == 1 ? @cost_entry.cost_type.unit : @cost_entry.cost_type.unit_plural) %> + + <% end %> + + + + <%= observe_field( "cost_entry_cost_type_id", :url => {:controller => :cost_objects, :action => :update_material_budget_item, :project_id => @cost_entry.project}, :with => "'cost_type_id=' + encodeURIComponent(value) + '&units=' + encodeURIComponent(document.getElementById('cost_entry_units').value) + '&fixed_date=' + encodeURIComponent(document.getElementById('cost_entry_spent_on').value) + '&element_id=cost_entry'") %> + <%= observe_field( "cost_entry_units", :frequency => 1, :url => {:controller => :cost_objects, :action => :update_material_budget_item, :project_id => @cost_entry.project}, :with => "'cost_type_id=' + encodeURIComponent(document.getElementById('cost_entry_cost_type_id').value) + '&units=' + encodeURIComponent(value) + '&fixed_date=' + encodeURIComponent(document.getElementById('cost_entry_spent_on').value) + '&element_id=cost_entry'") %> + <%= observe_field( "cost_entry_spent_on", :frequency => 1, :url => {:controller => :cost_objects, :action => :update_material_budget_item, :project_id => @cost_entry.project}, :with => "'cost_type_id=' + encodeURIComponent(document.getElementById('cost_entry_cost_type_id').value) + '&units=' + encodeURIComponent(document.getElementById('cost_entry_units').value) + '&fixed_date=' + encodeURIComponent(value) + '&element_id=cost_entry'") %> +
+ +
+ + + <% if User.current.allowed_to? :view_cost_rates, @cost_entry.project %> + + <%= number_to_currency(@cost_entry.calculated_costs) %> + + <%= update_page_tag do |page| + page << "makeEditable('cost_entry_costs', 'cost_entry[overridden_costs]');" + page << "edit($('cost_entry_costs'), 'cost_entry[overridden_costs]', '#{number_to_currency(@cost_entry.overridden_costs)}');" if @cost_entry.overridden_costs + end %> + <% else %> + + " size="7" name="cost_entry[overridden_costs]" id="cost_entry_costs_edit"/> <%= Setting.plugin_openproject_costs['costs_currency'] %> + +
<%= l(:help_override_rate) %> + <% end %> +
+
-

-

<%= f.text_field :comments, :size => 100 %>

+
+ <%= f.text_field :comments, size: 100 %> +
<%= submit_tag l(:button_save), class: 'button -highlight' %> From f04e0bfe8648e7e3f13fe169e2ada3b6b23d4c51 Mon Sep 17 00:00:00 2001 From: Jens Ulferts Date: Mon, 23 Mar 2015 18:49:37 +0100 Subject: [PATCH 3/3] placing budget select within attribute list of work package form --- ...work_packages_form_details_bottom.html.erb | 25 --------- lib/open_project/costs/engine.rb | 3 +- .../costs/hooks/work_package_hook.rb | 3 -- .../patches/work_packages_helper_patch.rb | 51 +++++++++++++++++++ 4 files changed, 53 insertions(+), 29 deletions(-) delete mode 100644 app/views/hooks/costs/_view_work_packages_form_details_bottom.html.erb create mode 100644 lib/open_project/costs/patches/work_packages_helper_patch.rb diff --git a/app/views/hooks/costs/_view_work_packages_form_details_bottom.html.erb b/app/views/hooks/costs/_view_work_packages_form_details_bottom.html.erb deleted file mode 100644 index 6253f212ca..0000000000 --- a/app/views/hooks/costs/_view_work_packages_form_details_bottom.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -<%#-- copyright -OpenProject Costs Plugin - -Copyright (C) 2009 - 2014 the OpenProject Foundation (OPF) - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -version 3. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -++#%> - -<% if @project && @project.module_enabled?(:costs_module) %> -
- <%= form.select :cost_object_id, CostObject.find_all_by_project_id(@project, :order => 'subject ASC').collect { |d| [d.subject, d.id] }, :include_blank => true%> -
-<% end %> diff --git a/lib/open_project/costs/engine.rb b/lib/open_project/costs/engine.rb index 697c98df19..3dad074583 100644 --- a/lib/open_project/costs/engine.rb +++ b/lib/open_project/costs/engine.rb @@ -101,7 +101,8 @@ module OpenProject::Costs end patches [:WorkPackage, :Project, :Query, :User, :TimeEntry, :PermittedParams, - :ProjectsController, :ApplicationHelper, :UsersHelper] + :ProjectsController, :ApplicationHelper, :UsersHelper, + :WorkPackagesHelper] extend_api_response(:v3, :work_packages, :work_package) do include Redmine::I18n diff --git a/lib/open_project/costs/hooks/work_package_hook.rb b/lib/open_project/costs/hooks/work_package_hook.rb index ccf725bc8e..f8efdfa8bb 100644 --- a/lib/open_project/costs/hooks/work_package_hook.rb +++ b/lib/open_project/costs/hooks/work_package_hook.rb @@ -22,9 +22,6 @@ class OpenProject::Costs::Hooks::WorkPackageHook < Redmine::Hook::ViewListener # Renders the Cost Object subject and basic costs information # render_on :view_work_packages_show_details_bottom, :partial => 'hooks/costs/view_work_packages_show_details_bottom' - # Renders a select tag with all the Cost Objects - render_on :view_work_packages_form_details_bottom, :partial => 'hooks/costs/view_work_packages_form_details_bottom' - # Renders a select tag with all the Cost Objects for the bulk edit page render_on :view_work_packages_bulk_edit_details_bottom, :partial => 'hooks/costs/view_work_packages_bulk_edit_details_bottom' diff --git a/lib/open_project/costs/patches/work_packages_helper_patch.rb b/lib/open_project/costs/patches/work_packages_helper_patch.rb new file mode 100644 index 0000000000..d18cdc6d76 --- /dev/null +++ b/lib/open_project/costs/patches/work_packages_helper_patch.rb @@ -0,0 +1,51 @@ +#-- copyright +# OpenProject Costs Plugin +# +# Copyright (C) 2009 - 2014 the OpenProject Foundation (OPF) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +#++ + +module OpenProject::Costs::Patches::WorkPackagesHelperPatch + def self.included(base) + base.class_eval do + unloadable + + def work_package_form_all_middle_attributes_with_costs(form, work_package, locals = {}) + attributes = work_package_form_all_middle_attributes_without_costs(form, work_package, locals) + + if work_package.project.module_enabled?(:costs_module) + attributes << work_package_form_budget_attribute(form, work_package, locals) + end + + attributes.compact + end + + def work_package_form_budget_attribute(form, work_package, locals) + field = work_package_form_field do + options = CostObject.find_all_by_project_id(@project, :order => 'subject ASC').collect { |d| [d.subject, d.id] } + form.select(:cost_object_id, options, include_blank: true) + end + + WorkPackagesHelper::WorkPackageAttribute.new(:cost_object_id, field) + end + + + alias_method_chain :work_package_form_all_middle_attributes, :costs + end + end + +end + +WorkPackagesHelper.send(:include, OpenProject::Costs::Patches::WorkPackagesHelperPatch)