hv2-all-in-one/ui/hv2-ui/src/app/account/account.component.ts

57 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-09-09 15:49:49 +02:00
import { Component, Input, OnInit } from '@angular/core';
import { MatTableDataSource } from '@angular/material/table';
import { AccountEntryService, AccountService } from '../data-object-service';
import { Account, AccountEntry, NULL_AccountEntry } from '../data-objects';
import { MessageService } from '../message.service';
@Component({
selector: 'app-account',
templateUrl: './account.component.html',
styleUrls: ['./account.component.css']
})
export class AccountComponent implements OnInit {
@Input() selectedAccountId: number
2021-09-09 15:52:38 +02:00
collapse: boolean = false
2021-09-09 15:49:49 +02:00
account: Account
accountEntries: AccountEntry[]
accountEntriesDataSource: MatTableDataSource<AccountEntry>
accountEntriesDisplayedColumns: string[] = [ "description", "amount", "createdAt" ]
newAccountEntry: AccountEntry = NULL_AccountEntry
constructor(
private accountService: AccountService,
private accountEntryService: AccountEntryService,
private messageService: MessageService
) { }
async getAccountAndEntries(): Promise<void> {
try {
if (this.selectedAccountId) {
this.messageService.add(`Trying to load account ${this.selectedAccountId} and entries`)
this.account = await this.accountService.getAccount(this.selectedAccountId)
this.messageService.add(`Account: ${JSON.stringify(this.account, undefined, 4)}`)
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 getAccountAndEntries: ${JSON.stringify(err, undefined, 4)}`)
}
}
addAccountEntry() {
}
ngOnInit(): void {
this.messageService.add(`AccountComponent.ngOnInit, account: ${this.selectedAccountId}`)
this.getAccountAndEntries()
}
}