mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-10 16:05:22 +02:00
Default to last 30 days on transactions page if no filters
This commit is contained in:
parent
f8bb58151b
commit
b7cc49b7bf
2 changed files with 17 additions and 8 deletions
|
@ -53,6 +53,10 @@ class TransactionsController < ApplicationController
|
|||
end
|
||||
|
||||
updated_params["q"] = q_params.presence
|
||||
|
||||
# Add flag to indicate filters were explicitly cleared
|
||||
updated_params["filter_cleared"] = "1" if updated_params["q"].blank?
|
||||
|
||||
Current.session.update!(prev_transaction_page_params: updated_params)
|
||||
|
||||
redirect_to transactions_path(updated_params)
|
||||
|
@ -155,6 +159,11 @@ class TransactionsController < ApplicationController
|
|||
|
||||
cleaned_params.delete(:amount_operator) unless cleaned_params[:amount].present?
|
||||
|
||||
# Only add default start_date if params are blank AND filters weren't explicitly cleared
|
||||
if cleaned_params.blank? && params[:filter_cleared].blank?
|
||||
cleaned_params[:start_date] = 30.days.ago.to_date
|
||||
end
|
||||
|
||||
cleaned_params
|
||||
end
|
||||
|
||||
|
|
|
@ -70,17 +70,17 @@ class Transaction::Search
|
|||
end
|
||||
end
|
||||
|
||||
def cache_key_base
|
||||
[
|
||||
family.id,
|
||||
Digest::SHA256.hexdigest(attributes.sort.to_h.to_json), # cached by filters
|
||||
family.entries_cache_version
|
||||
].join("/")
|
||||
end
|
||||
|
||||
private
|
||||
Totals = Data.define(:count, :income_money, :expense_money)
|
||||
|
||||
def cache_key_base
|
||||
[
|
||||
family.id,
|
||||
Digest::SHA256.hexdigest(attributes.sort.to_h.to_json), # cached by filters
|
||||
family.entries_cache_version
|
||||
].join("/")
|
||||
end
|
||||
|
||||
def apply_active_accounts_filter(query, active_accounts_only_filter)
|
||||
if active_accounts_only_filter
|
||||
query.where(accounts: { is_active: true })
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue