Skip to content

Commit

Permalink
add sort options and filter (closes #471 #472)
Browse files Browse the repository at this point in the history
  • Loading branch information
doerfli committed Jun 13, 2024
1 parent 7dd6bc6 commit 91a3a1b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/controllers/recipes_controller.rb
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions app/views/recipes/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,15 @@
<div class="recipes" data-search-target="list">
<%= render partial: 'list' %>
</div>
<div class="pb-4">
<a href="/"><%= t('recipes.show.alphabetically')%></a> |
<a href="/?latest_first=true"><%= t('recipes.show.bydate') %></a> |
<a href="/?rating=5"><i class="fa-solid fa-5"></i>&nbsp;<i class="fa-solid fa-star"></i></i></a> |
<a href="/?rating=4"><i class="fa-solid fa-4"></i>&nbsp;<i class="fa-solid fa-star"></i></i></a> |
<a href="/?rating=3"><i class="fa-solid fa-3"></i>&nbsp;<i class="fa-solid fa-star"></i></i></a> |
<a href="/?rating=2"><i class="fa-solid fa-2"></i>&nbsp;<i class="fa-solid fa-star"></i></i></a> |
<a href="/?rating=1"><i class="fa-solid fa-1"></i>&nbsp;<i class="fa-solid fa-star"></i></i></a> |
<a href="/?rating_null=true"><i class="fa-solid fa-0"></i>&nbsp;<i class="fa-regular fa-star"></i></i></a>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 91a3a1b

Please sign in to comment.