Cashflow should use default period (and related) (#328)

* Fix cashflow and outflows widgets to respect user's default period preference

Resolves issue #118 where the Cashflow and Outflows widgets on the dashboard
were hardcoded to use a 30-day period instead of respecting the user's default
period preference setting.

Changes:
- Updated @cashflow_period to use Current.user&.default_period as fallback
- Updated @outflows_period to use Current.user&.default_period as fallback
- Both now follow the same pattern as the Periodable concern's set_period method

This ensures consistency across all dashboard widgets - Net Worth, Cashflow,
and Outflows now all respect the user's preference.

* Synchronize period selection across all dashboard widgets

All three dashboard widgets (Net Worth, Cashflow, and Outflows) now use
a single shared period parameter, ensuring consistent data magnitudes
across the dashboard.

Changes:
- Simplified controller to use single @period for all three widgets
- Removed widget-specific period parameters (cashflow_period, outflows_period)
- All widgets now use the shared 'period' parameter
- All period dropdowns use turbo_frame: "_top" to reload entire page
- Removed turbo_frame_tags from dashboard view for cleaner implementation

User experience improvement:
- Changing the period in any widget now updates all three widgets
- Ensures data consistency and easier comparison across widgets
- Maintains respect for user's default period preference

* Make Net Worth widget title styling consistent with Cashflow and Outflows

Changed Net Worth title from <p> with text-sm/text-secondary to <h2> with
text-lg to match the consistent styling used by Cashflow and Outflows widgets.

This provides a more unified visual appearance across all dashboard widgets.

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Juan José Mata
2025-11-14 19:15:30 +01:00
committed by GitHub
parent 54656c943a
commit 3c8ba643a0
5 changed files with 23 additions and 53 deletions

View File

@@ -7,40 +7,14 @@ class PagesController < ApplicationController
@balance_sheet = Current.family.balance_sheet
@accounts = Current.family.accounts.visible.with_attached_logo
# Handle cashflow period
cashflow_period_param = params[:cashflow_period]
@cashflow_period = if cashflow_period_param.present?
begin
Period.from_key(cashflow_period_param)
rescue Period::InvalidKeyError
Period.last_30_days
end
else
Period.last_30_days
end
# Handle outflows period
outflows_period_param = params[:outflows_period]
@outflows_period = if outflows_period_param.present?
begin
Period.from_key(outflows_period_param)
rescue Period::InvalidKeyError
Period.last_30_days
end
else
Period.last_30_days
end
family_currency = Current.family.currency
# Get data for cashflow section
income_totals = Current.family.income_statement.income_totals(period: @cashflow_period)
cashflow_expense_totals = Current.family.income_statement.expense_totals(period: @cashflow_period)
@cashflow_sankey_data = build_cashflow_sankey_data(income_totals, cashflow_expense_totals, family_currency)
# Use the same period for all widgets (set by Periodable concern)
income_totals = Current.family.income_statement.income_totals(period: @period)
expense_totals = Current.family.income_statement.expense_totals(period: @period)
# Get data for outflows section (using its own period)
outflows_expense_totals = Current.family.income_statement.expense_totals(period: @outflows_period)
@outflows_data = build_outflows_donut_data(outflows_expense_totals)
@cashflow_sankey_data = build_cashflow_sankey_data(income_totals, expense_totals, family_currency)
@outflows_data = build_outflows_donut_data(expense_totals)
@breadcrumbs = [ [ "Home", root_path ], [ "Dashboard", nil ] ]
end

View File

@@ -29,24 +29,20 @@
<div class="w-full space-y-6 pb-24">
<% if Current.family.accounts.any? %>
<%= turbo_frame_tag "cashflow_sankey_section" do %>
<section class="bg-container py-4 rounded-xl shadow-border-xs mb-6">
<%= render partial: "pages/dashboard/cashflow_sankey", locals: {
sankey_data: @cashflow_sankey_data,
period: @cashflow_period
} %>
</section>
<% end %>
<section class="bg-container py-4 rounded-xl shadow-border-xs mb-6">
<%= render partial: "pages/dashboard/cashflow_sankey", locals: {
sankey_data: @cashflow_sankey_data,
period: @period
} %>
</section>
<% if @outflows_data[:categories].present? %>
<%= turbo_frame_tag "outflows_donut_section" do %>
<section class="bg-container py-4 rounded-xl shadow-border-xs mb-6">
<%= render partial: "pages/dashboard/outflows_donut", locals: {
outflows_data: @outflows_data,
period: @outflows_period
} %>
</section>
<% end %>
<section class="bg-container py-4 rounded-xl shadow-border-xs mb-6">
<%= render partial: "pages/dashboard/outflows_donut", locals: {
outflows_data: @outflows_data,
period: @period
} %>
</section>
<% end %>
<section class="bg-container py-4 rounded-xl shadow-border-xs">

View File

@@ -5,8 +5,8 @@
<%= t("pages.dashboard.cashflow_sankey.title") %>
</h2>
<%= form_with url: root_path, method: :get, data: { controller: "auto-submit-form", turbo_frame: "cashflow_sankey_section" } do |form| %>
<%= form.select :cashflow_period,
<%= form_with url: root_path, method: :get, data: { controller: "auto-submit-form", turbo_frame: "_top" } do |form| %>
<%= form.select :period,
Period.as_options,
{ selected: period.key },
data: { "auto-submit-form-target": "auto" },

View File

@@ -6,7 +6,7 @@
<div class="space-y-2">
<div class="space-y-2">
<div class="flex items-center gap-2">
<p class="text-sm text-secondary font-medium"><%= t(".title") %></p>
<h2 class="text-lg font-medium"><%= t(".title") %></h2>
</div>
<p class="text-primary -space-x-0.5 text-3xl font-medium <%= "animate-pulse" if balance_sheet.syncing? %>">
@@ -21,7 +21,7 @@
</div>
</div>
<%= form_with url: root_path, method: :get, data: { controller: "auto-submit-form" } do |form| %>
<%= form_with url: root_path, method: :get, data: { controller: "auto-submit-form", turbo_frame: "_top" } do |form| %>
<%= form.select :period,
Period.as_options,
{ selected: period.key },

View File

@@ -5,8 +5,8 @@
<%= t("pages.dashboard.outflows_donut.title") %>
</h2>
<%= form_with url: root_path, method: :get, data: { controller: "auto-submit-form", turbo_frame: "outflows_donut_section" } do |form| %>
<%= form.select :outflows_period,
<%= form_with url: root_path, method: :get, data: { controller: "auto-submit-form", turbo_frame: "_top" } do |form| %>
<%= form.select :period,
Period.as_options,
{ selected: period.key },
data: { "auto-submit-form-target": "auto" },