Defaults/import fixes and ingredients sorting
This commit is contained in:
@@ -15,7 +15,7 @@ class BodyTrackersController < ApplicationController
|
||||
flash[:notice] = "Loaded #{new_units > 0 ? new_units : "no" } new" \
|
||||
" #{'unit'.pluralize(new_units)}"
|
||||
|
||||
available = Quantity.where(project: @project).map { |q| [[q.name, q.domain], q] }.to_h
|
||||
available = @project.quantities.map { |q| [[q.name, q.domain], q] }.to_h
|
||||
new_quantities = available.length
|
||||
defaults = Quantity.where(project: nil)
|
||||
Quantity.each_with_level(defaults) do |q, level|
|
||||
|
||||
@@ -19,6 +19,7 @@ class IngredientsController < ApplicationController
|
||||
redirect_to project_ingredients_url(@project)
|
||||
else
|
||||
@ingredients = @project.ingredients.includes(:ref_unit)
|
||||
@ingredient.nutrients.new(ingredient: @ingredient) if @ingredient.nutrients.empty?
|
||||
render :index
|
||||
end
|
||||
end
|
||||
@@ -112,9 +113,11 @@ class IngredientsController < ApplicationController
|
||||
flash[:notice] = "Imported #{ingredients.map(&:persisted?).count(true)} out of" \
|
||||
" #{ingredients_params.length} ingredients"
|
||||
skipped = ingredients.select { |i| !i.persisted? }
|
||||
skipped_desc = skipped.map { |i| "#{i.name} - #{i.errors.full_messages.join(', ')}" }
|
||||
flash[:warning] = "Ingredients skipped due to errors:<br>" \
|
||||
" #{skipped_desc.join('<br>').truncate(1024)}"
|
||||
if skipped.length > 0
|
||||
skipped_desc = skipped.map { |i| "#{i.name} - #{i.errors.full_messages.join(', ')}" }
|
||||
flash[:warning] = "Ingredients skipped due to errors:<br>" \
|
||||
" #{skipped_desc.join('<br>').truncate(1024)}"
|
||||
end
|
||||
else
|
||||
warnings.unshift("Problems encountered during import - fix and try again:")
|
||||
flash[:warning] = warnings.join("<br>").truncate(1024, omission: '...(and other)')
|
||||
|
||||
Reference in New Issue
Block a user