diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index 68f2aea..86b1631 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -7,8 +7,6 @@ class RecipesController < ApplicationController # GET /recipes def index @criteria = ViewModels::RecipeCriteria.new(criteria_params) - @criteria.page = params[:page] - @criteria.per = params[:per] @recipes = Recipe.for_criteria(@criteria).includes(:tags) end diff --git a/app/javascript/components/TheRecipeList.vue b/app/javascript/components/TheRecipeList.vue index 3f1b2ef..e38c544 100644 --- a/app/javascript/components/TheRecipeList.vue +++ b/app/javascript/components/TheRecipeList.vue @@ -6,7 +6,7 @@ - +
- + @@ -213,4 +221,10 @@ } } - \ No newline at end of file + + + \ No newline at end of file diff --git a/app/models/recipe.rb b/app/models/recipe.rb index 2c83260..b93bb5f 100644 --- a/app/models/recipe.rb +++ b/app/models/recipe.rb @@ -4,7 +4,7 @@ class Recipe < ApplicationRecord has_many :recipe_ingredients, -> { order :sort_order }, inverse_of: :recipe, dependent: :destroy belongs_to :user - has_and_belongs_to_many :tags + has_and_belongs_to_many :tags, autosave: true scope :undeleted, -> { where('deleted <> ? OR deleted IS NULL', true) } scope :not_log, -> { where('is_log <> ? OR is_log IS NULL', true) } @@ -18,11 +18,23 @@ class Recipe < ApplicationRecord attr_accessor :converted_scale, :converted_system, :converted_unit + def cache_key + [ + 'recipes', + self.id.to_s, + self.updated_at.to_i.to_s, + converted_scale || '-', + converted_system || '-', + converted_unit || '-' + ].join('/') + end + def scale(factor, auto_unit = false) self.converted_scale = factor recipe_ingredients.each do |ri| ri.scale(factor, auto_unit) end + self end def convert_to_metric @@ -30,6 +42,7 @@ class Recipe < ApplicationRecord recipe_ingredients.each do |ri| ri.to_metric end + self end def convert_to_standard @@ -37,6 +50,7 @@ class Recipe < ApplicationRecord recipe_ingredients.each do |ri| ri.to_standard end + self end def convert_to_mass @@ -44,6 +58,7 @@ class Recipe < ApplicationRecord recipe_ingredients.each do |ri| ri.to_mass end + self end def convert_to_volume @@ -51,6 +66,7 @@ class Recipe < ApplicationRecord recipe_ingredients.each do |ri| ri.to_volume end + self end def tag_names @@ -107,7 +123,7 @@ class Recipe < ApplicationRecord end def self.for_criteria(criteria) - query = active.order(criteria.sort_column => criteria.sort_direction).page(criteria.page).per(criteria.per) + query = active.order(criteria.sort_column => criteria.sort_direction) if criteria.name.present? query = query.matches_tokens(:name, criteria.name.split(' ')) @@ -118,7 +134,9 @@ class Recipe < ApplicationRecord query = query.where(id: tags.joins(:recipes).pluck('recipes.id')) end - query + puts criteria.inspect + + query.page(criteria.page).per(criteria.per) end private diff --git a/app/models/view_models/recipe_criteria.rb b/app/models/view_models/recipe_criteria.rb index e1fa8f6..53f6d2c 100644 --- a/app/models/view_models/recipe_criteria.rb +++ b/app/models/view_models/recipe_criteria.rb @@ -14,6 +14,8 @@ module ViewModels self.send(setter, params[attr]) end end + + puts self.inspect end def sort_column diff --git a/public/manifest.json b/public/manifest.json index f9729af..ae35fa9 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -4,5 +4,6 @@ "start_url": ".", "display": "standalone", "background_color": "#4a4a4a", - "description": "A recipe manager." + "description": "A recipe manager.", + "theme_color": "rgb(121, 167, 54)" } \ No newline at end of file
@@ -49,18 +49,26 @@ -- {{ r.yields }}{{ formatRecipeTime(r.total_time, r.active_time) }}{{ formatRecipeTime(r.total_time, r.active_time) }} - - - - - - - +
+
+ + + +
+
+ + + +
+
+ +
+