Import fixes
This commit is contained in:
parent
3a09bf6fce
commit
eb43c4be21
@ -42,11 +42,17 @@ class IngredientsController < ApplicationController
|
||||
|
||||
CSV.foreach(params[:file].path, headers: true).with_index(2) do |row, line|
|
||||
r = row.to_h
|
||||
unless r.has_key?('Name')
|
||||
warnings << "Line 1: required 'Name' column is missing" if line == 2
|
||||
end
|
||||
i = {
|
||||
name: r.delete('Name'),
|
||||
ref_amount: 100.0,
|
||||
ref_unit: units['g'],
|
||||
group: r.delete('Group') || :other,
|
||||
nutrients_attributes: []
|
||||
}
|
||||
|
||||
r.each do |col, val|
|
||||
if col.blank?
|
||||
warnings << "Line 1: column header missing" if line == 2
|
||||
@ -64,8 +70,8 @@ class IngredientsController < ApplicationController
|
||||
" in column #{col}" unless column_units[quantity]
|
||||
end
|
||||
end
|
||||
next if quantities[quantity].blank? || val.blank?
|
||||
|
||||
next if val.blank?
|
||||
amount, amount_unit_sn, * = val.rstrip.partition(/\[.*\]$/)
|
||||
unit = nil
|
||||
if amount_unit_sn.present?
|
||||
@ -80,6 +86,7 @@ class IngredientsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
next if quantities[quantity].blank?
|
||||
if quantity == 'Reference'
|
||||
i.update({
|
||||
ref_amount: amount.to_d,
|
||||
|
@ -36,12 +36,18 @@ class CreateUnits < ActiveRecord::Migration
|
||||
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
Unit.create project: nil, shortname: "%", name: "percent"
|
||||
Unit.create project: nil, shortname: "g", name: "gram"
|
||||
Unit.create project: nil, shortname: "mg", name: "milligram"
|
||||
Unit.create project: nil, shortname: "ug", name: "microgram"
|
||||
Unit.create project: nil, shortname: "kg", name: "kilogram"
|
||||
Unit.create project: nil, shortname: "kcal", name: "kilocalorie"
|
||||
Unit.create project: nil, shortname: "%", name: "percent"
|
||||
|
||||
# https://www.fsai.ie/uploadedFiles/Consol_Reg1169_2011.pdf
|
||||
# https://www.fsai.ie/legislation/food_legislation/food_information_fic/nutrition_labelling.html
|
||||
e = Quantity.create project: nil, domain: :diet, parent: nil, name: "Energy",
|
||||
description: "Total energy"
|
||||
|
||||
Quantity.create project: nil, domain: :diet, parent: nil, name: "Proteins",
|
||||
description: "Total amount of proteins"
|
||||
|
||||
|
Reference in New Issue
Block a user