Added zero_nil to Quantity form and import
This commit is contained in:
parent
9bddc67a3f
commit
b1e7236460
@ -29,6 +29,8 @@ class BodyTrackersController < ApplicationController
|
|||||||
attrs = q.attributes.except('id', 'project_id', 'parent_id', 'lft', 'rgt',
|
attrs = q.attributes.except('id', 'project_id', 'parent_id', 'lft', 'rgt',
|
||||||
'created_at', 'updated_at')
|
'created_at', 'updated_at')
|
||||||
attrs['parent'] = q.parent ? available[[q.parent.name, q.parent.domain]] : nil
|
attrs['parent'] = q.parent ? available[[q.parent.name, q.parent.domain]] : nil
|
||||||
|
attrs['formula_attributes'] = q.formula.attributes.except('id', 'quantity_id',
|
||||||
|
'created_at', 'updated_at')
|
||||||
obj = @project.quantities.create(attrs)
|
obj = @project.quantities.create(attrs)
|
||||||
available[[q.name, q.domain]] = obj
|
available[[q.name, q.domain]] = obj
|
||||||
end
|
end
|
||||||
|
@ -14,5 +14,6 @@
|
|||||||
<%= f.fields_for :formula do |ff| %>
|
<%= f.fields_for :formula do |ff| %>
|
||||||
<p><%= ff.text_field :code, placeholder: t('.formula_placeholder'),
|
<p><%= ff.text_field :code, placeholder: t('.formula_placeholder'),
|
||||||
style: "width: 100%;" %></p>
|
style: "width: 100%;" %></p>
|
||||||
|
<p><%= ff.check_box :zero_nil, {label: ''} %><%= t('.zero_nil') %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
@ -123,6 +123,7 @@ en:
|
|||||||
null_parent: '- none -'
|
null_parent: '- none -'
|
||||||
formula_placeholder: 'provide if value of quantity has to be computed in terms of
|
formula_placeholder: 'provide if value of quantity has to be computed in terms of
|
||||||
other quantities'
|
other quantities'
|
||||||
|
zero_nil: 'substitute missing formula values with 0?'
|
||||||
units:
|
units:
|
||||||
index:
|
index:
|
||||||
heading: 'Units'
|
heading: 'Units'
|
||||||
|
@ -13,6 +13,8 @@ class LoadDefaults < ActiveRecord::Migration
|
|||||||
# https://www.fsai.ie/legislation/food_legislation/food_information_fic/nutrition_labelling.html
|
# https://www.fsai.ie/legislation/food_legislation/food_information_fic/nutrition_labelling.html
|
||||||
e1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Energy",
|
e1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Energy",
|
||||||
description: "Total energy"
|
description: "Total energy"
|
||||||
|
e2 = Quantity.create project: nil, domain: :diet, parent: e1, name: "Calculated",
|
||||||
|
description: "Total energy calculated from macronutrients"
|
||||||
|
|
||||||
p1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Proteins",
|
p1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Proteins",
|
||||||
description: "Total amount of proteins"
|
description: "Total amount of proteins"
|
||||||
@ -141,10 +143,9 @@ class LoadDefaults < ActiveRecord::Migration
|
|||||||
b9 = Quantity.create project: nil, domain: :measurement, parent: b1,
|
b9 = Quantity.create project: nil, domain: :measurement, parent: b1,
|
||||||
name: "VF", description: "Visceral fat"
|
name: "VF", description: "Visceral fat"
|
||||||
|
|
||||||
# Calculated quantities go at the and to make sure dependencies exist
|
# Formulas go at the and to make sure dependencies exist
|
||||||
e2 = Quantity.create project: nil, domain: :diet, parent: e1, name: "Calculated",
|
e2.create_formula code: "4*Proteins + 9*Fats + 4*Carbohydrates", zero_nil: true
|
||||||
description: "Total energy calculated from macronutrients",
|
b3.create_formula code: "'% fat' * 'Weight'", zero_nil: true
|
||||||
formula_attributes: {code: "4*Proteins + 9*Fats + 4*Carbohydrates", zero_nil: true}
|
|
||||||
|
|
||||||
Source.create project: nil, name: "nutrition label",
|
Source.create project: nil, name: "nutrition label",
|
||||||
description: "nutrition facts taken from package nutrition label"
|
description: "nutrition facts taken from package nutrition label"
|
||||||
|
Reference in New Issue
Block a user