fee pages

This commit is contained in:
2021-09-07 17:52:02 +02:00
parent 356c8c0bbd
commit cf35af9c1e
13 changed files with 288 additions and 5 deletions

View File

@ -0,0 +1,73 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatButton } from '@angular/material/button';
import { ActivatedRoute, Router } from '@angular/router';
import { FeeService } from '../data-object-service';
import { NULL_Fee, Fee } from '../data-objects';
import { MessageService } from '../message.service';
@Component({
selector: 'app-fee-details',
templateUrl: './fee-details.component.html',
styleUrls: ['./fee-details.component.css']
})
export class FeeDetailsComponent implements OnInit {
@ViewChild('submitButton') submitButton: MatButton
fee: Fee = NULL_Fee
fee_types: string[] = [ "total", "per_area" ]
readonly: boolean
constructor(
private feeService: FeeService,
private messageService: MessageService,
private route: ActivatedRoute,
private router: Router
) { }
async getFee(): Promise<void> {
try {
const id = +this.route.snapshot.paramMap.get('id')
this.readonly = false
if (id != 0) {
this.fee = await this.feeService.getFee(id)
this.readonly = true
}
this.messageService.add(`Fee is ${ JSON.stringify(this.fee, undefined, 4)}`)
} catch (err) {
this.messageService.add(`Error in getFee: ${ JSON.stringify(err, undefined, 4) }`)
}
}
async saveFee() {
try {
this.submitButton.disabled = true
this.messageService.add("saveFee")
this.messageService.add(JSON.stringify(this.fee, undefined, 4))
if (this.fee.enddate == null) {
this.fee.enddate = ''
}
if (this.fee.startdate == null) {
this.fee.startdate = ''
}
if (this.fee.id == 0) {
this.messageService.add("about to insert new fee")
this.fee = await this.feeService.postFee(this.fee)
this.messageService.add(`Successfully added fee with id ${this.fee.id}`)
} else {
this.messageService.add("about to update existing fee")
this.fee = await this.feeService.putFee(this.fee)
this.messageService.add(`Successfully changed fee with id ${this.fee.id}`)
}
this.router.navigate(['/fees'])
} finally {
this.submitButton.disabled = false
}
}
ngOnInit(): void {
this.getFee()
}
}