mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-07 22:45:20 +02:00
Balance sheet cache layer, non-blocking sync UI (#2356)
* Balance sheet cache layer with cache-busting * Update family cache timestamps during Sync * Less blocking sync loaders * Consolidate family data caching key logic * Fix turbo stream broadcasts * Remove dev delay * Add back account group sorting
This commit is contained in:
parent
dab693d74f
commit
10ce2c8e23
35 changed files with 529 additions and 466 deletions
61
app/models/balance_sheet/account_group.rb
Normal file
61
app/models/balance_sheet/account_group.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
class BalanceSheet::AccountGroup
|
||||
include Monetizable
|
||||
|
||||
monetize :total, as: :total_money
|
||||
|
||||
attr_reader :name, :color, :accountable_type, :accounts
|
||||
|
||||
def initialize(name:, color:, accountable_type:, accounts:, classification_group:)
|
||||
@name = name
|
||||
@color = color
|
||||
@accountable_type = accountable_type
|
||||
@accounts = accounts
|
||||
@classification_group = classification_group
|
||||
end
|
||||
|
||||
# A stable DOM id for this group.
|
||||
# Example outputs:
|
||||
# dom_id(tab: :asset) # => "asset_depository"
|
||||
# dom_id(tab: :all, mobile: true) # => "mobile_all_depository"
|
||||
#
|
||||
# Keeping all of the logic here means the view layer and broadcaster only
|
||||
# need to ask the object for its DOM id instead of rebuilding string
|
||||
# fragments in multiple places.
|
||||
def dom_id(tab: nil, mobile: false)
|
||||
parts = []
|
||||
parts << "mobile" if mobile
|
||||
parts << (tab ? tab.to_s : classification.to_s)
|
||||
parts << key
|
||||
parts.compact.join("_")
|
||||
end
|
||||
|
||||
def key
|
||||
accountable_type.to_s.underscore
|
||||
end
|
||||
|
||||
def total
|
||||
accounts.sum(&:converted_balance)
|
||||
end
|
||||
|
||||
def weight
|
||||
return 0 if classification_group.total.zero?
|
||||
|
||||
total / classification_group.total.to_d * 100
|
||||
end
|
||||
|
||||
def syncing?
|
||||
accounts.any?(&:syncing?)
|
||||
end
|
||||
|
||||
# "asset" or "liability"
|
||||
def classification
|
||||
classification_group.classification
|
||||
end
|
||||
|
||||
def currency
|
||||
classification_group.currency
|
||||
end
|
||||
|
||||
private
|
||||
attr_reader :classification_group
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue