mirror of
https://github.com/we-promise/sure.git
synced 2026-04-10 07:44:48 +00:00
- Added pre-loading of series in AccountableSparklinesController and AccountsController to catch errors before rendering. - Updated the accounts view to use the pre-loaded sparkline series variable. - Adjusted the test for graceful handling of errors in the sparkline series method. This enhances the robustness of the sparkline feature and improves error visibility in the UI.
35 lines
1003 B
Ruby
35 lines
1003 B
Ruby
class AccountableSparklinesController < ApplicationController
|
|
def show
|
|
@accountable = Accountable.from_type(params[:accountable_type]&.classify)
|
|
|
|
# Pre-load the series to catch any errors before rendering
|
|
@series = Rails.cache.fetch(cache_key) do
|
|
account_ids = family.accounts.active.where(accountable_type: @accountable.name).pluck(:id)
|
|
|
|
builder = Balance::ChartSeriesBuilder.new(
|
|
account_ids: account_ids,
|
|
currency: family.currency,
|
|
period: Period.last_30_days,
|
|
favorable_direction: @accountable.favorable_direction,
|
|
interval: "1 day"
|
|
)
|
|
|
|
builder.balance_series
|
|
end
|
|
|
|
render layout: false
|
|
rescue => e
|
|
Rails.logger.error "Accountable sparkline error for #{@accountable&.name}: #{e.message}"
|
|
render partial: "accountable_sparklines/error", layout: false
|
|
end
|
|
|
|
private
|
|
def family
|
|
Current.family
|
|
end
|
|
|
|
def cache_key
|
|
family.build_cache_key("#{@accountable.name}_sparkline")
|
|
end
|
|
end
|