more details pages
This commit is contained in:
@ -0,0 +1,31 @@
|
||||
<section class="mat-typography">
|
||||
<mat-card class="defaultCard">
|
||||
<mat-card-header>
|
||||
<mat-card-title>
|
||||
{{commercialPremise?.description}} {{premise?.description}}
|
||||
</mat-card-title>
|
||||
<mat-card-subtitle>
|
||||
ID: {{commercialPremise?.id}}
|
||||
</mat-card-subtitle>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<div>
|
||||
<form (ngSubmit)="saveCommercialPremise()">
|
||||
<div>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Beschreibung</mat-label>
|
||||
<input matInput name="description" [(ngModel)]="commercialPremise.description"/>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Haus</mat-label>
|
||||
<mat-select [(ngModel)]="commercialPremise.premise" name="premise">
|
||||
<mat-option *ngFor="let p of premises" [value]="p.id">{{p.description}}</mat-option>
|
||||
</mat-select>
|
||||
</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 { CommercialUnitDetailsComponent } from './commercial-unit-details.component';
|
||||
|
||||
describe('CommercialUnitDetailsComponent', () => {
|
||||
let component: CommercialUnitDetailsComponent;
|
||||
let fixture: ComponentFixture<CommercialUnitDetailsComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ CommercialUnitDetailsComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CommercialUnitDetailsComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,73 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { MatButton } from '@angular/material/button';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { CommercialPremiseService, PremiseService } from '../data-object-service';
|
||||
import { NULL_CommercialPremise, NULL_Premise, CommercialPremise, Premise } from '../data-objects';
|
||||
import { MessageService } from '../message.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-commercial-unit-details',
|
||||
templateUrl: './commercial-unit-details.component.html',
|
||||
styleUrls: ['./commercial-unit-details.component.css']
|
||||
})
|
||||
export class CommercialUnitDetailsComponent implements OnInit {
|
||||
|
||||
@ViewChild('submitButton') submitButton: MatButton
|
||||
|
||||
commercialPremise: CommercialPremise = NULL_CommercialPremise
|
||||
premise: Premise = NULL_Premise
|
||||
|
||||
premises: Premise[]
|
||||
|
||||
constructor(
|
||||
private commercialPremiseService: CommercialPremiseService,
|
||||
private premiseService: PremiseService,
|
||||
private messageService: MessageService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
|
||||
|
||||
async getCommercialPremise(): Promise<void> {
|
||||
try {
|
||||
const id = +this.route.snapshot.paramMap.get('id')
|
||||
if (id != 0) {
|
||||
this.commercialPremise = await this.commercialPremiseService.getCommercialPremise(id)
|
||||
this.premise = await this.premiseService.getPremise(this.commercialPremise.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 saveCommercialPremise() {
|
||||
this.submitButton.disabled = true
|
||||
this.messageService.add(`saveCommercialPremise: ${ JSON.stringify(this.commercialPremise, undefined, 4) }`)
|
||||
if (this.commercialPremise.id == 0) {
|
||||
this.messageService.add("about to insert new commercialPremise")
|
||||
this.commercialPremise = await this.commercialPremiseService.postCommercialPremise(this.commercialPremise)
|
||||
this.messageService.add(`Successfully added flat with id ${this.commercialPremise.id}`)
|
||||
} else {
|
||||
this.messageService.add("about to update existing commercialPremise")
|
||||
}
|
||||
this.router.navigate(['/commercialunits'])
|
||||
}
|
||||
|
||||
|
||||
ngOnInit(): void {
|
||||
this.getPremises()
|
||||
this.getCommercialPremise()
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user