OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Render the costs subform in rails
Oliver Günther0b27a59d4dec
diff --git a/frontend/src/global_styles/content/_table.sass b/frontend/src/global_styles/content/_table.sassindex 36aa5d6f583..3f804fd6510 100644--- a/frontend/src/global_styles/content/_table.sass+++ b/frontend/src/global_styles/content/_table.sass@@ -166,6 +166,9 @@ table.generic-tablepadding-bottom: 0.5remvertical-align: top+ &.form--td+ vertical-align: middle+// Center input fields and select boxes vertically in tables.form--fieldmargin: 0pxdiff --git a/modules/budgets/app/controllers/budgets_controller.rb b/modules/budgets/app/controllers/budgets_controller.rbindex 2d47f2c1c85..f09bb8c9e66 100644--- a/modules/budgets/app/controllers/budgets_controller.rb+++ b/modules/budgets/app/controllers/budgets_controller.rb@@ -239,8 +239,8 @@ class BudgetsController < ApplicationController}if current_user.allowed_to?(permission, project)- response["#{element_id}_costs_text"] = number_to_currency(costs)- response["#{element_id}_cost_value"] = unitless_currency_number(costs)+ response["#{element_id}_costs"] = number_to_currency(costs)+ response["#{element_id}_cost_value"] = response["#{element_id}_amount"] = unitless_currency_number(costs)endresponsediff --git a/modules/budgets/app/views/budgets/items/_budget_override_cost_form.html.erb b/modules/budgets/app/views/budgets/items/_budget_override_cost_form.html.erbnew file mode 100644index 00000000000..55d6b20edfc--- /dev/null+++ b/modules/budgets/app/views/budgets/items/_budget_override_cost_form.html.erb@@ -0,0 +1,18 @@+<section class="costs--edit-form" hidden>+ <div class="form--field">+ <div class="form--field-container">+ <div class="costs--edit-planned-costs-cancel-btn form--field-affix -transparent icon icon-close"></div>+ <div class="form--text-field-container">+ <%= text_field_tag(+ field_name,+ unitless_currency_number(cost_value),+ class: 'currency form--text-field',+ placeholder: t(:label_example_placeholder, decimal: unitless_currency_number(1000.50)),+ ) %>+ </div>+ <div class="form--field-affix">+ <%= Setting.plugin_costs['costs_currency'] %>+ </div>+ </div>+ </div>+</section>\ No newline at end of filediff --git a/modules/budgets/app/views/budgets/items/_labor_budget_item.html.erb b/modules/budgets/app/views/budgets/items/_labor_budget_item.html.erbindex d487db21276..e24adf012cd 100644--- a/modules/budgets/app/views/budgets/items/_labor_budget_item.html.erb+++ b/modules/budgets/app/views/budgets/items/_labor_budget_item.html.erb@@ -61,19 +61,19 @@ See COPYRIGHT and LICENSE files for more details.inputmode: :decimal,placeholder: t(:label_example_placeholder, decimal: unitless_currency_number(1000.50)),class: 'budget-item-value form--text-field',- data: { :'request-key' => 'hours' } %>+ data: {:'request-key' => 'hours'} %></div></div></td><td class="user"><label class="hidden-for-sighted" for="<%= id_prefix %>_user_id"><%= t(:label_user) %></label><%= cost_form.select :user_id,- Principal.possible_assignee(@project).sort.map { |u| [u.name, u.id] },- { prompt: true },+ Principal.possible_assignee(@project).sort.map {|u| [u.name, u.id]},+ {prompt: true},{index: id_or_index,class: 'form--select budget-item-value',- data: { :'request-key' => 'user_id' }+ data: {:'request-key' => 'user_id'}} %></td>@@ -82,29 +82,27 @@ See COPYRIGHT and LICENSE files for more details.<%= cost_form.text_field :comments, index: id_or_index, size: 40 %></td><% if User.current.allowed_to?(:view_cost_rates, @project) %>- <td class="currency budget-table--fields">+ <td class="currency form--td budget-table--fields"><%# Keep current budget as hidden field because otherwise they will be overridden %><% if templated == false && labor_budget_item.overridden_costs? %><%= cost_form.hidden_field :amount, index: id_or_index, value: unitless_currency_number(labor_budget_item.amount) %><% end %><% cost_value = labor_budget_item.amount || labor_budget_item.calculated_costs(@budget.fixed_date, @budget.project_id) %>- <%= cost_form.hidden_field :currency, index: id_or_index, value: Setting.plugin_costs['costs_currency'] %>- <cost-unit-subform obj-id="<%= id_prefix %>"- obj-name="<%= "#{name_prefix}[amount]" %>"- data-placeholder="<%= t(:label_example_placeholder, decimal: unitless_currency_number(1000.50)) %>" %>- <a id="<%= "#{id_prefix}_costs" %>" class="costs--edit-planned-costs-btn icon-context icon-edit" title="<%= t(:help_click_to_edit) %>">- <% if labor_budget_item.costs_visible_by?(User.current) %>- <%= cost_form.hidden_field :cost_value, index: id_or_index, value: unitless_currency_number(cost_value) %>- <span id="<%= "#{id_prefix}_costs_text" %>">- <%= number_to_currency(cost_value) %>- </span>- <% end %>- </a>- </cost-unit-subform>+ <a id="<%= "#{id_prefix}_costs" %>" class="costs--edit-planned-costs-btn icon-context icon-edit" title="<%= t(:help_click_to_edit) %>">+ <% if labor_budget_item.costs_visible_by?(User.current) %>+ <%= number_to_currency(cost_value) %>+ <% end %>+ </a>+ <%= render partial: '/budgets/items/budget_override_cost_form',+ locals: {+ field_name: "#{name_prefix}[amount]",+ cost_value: cost_value,+ }+ %></td><% end %>- <td class="delete budget-table--fields buttons">+ <td class="delete form--td budget-table--fields buttons"><a class="delete-budget-item no-decoration-on-hover" title="<%= t(:button_delete) %>" href="#"><%= op_icon('icon-context icon-delete') %><span class="hidden-for-sighted"><%= t(:button_delete) %></span>diff --git a/modules/budgets/app/views/budgets/items/_material_budget_item.html.erb b/modules/budgets/app/views/budgets/items/_material_budget_item.html.erbindex 2eebec44789..2e06b95a21e 100644--- a/modules/budgets/app/views/budgets/items/_material_budget_item.html.erb+++ b/modules/budgets/app/views/budgets/items/_material_budget_item.html.erb@@ -61,11 +61,11 @@ See COPYRIGHT and LICENSE files for more details.inputmode: :decimal,placeholder: t(:label_example_placeholder, decimal: unitless_currency_number(1000.50)),class: 'budget-item-value form--text-field',- data: { :'request-key' => 'units' } %>+ data: {:'request-key' => 'units'} %></div></div></td>- <td class="unit_currency budget-table--fields" id="<%= "#{id_prefix}_unit_name" %>">+ <td class="unit_currency form--td budget-table--fields" id="<%= "#{id_prefix}_unit_name" %>"><%= h material_budget_item.cost_type.unit_plural if material_budget_item.cost_type %></td><td class="cost_type">@@ -76,7 +76,7 @@ See COPYRIGHT and LICENSE files for more details.{index: id_or_index,class: 'form--select budget-item-value',- data: { :'request-key' => 'cost_type_id' }+ data: {:'request-key' => 'cost_type_id'}} %></td><td class="comment">@@ -84,28 +84,26 @@ See COPYRIGHT and LICENSE files for more details.<%= cost_form.text_field :comments, index: id_or_index, size: 40 %></td><% if User.current.allowed_to? :view_cost_rates, @project %>- <td class="currency budget-table--fields">+ <td class="currency form--td budget-table--fields"><%# Keep current budget as hidden field because otherwise they will be overridden %><% if templated == false && material_budget_item.overridden_costs? %><%= cost_form.hidden_field :amount, index: id_or_index, value: unitless_currency_number(material_budget_item.amount) %><% end %><% cost_value = material_budget_item.amount || material_budget_item.calculated_costs(@budget.fixed_date) %>- <%= cost_form.hidden_field :currency, index: id_or_index, value: Setting.plugin_costs['costs_currency'] %>- <%= cost_form.hidden_field :cost_value, index: id_or_index, value: unitless_currency_number(cost_value) %>-- <cost-unit-subform obj-id="<%= id_prefix %>"- obj-name="<%= "#{name_prefix}[amount]" %>"- data-placeholder="<%= t(:label_example_placeholder, decimal: unitless_currency_number(1000.50)) %>" %>- <a id="<%= id_prefix %>_costs" class="costs--edit-planned-costs-btn icon-context icon-edit" role="button" title="<%= t(:help_click_to_edit) %>">- <span id="<%= "#{id_prefix}_costs_text" %>">- <%= number_to_currency(cost_value) %>- </span>- </a>- </cost-unit-subform>+ <a id="<%= id_prefix %>_costs" class="costs--edit-planned-costs-btn icon-context icon-edit" role="button" title="<%= t(:help_click_to_edit) %>">+ <%= number_to_currency(cost_value) %>+ </a>+ </a>+ <%= render partial: '/budgets/items/budget_override_cost_form',+ locals: {+ field_name: "#{name_prefix}[amount]",+ cost_value: cost_value,+ }+ %></td><% end %>- <td class="delete budget-table--fields buttons">+ <td class="delete form--td budget-table--fields buttons"><a class="delete-budget-item no-decoration-on-hover" title="<%= t(:button_delete) %>"><%= op_icon('icon-context icon-delete') %><span class="hidden-for-sighted"><%= t(:button_delete) %></span>diff --git a/modules/budgets/frontend/module/augment/planned-costs-form.ts b/modules/budgets/frontend/module/augment/planned-costs-form.tsindex ccfb0cffef6..24c457331b8 100644--- a/modules/budgets/frontend/module/augment/planned-costs-form.ts+++ b/modules/budgets/frontend/module/augment/planned-costs-form.ts@@ -27,84 +27,21 @@//++export class PlannedCostsFormAugment {-- public obj:JQuery;- public objId:string;- public objName:string;- public placeholder:string;-static listen() {jQuery(document).on('click', '.costs--edit-planned-costs-btn', (evt) => {- const form = jQuery(evt.target as any).closest('cost-unit-subform') as JQuery;- new PlannedCostsFormAugment(form);- });- }-- constructor(public $element:JQuery) {- this.objId = this.$element.attr('obj-id')!;- this.objName = this.$element.attr('obj-name')!;- this.obj = jQuery(`#${this.objId}_costs`) as any;- this.placeholder = this.$element.data('placeholder');-- this.makeEditable();- }-- public makeEditable() {- this.edit_and_focus();- }-- private edit_and_focus() {- this.edit();+ const link = evt.target as HTMLElement;+ const form = link.nextElementSibling as HTMLElement;- jQuery('#' + this.objId + '_costs_edit').trigger('focus');- jQuery('#' + this.objId + '_costs_edit').trigger('select');- }-- private getCurrency() {- return jQuery('#' + this.objId + '_currency').val();- }-- private getValue() {- let costValueElement = jQuery('#' + this.objId + '_cost_value');- return costValueElement.length > 0 ? costValueElement.val() : '0.00';- }-- private edit() {- this.obj.hide();-- const id = this.obj[0].id;- const currency = this.getCurrency();- const value = this.getValue();- const name = this.objName;- const placeholder = this.placeholder;-- const template = `- <section class="form--section" id="${id}_section">- <div class="form--field">- <div class="form--field-container">- <div id="${id}_cancel" class="form--field-affix -transparent icon icon-close"></div>- <div id="${id}_editor" class="form--text-field-container">- <input id="${id}_edit"- class="form--text-field"- name="${name}"- value="${value}"- placeholder="${placeholder}"- class="currency"- type="text" />- </div>- <div class="form--field-affix" id="${id}_affix">${currency}</div>- </div>- </div>- </section>- `;+ link.hidden = true;+ form.hidden = false;+ });- jQuery(template).insertAfter(this.obj);+ jQuery(document).on('click', '.costs--edit-planned-costs-cancel-btn', (evt) => {+ const form = evt.target.closest('.costs--edit-form') as HTMLElement;+ const link = form.previousElementSibling as HTMLElement;- const that = this;- jQuery('#' + id + '_cancel').on('click', function () {- jQuery('#' + id + '_section').remove();- that.obj.show();- return false;+ link.hidden = false;+ form.hidden = true;});}}diff --git a/modules/budgets/spec/features/budgets/update_budget_spec.rb b/modules/budgets/spec/features/budgets/update_budget_spec.rbindex 7404d04162d..a13f63b799f 100644--- a/modules/budgets/spec/features/budgets/update_budget_spec.rb+++ b/modules/budgets/spec/features/budgets/update_budget_spec.rb@@ -162,7 +162,7 @@ describe 'updating a budget', type: :feature, js: true do# Open first itembudget_page.open_edit_planned_costs! material_budget_item.id, type: :material- expect(page).to have_field("budget_existing_material_budget_item_attributes_#{material_budget_item.id}_costs_edit")+ expect(page).to have_field("budget_existing_material_budget_item_attributes_#{material_budget_item.id}_amount")click_on 'OK'expect(budget_page).to have_content(I18n.t(:notice_successful_update, locale: :de))diff --git a/modules/budgets/spec/support/pages/budget_form.rb b/modules/budgets/spec/support/pages/budget_form.rbindex 881aab6e624..a694bc1a112 100644--- a/modules/budgets/spec/support/pages/budget_form.rb+++ b/modules/budgets/spec/support/pages/budget_form.rb@@ -73,7 +73,7 @@ module Pagesopen_edit_planned_costs!(id, type: type)row_id = "#budget_existing_#{type}_budget_item_attributes_#{id}"- editor_name = "budget_existing_#{type}_budget_item_attributes_#{id}_costs_edit"+ editor_name = "budget_existing_#{type}_budget_item_attributes_#{id}_amount"page.within row_id dofill_in editor_name, with: costsdiff --git a/modules/costs/app/views/costlog/edit.html.erb b/modules/costs/app/views/costlog/edit.html.erbindex fc9bcb6dcee..cdab4102be6 100644--- a/modules/costs/app/views/costlog/edit.html.erb+++ b/modules/costs/app/views/costlog/edit.html.erb@@ -113,25 +113,27 @@ See COPYRIGHT and LICENSE files for more details.<% end %></div>- <cost-unit-subform obj-id="cost_entry"- obj-name="cost_entry[overridden_costs]"- data-placeholder="<%= t(:label_example_placeholder, decimal: unitless_currency_number(1000.50)) %>" %>- <div class="form--field">- <label for="cost_entry_costs_edit" class="form--label"><%= CostEntry.human_attribute_name(:costs) %></label>- <span class="form--field-container">- <%= hidden_field_tag :currency, Setting.plugin_costs['costs_currency'], id: 'cost_entry_currency' %>- <% if User.current.allowed_to?(:view_cost_rates, @cost_entry.project) %>- <%= hidden_field_tag :cost_value, unitless_currency_number(@cost_entry.real_costs), id: 'cost_entry_cost_value' %>- <a href="#"- id="cost_entry_costs"- class="costs--edit-planned-costs-btn icon-context icon-edit"- title="<%= t(:help_click_to_edit) %>">- <span id="cost_entry_costs_text">- <%= number_to_currency(@cost_entry.real_costs) %>- </span>- </a>- </span>- <% else %>+ <div class="form--field">+ <label for="cost_entry_costs_edit" class="form--label"><%= CostEntry.human_attribute_name(:costs) %></label>+ <% if User.current.allowed_to?(:view_cost_rates, @cost_entry.project) %>+ <span class="form--field-container">+ <a href="#"+ id="cost_entry_costs"+ class="costs--edit-planned-costs-btn icon-context icon-edit"+ role="button"+ title="<%= t(:help_click_to_edit) %>">+ <%= number_to_currency(@cost_entry.real_costs) %>+ </a>+ <%= render partial: '/budgets/items/budget_override_cost_form',+ locals: {+ field_name: "cost_entry[overridden_costs]",+ cost_value: unitless_currency_number(@cost_entry.real_costs),+ }+ %>++ </span>+ <% else %>+ <span class="form--field-container"><%= f.text_field :overridden_costs,value: @cost_entry.overridden_costs ? unitless_currency_number(@cost_entry.overridden_costs).strip : '',placeholder: t(:label_example_placeholder, decimal: unitless_currency_number(1000.50)),@@ -140,13 +142,12 @@ See COPYRIGHT and LICENSE files for more details.id: 'cost_entry_cost_value',container_class: '-middle',size: 7 %>- </span>- <div class="form--field-instructions">- <p><%= t(:help_override_rate) %></p>- </div>- <% end %>- </div>- </cost-unit-subform>+ </span>+ <div class="form--field-instructions">+ <p><%= t(:help_override_rate) %></p>+ </div>+ <% end %>+ </div><div class="form--field"><%= f.text_field :comments, size: 100, container_class: '-wide' %>diff --git a/modules/costs/spec/features/cost_entries/add_cost_entry_spec.rb b/modules/costs/spec/features/cost_entries/add_cost_entry_spec.rbindex 2adee36d2eb..5502b6cc524 100644--- a/modules/costs/spec/features/cost_entries/add_cost_entry_spec.rb+++ b/modules/costs/spec/features/cost_entries/add_cost_entry_spec.rb@@ -93,7 +93,7 @@ describe 'Work Package cost fields', type: :feature, js: true do# Override costsfind('#cost_entry_costs').clickSeleniumHubWaiter.wait- fill_in 'cost_entry_costs_edit', with: '15.52'+ fill_in 'cost_entry_overridden_costs', with: '15.52'click_on 'Save'@@ -130,7 +130,7 @@ describe 'Work Package cost fields', type: :feature, js: true do# Override costsfind('#cost_entry_costs').clickSeleniumHubWaiter.wait- fill_in 'cost_entry_costs_edit', with: '1.350,25'+ fill_in 'cost_entry_overridden_costs', with: '1.350,25'click_on I18n.t(:button_save)@@ -152,7 +152,7 @@ describe 'Work Package cost fields', type: :feature, js: true do# Update the costs in german localeSeleniumHubWaiter.wait- fill_in 'cost_entry_costs_edit', with: '55.000,55'+ fill_in 'cost_entry_overridden_costs', with: '55.000,55'click_on I18n.t(:button_save)expect(page).to have_selector('#cost_entry_costs', text: '55.000,55 EUR')