account entries stuff
This commit is contained in:
parent
eae137bea8
commit
e55578759f
@ -1,4 +1,5 @@
|
|||||||
import { Component, Input, OnInit } from '@angular/core';
|
import { Component, Input, OnInit, ViewChild } from '@angular/core';
|
||||||
|
import { MatButton } from '@angular/material/button';
|
||||||
import { MatTableDataSource } from '@angular/material/table';
|
import { MatTableDataSource } from '@angular/material/table';
|
||||||
import { AccountEntryService, AccountService } from '../data-object-service';
|
import { AccountEntryService, AccountService } from '../data-object-service';
|
||||||
import { Account, AccountEntry, NULL_AccountEntry } from '../data-objects';
|
import { Account, AccountEntry, NULL_AccountEntry } from '../data-objects';
|
||||||
@ -12,6 +13,7 @@ import { MessageService } from '../message.service';
|
|||||||
export class AccountComponent implements OnInit {
|
export class AccountComponent implements OnInit {
|
||||||
|
|
||||||
@Input() selectedAccountId: number
|
@Input() selectedAccountId: number
|
||||||
|
@ViewChild('addAccountEntryButton') addAccountEntryButton: MatButton
|
||||||
|
|
||||||
collapse: boolean = false
|
collapse: boolean = false
|
||||||
|
|
||||||
@ -29,28 +31,48 @@ export class AccountComponent implements OnInit {
|
|||||||
private messageService: MessageService
|
private messageService: MessageService
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
async getAccountAndEntries(): Promise<void> {
|
async getAccount(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (this.selectedAccountId) {
|
if (this.selectedAccountId) {
|
||||||
this.messageService.add(`Trying to load account ${this.selectedAccountId} and entries`)
|
this.messageService.add(`Trying to load account ${this.selectedAccountId} and entries`)
|
||||||
this.account = await this.accountService.getAccount(this.selectedAccountId)
|
this.account = await this.accountService.getAccount(this.selectedAccountId)
|
||||||
this.messageService.add(`Account: ${JSON.stringify(this.account, undefined, 4)}`)
|
this.messageService.add(`Account: ${JSON.stringify(this.account, undefined, 4)}`)
|
||||||
this.accountEntries = await this.accountEntryService.getAccountEntrysByAccount(this.selectedAccountId)
|
this.getAccountEntries()
|
||||||
this.messageService.add(`AccountEntries: ${JSON.stringify(this.accountEntries, undefined, 4)}`)
|
|
||||||
this.accountEntriesDataSource = new MatTableDataSource<AccountEntry>(this.accountEntries)
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.messageService.add(`Error in getAccountAndEntries: ${JSON.stringify(err, undefined, 4)}`)
|
this.messageService.add(`Error in getAccount: ${JSON.stringify(err, undefined, 4)}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addAccountEntry() {
|
async getAccountEntries(): Promise<void> {
|
||||||
|
try {
|
||||||
|
this.accountEntries = await this.accountEntryService.getAccountEntrysByAccount(this.selectedAccountId)
|
||||||
|
this.messageService.add(`AccountEntries: ${JSON.stringify(this.accountEntries, undefined, 4)}`)
|
||||||
|
this.accountEntriesDataSource = new MatTableDataSource<AccountEntry>(this.accountEntries)
|
||||||
|
} catch (err) {
|
||||||
|
this.messageService.add(`Error in getAccountEntries: ${JSON.stringify(err, undefined, 4)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async addAccountEntry(): Promise<void> {
|
||||||
|
try {
|
||||||
|
this.addAccountEntryButton.disabled = true
|
||||||
|
this.newAccountEntry.account = this.account.id
|
||||||
|
this.messageService.add(`addAccountEntry: ${ JSON.stringify(this.newAccountEntry, undefined, 4) }`)
|
||||||
|
this.newAccountEntry = await this.accountEntryService.postAccountEntry(this.newAccountEntry)
|
||||||
|
this.messageService.add(`New accountEntry created: ${this.newAccountEntry.id}`)
|
||||||
|
this.newAccountEntry = { 'account': this.account.id, 'amount': 0, 'created_at': '', 'description': '', 'id': 0 }
|
||||||
|
this.getAccountEntries()
|
||||||
|
} catch (err) {
|
||||||
|
this.messageService.add(`Error in addAccountEntry: ${JSON.stringify(err, undefined, 4)}`)
|
||||||
|
} finally {
|
||||||
|
this.addAccountEntryButton.disabled = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.messageService.add(`AccountComponent.ngOnInit, account: ${this.selectedAccountId}`)
|
this.messageService.add(`AccountComponent.ngOnInit, account: ${this.selectedAccountId}`)
|
||||||
this.getAccountAndEntries()
|
this.getAccount()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user