1
0

Error reporting on failed loading of default(s)

This commit is contained in:
cryptogopher 2020-05-11 20:40:29 +02:00
parent fd184df9c7
commit ffb87a09c4
3 changed files with 20 additions and 6 deletions

View File

@ -9,6 +9,8 @@ class BodyTrackersController < ApplicationController
end
def defaults
failed_objects = []
# Units
available_units = @project.units.pluck(:shortname, :id).to_h
defaults = Unit.where(project: nil).map do |u|
@ -38,7 +40,11 @@ class BodyTrackersController < ApplicationController
attrs['formula_attributes']['unit_id'] = available_units[q.formula.unit.shortname]
end
obj = @project.quantities.create(attrs)
available_quantities[[q.name, q.domain]] = obj if obj.persisted?
if obj.persisted?
available_quantities[[q.name, q.domain]] = obj
else
failed_objects << obj
end
end
end
@ -62,6 +68,13 @@ class BodyTrackersController < ApplicationController
flash[:notice] += " and #{new_sources.length > 0 ? new_sources.length : "no" } new" \
" #{'source'.pluralize(new_sources.length)}"
if failed_objects.present?
flash[:notice] += " (loading #{failed_objects.length} objects failed, see errors)"
flash[:error] = failed_objects.map do |o|
"<p>#{o.class.name} #{o.name}: #{o.errors.full_messages.join(', ')}</p>"
end.join.html_safe
end
redirect_to :back
end
end

View File

@ -44,6 +44,7 @@ class Quantity < ActiveRecord::Base
end
end
# TODO: move as an association extension module
def self.filter(project, filters)
quantities = all

View File

@ -47,11 +47,11 @@ en:
formula:
attributes:
code:
disallowed_syntax: 'cannot be parsed: %{syntax}'
disallowed_token: 'includes disallowed token: "%{token}"'
disallowed_keyword: 'includes disallowed keyword: "%{keyword}"'
disallowed_method: 'includes disallowed method call: "%{method}"'
unknown_dependency: 'contains undefined dependency: %{identifier}'
disallowed_syntax: 'cannot be parsed "%{syntax}"'
disallowed_token: 'includes disallowed token "%{token}"'
disallowed_keyword: 'includes disallowed keyword "%{keyword}"'
disallowed_method: 'includes disallowed method call "%{method}"'
unknown_dependency: 'contains undefined dependency "%{identifier}"'
computation_failed: 'computation failed for "%{quantity}": %{description}
(%{count} values missing)'
body_trackers: