fee pages
This commit is contained in:
49
ui/hv2-ui/src/app/fee-details/fee-details.component.html
Normal file
49
ui/hv2-ui/src/app/fee-details/fee-details.component.html
Normal file
@ -0,0 +1,49 @@
|
||||
<section class="mat-typography">
|
||||
<mat-card class="defaultCard">
|
||||
<mat-card-header>
|
||||
<mat-card-title>
|
||||
{{fee?.description}}
|
||||
</mat-card-title>
|
||||
<mat-card-subtitle>
|
||||
ID: {{fee?.id}}
|
||||
</mat-card-subtitle>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<div>
|
||||
<form (ngSubmit)="saveFee()">
|
||||
<div>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Beschreibung</mat-label>
|
||||
<input matInput name="description" [(ngModel)]="fee.description"/>
|
||||
</mat-form-field>
|
||||
</div><div>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Betrag (€)</mat-label>
|
||||
<input matInput type="number" name="amount" [(ngModel)]="fee.amount" [readonly]="readonly"/>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Typ</mat-label>
|
||||
<mat-select [(ngModel)]="fee.fee_type" name="fee_type">
|
||||
<mat-option *ngFor="let p of fee_types" [value]="p">{{p}}</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div><div>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Beginn</mat-label>
|
||||
<input matInput name="startdate" [(ngModel)]="fee.startdate" [matDatepicker]="startdatepicker" [readonly]="readonly"/>
|
||||
<mat-datepicker-toggle matSuffix [for]="startdatepicker" [disabled]="readonly"></mat-datepicker-toggle>
|
||||
<mat-datepicker #startdatepicker></mat-datepicker>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Ende</mat-label>
|
||||
<input matInput name="enddate" [(ngModel)]="fee.enddate" [matDatepicker]="enddatepicker"/>
|
||||
<mat-datepicker-toggle matSuffix [for]="enddatepicker"></mat-datepicker-toggle>
|
||||
<mat-datepicker #enddatepicker></mat-datepicker>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<button #submitButton type="submit" mat-raised-button color="primary">Speichern</button>
|
||||
</form>
|
||||
</div>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</section>
|
25
ui/hv2-ui/src/app/fee-details/fee-details.component.spec.ts
Normal file
25
ui/hv2-ui/src/app/fee-details/fee-details.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { FeeDetailsComponent } from './fee-details.component';
|
||||
|
||||
describe('FeeDetailsComponent', () => {
|
||||
let component: FeeDetailsComponent;
|
||||
let fixture: ComponentFixture<FeeDetailsComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ FeeDetailsComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(FeeDetailsComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
73
ui/hv2-ui/src/app/fee-details/fee-details.component.ts
Normal file
73
ui/hv2-ui/src/app/fee-details/fee-details.component.ts
Normal 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()
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user