diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 59d8ec7c..cba97434 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -49,13 +49,12 @@ module ApplicationHelper end # Styles to use when displaying a change in value - def trend_styles(trend, mode: :asset) - puts mode == :liability ? "it is a liability" : "it is an asset" + def trend_styles(trend) bg_class, text_class, symbol, icon = case trend.direction when "up" - mode == :liability ? [ "bg-red-500/5", "text-red-500", "+", "arrow-up" ] : [ "bg-green-500/5", "text-green-500", "+", "arrow-up" ] + trend.type == :liability ? [ "bg-red-500/5", "text-red-500", "+", "arrow-up" ] : [ "bg-green-500/5", "text-green-500", "+", "arrow-up" ] when "down" - mode == :liability ? [ "bg-green-500/5", "text-green-500", "-", "arrow-down" ] : [ "bg-red-500/5", "text-red-500", "-", "arrow-down" ] + trend.type == :liability ? [ "bg-green-500/5", "text-green-500", "-", "arrow-down" ] : [ "bg-red-500/5", "text-red-500", "-", "arrow-down" ] when "flat" [ "bg-gray-500/5", "text-gray-500", "", "minus" ] else @@ -65,7 +64,7 @@ module ApplicationHelper { bg_class: bg_class, text_class: text_class, symbol: symbol, icon: icon } end - def trend_label(period) + def period_label(period) return "since account creation" if period.date_range.nil? start_date, end_date = period.date_range.first, period.date_range.last diff --git a/app/views/accounts/_account_valuation_list.html.erb b/app/views/accounts/_account_valuation_list.html.erb index 5efd509a..af4eca87 100644 --- a/app/views/accounts/_account_valuation_list.html.erb +++ b/app/views/accounts/_account_valuation_list.html.erb @@ -1,7 +1,7 @@ <%# locals: (valuation_series:, classification:) %> <% valuation_series.data.reverse_each.with_index do |valuation_item, index| %> <% valuation, trend = valuation_item.values_at(:raw, :trend) %> - <% valuation_styles = trend_styles(valuation_item[:trend], mode: classification) %> + <% valuation_styles = trend_styles(valuation_item[:trend]) %> <%= turbo_frame_tag dom_id(valuation) do %>
Total Value
-- <%= balance.symbol %> - <%= format_currency(balance.amount, precision: 0, unit: '') %> - <%- if balance.precision.positive? -%> - <%= balance.separator %><%= balance.cents %> - <% end %> -
- <% if @balance_series.nil? %> -Data not available for the selected period
- <% elsif @balance_series.trend.amount == 0 %> -No change vs. prior period
- <% else %> -- <%= balance_trend_styles[:symbol] %><%= number_to_currency(@balance_series.trend.amount.abs, precision: 2) %> - (<%= lucide_icon(@balance_series.trend.amount > 0 ? 'arrow-up' : 'arrow-down', class: "w-4 h-4 align-text-bottom inline") %> <%= @balance_series.trend.percent %>%) - <%= trend_label(@period) %> -
- <% end %> + <%= render partial: "shared/balance_heading", locals: { + label: "Total Value", + period: @period, + balance: Money.from_amount(@account.balance, @account.currency), + trend: @balance_series.trend + } + %><%= label %>
++ <%= balance.symbol %> + font-medium"><%= format_currency(balance.amount, precision: 0, unit: '') %> + <%- if balance.precision.positive? -%> + + <%= balance.separator %><%= balance.cents %> + + <% end %> +
+ <% if trend.nil? %> +Data not available for the selected period
+ <% elsif trend.direction == "flat" %> +No change vs. prior period
+ <% else %> + <% styles = trend_styles(trend) %> ++ <%= styles[:symbol] %><%= format_currency(trend.amount.abs, precision: balance.precision) %> + (<%= lucide_icon(styles[:icon], class: "w-4 h-4 align-text-bottom inline") %><%= trend.percent %>%) + <%= period_label(period) %> +
+ <% end %> +