Error reporting on failed loading of default(s)
This commit is contained in:
parent
fd184df9c7
commit
ffb87a09c4
@ -9,6 +9,8 @@ class BodyTrackersController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def defaults
|
def defaults
|
||||||
|
failed_objects = []
|
||||||
|
|
||||||
# Units
|
# Units
|
||||||
available_units = @project.units.pluck(:shortname, :id).to_h
|
available_units = @project.units.pluck(:shortname, :id).to_h
|
||||||
defaults = Unit.where(project: nil).map do |u|
|
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]
|
attrs['formula_attributes']['unit_id'] = available_units[q.formula.unit.shortname]
|
||||||
end
|
end
|
||||||
obj = @project.quantities.create(attrs)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -62,6 +68,13 @@ class BodyTrackersController < ApplicationController
|
|||||||
flash[:notice] += " and #{new_sources.length > 0 ? new_sources.length : "no" } new" \
|
flash[:notice] += " and #{new_sources.length > 0 ? new_sources.length : "no" } new" \
|
||||||
" #{'source'.pluralize(new_sources.length)}"
|
" #{'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
|
redirect_to :back
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -44,6 +44,7 @@ class Quantity < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: move as an association extension module
|
||||||
def self.filter(project, filters)
|
def self.filter(project, filters)
|
||||||
quantities = all
|
quantities = all
|
||||||
|
|
||||||
|
@ -47,11 +47,11 @@ en:
|
|||||||
formula:
|
formula:
|
||||||
attributes:
|
attributes:
|
||||||
code:
|
code:
|
||||||
disallowed_syntax: 'cannot be parsed: %{syntax}'
|
disallowed_syntax: 'cannot be parsed "%{syntax}"'
|
||||||
disallowed_token: 'includes disallowed token: "%{token}"'
|
disallowed_token: 'includes disallowed token "%{token}"'
|
||||||
disallowed_keyword: 'includes disallowed keyword: "%{keyword}"'
|
disallowed_keyword: 'includes disallowed keyword "%{keyword}"'
|
||||||
disallowed_method: 'includes disallowed method call: "%{method}"'
|
disallowed_method: 'includes disallowed method call "%{method}"'
|
||||||
unknown_dependency: 'contains undefined dependency: %{identifier}'
|
unknown_dependency: 'contains undefined dependency "%{identifier}"'
|
||||||
computation_failed: 'computation failed for "%{quantity}": %{description}
|
computation_failed: 'computation failed for "%{quantity}": %{description}
|
||||||
(%{count} values missing)'
|
(%{count} values missing)'
|
||||||
body_trackers:
|
body_trackers:
|
||||||
|
Reference in New Issue
Block a user