mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-09 15:35:22 +02:00
Add sorting by name and date,
This commit is contained in:
parent
cf1b4d3056
commit
eb6e73b5ab
2 changed files with 33 additions and 6 deletions
|
@ -4,7 +4,14 @@ class RulesController < ApplicationController
|
|||
before_action :set_rule, only: [ :edit, :update, :destroy, :apply, :confirm ]
|
||||
|
||||
def index
|
||||
@rules = Current.family.rules.order(created_at: :desc)
|
||||
@sort_by = params[:sort_by] || "name"
|
||||
@direction = params[:direction] || "asc"
|
||||
|
||||
allowed_columns = [ "name", "created_at" ]
|
||||
@sort_by = "name" unless allowed_columns.include?(@sort_by)
|
||||
@direction = "asc" unless [ "asc", "desc" ].include?(@direction)
|
||||
|
||||
@rules = Current.family.rules.order(@sort_by => @direction)
|
||||
render layout: "settings"
|
||||
end
|
||||
|
||||
|
|
|
@ -33,11 +33,31 @@
|
|||
<div class="bg-container shadow-border-xs rounded-xl p-4">
|
||||
|
||||
<% if @rules.any? %>
|
||||
<div class="rounded-xl bg-gray-25 space-y-1">
|
||||
<div class="flex items-center gap-1.5 px-4 py-2 text-xs font-medium text-secondary uppercase">
|
||||
<p>Rules</p>
|
||||
<span class="text-subdued">·</span>
|
||||
<p><%= @rules.count %></p>
|
||||
<div class="rounded-xl bg-gray-25">
|
||||
<div class="flex items-center justify-between px-4 py-2">
|
||||
<div class="flex items-center gap-1.5 text-xs font-medium text-secondary uppercase">
|
||||
<p>Rules</p>
|
||||
<span class="text-subdued">·</span>
|
||||
<p><%= @rules.count %></p>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-1 text-xs uppercase">
|
||||
<span class="text-secondary">Sort by:</span>
|
||||
<div class="flex items-center">
|
||||
<%= link_to "Name", rules_path(sort_by: "name", direction: (@sort_by == "name" && @direction == "asc") ? "desc" : "asc"),
|
||||
class: "px-2 py-1 rounded #{@sort_by == 'name' ? 'bg-accent-light text-accent font-medium' : 'hover:bg-gray-100'}" %>
|
||||
<% if @sort_by == "name" %>
|
||||
<%= lucide_icon(@direction == "asc" ? "arrow-up" : "arrow-down", class: "w-3 h-3 text-accent") %>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="flex items-center">
|
||||
<%= link_to "Date", rules_path(sort_by: "created_at", direction: (@sort_by == "created_at" && @direction == "asc") ? "desc" : "asc"),
|
||||
class: "px-2 py-1 rounded #{@sort_by == 'created_at' ? 'bg-accent-light text-accent font-medium' : 'hover:bg-gray-100'}" %>
|
||||
<% if @sort_by == "created_at" %>
|
||||
<%= lucide_icon(@direction == "asc" ? "arrow-up" : "arrow-down", class: "w-3 h-3 text-accent") %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-1 p-1">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue