Skip to content

Commit

Permalink
Merge pull request #197 from moneymanagerex/vm-12
Browse files Browse the repository at this point in the history
fix(#196): ViewModel.update
  • Loading branch information
georgeef authored Nov 2, 2024
2 parents 83ff873 + b8219ae commit d44a666
Show file tree
Hide file tree
Showing 55 changed files with 307 additions and 209 deletions.
2 changes: 1 addition & 1 deletion MMEX/Data/AssetData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension AssetData: DataProtocol {
static let dataName = ("Asset", "Assets")

func shortDesc() -> String {
"\(self.name), \(self.id)"
"#\(self.id.value): \(self.name)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/AttachmentData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension AttachmentData: DataProtocol {
static let dataName = ("Attachment", "Attachments")

func shortDesc() -> String {
"\(self.id)"
"#\(self.id.value)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/BudgetTableData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension BudgetTableData: DataProtocol {
static let dataName = ("Budget Table", "Budget Tables")

func shortDesc() -> String {
"\(self.id)"
"#\(self.id.value)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/CategoryData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension CategoryData: DataProtocol {
static let dataName = ("Category", "Categories")

func shortDesc() -> String {
"\(self.name), \(self.id)"
"#\(self.id.value): \(self.name)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/CurrencyHistoryData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension CurrencyHistoryData: DataProtocol {
static let dataName = ("Currency History", "Currency History")

func shortDesc() -> String {
"\(self.id)"
"#\(self.id.value)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/FieldContentData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension FieldContentData: DataProtocol {
static let dataName = ("Field Content", "Field Contents")

func shortDesc() -> String {
"\(self.id)"
"#\(self.id.value)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/FieldData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension FieldData: DataProtocol {
static let dataName = ("Field", "Fields")

func shortDesc() -> String {
"\(self.id)"
"#\(self.id.value)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/ScheduledData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extension ScheduledData: DataProtocol {
static let dataName = ("Scheduled Transaction", "Scheduled Transactions")

func shortDesc() -> String {
"\(self.id)"
"#\(self.id.value)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/ScheduledSplitData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension ScheduledSplitData: DataProtocol {
static let dataName = ("Scheduled Transaction Split", "Scheduled Transaction Splits")

func shortDesc() -> String {
"\(self.id)"
"#\(self.id.value)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/StockData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension StockData: DataProtocol {
static let dataName = ("Stock", "Stocks")

func shortDesc() -> String {
"\(self.name), \(self.id)"
"#\(self.id.value): \(self.name)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/TagLinkData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension TagLinkData: DataProtocol {
static let dataName = ("Tag Link", "Tag Links")

func shortDesc() -> String {
"\(self.id)"
"#\(self.id.value)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/TransactionData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extension TransactionData: DataProtocol {
static let dataName = ("Transaction", "Transactions")

func shortDesc() -> String {
"\(self.id)"
"#\(self.id.value)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/TransactionLinkData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension TransactionLinkData: DataProtocol {
static let dataName = ("Transaction Link", "Transaction Links")

func shortDesc() -> String {
"\(self.id)"
"#\(self.id.value)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/TransactionShareData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension TransactionShareData: DataProtocol {
static let dataName = ("Transaction Share", "Transaction Shares")

func shortDesc() -> String {
"\(self.id)"
"#\(self.id.value)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Data/TransactionSplitData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension TransactionSplitData: DataProtocol {
static let dataName = ("Transaction Split", "Transaction Splits")

func shortDesc() -> String {
"\(self.id)"
"#\(self.id.value)"
}
}

Expand Down
2 changes: 1 addition & 1 deletion MMEX/Repository/AccountRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ extension AccountRepository {
// load account of a stock
func pluck(for stock: StockData) -> RepositoryPluckResult<AccountData> {
return pluck(
key: "\(stock.accountId)",
key: "\(stock.accountId.value)",
from: Self.table.filter(Self.col_id == Int64(stock.accountId))
)
}
Expand Down
2 changes: 1 addition & 1 deletion MMEX/Repository/CategoryRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ extension CategoryRepository {
// load category of a payee
func pluck(for payee: PayeeData) -> RepositoryPluckResult<CategoryData> {
return pluck(
key: "\(payee.categoryId)",
key: "\(payee.categoryId.value)",
from: Self.table.filter(Self.col_id == Int64(payee.categoryId))
)
}
Expand Down
4 changes: 2 additions & 2 deletions MMEX/Repository/CurrencyRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ extension CurrencyRepository {
func pluck(for account: AccountData) -> RepositoryPluckResult<CurrencyData> {
log.trace("DEBUG: CurrencyRepository.pluck(account: \(account.name)")
return pluck(
key: "\(account.currencyId)",
key: "\(account.currencyId.value)",
from: Self.table.filter(Self.col_id == Int64(account.currencyId))
)
}
Expand All @@ -175,7 +175,7 @@ extension CurrencyRepository {
func pluck(for asset: AssetData) -> RepositoryPluckResult<CurrencyData> {
log.trace("DEBUG: CurrencyRepository.pluck(asset: \(asset.name)")
return pluck(
key: "\(asset.currencyId)",
key: "\(asset.currencyId.value)",
from: Self.table.filter(Self.col_id == Int64(asset.currencyId))
)
}
Expand Down
2 changes: 1 addition & 1 deletion MMEX/Repository/RepositoryProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ extension RepositoryProtocol {
log.trace("DEBUG: RepositoryProtocol.insert(main=\(Thread.isMainThread)): \(query.expression.description)")
let rowid = try db.run(query)
data.id = DataId(rowid)
let desc = data.shortDesc()
let desc = "#\(data.id.value): \(data.shortDesc())"
log.info("INFO: RepositoryProtocol.insert(\(Self.repositoryName)): \(desc)")
return true
} catch {
Expand Down
2 changes: 1 addition & 1 deletion MMEX/View/Category/CategoryDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct CategoryDetailView: View {

// TODO show name and link to its partent
Section(header: Text("Parent ID")) {
Text("\(category.parentId)")
Text("\(category.parentId.value)")
}

Button("Delete Category") {
Expand Down
2 changes: 1 addition & 1 deletion MMEX/View/Insights/InsightsSummary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct InsightsSummaryView: View {
Chart(stats) {
BarMark(
x: .value("Amount", $0.income),
y: .value("Account", env.accountCache[$0.accountId]?.name ?? "#\($0.accountId)")
y: .value("Account", env.accountCache[$0.accountId]?.name ?? "#\($0.accountId.value)")
)
.foregroundStyle(by: .value("Status", $0.status.fullName))
}
Expand Down
28 changes: 17 additions & 11 deletions MMEX/View/Repository/RepositoryListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ where GroupType.MainRepository == ListType.MainRepository,
vm.searchGroup(vmGroup, search: search, expand: true)
}
.navigationTitle(MainData.dataName.1)
.onAppear { Task {
let _ = log.debug("DEBUG: RepositoryListView.onAppear()")
.onAppear {
if deleteData || newData != nil { return }
log.debug("DEBUG: RepositoryListView.onAppear()")
groupChoice = vmGroup.choice
await load()
} }
Task { await load() }
}
.refreshable {
if deleteData || newData != nil { return }
log.debug("DEBUG: RepositoryListView.refreshable()")
vm.unloadGroup(vmGroup)
vm.unloadList(vmList)
await load()
Expand All @@ -151,11 +154,13 @@ where GroupType.MainRepository == ListType.MainRepository,
editView: editView
)
.onDisappear {
if newData != nil { Task {
guard newData != nil else { return }
log.debug("DEBUG: RepositoryListView.RepositoryCreateView.onDisappear()")
Task {
await vm.reloadList(nil as MainData?, newData)
newData = nil
vm.searchGroup(vmGroup, search: search)
} }
newData = nil
}
}
}
}
Expand Down Expand Up @@ -234,13 +239,14 @@ where GroupType.MainRepository == ListType.MainRepository,
// deleteData = false
//}
.onDisappear {
log.debug("DEBUG: RepositoryListView.itemView.onDisappear")
if deleteData || newData != nil { Task {
guard deleteData || newData != nil else { return }
log.debug("DEBUG: RepositoryListView.RepositoryReadView.onDisappear")
Task {
await vm.reloadList(data, newData)
vm.searchGroup(vmGroup, search: search)
newData = nil
deleteData = false
vm.searchGroup(vmGroup, search: search)
} }
}
}
) {
env.theme.item.view(
Expand Down
2 changes: 1 addition & 1 deletion MMEX/View/Transaction/TransactionAddView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct TransactionAddView: View {
)
{ newTxn in
// Handle saving in preview
log.info("New transaction: \(newTxn.id)")
log.info("New transaction: #\(newTxn.id.value)")
}
.environmentObject(EnvironmentManager())
}
Expand Down
2 changes: 1 addition & 1 deletion MMEX/View/Transaction/TransactionListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct TransactionListView: View {
Text(getPayeeName(for: txn))
.font(.system(size: 16))
.lineLimit(1) // Prevent wrapping
Text("\(txn.transCode.id)") // Replace with transcode name if available
Text("\(txn.transCode.rawValue)") // Replace with transcode name if available
.font(.system(size: 14))
.foregroundColor(.gray)
}
Expand Down
4 changes: 2 additions & 2 deletions MMEX/ViewModel/Group/AccountGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ enum AccountGroupChoice: String, GroupChoiceProtocol {
struct AccountGroup: GroupProtocol {
typealias MainRepository = AccountRepository
typealias GroupChoice = AccountGroupChoice
let loadName: String = "Group\(MainRepository.repositoryName)"
let idleValue: ValueType = []

var choice: GroupChoice = .defaultValue
Expand Down Expand Up @@ -113,8 +112,9 @@ extension ViewModel {
accountGroup.append(name, dict[g] ?? [], true, g)
}
}

accountGroup.state.loaded()
log.info("INFO: ViewModel.loadAccountGroup(\(choice.rawValue), main=\(Thread.isMainThread))")
}

func unloadAccountGroup() {
Expand Down
2 changes: 1 addition & 1 deletion MMEX/ViewModel/Group/AssetGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ enum AssetGroupChoice: String, GroupChoiceProtocol {
struct AssetGroup: GroupProtocol {
typealias MainRepository = AssetRepository
typealias GroupChoice = AssetGroupChoice
let loadName: String = "Group\(MainRepository.repositoryName)"
let idleValue: ValueType = []

var choice: GroupChoice = .defaultValue
Expand Down Expand Up @@ -104,6 +103,7 @@ extension ViewModel {
}

assetGroup.state.loaded()
log.info("INFO: ViewModel.loadAssetGroup(\(choice.rawValue), main=\(Thread.isMainThread))")
}

func unloadAssetGroup() {
Expand Down
2 changes: 1 addition & 1 deletion MMEX/ViewModel/Group/CategoryGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ enum CategoryGroupChoice: String, GroupChoiceProtocol {
struct CategoryGroup: GroupProtocol {
typealias MainRepository = CategoryRepository
typealias GroupChoice = CategoryGroupChoice
let loadName: String = "Group\(MainRepository.repositoryName)"
let idleValue: ValueType = []

var choice: GroupChoice = .defaultValue
Expand Down Expand Up @@ -69,6 +68,7 @@ extension ViewModel {
}

categoryGroup.state.loaded()
log.info("INFO: ViewModel.loadCategoryGroup(\(choice.rawValue), main=\(Thread.isMainThread))")
}

func unloadCategoryGroup() {
Expand Down
2 changes: 1 addition & 1 deletion MMEX/ViewModel/Group/CurrencyGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ enum CurrencyGroupChoice: String, GroupChoiceProtocol {
struct CurrencyGroup: GroupProtocol {
typealias MainRepository = CurrencyRepository
typealias GroupChoice = CurrencyGroupChoice
let loadName: String = "Group\(MainRepository.repositoryName)"
let idleValue: ValueType = []

var choice: GroupChoice = .defaultValue
Expand Down Expand Up @@ -68,6 +67,7 @@ extension ViewModel {
}

currencyGroup.state.loaded()
log.info("INFO: ViewModel.loadCurrencyGroup(\(choice.rawValue), main=\(Thread.isMainThread))")
}

func unloadCurrencyGroup() {
Expand Down
2 changes: 2 additions & 0 deletions MMEX/ViewModel/Group/GroupProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ protocol GroupProtocol: LoadProtocol where ValueType == [GroupData] {
}

extension GroupProtocol {
var loadName: String { "Group(\(MainRepository.repositoryName))" }

mutating func append(_ name: String?, _ dataId: [DataId], _ isVisible: Bool, _ isExpanded: Bool) {
guard state == .loading else {
log.error("ERROR: GroupProtocol.append(): state != loading.")
Expand Down
2 changes: 1 addition & 1 deletion MMEX/ViewModel/Group/PayeeGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ enum PayeeGroupChoice: String, GroupChoiceProtocol {
struct PayeeGroup: GroupProtocol {
typealias MainRepository = PayeeRepository
typealias GroupChoice = PayeeGroupChoice
let loadName: String = "Group\(MainRepository.repositoryName)"
let idleValue: ValueType = []

var choice: GroupChoice = .defaultValue
Expand Down Expand Up @@ -95,6 +94,7 @@ extension ViewModel {
}

payeeGroup.state.loaded()
log.info("INFO: ViewModel.loadPayeeGroup(\(choice.rawValue), main=\(Thread.isMainThread))")
}

func unloadPayeeGroup() {
Expand Down
2 changes: 1 addition & 1 deletion MMEX/ViewModel/Group/StockGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ enum StockGroupChoice: String, GroupChoiceProtocol {
struct StockGroup: GroupProtocol {
typealias MainRepository = StockRepository
typealias GroupChoice = StockGroupChoice
let loadName: String = "Group\(MainRepository.repositoryName)"
let idleValue: ValueType = []

var choice: GroupChoice = .defaultValue
Expand Down Expand Up @@ -84,6 +83,7 @@ extension ViewModel {
}

stockGroup.state.loaded()
log.info("INFO: ViewModel.loadStockGroup(\(choice.rawValue), main=\(Thread.isMainThread))")
}

func unloadStockGroup() {
Expand Down
Loading

0 comments on commit d44a666

Please sign in to comment.