diff --git a/app/assets/javascripts/application_legacy.js b/app/assets/javascripts/application_legacy.js index a5065137..80c5a812 100644 --- a/app/assets/javascripts/application_legacy.js +++ b/app/assets/javascripts/application_legacy.js @@ -99,7 +99,7 @@ $(function() { // Submission will be done after 500ms of not typed, unless data-submit-onchange=changed, // in which case it happens when the input box loses its focus ('changed' event). // (changeDate is for bootstrap-datepicker) - $(document).on('changed keyup focusin changeDate', 'form[data-submit-onchange] input[type=text]:not([data-ignore-onchange])', function(e) { + $(document).on('changed keyup focusin changeDate', 'form[data-submit-onchange] input[type=number]:not([data-ignore-onchange])', function(e) { var input = $(this); // when form has data-submit-onchange=changed, don't do updates while typing if (e.type!='changed' && e.type!='changeDate' && input.parents('form[data-submit-onchange=changed]').length>0) { diff --git a/app/assets/javascripts/delta_input.js b/app/assets/javascripts/delta_input.js index 5c0da86f..ddfb8c87 100644 --- a/app/assets/javascripts/delta_input.js +++ b/app/assets/javascripts/delta_input.js @@ -6,7 +6,7 @@ $(function() { $(document).on('click', 'button[data-decrement]', function() { data_delta_update($('#'+$(this).data('decrement')), -1); }); - $(document).on('change keyup', 'input[type="text"][data-delta]', function() { + $(document).on('change keyup', 'input[type="number"][data-delta]', function() { data_delta_update(this, 0); }); }); diff --git a/app/assets/stylesheets/delta_input.less b/app/assets/stylesheets/delta_input.less index 753d6a83..d3719fd4 100644 --- a/app/assets/stylesheets/delta_input.less +++ b/app/assets/stylesheets/delta_input.less @@ -17,6 +17,12 @@ form.delta-input, .delta-input form { input[data-delta] { text-align: center; height: 14px; + + -moz-appearance: textfield; + + &::-webkit-inner-spin-button { + -webkit-appearance: none; + } } .btn-ordering { diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4f198b74..5efa4cdf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -268,7 +268,7 @@ def foodcoop_css_tag(_options = {}) stylesheet_link_tag foodcoop_css_path, media: 'all' end - def format_number(value) - format('%g', format('%.2f', value)) + def format_number(value, max_precision = 2) + number_with_precision(value, precision: max_precision, strip_insignificant_zeros: true, separator: '.', delimiter: '') end end diff --git a/app/helpers/articles_helper.rb b/app/helpers/articles_helper.rb index 45781967..5066d3a8 100644 --- a/app/helpers/articles_helper.rb +++ b/app/helpers/articles_helper.rb @@ -49,7 +49,7 @@ def format_unit_with_ratios(unit_property, article) return base if first_si_convertible_unit.nil? quantity = article.convert_quantity(1, unit_code, first_si_convertible_unit) - "#{base} (#{format_number(quantity)}\u00a0#{ArticleUnitsLib.units.to_h[first_si_convertible_unit][:symbol]})" + "#{base} (#{number_with_precision(quantity, precision: 2, strip_insignificant_zeros: true)}\u00a0#{ArticleUnitsLib.units.to_h[first_si_convertible_unit][:symbol]})" end def format_supplier_order_unit_with_ratios(article) diff --git a/app/helpers/group_order_articles_helper.rb b/app/helpers/group_order_articles_helper.rb index db2fd087..c970a0cc 100644 --- a/app/helpers/group_order_articles_helper.rb +++ b/app/helpers/group_order_articles_helper.rb @@ -19,7 +19,7 @@ def group_order_article_edit_result(goa, convert_to_billing_unit = true) article_version.billing_unit, article_version.group_order_unit)) end f.input_field(:result, as: :delta, class: 'input-nano', data: input_data, id: "r_#{goa.id}", - value: converted_value.round(3)) + value: format_number(converted_value, 3)) end else result diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 91e08a46..3900054a 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -78,7 +78,7 @@ def pkg_helper(article, options = {}) first_ratio = article&.article_unit_ratios&.first return '' if first_ratio.nil? || first_ratio.quantity == 1 - uq_text = "× #{first_ratio.quantity} #{ArticleUnitsLib.units[first_ratio.unit][:symbol]}" + uq_text = "× #{number_with_precision(first_ratio.quantity, precision: 3, strip_insignificant_zeros: true)} #{ArticleUnitsLib.units[first_ratio.unit][:symbol]}" else unit = ArticleUnitsLib.units[options[:unit]] uq_text = unit[:symbol] || unit[:name] diff --git a/app/inputs/delta_input.rb b/app/inputs/delta_input.rb index 12d6fe4f..50423d88 100644 --- a/app/inputs/delta_input.rb +++ b/app/inputs/delta_input.rb @@ -2,7 +2,8 @@ class DeltaInput < SimpleForm::Inputs::StringInput # for now, need to pass id or it won't work def input(wrapper_options) options = merge_wrapper_options(input_html_options, wrapper_options) - options[:type] = 'text' + options[:type] = 'number' + options[:step] = 'any' options[:data] ||= {} options[:data][:delta] ||= 1 options[:autocomplete] ||= 'off' diff --git a/app/views/group_orders/_form.html.haml b/app/views/group_orders/_form.html.haml index 1fc0f36c..3e854004 100644 --- a/app/views/group_orders/_form.html.haml +++ b/app/views/group_orders/_form.html.haml @@ -117,9 +117,9 @@ - quantity_data['minimum_order_quantity'] = @ordering_data[:order_articles][order_article.id][:minimum_order_quantity] unless @ordering_data[:order_articles][order_article.id][:minimum_order_quantity].nil? - quantity_data['e2e-order-article-id'] = order_article.id %td.quantity.group-order-input{class: ('stock-order' if @order.stockit?)} - %span.used= format_number(@ordering_data[:order_articles][order_article.id][:used_quantity]) + %span.used= number_with_precision(@ordering_data[:order_articles][order_article.id][:used_quantity], precision: 3, strip_insignificant_zeros: true) + - %span.unused= format_number(@ordering_data[:order_articles][order_article.id][:quantity] - @ordering_data[:order_articles][order_article.id][:used_quantity]) + %span.unused= number_with_precision(@ordering_data[:order_articles][order_article.id][:quantity] - @ordering_data[:order_articles][order_article.id][:used_quantity], precision: 3, strip_insignificant_zeros: true) .btn-group.numeric-step %a.btn.btn-ordering.increase %i.icon-plus @@ -131,9 +131,9 @@ %td.tolerance.group-order-input{style: ('display:none' if @order.stockit?)} - if (order_article.article_version.uses_tolerance?) - %span.used= format_number(@ordering_data[:order_articles][order_article.id][:used_tolerance]) + %span.used= number_with_precision(@ordering_data[:order_articles][order_article.id][:used_tolerance], precision: 3, strip_insignificant_zeros: true) + - %span.unused= format_number(@ordering_data[:order_articles][order_article.id][:tolerance] - @ordering_data[:order_articles][order_article.id][:used_tolerance]) + %span.unused= number_with_precision(@ordering_data[:order_articles][order_article.id][:tolerance] - @ordering_data[:order_articles][order_article.id][:used_tolerance], precision: 3, strip_insignificant_zeros: true) .btn-group %a.btn.btn-ordering.increase %i.icon-plus diff --git a/app/views/orders/_articles.html.haml b/app/views/orders/_articles.html.haml index 97270f3a..95ad0516 100644 --- a/app/views/orders/_articles.html.haml +++ b/app/views/orders/_articles.html.haml @@ -29,14 +29,14 @@ %td= format_group_order_unit_with_ratios(order_article.article_version) %td= "#{number_to_currency(net_price)} / #{number_to_currency(gross_price)}" - if order.stockit? - %td= units + %td= = number_with_precision(units, precision: 3, strip_insignificant_zeros: true) - else - if order_article.tolerance > 0 - %td= "#{order_article.quantity} + #{order_article.tolerance}" + %td= "#{number_with_precision(order_article.quantity, precision: 3, strip_insignificant_zeros: true)} + #{number_with_precision(order_article.tolerance, precision: 3, strip_insignificant_zeros: true)}" - else - %td= "#{order_article.quantity}" + %td= "#{number_with_precision(order_article.quantity, precision: 3, strip_insignificant_zeros: true)}" %td{title: units_history_line(order_article, plain: true)} - = units + = number_with_precision(units, precision: 3, strip_insignificant_zeros: true) = pkg_helper article %p = t '.prices_sum' diff --git a/app/views/shared/articles_by/_article_single_goa.html.haml b/app/views/shared/articles_by/_article_single_goa.html.haml index cdade7ab..a791ae08 100644 --- a/app/views/shared/articles_by/_article_single_goa.html.haml +++ b/app/views/shared/articles_by/_article_single_goa.html.haml @@ -1,6 +1,6 @@ %tr{class: if goa.result == 0 then 'unavailable' end, id: "goa_#{goa.id}"} - article_version = goa.order_article.article_version %td{:style => "width:70%"}= goa.group_order.ordergroup_name - %td.center= "#{article_version.convert_quantity(goa.quantity, article_version.group_order_unit, article_version.billing_unit)} + #{article_version.convert_quantity(goa.tolerance, article_version.group_order_unit, article_version.billing_unit)}" + %td.center= "#{number_with_precision(article_version.convert_quantity(goa.quantity, article_version.group_order_unit, article_version.billing_unit), precision: 3, strip_insignificant_zeros: true)} + #{number_with_precision(article_version.convert_quantity(goa.tolerance, article_version.group_order_unit, article_version.billing_unit), precision: 3, strip_insignificant_zeros: true)}" %td.center.input-delta= group_order_article_edit_result(goa) %td.price{data: {value: goa.total_price}}= number_to_currency(goa.total_price) diff --git a/app/views/shared/articles_by/_group_single_goa.html.haml b/app/views/shared/articles_by/_group_single_goa.html.haml index 59a1b80c..dfbbe925 100644 --- a/app/views/shared/articles_by/_group_single_goa.html.haml +++ b/app/views/shared/articles_by/_group_single_goa.html.haml @@ -2,7 +2,7 @@ - article_version = goa.order_article.article_version %td.name= goa.order_article.article_version.name %td= format_billing_unit_with_ratios(article_version) - %td.center= "#{article_version.convert_quantity(goa.quantity, article_version.group_order_unit, article_version.billing_unit)} + #{article_version.convert_quantity(goa.tolerance, article_version.group_order_unit, article_version.billing_unit)}" + %td.center= "#{number_with_precision(article_version.convert_quantity(goa.quantity, article_version.group_order_unit, article_version.billing_unit), precision: 3, strip_insignificant_zeros: true)} + #{number_with_precision(article_version.convert_quantity(goa.tolerance, article_version.group_order_unit, article_version.billing_unit), precision: 3, strip_insignificant_zeros: true)}" %td.center.input-delta= group_order_article_edit_result(goa) %td.symbol × %td= number_to_currency(article_version.convert_quantity(article_version.fc_price, article_version.billing_unit, article_version.supplier_order_unit))