Added MealsController#new and form autocomplete for Food
Renamed QuantityColumn -> Exposure
This commit is contained in:
@@ -9,7 +9,7 @@ class FoodsController < ApplicationController
|
||||
|
||||
before_action :init_session_filters
|
||||
before_action :find_project_by_project_id,
|
||||
only: [:index, :new, :create, :nutrients, :filter, :import]
|
||||
only: [:index, :new, :create, :nutrients, :filter, :autocomplete, :import]
|
||||
before_action :find_quantity_by_quantity_id, only: [:toggle_column]
|
||||
before_action :find_food, only: [:edit, :update, :destroy, :toggle]
|
||||
before_action :authorize
|
||||
@@ -63,7 +63,7 @@ class FoodsController < ApplicationController
|
||||
end
|
||||
|
||||
def toggle_column
|
||||
@project.nutrient_columns.toggle!(@quantity)
|
||||
@project.nutrient_exposures.toggle!(@quantity)
|
||||
prepare_nutrients
|
||||
end
|
||||
|
||||
@@ -73,6 +73,10 @@ class FoodsController < ApplicationController
|
||||
render :index
|
||||
end
|
||||
|
||||
def autocomplete
|
||||
@foods = @project.foods.where("name LIKE ?", "%#{params[:term]}%")
|
||||
end
|
||||
|
||||
def import
|
||||
warnings = []
|
||||
|
||||
|
||||
@@ -13,6 +13,17 @@ class MealsController < ApplicationController
|
||||
prepare_meals
|
||||
end
|
||||
|
||||
def new
|
||||
@meal = @project.meals.new
|
||||
@meal.ingredients.new
|
||||
end
|
||||
|
||||
def create
|
||||
end
|
||||
|
||||
def destroy
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def prepare_meals
|
||||
|
||||
@@ -33,7 +33,7 @@ class MeasurementsController < ApplicationController
|
||||
@measurement.routine.project = @project
|
||||
@routine = @measurement.routine
|
||||
if @measurement.save
|
||||
if @routine.columns.empty?
|
||||
if @routine.exposures.empty?
|
||||
@routine.quantities << @measurement.readouts.map(&:quantity).first(6)
|
||||
end
|
||||
|
||||
@@ -83,7 +83,7 @@ class MeasurementsController < ApplicationController
|
||||
end
|
||||
|
||||
def toggle_column
|
||||
@routine.columns.toggle!(@quantity)
|
||||
@routine.exposures.toggle!(@quantity)
|
||||
prepare_readouts
|
||||
end
|
||||
|
||||
|
||||
@@ -122,6 +122,6 @@ class QuantitiesController < ApplicationController
|
||||
|
||||
def prepare_quantities
|
||||
@quantities = @project.quantities.filter(@project, session[:q_filters])
|
||||
.includes(:columns, :formula, :parent)
|
||||
.includes(:exposures, :formula, :parent)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user