changes for details
This commit is contained in:
40
ui/hv2-ui/src/app/flat-details/flat-details.component.html
Normal file
40
ui/hv2-ui/src/app/flat-details/flat-details.component.html
Normal file
@ -0,0 +1,40 @@
|
||||
<section class="mat-typography">
|
||||
<mat-card class="defaultCard">
|
||||
<mat-card-header>
|
||||
<mat-card-title>
|
||||
{{flat?.description}} {{flat?.flat_no}} {{premise?.description}}
|
||||
</mat-card-title>
|
||||
<mat-card-subtitle>
|
||||
ID: {{flat?.id}}
|
||||
</mat-card-subtitle>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<div>
|
||||
<form (ngSubmit)="saveFlat()">
|
||||
<div>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Beschreibung</mat-label>
|
||||
<input matInput name="description" [(ngModel)]="flat.description"/>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Haus</mat-label>
|
||||
<mat-select [(ngModel)]="flat.premise" name="premise">
|
||||
<mat-option *ngFor="let p of premises" [value]="p.id">{{p.description}}</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div><div>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Fläche</mat-label>
|
||||
<input matInput name="area" [(ngModel)]="flat.area"/>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Wohnungsnummer</mat-label>
|
||||
<input matInput name="flat_no" [(ngModel)]="flat.flat_no"/>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<button #submitButton type="submit" mat-raised-button color="primary">Speichern</button>
|
||||
</form>
|
||||
</div>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</section>
|
@ -0,0 +1,25 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { FlatDetailsComponent } from './flat-details.component';
|
||||
|
||||
describe('FlatDetailsComponent', () => {
|
||||
let component: FlatDetailsComponent;
|
||||
let fixture: ComponentFixture<FlatDetailsComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ FlatDetailsComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(FlatDetailsComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
83
ui/hv2-ui/src/app/flat-details/flat-details.component.ts
Normal file
83
ui/hv2-ui/src/app/flat-details/flat-details.component.ts
Normal file
@ -0,0 +1,83 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { MatButton } from '@angular/material/button';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { FlatService, PremiseService } from '../data-object-service';
|
||||
import { Flat, Premise } from '../data-objects';
|
||||
import { MessageService } from '../message.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-flat-details',
|
||||
templateUrl: './flat-details.component.html',
|
||||
styleUrls: ['./flat-details.component.css']
|
||||
})
|
||||
export class FlatDetailsComponent implements OnInit {
|
||||
|
||||
flat: Flat = {
|
||||
id: 0,
|
||||
description: '',
|
||||
premise: 0,
|
||||
area: 0.0,
|
||||
flat_no: 0
|
||||
}
|
||||
|
||||
premise: Premise = {
|
||||
id: 0,
|
||||
description: '',
|
||||
street: '',
|
||||
zip: '',
|
||||
city: ''
|
||||
}
|
||||
|
||||
premises: Premise[]
|
||||
|
||||
@ViewChild('submitButton') submitButton: MatButton
|
||||
|
||||
constructor(
|
||||
private flatService: FlatService,
|
||||
private premiseService: PremiseService,
|
||||
private messageService: MessageService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
async getFlat(): Promise<void> {
|
||||
try {
|
||||
const id = +this.route.snapshot.paramMap.get('id')
|
||||
if (id != 0) {
|
||||
this.flat = await this.flatService.getFlat(id)
|
||||
this.premise = await this.premiseService.getPremise(this.flat.premise)
|
||||
}
|
||||
} catch (err) {
|
||||
this.messageService.add(JSON.stringify(err, undefined, 4))
|
||||
}
|
||||
}
|
||||
|
||||
async getPremises(): Promise<void> {
|
||||
try {
|
||||
this.messageService.add("Trying to load premises")
|
||||
this.premises = await this.premiseService.getPremises()
|
||||
this.messageService.add("Premises loaded")
|
||||
} catch (err) {
|
||||
this.messageService.add(JSON.stringify(err, undefined, 4))
|
||||
}
|
||||
}
|
||||
|
||||
async saveFlat() {
|
||||
this.submitButton.disabled = true
|
||||
this.messageService.add(`saveFlat: ${ JSON.stringify(this.flat, undefined, 4) }`)
|
||||
if (this.flat.id == 0) {
|
||||
this.messageService.add("about to insert new flat")
|
||||
this.flat = await this.flatService.postFlat(this.flat)
|
||||
this.messageService.add(`Successfully added flat with id ${this.flat.id}`)
|
||||
} else {
|
||||
this.messageService.add("about to update existing flat")
|
||||
}
|
||||
this.router.navigate(['/flats'])
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.getPremises()
|
||||
this.getFlat()
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user