From ec9fde599099e17542e674ce585dac02faeeaab4 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 19 Jul 2025 17:25:57 -0700 Subject: [PATCH] sort and tag filtering working on content#index pages again --- app/controllers/content_controller.rb | 11 ++- .../display/_tailwind_foldered_index.html.erb | 86 ++++++++++++------- app/views/content/gallery.html.erb | 2 +- 3 files changed, 65 insertions(+), 34 deletions(-) diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index fbcb461c..5b6bec89 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -54,7 +54,16 @@ class ContentController < ApplicationController @content.select!(&:favorite?) end - @content = @content.sort_by {|x| [x.favorite? ? 0 : 1, x.name] } + # Sort content with favorites always first, then by selected sort option + sort_option = params[:sort] || 'updated_at' + @content = case sort_option + when 'alphabetical' + @content.sort_by { |x| [x.favorite? ? 0 : 1, x.name.downcase] } + when 'created_at' + @content.sort_by { |x| [x.favorite? ? 0 : 1, x.created_at] }.reverse + else # 'updated_at' or default + @content.sort_by { |x| [x.favorite? ? 0 : 1, x.updated_at] }.reverse + end @folders = current_user .folders .where(context: @content_type_name, parent_folder_id: nil) diff --git a/app/views/content/display/_tailwind_foldered_index.html.erb b/app/views/content/display/_tailwind_foldered_index.html.erb index e77d7bb3..7e04d7b7 100644 --- a/app/views/content/display/_tailwind_foldered_index.html.erb +++ b/app/views/content/display/_tailwind_foldered_index.html.erb @@ -451,33 +451,47 @@
- Recently edited - Alphabetical - Favorites first - Date created + <%= link_to url_for(params.permit(:slug, :favorite_only).merge({ sort: 'updated_at' })), class: "block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 #{'bg-gray-100 font-medium' if params[:sort] == 'updated_at' || params[:sort].blank?}" do %> + Recently edited + <% end %> + <%= link_to url_for(params.permit(:slug, :favorite_only).merge({ sort: 'alphabetical' })), class: "block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 #{'bg-gray-100 font-medium' if params[:sort] == 'alphabetical'}" do %> + Alphabetical + <% end %> + <%= link_to url_for(params.permit(:slug, :favorite_only).merge({ sort: 'created_at' })), class: "block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 #{'bg-gray-100 font-medium' if params[:sort] == 'created_at'}" do %> + Date created + <% end %>
- <% if defined?(page_tags) && page_tags.any? %> + <% if true # Always show tag filter so users can start tagging %>
<%= form_with url: "", method: :get, local: true, class: "contents" do |form| %> + <%= hidden_field_tag :sort, params[:sort] if params[:sort].present? %> +
+ <% else %> +
+ label_outline +

No tags yet

+

Add tags to your <%= @content_type_name.downcase.pluralize %> to filter by them

<% end %> -
- -
@@ -532,13 +554,13 @@ - <% if defined?(filtered_page_tags) && filtered_page_tags.any? %> + <% if @filtered_page_tags && @filtered_page_tags.any? %>
Filtered by: - <% filtered_page_tags.each do |page_tag| %> + <% @filtered_page_tags.each do |page_tag| %> <%= page_tag.tag %> - <%= link_to(polymorphic_path(content_type_class, { slug: params.fetch(:slug, []) - [page_tag.slug] })) do %> + <%= link_to(polymorphic_path(content_type_class, params.permit(:sort, :favorite_only).merge({ slug: params.fetch(:slug, []) - [page_tag.slug] }))) do %> diff --git a/app/views/content/gallery.html.erb b/app/views/content/gallery.html.erb index f626463e..cb64415a 100644 --- a/app/views/content/gallery.html.erb +++ b/app/views/content/gallery.html.erb @@ -211,7 +211,7 @@ <% if @content.updatable_by?(current_user) %>

Upload more images

- <%= form_tag upload_image_path(content_type: @content.class.name, content_id: @content.id), + <%= form_tag polymorphic_path(@content), method: :patch, multipart: true, class: "flex items-center space-x-2" do %> <%= file_field_tag 'image_uploads[]', multiple: true, accept: 'image/*', class: "border border-gray-300 rounded-md py-2 px-3 text-sm" %>