43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { Component, inject, signal } from '@angular/core';
|
|
import { Apartment } from '../../services/apartment.service';
|
|
import { WorkspaceService } from '../../services/workspace.service';
|
|
import { ApartmentForm } from '../apartment-form/apartment-form';
|
|
import { ApartmentList } from '../apartment-list/apartment-list';
|
|
|
|
@Component({
|
|
selector: 'app-apartments-page',
|
|
imports: [ApartmentForm, ApartmentList],
|
|
templateUrl: './apartments-page.html',
|
|
})
|
|
export class ApartmentsPage {
|
|
readonly workspace = inject(WorkspaceService);
|
|
|
|
readonly showForm = signal(false);
|
|
readonly editingApartment = signal<Apartment | null>(null);
|
|
|
|
constructor() {
|
|
this.workspace.loadApartments();
|
|
}
|
|
|
|
openAddForm(): void {
|
|
this.workspace.clearApartmentSaveError();
|
|
this.editingApartment.set(null);
|
|
this.showForm.set(true);
|
|
}
|
|
|
|
openEditForm(apartment: Apartment): void {
|
|
this.workspace.clearApartmentSaveError(apartment.id);
|
|
this.editingApartment.set(apartment);
|
|
this.showForm.set(true);
|
|
}
|
|
|
|
closeForm(): void {
|
|
this.showForm.set(false);
|
|
this.editingApartment.set(null);
|
|
}
|
|
|
|
saveApartment(apartment: Apartment): void {
|
|
this.workspace.saveApartment(apartment, this.editingApartment()?.id, () => this.closeForm());
|
|
}
|
|
}
|