mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Add Money and Money Series (#505)
* Add Money class * Standardize creation of money series * Formatting * Fix test
This commit is contained in:
parent
89ea12e9a1
commit
0fe9b6d34a
16 changed files with 228 additions and 161 deletions
|
@ -1,6 +1,6 @@
|
|||
<%# locals: (valuation_series:, classification:) %>
|
||||
<% valuation_series.with_index do |valuation_item, index| %>
|
||||
<% valuation, trend = valuation_item.values_at(:value, :trend) %>
|
||||
<% 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) %>
|
||||
<%= turbo_frame_tag dom_id(valuation) do %>
|
||||
<div class="p-4 flex items-center">
|
||||
|
@ -41,7 +41,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% unless index == valuation_series.size - 1 %>
|
||||
<% unless index == valuation_series.data.size - 1 %>
|
||||
<div class="h-px bg-alpha-black-50 ml-20 mr-4"></div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<%= turbo_stream_from @account %>
|
||||
<% balance_trend_styles = @balance_series.nil? ? {} : trend_styles(@balance_series[:trend], mode: @account.classification) %>
|
||||
<% balance_trend_styles = trend_styles(@balance_series.trend, mode: @account.classification) %>
|
||||
<% balance = Money.from_amount(@account.balance, @account.currency) %>
|
||||
<div class="space-y-4">
|
||||
<div class="flex justify-between items-center">
|
||||
<div class="flex items-center gap-3">
|
||||
|
@ -11,7 +12,7 @@
|
|||
<div class="flex items-center gap-3">
|
||||
<div class="relative cursor-not-allowed">
|
||||
<div class="flex items-center gap-2 px-3 py-2">
|
||||
<span class="text-gray-900"><%= @account.currency %> <%= @account.currency.unit %></span>
|
||||
<span class="text-gray-900"><%= balance.currency %> <%= balance.symbol %></span>
|
||||
<%= lucide_icon("chevron-down", class: "w-5 h-5 text-gray-500") %>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -27,22 +28,21 @@
|
|||
<div class="p-4 flex justify-between">
|
||||
<div class="space-y-2">
|
||||
<p class="text-sm text-gray-500">Total Value</p>
|
||||
<%# TODO: Will need a better way to split a formatted monetary value into these 3 parts %>
|
||||
<p class="text-gray-900">
|
||||
<span class="text-gray-500"><%= @account.currency.unit %></span>
|
||||
<span class="text-xl font-medium"><%= format_currency(@account.balance, precision: 0, unit: '') %></span>
|
||||
<%- if @account.currency.precision.positive? -%>
|
||||
<span class="text-gray-500"><%= @account.currency.separator %><%= @account.balance.cents(precision: @account.currency.precision) %></span>
|
||||
<span class="text-gray-500"><%= balance.symbol %></span>
|
||||
<span class="text-xl font-medium"><%= format_currency(balance.amount, precision: 0, unit: '') %></span>
|
||||
<%- if balance.precision.positive? -%>
|
||||
<span class="text-gray-500"><%= balance.separator %><%= balance.cents %></span>
|
||||
<% end %>
|
||||
</p>
|
||||
<% if @balance_series.nil? %>
|
||||
<p class="text-sm text-gray-500">Data not available for the selected period</p>
|
||||
<% elsif @balance_series[:trend].amount == 0 %>
|
||||
<% elsif @balance_series.trend.amount == 0 %>
|
||||
<p class="text-sm text-gray-500">No change vs. prior period</p>
|
||||
<% else %>
|
||||
<p class="text-sm <%= balance_trend_styles[:text_class] %>">
|
||||
<span><%= balance_trend_styles[:symbol] %><%= number_to_currency(@balance_series[:trend].amount.abs, precision: 2) %></span>
|
||||
<span>(<%= lucide_icon(@balance_series[:trend].amount > 0 ? 'arrow-up' : 'arrow-down', class: "w-4 h-4 align-text-bottom inline") %> <%= @balance_series[:trend].percent %>%)</span>
|
||||
<span><%= balance_trend_styles[:symbol] %><%= number_to_currency(@balance_series.trend.amount.abs, precision: 2) %></span>
|
||||
<span>(<%= lucide_icon(@balance_series.trend.amount > 0 ? 'arrow-up' : 'arrow-down', class: "w-4 h-4 align-text-bottom inline") %> <%= @balance_series.trend.percent %>%)</span>
|
||||
<span class="text-gray-500"><%= trend_label(@period) %></span>
|
||||
</p>
|
||||
<% end %>
|
||||
|
@ -53,7 +53,7 @@
|
|||
</div>
|
||||
<div class="h-96 flex items-center justify-center text-2xl font-bold">
|
||||
<% if @balance_series %>
|
||||
<div data-controller="line-chart" id="lineChart" class="w-full h-full" data-line-chart-series-value="<%= @balance_series[:series_data].to_json %>"></div>
|
||||
<div data-controller="line-chart" id="lineChart" class="w-full h-full" data-line-chart-series-value="<%= @balance_series.serialize_for_d3_chart %>"></div>
|
||||
<% else %>
|
||||
<div class="w-full h-full flex items-center justify-center">
|
||||
<p class="text-gray-500">No data available for the selected period.</p>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue