changes for details

This commit is contained in:
2021-09-01 17:58:49 +02:00
parent 5099e4ae63
commit 13c9cb4d96
16 changed files with 347 additions and 22 deletions

View File

@ -0,0 +1,39 @@
<section class="mat-typography">
<mat-card class="defaultCard">
<mat-card-header>
<mat-card-title>
{{premise?.description}}
</mat-card-title>
<mat-card-subtitle>
ID: {{premise?.id}}
</mat-card-subtitle>
</mat-card-header>
<mat-card-content>
<div>
<form (ngSubmit)="savePremise()">
<div>
<mat-form-field appearance="outline">
<mat-label>Beschreibung</mat-label>
<input matInput name="description" [(ngModel)]="premise.description"/>
</mat-form-field>
</div><div>
<mat-form-field appearance="outline">
<mat-label>Strasse</mat-label>
<input matInput name="street" [(ngModel)]="premise.street"/>
</mat-form-field>
</div><div>
<mat-form-field appearance="outline">
<mat-label>PLZ</mat-label>
<input matInput name="zip" [(ngModel)]="premise.zip"/>
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Ort</mat-label>
<input matInput name="city" [(ngModel)]="premise.city"/>
</mat-form-field>
</div>
<button #submitButton type="submit" mat-raised-button color="primary">Speichern</button>
</form>
</div>
</mat-card-content>
</mat-card>
</section>

View File

@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PremiseDetailsComponent } from './premise-details.component';
describe('PremiseDetailsComponent', () => {
let component: PremiseDetailsComponent;
let fixture: ComponentFixture<PremiseDetailsComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ PremiseDetailsComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(PremiseDetailsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,62 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatButton } from '@angular/material/button';
import { ActivatedRoute, Router } from '@angular/router';
import { PremiseService } from '../data-object-service';
import { Premise } from '../data-objects';
import { MessageService } from '../message.service';
@Component({
selector: 'app-premise-details',
templateUrl: './premise-details.component.html',
styleUrls: ['./premise-details.component.css']
})
export class PremiseDetailsComponent implements OnInit {
@ViewChild('submitButton') submitButton: MatButton
premise: Premise = {
id: 0,
description: '',
street: '',
zip: '',
city: ''
}
constructor(
private premiseService: PremiseService,
private messageService: MessageService,
private route: ActivatedRoute,
private router: Router
) { }
async getPremise(): Promise<void> {
try {
const id = +this.route.snapshot.paramMap.get('id')
if (id != 0) {
this.premise = await this.premiseService.getPremise(id)
}
} catch (err) {
this.messageService.add(JSON.stringify(err, undefined, 4))
}
}
async savePremise() {
this.submitButton.disabled = true
this.messageService.add("savePremise")
this.messageService.add(JSON.stringify(this.premise, undefined, 4))
if (this.premise.id == 0) {
this.messageService.add("about to insert new premise")
this.premise = await this.premiseService.postPremise(this.premise)
this.messageService.add(`Successfully added premises with id ${this.premise.id}`)
} else {
this.messageService.add("about to update existing premise")
}
this.router.navigate(['/premises'])
// this.submitButton.disabled = false
}
ngOnInit(): void {
this.getPremise()
}
}