mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 16:19:40 +02:00
parent
2181cdd118
commit
8b19b36a9c
4 changed files with 26 additions and 9 deletions
|
@ -1,6 +1,7 @@
|
||||||
class AccountsController < ApplicationController
|
class AccountsController < ApplicationController
|
||||||
include Filterable
|
include Filterable
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
before_action :set_account, only: %i[ show update destroy sync ]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@account = Account.new(
|
@account = Account.new(
|
||||||
|
@ -10,7 +11,6 @@ class AccountsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@account = Current.family.accounts.find(params[:id])
|
|
||||||
@balance_series = @account.series(period: @period)
|
@balance_series = @account.series(period: @period)
|
||||||
@valuation_series = @account.valuations.to_series
|
@valuation_series = @account.valuations.to_series
|
||||||
end
|
end
|
||||||
|
@ -19,8 +19,6 @@ class AccountsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@account = Current.family.accounts.find(params[:id])
|
|
||||||
|
|
||||||
if @account.update(account_params.except(:accountable_type))
|
if @account.update(account_params.except(:accountable_type))
|
||||||
|
|
||||||
@account.sync_later if account_params[:is_active] == "1"
|
@account.sync_later if account_params[:is_active] == "1"
|
||||||
|
@ -50,8 +48,12 @@ class AccountsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@account.destroy!
|
||||||
|
redirect_to accounts_path, notice: t(".success")
|
||||||
|
end
|
||||||
|
|
||||||
def sync
|
def sync
|
||||||
@account = Current.family.accounts.find(params[:id])
|
|
||||||
@account.sync_later
|
@account.sync_later
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -67,6 +69,10 @@ class AccountsController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def set_account
|
||||||
|
@account = Current.family.accounts.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
def account_params
|
def account_params
|
||||||
params.require(:account).permit(:name, :accountable_type, :balance, :currency, :subtype, :is_active)
|
params.require(:account).permit(:name, :accountable_type, :balance, :currency, :subtype, :is_active)
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,9 +6,9 @@ class Account < ApplicationRecord
|
||||||
|
|
||||||
broadcasts_refreshes
|
broadcasts_refreshes
|
||||||
belongs_to :family
|
belongs_to :family
|
||||||
has_many :balances
|
has_many :balances, dependent: :destroy
|
||||||
has_many :valuations
|
has_many :valuations, dependent: :destroy
|
||||||
has_many :transactions
|
has_many :transactions, dependent: :destroy
|
||||||
|
|
||||||
monetize :balance
|
monetize :balance
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,17 @@
|
||||||
<%= lucide_icon("chevron-down", class: "w-5 h-5 text-gray-500") %>
|
<%= lucide_icon("chevron-down", class: "w-5 h-5 text-gray-500") %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="cursor-not-allowed">
|
<div class="relative cursor-pointer" data-controller="dropdown">
|
||||||
<%= lucide_icon("more-horizontal", class: "w-5 h-5 text-gray-500") %>
|
<div class="flex hover:bg-gray-100 p-2 rounded" data-action="click->dropdown#toggleMenu">
|
||||||
|
<%= lucide_icon("more-horizontal", class: "w-5 h-5 text-gray-500") %>
|
||||||
|
</div>
|
||||||
|
<div class="absolute z-10 top-10 right-0 border border-alpha-black-25 bg-white rounded-lg shadow-xs hidden" data-dropdown-target="menu">
|
||||||
|
<div class="w-48 px-3 text-sm leading-6 text-gray-900 bg-white shadow-lg shrink rounded-xl ring-1 ring-gray-900/5">
|
||||||
|
<%= button_to account_path(@account), method: :delete, class: "block w-full py-2 text-red-600 hover:text-red-800 flex items-center", data: { turbo_confirm: "Are you sure you want to delete the account \"#{@account.name}\"?" } do %>
|
||||||
|
<%= lucide_icon("trash-2", class: "w-5 h-5 mr-2") %> Delete account
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,6 +3,8 @@ en:
|
||||||
accounts:
|
accounts:
|
||||||
create:
|
create:
|
||||||
success: New account created successfully
|
success: New account created successfully
|
||||||
|
destroy:
|
||||||
|
success: Account deleted successfully
|
||||||
index:
|
index:
|
||||||
new_account: New account
|
new_account: New account
|
||||||
new:
|
new:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue