one-way-binding in account entry form works now

This commit is contained in:
Wolfgang Hottgenroth 2021-11-02 12:36:35 +01:00
parent 0ab106d021
commit 272500df8c
Signed by: wn
GPG Key ID: 6C1E5E531E0D5D7F
3 changed files with 35 additions and 27 deletions

View File

@ -1,12 +1,12 @@
<div id="firstBlock">
<form (ngSubmit)="addAccountEntry(userForm)" #userForm="ngForm">
<form (ngSubmit)="addAccountEntry(accountEntryForm)" #accountEntryForm="ngForm">
<mat-form-field appearance="outline" id="addEntryfield">
<mat-label>Datum</mat-label>
<input matInput ngModel name="createdAt" [matDatepicker]="createdAtPicker"/>
<mat-datepicker-toggle matSuffix [for]="createdAtPicker"></mat-datepicker-toggle>
<mat-datepicker #createdAtPicker></mat-datepicker>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-form-field appearance="outline" *ngIf="!shallBeRentPayment">
<mat-label>Kategorie</mat-label>
<mat-select ngModel name="category" [disabled]="shallBeRentPayment">
<mat-option *ngFor="let p of accountEntryCategories" [value]="p.id">{{p.description}}</mat-option>

View File

@ -39,7 +39,6 @@ export class AccountComponent implements OnInit {
accountEntryCategoriesMap: Map<number, AccountEntryCategory>
accountEntryCategoriesInverseMap: Map<string, AccountEntryCategory>
// newAccountEntry: AccountEntry = NULL_AccountEntry
constructor(
@ -87,24 +86,38 @@ export class AccountComponent implements OnInit {
}
}
async addAccountEntry(userForm: any): Promise<void> {
this.messageService.add(`${JSON.stringify(userForm.value, undefined, 4)}`)
userForm.reset()
/*
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': undefined, 'created_at': '', 'description': '', 'id': 0, 'account_entry_category': 0 }
this.getAccountEntries()
} catch (err) {
this.messageService.add(`Error in addAccountEntry: ${JSON.stringify(err, undefined, 4)}`)
} finally {
this.addAccountEntryButton.disabled = false
async addAccountEntry(formData: any): Promise<void> {
try {
this.addAccountEntryButton.disabled = true
this.messageService.add(`${JSON.stringify(formData.value, undefined, 4)}`)
let newAccountEntry: AccountEntry = {
description: formData.value.description,
account: this.account.id,
created_at: formData.value.createdAt,
amount: formData.value.amount,
id: 0,
account_entry_category: 0
}
*/
if (this.shallBeRentPayment) {
newAccountEntry.account_entry_category = this.accountEntryCategoriesInverseMap.get('Mietzahlung').id
this.messageService.add(`shall be rentpayment, category is ${newAccountEntry.account_entry_category}`)
} else {
newAccountEntry.account_entry_category = formData.value.category
this.messageService.add(`category is ${newAccountEntry.account_entry_category}`)
}
this.messageService.add(`addAccountEntry: ${ JSON.stringify(newAccountEntry, undefined, 4) }`)
newAccountEntry = await this.accountEntryService.postAccountEntry(newAccountEntry)
this.messageService.add(`New accountEntry created: ${newAccountEntry.id}`)
this.getAccountEntries()
} catch (err) {
this.messageService.add(`Error in addAccountEntry: ${JSON.stringify(err, undefined, 4)}`)
} finally {
formData.reset()
this.addAccountEntryButton.disabled = false
}
}
async getAccountEntryCategories(): Promise<void> {
@ -125,13 +138,8 @@ export class AccountComponent implements OnInit {
private async init(): Promise<void> {
this.messageService.add(`AccountComponent.init, account: ${this.selectedAccountId}`)
this.newAccountEntry = NULL_AccountEntry
this.getAccount()
await this.getAccountEntryCategories()
if (this.shallBeRentPayment) {
this.messageService.add('shall be rentpayment')
this.newAccountEntry.account_entry_category = this.accountEntryCategoriesInverseMap.get('Mietzahlung').id
}
}
ngOnInit(): void {

View File

@ -1,5 +1,5 @@
// export const serviceBaseUrl = "https://api.hv.nober.de";
export const serviceBaseUrl = "https://api.hv.nober.de";
// export const serviceBaseUrl = "http://172.16.10.38:5000";
export const serviceBaseUrl = "http://localhost:8080"
// export const serviceBaseUrl = "http://localhost:8080"
export const authserviceBaseUrl = "https://authservice.hottis.de"
export const applicationId = "hv2"