Replaced Quantity 'primary' attr with ColumnView model
This commit is contained in:
parent
ccf26d1830
commit
0c0ca1d286
@ -6,7 +6,7 @@ class IngredientsController < ApplicationController
|
|||||||
before_action :init_session_filters
|
before_action :init_session_filters
|
||||||
before_action :find_project_by_project_id,
|
before_action :find_project_by_project_id,
|
||||||
only: [:index, :nutrients, :create, :import, :filter, :filter_nutrients]
|
only: [:index, :nutrients, :create, :import, :filter, :filter_nutrients]
|
||||||
before_action :find_quantity, only: [:toggle_nutrient_column]
|
before_action :find_quantity_by_quantity_id, only: [:toggle_column]
|
||||||
before_action :find_ingredient, only: [:destroy, :toggle]
|
before_action :find_ingredient, only: [:destroy, :toggle]
|
||||||
before_action :authorize
|
before_action :authorize
|
||||||
|
|
||||||
@ -25,8 +25,8 @@ class IngredientsController < ApplicationController
|
|||||||
prepare_nutrients
|
prepare_nutrients
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_nutrient_column
|
def toggle_column
|
||||||
@quantity.toggle_primary!
|
@project.nutrients_column_view.toggle_column!(@quantity)
|
||||||
prepare_nutrients
|
prepare_nutrients
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -207,7 +207,7 @@ class IngredientsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def prepare_nutrients
|
def prepare_nutrients
|
||||||
@quantities = @project.quantities.diet.where(primary: true)
|
@quantities = @project.nutrients_column_view.quantities
|
||||||
ingredients, requested_n, extra_n, @formula_q = @project.ingredients
|
ingredients, requested_n, extra_n, @formula_q = @project.ingredients
|
||||||
.filter(@project, session[:i_filters], @quantities)
|
.filter(@project, session[:i_filters], @quantities)
|
||||||
|
|
||||||
|
@ -3,8 +3,9 @@ class MeasurementsController < ApplicationController
|
|||||||
|
|
||||||
before_action :init_session_filters
|
before_action :init_session_filters
|
||||||
before_action :find_project_by_project_id, only: [:index, :new, :create]
|
before_action :find_project_by_project_id, only: [:index, :new, :create]
|
||||||
before_action :find_quantity, only: [:toggle_quantity]
|
before_action :find_quantity_by_quantity_id, only: [:toggle_column]
|
||||||
before_action :find_measurement, only: [:edit, :update, :destroy, :retake, :readouts]
|
before_action :find_measurement,
|
||||||
|
only: [:edit, :update, :destroy, :retake, :readouts, :toggle_column]
|
||||||
before_action :authorize
|
before_action :authorize
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@ -61,8 +62,8 @@ class MeasurementsController < ApplicationController
|
|||||||
prepare_readouts
|
prepare_readouts
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_quantity
|
def toggle_column
|
||||||
@quantity.toggle_primary!
|
@measurement.column_view.toggle_column!(@quantity)
|
||||||
prepare_readouts
|
prepare_readouts
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -103,7 +104,7 @@ class MeasurementsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def prepare_readouts
|
def prepare_readouts
|
||||||
@quantities = @project.quantities.measurement.where(primary: true)
|
@quantities = @measurement.column_view.quantities
|
||||||
@measurements, @requested_r, @extra_r, @formula_q = @project.measurements
|
@measurements, @requested_r, @extra_r, @formula_q = @project.measurements
|
||||||
.includes(:source)
|
.includes(:source)
|
||||||
.filter(session[:m_filters], @quantities)
|
.filter(session[:m_filters], @quantities)
|
||||||
|
@ -3,7 +3,7 @@ class QuantitiesController < ApplicationController
|
|||||||
|
|
||||||
before_action :init_session_filters
|
before_action :init_session_filters
|
||||||
before_action :find_project_by_project_id, only: [:index, :parents, :create, :filter]
|
before_action :find_project_by_project_id, only: [:index, :parents, :create, :filter]
|
||||||
before_action :find_quantity, only: [:edit, :update, :destroy, :toggle, :move]
|
before_action :find_quantity, only: [:edit, :update, :destroy, :move]
|
||||||
before_action :authorize
|
before_action :authorize
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@ -55,11 +55,6 @@ class QuantitiesController < ApplicationController
|
|||||||
render :index
|
render :index
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle
|
|
||||||
@quantity.toggle_primary!
|
|
||||||
prepare_quantities
|
|
||||||
end
|
|
||||||
|
|
||||||
def move
|
def move
|
||||||
direction = params[:direction].to_sym
|
direction = params[:direction].to_sym
|
||||||
case direction
|
case direction
|
||||||
@ -90,8 +85,7 @@ class QuantitiesController < ApplicationController
|
|||||||
:parent_id,
|
:parent_id,
|
||||||
:name,
|
:name,
|
||||||
:description,
|
:description,
|
||||||
:formula,
|
:formula
|
||||||
:primary
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,10 +5,11 @@ module IngredientsHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def nutrient_column_options
|
def toggle_column_options
|
||||||
disabled = []
|
disabled = []
|
||||||
|
enabled_columns = @project.nutrients_column_view.quantities
|
||||||
options = nested_set_options(@project.quantities.diet) do |q|
|
options = nested_set_options(@project.quantities.diet) do |q|
|
||||||
disabled << q.id if q.primary
|
disabled << q.id if enabled_columns.include?(q)
|
||||||
raw("#{' ' * q.level}#{q.name}")
|
raw("#{' ' * q.level}#{q.name}")
|
||||||
end
|
end
|
||||||
options_for_select(options, disabled: disabled)
|
options_for_select(options, disabled: disabled)
|
||||||
|
@ -12,10 +12,11 @@ module MeasurementsHelper
|
|||||||
amount.nil? ? '-' : "#{amount} [#{unitname || '-'}]"
|
amount.nil? ? '-' : "#{amount} [#{unitname || '-'}]"
|
||||||
end
|
end
|
||||||
|
|
||||||
def quantity_toggle_options
|
def toggle_column_options
|
||||||
disabled = []
|
disabled = []
|
||||||
|
enabled_columns = @measurement.column_view.quantities
|
||||||
options = nested_set_options(@project.quantities.measurement) do |q|
|
options = nested_set_options(@project.quantities.measurement) do |q|
|
||||||
disabled << q.id if q.primary
|
disabled << q.id if enabled_columns.include?(q)
|
||||||
raw("#{' ' * q.level}#{q.name}")
|
raw("#{' ' * q.level}#{q.name}")
|
||||||
end
|
end
|
||||||
options_for_select(options, disabled: disabled)
|
options_for_select(options, disabled: disabled)
|
||||||
|
@ -1,2 +1,17 @@
|
|||||||
class ColumnView < ActiveRecord::Base
|
class ColumnView < ActiveRecord::Base
|
||||||
|
enum domain: Quantity.domains
|
||||||
|
|
||||||
|
belongs_to :project, required: true
|
||||||
|
has_and_belongs_to_many :quantities
|
||||||
|
|
||||||
|
validates :name, presence: true, uniqueness: {scope: :domain}
|
||||||
|
validates :domain, inclusion: {in: domains.keys}
|
||||||
|
|
||||||
|
# TODO: enforce column_view - quantity 'domain' identity
|
||||||
|
def toggle_column!(q)
|
||||||
|
column = self.quantities.find(q.id)
|
||||||
|
self.quantites.destroy(column)
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
self.quantities.create!(quantity: q)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -28,6 +28,33 @@ class Measurement < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Copy/rename ColumnView on Measurement rename
|
||||||
|
after_save do
|
||||||
|
old_column_view = self.project.column_views
|
||||||
|
.find_by(name: self.name_was, domain: :measurement)
|
||||||
|
return unless old_column_view
|
||||||
|
|
||||||
|
if self.project.measurements.exists?(name: self.name_was)
|
||||||
|
return unless old_column_view.quantities.exist?
|
||||||
|
self.column_view.quantities.create(old_column_view.quantities)
|
||||||
|
self.column_view.save!
|
||||||
|
else
|
||||||
|
old_column_view.name = self.name
|
||||||
|
old_column_view.save!
|
||||||
|
end
|
||||||
|
end, if: :name_changed?
|
||||||
|
|
||||||
|
# Destroy ColumnView after last Measurement destruction
|
||||||
|
after_destroy do
|
||||||
|
unless self.project.measurements.exists?(name: self.name)
|
||||||
|
self.column_view.destroy!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def column_view
|
||||||
|
self.project.column_views.find_or_create_by(name: self.name, domain: :measurement)
|
||||||
|
end
|
||||||
|
|
||||||
def toggle_hidden!
|
def toggle_hidden!
|
||||||
self.toggle!(:hidden)
|
self.toggle!(:hidden)
|
||||||
end
|
end
|
||||||
|
@ -15,6 +15,7 @@ class Quantity < ActiveRecord::Base
|
|||||||
|
|
||||||
acts_as_nested_set dependent: :destroy, scope: :project
|
acts_as_nested_set dependent: :destroy, scope: :project
|
||||||
belongs_to :project, required: false
|
belongs_to :project, required: false
|
||||||
|
has_and_belongs_to_many :column_views
|
||||||
|
|
||||||
validates :name, presence: true, uniqueness: {scope: :project_id}
|
validates :name, presence: true, uniqueness: {scope: :project_id}
|
||||||
validates :domain, inclusion: {in: domains.keys}
|
validates :domain, inclusion: {in: domains.keys}
|
||||||
@ -26,7 +27,6 @@ class Quantity < ActiveRecord::Base
|
|||||||
after_initialize do
|
after_initialize do
|
||||||
if new_record?
|
if new_record?
|
||||||
self.domain ||= :diet
|
self.domain ||= :diet
|
||||||
self.primary = false if self.primary.nil?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -46,10 +46,6 @@ class Quantity < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def toggle_primary!
|
|
||||||
self.toggle!(:primary)
|
|
||||||
end
|
|
||||||
|
|
||||||
def formula_quantities
|
def formula_quantities
|
||||||
Formula.new(self.project, self.formula).get_quantities
|
Formula.new(self.project, self.formula).get_quantities
|
||||||
end
|
end
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
<fieldset id="options" class="collapsible">
|
<fieldset id="options" class="collapsible">
|
||||||
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
|
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
|
||||||
<div>
|
<div>
|
||||||
<%= form_tag toggle_nutrient_column_project_ingredients_path(@project),
|
<%= form_tag toggle_column_project_ingredients_path(@project),
|
||||||
id: 'nutrient-column-add-form', name: 'nutrient-column-add-form',
|
id: 'toggle-column-form', name: 'toggle-column-form',
|
||||||
method: :post, remote: true do %>
|
method: :post, remote: true do %>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width:100%"></td>
|
<td style="width:100%"></td>
|
||||||
<td>
|
<td>
|
||||||
<%= select_tag 'id', nutrient_column_options %>
|
<%= select_tag 'id', toggle_column_options %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= submit_tag l(:button_add) %>
|
<%= submit_tag l(:button_add) %>
|
||||||
@ -27,7 +27,7 @@
|
|||||||
<% @quantities.each do |q| %>
|
<% @quantities.each do |q| %>
|
||||||
<td class="action" style="width:<%= 100/total_width %>%">
|
<td class="action" style="width:<%= 100/total_width %>%">
|
||||||
<%= link_to l(:button_hide),
|
<%= link_to l(:button_hide),
|
||||||
toggle_nutrient_column_project_ingredients_path(@project, id: q.id),
|
toggle_column_project_ingredients_path(@project, quantity_id: q.id),
|
||||||
{class: "icon icon-close", method: :post, remote: true} %>
|
{class: "icon icon-close", method: :post, remote: true} %>
|
||||||
</td>
|
</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
<fieldset id="options" class="collapsible">
|
<fieldset id="options" class="collapsible">
|
||||||
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
|
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
|
||||||
<div>
|
<div>
|
||||||
<%= form_tag toggle_quantity_project_measurements_path(@project),
|
<%= form_tag toggle_column_measurement_path(@measurement),
|
||||||
id: 'quantity-toggle-form', name: 'quantity-toggle-form',
|
id: 'toggle-column-form', name: 'toggle-column-form',
|
||||||
method: :post, remote: true do %>
|
method: :post, remote: true do %>
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width:100%"></td>
|
<td style="width:100%"></td>
|
||||||
<td>
|
<td>
|
||||||
<%= select_tag 'id', quantity_toggle_options %>
|
<%= select_tag 'id', toggle_column_options %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= submit_tag l(:button_add) %>
|
<%= submit_tag l(:button_add) %>
|
||||||
@ -27,7 +27,7 @@
|
|||||||
<% @quantities.each do |q| %>
|
<% @quantities.each do |q| %>
|
||||||
<td class="action" style="width:<%= 100/total_width %>%">
|
<td class="action" style="width:<%= 100/total_width %>%">
|
||||||
<%= link_to l(:button_hide),
|
<%= link_to l(:button_hide),
|
||||||
toggle_quantity_project_measurements_path(@project, id: q.id),
|
toggle_column_measurement_path(@measurement, quantity_id: q.id),
|
||||||
{class: "icon icon-close", method: :post, remote: true} %>
|
{class: "icon icon-close", method: :post, remote: true} %>
|
||||||
</td>
|
</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -13,5 +13,4 @@
|
|||||||
<p><%= f.text_field :description, style: "width: 100%;" %></p>
|
<p><%= f.text_field :description, style: "width: 100%;" %></p>
|
||||||
<p><%= f.text_field :formula, placeholder: t('.formula_placeholder'),
|
<p><%= f.text_field :formula, placeholder: t('.formula_placeholder'),
|
||||||
style: "width: 100%;" %></p>
|
style: "width: 100%;" %></p>
|
||||||
<p><%= f.check_box :primary %></p>
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -19,18 +19,9 @@
|
|||||||
next if q.new_record?
|
next if q.new_record?
|
||||||
quantity_class = "quantity"
|
quantity_class = "quantity"
|
||||||
quantity_class += " project idnt idnt-#{level+1}"
|
quantity_class += " project idnt idnt-#{level+1}"
|
||||||
quantity_class += " primary" if q.primary
|
|
||||||
%>
|
%>
|
||||||
<tr id="quantity-<%= q.id %>" class="<%= quantity_class %>">
|
<tr id="quantity-<%= q.id %>" class="<%= quantity_class %>">
|
||||||
<td class="name">
|
<td class="name"><%= q.name %></td>
|
||||||
<%= link_to '', toggle_quantity_path(q), {
|
|
||||||
remote: true,
|
|
||||||
method: :post,
|
|
||||||
class: "icon #{q.primary ? "icon-fav" : "icon-fav-off"}"
|
|
||||||
}
|
|
||||||
%>
|
|
||||||
<%= q.name %>
|
|
||||||
</td>
|
|
||||||
<td class="order">
|
<td class="order">
|
||||||
<% [:up, :down, :left, :right].each do |direction| %>
|
<% [:up, :down, :left, :right].each do |direction| %>
|
||||||
<%=
|
<%=
|
||||||
|
@ -13,9 +13,7 @@ en:
|
|||||||
field_domain: 'Domain'
|
field_domain: 'Domain'
|
||||||
field_parent_quantity: 'Parent'
|
field_parent_quantity: 'Parent'
|
||||||
field_formula: 'Formula'
|
field_formula: 'Formula'
|
||||||
field_primary: 'Primary'
|
|
||||||
field_shortname: 'Short name'
|
field_shortname: 'Short name'
|
||||||
button_primary: 'Primary'
|
|
||||||
button_retake: 'Retake'
|
button_retake: 'Retake'
|
||||||
activerecord:
|
activerecord:
|
||||||
errors:
|
errors:
|
||||||
|
@ -9,9 +9,7 @@ resources :projects, shallow: true do
|
|||||||
member do
|
member do
|
||||||
get 'retake'
|
get 'retake'
|
||||||
get 'readouts'
|
get 'readouts'
|
||||||
end
|
post 'toggle_column'
|
||||||
collection do
|
|
||||||
post 'toggle_quantity'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :ingredients, only: [:index, :create, :destroy] do
|
resources :ingredients, only: [:index, :create, :destroy] do
|
||||||
@ -20,14 +18,13 @@ resources :projects, shallow: true do
|
|||||||
get 'nutrients'
|
get 'nutrients'
|
||||||
get 'filter'
|
get 'filter'
|
||||||
get 'filter_nutrients'
|
get 'filter_nutrients'
|
||||||
post 'toggle_nutrient_column'
|
|
||||||
post 'import'
|
post 'import'
|
||||||
|
post 'toggle_column'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :sources, only: [:index, :create, :destroy]
|
resources :sources, only: [:index, :create, :destroy]
|
||||||
resources :quantities, only: [:index, :create, :edit, :update, :destroy] do
|
resources :quantities, only: [:index, :create, :edit, :update, :destroy] do
|
||||||
member do
|
member do
|
||||||
post 'toggle'
|
|
||||||
post 'move/:direction', to: 'quantities#move', as: :move
|
post 'move/:direction', to: 'quantities#move', as: :move
|
||||||
end
|
end
|
||||||
collection do
|
collection do
|
||||||
|
@ -13,7 +13,6 @@ class CreateSchema < ActiveRecord::Migration
|
|||||||
t.string :name
|
t.string :name
|
||||||
t.string :formula
|
t.string :formula
|
||||||
t.string :description
|
t.string :description
|
||||||
t.boolean :primary
|
|
||||||
# fields for awesome_nested_set
|
# fields for awesome_nested_set
|
||||||
t.references :parent
|
t.references :parent
|
||||||
t.integer :lft, null: false, index: true
|
t.integer :lft, null: false, index: true
|
||||||
|
@ -12,13 +12,13 @@ class LoadDefaults < ActiveRecord::Migration
|
|||||||
# https://www.fsai.ie/uploadedFiles/Consol_Reg1169_2011.pdf
|
# https://www.fsai.ie/uploadedFiles/Consol_Reg1169_2011.pdf
|
||||||
# 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", primary: true
|
description: "Total energy"
|
||||||
|
|
||||||
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", primary: true
|
description: "Total amount of proteins"
|
||||||
|
|
||||||
f1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Fats",
|
f1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Fats",
|
||||||
description: "Total lipids, including phospholipids", primary: true
|
description: "Total lipids, including phospholipids"
|
||||||
f2 = Quantity.create project: nil, domain: :diet, parent: f1, name: "Fatty acids",
|
f2 = Quantity.create project: nil, domain: :diet, parent: f1, name: "Fatty acids",
|
||||||
description: ""
|
description: ""
|
||||||
f3 = Quantity.create project: nil, domain: :diet, parent: f2, name: "Saturated",
|
f3 = Quantity.create project: nil, domain: :diet, parent: f2, name: "Saturated",
|
||||||
@ -45,7 +45,7 @@ class LoadDefaults < ActiveRecord::Migration
|
|||||||
description: "Docosahexaenoic acid"
|
description: "Docosahexaenoic acid"
|
||||||
|
|
||||||
c1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Carbohydrates",
|
c1 = Quantity.create project: nil, domain: :diet, parent: nil, name: "Carbohydrates",
|
||||||
description: "Total amount of carbohydrates", primary: true
|
description: "Total amount of carbohydrates"
|
||||||
c2 = Quantity.create project: nil, domain: :diet, parent: c1, name: "Digestible",
|
c2 = Quantity.create project: nil, domain: :diet, parent: c1, name: "Digestible",
|
||||||
description: ""
|
description: ""
|
||||||
c3 = Quantity.create project: nil, domain: :diet, parent: c2, name: "Sugars",
|
c3 = Quantity.create project: nil, domain: :diet, parent: c2, name: "Sugars",
|
||||||
@ -137,7 +137,7 @@ class LoadDefaults < ActiveRecord::Migration
|
|||||||
|
|
||||||
# Calculated quantities go at the and to make sure dependencies exist
|
# Calculated quantities go at the and to make sure dependencies exist
|
||||||
e2 = Quantity.create project: nil, domain: :diet, parent: e1, name: "Calculated",
|
e2 = Quantity.create project: nil, domain: :diet, parent: e1, name: "Calculated",
|
||||||
description: "Total energy calculated from macronutrients", primary: true,
|
description: "Total energy calculated from macronutrients",
|
||||||
formula: "4*Proteins + 9*Fats + 4*Carbohydrates"
|
formula: "4*Proteins + 9*Fats + 4*Carbohydrates"
|
||||||
|
|
||||||
Source.create project: nil, name: "nutrition label",
|
Source.create project: nil, name: "nutrition label",
|
||||||
|
6
init.rb
6
init.rb
@ -24,10 +24,10 @@ Redmine::Plugin.register :body_tracking do
|
|||||||
}, read: true
|
}, read: true
|
||||||
permission :manage_common, {
|
permission :manage_common, {
|
||||||
body_trackers: [:defaults],
|
body_trackers: [:defaults],
|
||||||
measurements: [:new, :create, :edit, :update, :destroy, :retake, :toggle_quantity],
|
measurements: [:new, :create, :edit, :update, :destroy, :retake, :toggle_column],
|
||||||
ingredients: [:create, :destroy, :toggle, :import, :toggle_nutrient_column],
|
ingredients: [:create, :destroy, :toggle, :import, :toggle_column],
|
||||||
sources: [:create, :destroy],
|
sources: [:create, :destroy],
|
||||||
quantities: [:create, :edit, :update, :destroy, :toggle, :move],
|
quantities: [:create, :edit, :update, :destroy, :move],
|
||||||
units: [:create, :destroy],
|
units: [:create, :destroy],
|
||||||
}, require: :loggedin
|
}, require: :loggedin
|
||||||
end
|
end
|
||||||
|
@ -3,14 +3,16 @@ module BodyTracking
|
|||||||
ApplicationController.class_eval do
|
ApplicationController.class_eval do
|
||||||
private
|
private
|
||||||
|
|
||||||
# :find_* methods are called before :authorize,
|
def find_quantity(id = params[:id])
|
||||||
# @project is required for :authorize to succeed
|
@quantity = Quantity.find(id)
|
||||||
def find_quantity
|
|
||||||
@quantity = Quantity.find(params[:id])
|
|
||||||
@project = @quantity.project
|
@project = @quantity.project
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_quantity_by_quantity_id
|
||||||
|
find_quantity(params[:quantity_id])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,8 +5,13 @@ module BodyTracking
|
|||||||
has_many :ingredients, -> { order "name" }, dependent: :destroy
|
has_many :ingredients, -> { order "name" }, dependent: :destroy
|
||||||
|
|
||||||
has_many :sources, dependent: :destroy
|
has_many :sources, dependent: :destroy
|
||||||
|
has_many :column_views, dependent: :destroy
|
||||||
has_many :quantities, -> { order "lft" }, dependent: :destroy
|
has_many :quantities, -> { order "lft" }, dependent: :destroy
|
||||||
has_many :units, dependent: :destroy
|
has_many :units, dependent: :destroy
|
||||||
|
|
||||||
|
def nutrients_column_view
|
||||||
|
self.column_views.find_or_create_by(name: 'Nutrients', domain: :diet)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user