Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/controllers/community_news_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def index
base_scope = authorized_scope(CommunityNews.includes([ :bookmarks, :primary_asset,
:author, :organization, author: :person ]))
filtered = base_scope.search_by_params(params)
@sort = %w[created_at updated_at].include?(params[:sort]) ? params[:sort] : "updated_at"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default to a Desc 'Updated_at" sort

@sort_direction = params[:direction] == "asc" ? "asc" : "desc"
filtered = filtered.reorder(@sort => @sort_direction)
@community_news = filtered.paginate(page: params[:page], per_page: per_page).decorate
@count_display = filtered.count == base_scope.count ? base_scope.count : "#{filtered.count}/#{base_scope.count}"

Expand Down
30 changes: 28 additions & 2 deletions app/views/community_news/_community_news_results.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
<%= turbo_stream.replace("community_news_count", partial: "community_news_count") %>
<% if @community_news.any? %>
<%
sort_base = params.permit(:title, :query, :published, :number_of_items_per_page).to_h.symbolize_keys
sort_icon = ->(column) {
if @sort == column
@sort_direction == "asc" ? "fa-arrow-up" : "fa-arrow-down"
else
"fa-sort"
end
}
%>
<div class="overflow-x-auto bg-white border border-gray-200 rounded-xl shadow-sm animate-fade blur-on-submit">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-sm font-semibold text-gray-700">Title</th>
<th class="px-6 py-3 text-left text-sm font-semibold text-gray-700">Author</th>
<th class="px-6 py-3 text-left text-sm font-semibold text-gray-700">Organization</th>
<th class="px-6 py-3 text-center text-sm font-semibold text-gray-700">Updated</th>
<th class="px-6 py-3 text-center text-sm font-semibold text-gray-700 whitespace-nowrap min-w-[7rem]">
<%= link_to community_news_index_path(sort_base.merge(sort: "created_at", direction: (@sort == "created_at" && @sort_direction == "desc") ? "asc" : "desc", page: nil)),
data: { turbo_frame: "community_news_results" },
class: "inline-flex items-center justify-center gap-1 text-gray-700 hover:text-gray-900" do %>
Created At
<i class="fa-solid <%= sort_icon.call("created_at") %> text-xs opacity-70"></i>
<% end %>
</th>
<th class="px-6 py-3 text-center text-sm font-semibold text-gray-700 whitespace-nowrap min-w-[7rem]">
<%= link_to community_news_index_path(sort_base.merge(sort: "updated_at", direction: (@sort == "updated_at" && @sort_direction == "desc") ? "asc" : "desc", page: nil)),
data: { turbo_frame: "community_news_results" },
class: "inline-flex items-center justify-center gap-1 text-gray-700 hover:text-gray-900" do %>
Updated
<i class="fa-solid <%= sort_icon.call("updated_at") %> text-xs opacity-70"></i>
<% end %>
</th>
<th class="px-6 py-3 text-center text-sm font-semibold text-gray-700">Actions</th>
</tr>
</thead>
Expand Down Expand Up @@ -43,7 +68,8 @@

<td class="px-6 py-4 text-gray-600"><%= news.organization&.name || "—" %></td>

<td class="px-6 py-4 text-center text-sm text-gray-500"><%= news.updated_at.strftime("%b %d, %Y") %></td>
<td class="px-6 py-4 text-center text-sm text-gray-500 whitespace-nowrap"><%= news.created_at.strftime("%b %d, %Y") %></td>
<td class="px-6 py-4 text-center text-sm text-gray-500 whitespace-nowrap"><%= news.updated_at.strftime("%b %d, %Y") %></td>

<td class="px-6 py-4 text-right">
<div class="inline-flex gap-2">
Expand Down
9 changes: 9 additions & 0 deletions app/views/community_news/_results_skeleton.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<div class="h-4 w-16 mx-auto rounded bg-gray-200"></div>
</th>

<th class="px-6 py-3 text-center">
<div class="h-4 w-16 mx-auto rounded bg-gray-200"></div>
</th>

<th class="px-6 py-3 text-right">
<div class="h-4 w-20 ml-auto rounded bg-gray-200"></div>
</th>
Expand Down Expand Up @@ -55,6 +59,11 @@
<div class="h-4 w-52 rounded bg-gray-200"></div>
</td>

<!-- Created At -->
<td class="px-6 py-4 text-center">
<div class="h-4 w-20 mx-auto rounded bg-gray-200"></div>
</td>

<!-- Updated -->
<td class="px-6 py-4 text-center">
<div class="h-4 w-20 mx-auto rounded bg-gray-200"></div>
Expand Down