Refactor application structure to use WorkspaceService for state management
- Removed direct state management from components and centralized it in WorkspaceService. - Updated ApartmentsPage, TenantsPage, LeasesPage, and DashboardPage to utilize WorkspaceService for data handling. - Introduced SessionService to manage user session state and authentication. - Simplified component templates to reflect new service-based architecture. - Removed unused ConfigService and its tests. - Added lease.html template for lease document generation. - Created app.routes.spec.ts for route mapping tests.
This commit is contained in:
1 parent
be1f680a62
commit
82f339e209
33 files changed
+292
-929
No files matched your search
@@ -10,7 +10,7 @@
|
||||
<span aria-hidden="true">+</span> Ajouter un locataire
|
||||
</button>
|
||||
</header>
|
||||
@if (tenants().length === 0) {
|
||||
@if (workspace.tenants().length === 0) {
|
||||
<article class="empty-state">
|
||||
<p class="eyebrow">Premier dossier</p>
|
||||
<h2>Aucun locataire enregistré</h2>
|
||||
@@ -21,14 +21,14 @@
|
||||
</article>
|
||||
} @else {
|
||||
<div class="tenant-grid">
|
||||
@for (tenant of tenants(); track tenant.id) {
|
||||
@for (tenant of workspace.tenants(); track tenant.id) {
|
||||
<app-tenant-card
|
||||
[tenant]="tenant"
|
||||
[attachmentError]="attachmentError()"
|
||||
[attachmentError]="workspace.tenantAttachmentError()"
|
||||
(editRequested)="openEditForm($event)"
|
||||
(deleteRequested)="deleteRequested.emit($event)"
|
||||
(attachmentUploadRequested)="attachmentUploadRequested.emit($event)"
|
||||
(attachmentDownloadRequested)="attachmentDownloadRequested.emit($event)"
|
||||
(deleteRequested)="workspace.deleteTenant($event)"
|
||||
(attachmentUploadRequested)="workspace.uploadTenantAttachment($event.tenantId, $event.file)"
|
||||
(attachmentDownloadRequested)="workspace.downloadTenantAttachment($event.tenantId, $event.attachment)"
|
||||
/>
|
||||
}
|
||||
</div>
|
||||
@@ -38,6 +38,6 @@
|
||||
<app-tenant-form
|
||||
[tenant]="editingTenant()"
|
||||
(cancelled)="closeForm()"
|
||||
(submitted)="tenantSaved.emit($event); closeForm()"
|
||||
(submitted)="workspace.saveTenant($event.tenant, editingTenant()?.id); closeForm()"
|
||||
/>
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { TenantsPage } from './tenants-page';
|
||||
import { WorkspaceService } from '../../services/workspace.service';
|
||||
|
||||
describe('TenantsPage', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({ providers: [{ provide: WorkspaceService, useValue: { loadTenants: () => undefined } }] }));
|
||||
|
||||
it('opens and closes the focused tenant form module', () => {
|
||||
const fixture = TestBed.createComponent(TenantsPage);
|
||||
fixture.componentRef.setInput('tenants', []);
|
||||
const component = fixture.componentInstance;
|
||||
|
||||
component.openAddForm();
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { Component, input, output, signal } from '@angular/core';
|
||||
import { Component, inject, signal } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { Tenant } from '../../services/tenant.service';
|
||||
import { TenantCard, TenantAttachmentRequest } from '../tenant-card/tenant-card';
|
||||
import { TenantForm, TenantSaveRequest } from '../tenant-form/tenant-form';
|
||||
|
||||
export type { TenantAttachmentRequest, TenantSaveRequest };
|
||||
import { WorkspaceService } from '../../services/workspace.service';
|
||||
import { TenantCard } from '../tenant-card/tenant-card';
|
||||
import { TenantForm } from '../tenant-form/tenant-form';
|
||||
|
||||
@Component({
|
||||
selector: 'app-tenants-page',
|
||||
@@ -13,16 +12,13 @@ export type { TenantAttachmentRequest, TenantSaveRequest };
|
||||
styleUrl: './tenants-page.css',
|
||||
})
|
||||
export class TenantsPage {
|
||||
readonly tenants = input.required<Tenant[]>();
|
||||
readonly attachmentError = input('');
|
||||
readonly tenantSaved = output<TenantSaveRequest>();
|
||||
readonly deleteRequested = output<string>();
|
||||
readonly attachmentUploadRequested = output<{ tenantId: string; file: File }>();
|
||||
readonly attachmentDownloadRequested = output<TenantAttachmentRequest>();
|
||||
readonly workspace = inject(WorkspaceService);
|
||||
|
||||
readonly showForm = signal(false);
|
||||
readonly editingTenant = signal<Tenant | null>(null);
|
||||
|
||||
constructor() { this.workspace.loadTenants(); }
|
||||
|
||||
openAddForm(): void {
|
||||
this.editingTenant.set(null);
|
||||
this.showForm.set(true);
|
||||
|
||||
Reference in new issue
Block a user