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>
|
||||
{{parking?.description}} {{premise?.description}}
|
||||
</mat-card-title>
|
||||
<mat-card-subtitle>
|
||||
ID: {{parking?.id}}
|
||||
</mat-card-subtitle>
|
||||
</mat-card-header>
|
||||
<mat-card-content>
|
||||
<div>
|
||||
<form (ngSubmit)="saveParking()">
|
||||
<div>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Beschreibung</mat-label>
|
||||
<input matInput name="description" [(ngModel)]="parking.description"/>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Haus</mat-label>
|
||||
<mat-select [(ngModel)]="parking.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 { ParkingDetailsComponent } from './parking-details.component';
|
||||
|
||||
describe('ParkingDetailsComponent', () => {
|
||||
let component: ParkingDetailsComponent;
|
||||
let fixture: ComponentFixture<ParkingDetailsComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ ParkingDetailsComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ParkingDetailsComponent);
|
||||
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 { ParkingService, PremiseService } from '../data-object-service';
|
||||
import { NULL_Parking, NULL_Premise, Parking, Premise } from '../data-objects';
|
||||
import { MessageService } from '../message.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-parking-details',
|
||||
templateUrl: './parking-details.component.html',
|
||||
styleUrls: ['./parking-details.component.css']
|
||||
})
|
||||
export class ParkingDetailsComponent implements OnInit {
|
||||
|
||||
@ViewChild('submitButton') submitButton: MatButton
|
||||
|
||||
parking: Parking = NULL_Parking
|
||||
premise: Premise = NULL_Premise
|
||||
|
||||
premises: Premise[]
|
||||
|
||||
constructor(
|
||||
private parkingService: ParkingService,
|
||||
private premiseService: PremiseService,
|
||||
private messageService: MessageService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
|
||||
|
||||
async getParking(): Promise<void> {
|
||||
try {
|
||||
const id = +this.route.snapshot.paramMap.get('id')
|
||||
if (id != 0) {
|
||||
this.parking = await this.parkingService.getParking(id)
|
||||
this.premise = await this.premiseService.getPremise(this.parking.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 saveParking() {
|
||||
this.submitButton.disabled = true
|
||||
this.messageService.add(`saveParking: ${ JSON.stringify(this.parking, undefined, 4) }`)
|
||||
if (this.parking.id == 0) {
|
||||
this.messageService.add("about to insert new parking")
|
||||
this.parking = await this.parkingService.postParking(this.parking)
|
||||
this.messageService.add(`Successfully added flat with id ${this.parking.id}`)
|
||||
} else {
|
||||
this.messageService.add("about to update existing parking")
|
||||
}
|
||||
this.router.navigate(['/parkings'])
|
||||
}
|
||||
|
||||
|
||||
ngOnInit(): void {
|
||||
this.getPremises()
|
||||
this.getParking()
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user