1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 07:39:39 +02:00

Add Live Data to Account Page (#464)

* Add trends, time series, seed data

* Remove test data

* Replace old view values with helpers

* Fix tooltip bugs in D3 chart

* Fix tests

* Fix smoke test

* Add CRUD actions for valuations

* Scaffold out inline editing with Turbo
This commit is contained in:
Zach Gollwitzer 2024-02-20 09:07:55 -05:00 committed by GitHub
parent 298b50a909
commit b5b2d335fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 512 additions and 167 deletions

View file

@ -9,9 +9,7 @@ class AccountsController < ApplicationController
end
def show
# Temporary while dummy data is being used
# @account = Current.family.accounts.find(params[:id])
@account = sample_account
@account = Current.family.accounts.find(params[:id])
end
def create
@ -25,40 +23,9 @@ class AccountsController < ApplicationController
end
end
private
def account_params
params.require(:account).permit(:name, :accountable_type, :original_balance, :original_currency, :subtype)
end
def sample_account
OpenStruct.new(
id: 1,
name: "Sample Account",
original_balance: BigDecimal("1115181"),
original_currency: "USD",
converted_balance: BigDecimal("1115181"), # Assuming conversion rate is 1 for simplicity
converted_currency: "USD",
dollar_change: BigDecimal("1553.43"), # Added dollar change
percent_change: BigDecimal("0.9"), # Added percent change
subtype: "Checking",
accountable_type: "Depository",
balances: sample_balances
)
end
def sample_balances
4.times.map do |i|
OpenStruct.new(
date: "Feb #{12 + i} 2024",
description: "Manually entered",
amount: BigDecimal("1000") + (i * BigDecimal("100")),
change: i == 3 ? -50 : (i == 2 ? 0 : 100 + (i * 10)),
percentage_change: i == 3 ? -5 : (i == 2 ? 0 : 10 + i),
icon: i == 3 ? "arrow-down" : (i == 2 ? "minus" : (i.even? ? "arrow-down" : "arrow-up"))
)
end
end
end

View file

@ -0,0 +1,62 @@
class ValuationsController < ApplicationController
before_action :authenticate_user!
def create
@account = Current.family.accounts.find(params[:account_id])
# TODO: handle STI once we allow for different types of valuations
@valuation = @account.valuations.new(valuation_params.merge(type: "Appraisal", currency: Current.family.currency))
if @valuation.save
respond_to do |format|
format.html { redirect_to account_path(@account), notice: "Valuation created" }
format.turbo_stream
end
else
render :new, status: :unprocessable_entity
end
rescue ActiveRecord::RecordNotUnique
flash.now[:error] = "Valuation already exists for this date"
render :new, status: :unprocessable_entity
end
def show
@valuation = Current.family.accounts.find(params[:account_id]).valuations.find(params[:id])
end
def edit
@valuation = Valuation.find(params[:id])
end
def update
@valuation = Valuation.find(params[:id])
if @valuation.update(valuation_params)
redirect_to account_path(@valuation.account), notice: "Valuation updated"
else
render :edit, status: :unprocessable_entity
end
rescue ActiveRecord::RecordNotUnique
flash.now[:error] = "Valuation already exists for this date"
render :edit, status: :unprocessable_entity
end
def destroy
@valuation = Valuation.find(params[:id])
account = @valuation.account
@valuation.destroy
respond_to do |format|
format.html { redirect_to account_path(account), notice: "Valuation deleted" }
format.turbo_stream
end
end
def new
@account = Current.family.accounts.find(params[:account_id])
@valuation = @account.valuations.new
end
private
def valuation_params
params.require(:valuation).permit(:date, :value)
end
end