From 91a3a1b0248869a843e2ae53d53ee558def89065 Mon Sep 17 00:00:00 2001 From: Marc Doerflinger Date: Thu, 13 Jun 2024 14:40:27 +0000 Subject: [PATCH] add sort options and filter (closes #471 #472) --- app/controllers/recipes_controller.rb | 11 +++++++---- app/views/recipes/index.html.erb | 10 ++++++++++ config/locales/de.yml | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb index 5414d931..4f6ab486 100644 --- a/app/controllers/recipes_controller.rb +++ b/app/controllers/recipes_controller.rb @@ -1,15 +1,19 @@ class RecipesController < ApplicationController include Secured - + def index @recipes = Recipe if params[:latest_first] @recipes = @recipes.order(created_at: :desc) - else + elsif params[:rating] + @recipes = @recipes.where(rating: params[:rating]).order(name: :asc) + elsif params[:rating_null] + @recipes = @recipes.where(rating: nil).order(name: :asc) + else @recipes = @recipes.order(favorite: :desc).order(name: :asc) end - + @recipes = @recipes.page params[:page] end @@ -20,7 +24,6 @@ def filter_by_tag def search logger.debug "Search recipe for #{params[:term]}" - # @recipes = Recipe.where(ilike(:name, "%#{params[:term]}")) if params[:term].nil? @recipes = Recipe.all.order_by_name else diff --git a/app/views/recipes/index.html.erb b/app/views/recipes/index.html.erb index 559b2397..031140dd 100644 --- a/app/views/recipes/index.html.erb +++ b/app/views/recipes/index.html.erb @@ -9,5 +9,15 @@
<%= render partial: 'list' %>
+
+ <%= t('recipes.show.alphabetically')%> | + <%= t('recipes.show.bydate') %> | +   | +   | +   | +   | +   | +   +
diff --git a/config/locales/de.yml b/config/locales/de.yml index 7bb6479c..858b2d5b 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -34,6 +34,8 @@ de: durationunit: 'Min' tags: 'Tags' source: 'Quelle' + alphabetically: 'Alphabetisch' + bydate: 'Neueste zuerst' delete: are_you_sure: 'Wollen Sie dieses Rezept wirklich löschen?' info: 'Zu löschende Bilder auswählen'