Skip to content

Commit

Permalink
Fixes #60
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Apr 21, 2024
1 parent 13b19a3 commit 91fba6d
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/application_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/delta_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down
6 changes: 6 additions & 0 deletions app/assets/stylesheets/delta_input.less
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,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
2 changes: 1 addition & 1 deletion app/helpers/articles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/group_order_articles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/orders_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion app/inputs/delta_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions app/views/group_orders/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/views/orders/_articles.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/articles_by/_article_single_goa.html.haml
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion app/views/shared/articles_by/_group_single_goa.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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 &times;
%td= number_to_currency(article_version.convert_quantity(article_version.fc_price, article_version.billing_unit, article_version.supplier_order_unit))
Expand Down

0 comments on commit 91fba6d

Please sign in to comment.