1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-05 13:35:21 +02:00

Account namespace updates: part 5 (valuations) (#901)

* Move Valuation to Account namespace

* Move account history to controller

* Clean up valuation controller and views

* Translations and cleanup

* Remove unused scopes and methods

* Pass brakeman
This commit is contained in:
Zach Gollwitzer 2024-06-21 16:23:28 -04:00 committed by GitHub
parent 0bc0d87768
commit 12380dc8ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
45 changed files with 478 additions and 346 deletions

View file

@ -1,29 +0,0 @@
<%# locals: (account:, valuations:) %>
<div class="bg-white space-y-4 p-5 border border-alpha-black-25 rounded-xl shadow-xs">
<div class="flex justify-between items-center">
<h3 class="font-medium text-lg">History</h3>
<%= link_to new_account_valuation_path(account), data: { turbo_frame: dom_id(Valuation.new) }, class: "flex gap-1 font-medium items-center bg-gray-50 text-gray-900 p-2 rounded-lg" do %>
<%= lucide_icon("plus", class: "w-5 h-5 text-gray-900") %>
<span class="text-sm">New entry</span>
<% end %>
</div>
<div class="rounded-xl bg-gray-25 p-1">
<div class="flex flex-col rounded-lg space-y-1">
<div class="text-xs font-medium text-gray-500 uppercase flex items-center px-4 py-2">
<div class="w-16">date</div>
<div class="flex items-center justify-between grow">
<div></div>
<div>value</div>
</div>
<div class="w-56 text-right">change</div>
<div class="w-[72px]"></div>
</div>
<div class="rounded-lg bg-white border-alpha-black-25 shadow-xs">
<%= turbo_frame_tag dom_id(Valuation.new) %>
<%= turbo_frame_tag "valuations_list" do %>
<%= render partial: "accounts/account_valuation_list", locals: { valuation_series: valuations } %>
<% end %>
</div>
</div>
</div>
</div>

View file

@ -1,57 +0,0 @@
<%# locals: (valuation_series:) %>
<% valuation_series.values.reverse_each.with_index do |valuation, index| %>
<% valuation_styles = trend_styles(valuation.trend) %>
<%= turbo_frame_tag dom_id(valuation.original) do %>
<div class="p-4 flex items-center">
<div class="w-16">
<div class="w-8 h-8 rounded-full p-1.5 flex items-center justify-center <%= valuation_styles[:bg_class] %>">
<%= lucide_icon(valuation_styles[:icon], class: "w-4 h-4 #{valuation_styles[:text_class]}") %>
</div>
</div>
<div class="flex items-center justify-between grow">
<div class="text-sm">
<p><%= valuation.date %></p>
<%# TODO: Add descriptive name of valuation %>
<p class="text-gray-500">Manually entered</p>
</div>
<div class="flex text-sm font-medium text-right"><%= format_money valuation.value %></div>
</div>
<div class="flex w-56 justify-end text-right text-sm font-medium">
<% if valuation.trend.value == 0 %>
<span class="text-gray-500">No change</span>
<% else %>
<span class="<%= valuation_styles[:text_class] %>"><%= valuation_styles[:symbol] %><%= format_money valuation.trend.value.abs %></span>
<span class="<%= valuation_styles[:text_class] %>">(<%= lucide_icon(valuation_styles[:icon], class: "w-4 h-4 align-text-bottom inline") %> <%= valuation.trend.percent %>%)</span>
<% end %>
</div>
<div class="relative w-[72px]" data-controller="menu">
<button
data-menu-target="button"
class="ml-auto flex items-center justify-center hover:bg-gray-50 w-8 h-8 rounded-lg">
<%= lucide_icon("more-horizontal", class: "w-5 h-5 text-gray-500") %>
</button>
<div
data-menu-target="content"
class="absolute hidden min-w-[200px] z-10 top-10 right-0 bg-white p-1 rounded-sm shadow-xs border border-alpha-black-25 w-fit">
<%= link_to edit_valuation_path(valuation.original),
class: "flex gap-1 items-center hover:bg-gray-50 rounded-md p-2" do %>
<%= lucide_icon("pencil-line", class: "w-5 h-5 text-gray-500 shrink-0") %>
<span class="text-gray-900 text-sm">Edit entry</span>
<% end %>
<%= link_to valuation_path(valuation.original),
data: { turbo_method: :delete,
turbo_confirm: { title: t(".confirm_title"),
body: t(".confirm_body_html"),
accept: t(".confirm_accept") } },
class: "text-red-600 flex gap-1 items-center hover:bg-gray-50 rounded-md p-2" do %>
<%= lucide_icon("trash-2", class: "w-5 h-5 shrink-0") %>
<span class="text-sm">Delete entry</span>
<% end %>
</div>
</div>
</div>
<% unless index == valuation_series.values.size - 1 %>
<div class="h-px bg-alpha-black-50 ml-20 mr-4"></div>
<% end %>
<% end %>
<% end %>

View file

@ -56,11 +56,11 @@
<div class="p-4 flex justify-between">
<div class="space-y-2">
<%= render partial: "shared/value_heading", locals: {
label: "Total Value",
period: @period,
value: @account.balance_money,
trend: @balance_series.trend
} %>
label: "Total Value",
period: @period,
value: @account.balance_money,
trend: @balance_series.trend
} %>
</div>
<%= form_with url: account_path(@account), method: :get, class: "flex items-center gap-4", data: { controller: "auto-submit-form" } do %>
<%= render partial: "shared/period_select", locals: { value: @period.name } %>
@ -77,7 +77,23 @@
</div>
<div class="min-h-[800px]">
<div data-tabs-target="tab" id="account-history-tab">
<%= render partial: "accounts/account_history", locals: { account: @account, valuations: @valuation_series } %>
<div class="bg-white space-y-4 p-5 border border-alpha-black-25 rounded-xl shadow-xs">
<div class="flex items-center justify-between">
<%= tag.h2 t(".valuations"), class: "font-medium text-lg" %>
<%= link_to new_account_valuation_path(@account), data: { turbo_frame: dom_id(Account::Valuation.new) }, class: "flex gap-1 font-medium items-center bg-gray-50 text-gray-900 p-2 rounded-lg" do %>
<%= lucide_icon("plus", class: "w-5 h-5 text-gray-900") %>
<%= tag.span t(".new_entry"), class: "text-sm" %>
<% end %>
</div>
<div class="rounded-xl bg-gray-25 p-1">
<%= turbo_frame_tag dom_id(@account, "valuations"), src: account_valuations_path(@account) do %>
<div class="p-5 flex justify-center items-center">
<%= tag.p t(".loading_history"), class: "text-gray-500 animate-pulse text-sm" %>
</div>
<% end %>
</div>
</div>
</div>
<div data-tabs-target="tab" id="account-transactions-tab" class="hidden">
<%= render partial: "accounts/transactions", locals: { account: @account, transactions: @account.transactions.order(date: :desc) } %>