Merge corrections provided by Bambuch

This commit is contained in:
cryptogopher 2025-04-26 18:32:45 +02:00
parent f7e4fe2d38
commit cd9a64b5ad
6 changed files with 23 additions and 18 deletions

View File

@ -12,7 +12,7 @@ class Default::UnitsController < ApplicationController
end end
def index def index
@units = current_user.units.defaults_diff.includes(:base).includes(:subunits).ordered @units = current_user.units.defaults_diff.includes(:base, :subunits).ordered
end end
def import def import

View File

@ -21,10 +21,10 @@ class MeasurementsController < ApplicationController
quantities -= @prev_quantities quantities -= @prev_quantities
@readouts = current_user.readouts.build(quantities.map { |q| {quantity: q} }) @readouts = current_user.readouts.build(quantities.map { |q| {quantity: q} })
all_quantities = @prev_qantities + quantities all_quantities = @prev_quantities + quantities
@closest_ancestor = current_user.quantities @closest_ancestor = current_user.quantities
.common_ancestors(all_quantities.map(&:parent_id)).first .common_ancestors(all_quantities.map(&:parent_id)).first
all_quantites << @closest_ancestor if @closest_ancestor all_quantities << @closest_ancestor if @closest_ancestor
@units = current_user.units.ordered @units = current_user.units.ordered
end end

View File

@ -9,7 +9,7 @@ class QuantitiesController < ApplicationController
end end
def index def index
@quantities = current_user.quantities.ordered.includes(:parent).includes(:subquantities) @quantities = current_user.quantities.ordered.includes(:parent, :subquantities)
end end
def new def new

View File

@ -9,7 +9,7 @@ class UnitsController < ApplicationController
end end
def index def index
@units = current_user.units.ordered.includes(:base).includes(:subunits) @units = current_user.units.ordered.includes(:base, :subunits)
end end
def new def new

View File

@ -26,6 +26,7 @@ class UsersController < ApplicationController
raise ParameterInvalid unless allow_disguise?(@user) raise ParameterInvalid unless allow_disguise?(@user)
session[:revert_to_id] = current_user.id session[:revert_to_id] = current_user.id
bypass_sign_in(@user) bypass_sign_in(@user)
# TODO: add flash with disguised username?
redirect_to root_url redirect_to root_url
end end

View File

@ -22,7 +22,7 @@ module ApplicationHelper
def form_for(&block) def form_for(&block)
@template.content_tag(:table, class: "centered") { yield(self) } + @template.content_tag(:table, class: "centered") { yield(self) } +
# Display leftover error messages (there shouldn't be any) # Display leftover error messages (there shouldn't be any)
@template.content_tag(:div, @object&.errors.full_messages.join(@template.tag :br)) @template.content_tag(:div, @object&.errors.full_messages.join(@template.tag(:br)))
end end
private private
@ -38,20 +38,21 @@ module ApplicationHelper
end end
def label_for(method, options = {}) def label_for(method, options = {})
return "" if (options[:label] == false) return '' if options[:label] == false
text = options.delete(:label) text = options.delete(:label)
text ||= @object.class.human_attribute_name(method).capitalize text ||= @object.class.human_attribute_name(method).capitalize
classes = @template.class_names(required: options[:required], classes = @template.class_names(required: options[:required],
error: @object&.errors[method].present?) error: @object&.errors[method].present?)
label = label(method, "#{text}:", class: classes)
hint = options.delete(:hint)
label(method, text+":", class: classes) + label + (@template.tag(:br) + @template.content_tag(:em, hint) if hint)
(@template.tag(:br) + @template.content_tag(:em, options.delete(:hint)) if options[:hint])
end end
end end
def labelled_form_for(record, options = {}, &block) def labelled_form_for(record, options = {}, &block)
options = options.deep_merge builder: LabelledFormBuilder, data: {turbo: false} options = options.deep_merge(builder: LabelledFormBuilder, data: {turbo: false})
form_for(record, **options) { |f| f.form_for(&block) } form_for(record, **options) { |f| f.form_for(&block) }
end end
@ -75,12 +76,14 @@ module ApplicationHelper
def number_field(method, options = {}) def number_field(method, options = {})
value = object.public_send(method) value = object.public_send(method)
if value.is_a? BigDecimal if value.is_a?(BigDecimal)
options[:value] = value.to_scientific options[:value] = value.to_scientific
type = object.class.type_for_attribute(method) type = object.class.type_for_attribute(method)
options[:step] ||= BigDecimal(10).power(-type.scale) options[:step] ||= BigDecimal(10).power(-type.scale)
options[:max] ||= BigDecimal(10).power(type.precision - type.scale) - options[:step] options[:max] ||= BigDecimal(10).power(type.precision - type.scale) -
options[:min] = options[:min] == :step ? options[:step] : options[:min] || -options[:max] options[:step]
options[:min] = options[:min] == :step ? options[:step] : options[:min]
options[:min] ||= -options[:max]
end end
super super
end end
@ -107,20 +110,21 @@ module ApplicationHelper
# skip_default_ids causes turbo to generate unique ID for element with # skip_default_ids causes turbo to generate unique ID for element with
# [autofocus]. Otherwise IDs are not unique when multiple forms are open # [autofocus]. Otherwise IDs are not unique when multiple forms are open
# and the first input gets focus. # and the first input gets focus.
record_object, options = nil, record_object if record_object.is_a? Hash record_object, options = nil, record_object if record_object.is_a?(Hash)
options.merge! builder: TabularFormBuilder, skip_default_ids: true options.merge!(builder: TabularFormBuilder, skip_default_ids: true)
render_errors(record_object || record_name) render_errors(record_object || record_name)
fields_for(record_name, record_object, **options, &block) fields_for(record_name, record_object, **options, &block)
end end
def tabular_form_with(**options, &block) def tabular_form_with(**options, &block)
options = options.deep_merge builder: TabularFormBuilder, html: {autocomplete: 'off'} options = options.deep_merge(builder: TabularFormBuilder,
html: {autocomplete: 'off'})
form_with(**options, &block) form_with(**options, &block)
end end
def svg_tag(source, options = {}) def svg_tag(source, options = {})
content_tag :svg, options do content_tag :svg, options do
tag.use href: image_path(source + ".svg") + "#icon" tag.use(href: "#{image_path(source + ".svg")}#icon")
end end
end end