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 account: Account accountEntries: AccountEntry[] accountEntriesDataSource: MatTableDataSource accountEntriesDisplayedColumns: string[] = [ "description", "amount", "createdAt" ] newAccountEntry: AccountEntry = NULL_AccountEntry constructor( private accountService: AccountService, private accountEntryService: AccountEntryService, private messageService: MessageService ) { } async getAccountAndEntries(): Promise { 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(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() } }