implement organisation management
LocationBasedServices/smartguide/pipeline/head There was a failure building this commit
LocationBasedServices/smartguide/pipeline/pr-auth There was a failure building this commit

This commit is contained in:
2026-06-29 19:11:03 +02:00
parent c8179d44f6
commit 5a91887861
19 changed files with 1167 additions and 5 deletions
@@ -0,0 +1,38 @@
<h2 mat-dialog-title>
{{
data.mode === 'create'
? 'Organisation erstellen'
: 'Organisation bearbeiten'
}}
</h2>
<mat-dialog-content>
<form class="organization-form" [formGroup]="form" (ngSubmit)="submit()">
<mat-form-field appearance="outline">
<mat-label>Name</mat-label>
<input matInput formControlName="name" />
@if (form.controls.name.hasError('required')) {
<mat-error>Name ist erforderlich.</mat-error>
}
</mat-form-field>
<mat-form-field appearance="outline">
<mat-label>Externe Institutions-ID</mat-label>
<input matInput formControlName="otherInstId" />
</mat-form-field>
@if (data.mode === 'edit') {
<mat-checkbox formControlName="deleted">
Organisation als gelöscht markieren
</mat-checkbox>
}
</form>
</mat-dialog-content>
<mat-dialog-actions align="end">
<button mat-button type="button" (click)="close()">Abbrechen</button>
<button mat-flat-button color="primary" type="button" (click)="submit()">
<mat-icon>save</mat-icon>
Speichern
</button>
</mat-dialog-actions>
@@ -0,0 +1,20 @@
.organization-form {
display: grid;
gap: 12px;
min-width: min(540px, calc(100vw - 64px));
padding-top: 4px;
}
.organization-form mat-form-field {
width: 100%;
}
mat-dialog-actions {
padding: 12px 24px 20px;
}
@media (max-width: 600px) {
.organization-form {
min-width: 0;
}
}
@@ -0,0 +1,105 @@
import { CommonModule } from '@angular/common';
import { Component, inject } from '@angular/core';
import {
FormControl,
FormGroup,
ReactiveFormsModule,
Validators,
} from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatCheckboxModule } from '@angular/material/checkbox';
import {
MAT_DIALOG_DATA,
MatDialogModule,
MatDialogRef,
} from '@angular/material/dialog';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import type {
CreateOrganizationPayload,
OrganizationProfile,
UpdateOrganizationPayload,
} from '../../../shared/services/organization-management.service';
export interface OrganizationDialogData {
mode: 'create' | 'edit';
organization?: OrganizationProfile;
}
export type OrganizationDialogResult =
| { mode: 'create'; payload: CreateOrganizationPayload }
| {
mode: 'edit';
organizationId: string;
payload: UpdateOrganizationPayload;
};
@Component({
selector: 'app-organization-dialog',
imports: [
CommonModule,
ReactiveFormsModule,
MatButtonModule,
MatCheckboxModule,
MatDialogModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
],
templateUrl: './organization-dialog.component.html',
styleUrl: './organization-dialog.component.scss',
standalone: true,
})
export class OrganizationDialogComponent {
private readonly dialogRef =
inject<
MatDialogRef<
OrganizationDialogComponent,
OrganizationDialogResult | undefined
>
>(MatDialogRef);
protected readonly data = inject<OrganizationDialogData>(MAT_DIALOG_DATA);
protected readonly form = new FormGroup({
name: new FormControl(this.data.organization?.name ?? '', {
nonNullable: true,
validators: [Validators.required],
}),
otherInstId: new FormControl(
this.data.organization?.other_inst_id ?? '',
{ nonNullable: true },
),
deleted: new FormControl(this.data.organization?.deleted ?? false, {
nonNullable: true,
}),
});
protected submit(): void {
if (this.form.invalid) {
this.form.markAllAsTouched();
return;
}
const value = this.form.getRawValue();
const payload = {
name: value.name.trim(),
other_inst_id: value.otherInstId.trim(),
};
if (this.data.mode === 'create') {
this.dialogRef.close({ mode: 'create', payload });
return;
}
this.dialogRef.close({
mode: 'edit',
organizationId: this.data.organization!.id,
payload: { ...payload, deleted: value.deleted },
});
}
protected close(): void {
this.dialogRef.close(undefined);
}
}
@@ -0,0 +1,105 @@
<section class="organizations-page">
<header class="page-header">
<div>
<h1>Organisationen</h1>
<p>Mandanten, externe Institutions-IDs und Status verwalten.</p>
</div>
<button
mat-flat-button
color="primary"
type="button"
(click)="startCreate()">
<mat-icon>add_business</mat-icon>
Neue Organisation
</button>
</header>
<section class="table-panel">
<div class="table-header">
<strong>{{ total }} Organisationen</strong>
@if (isLoading) {
<span>Wird geladen...</span>
}
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Name</th>
<th>Externe Institutions-ID</th>
<th>Mitglieder</th>
<th>Status</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody>
@for (organization of organizations; track organization.id) {
<tr [class.deleted]="organization.deleted">
<td>
<button
class="link-button"
type="button"
(click)="startEdit(organization)">
{{ organization.name }}
</button>
</td>
<td>{{ organization.other_inst_id || '–' }}</td>
<td>{{ organization.member_count }}</td>
<td>
<span
class="status"
[class.status--deleted]="organization.deleted">
{{ organization.deleted ? 'deleted' : 'active' }}
</span>
</td>
<td>
<div class="row-actions">
<button
mat-icon-button
type="button"
aria-label="Bearbeiten"
(click)="startEdit(organization)">
<mat-icon>edit</mat-icon>
</button>
<button
mat-icon-button
type="button"
aria-label="Deaktivieren"
[disabled]="organization.deleted"
(click)="deleteOrganization(organization)">
<mat-icon>delete</mat-icon>
</button>
</div>
</td>
</tr>
} @empty {
<tr>
<td colspan="6" class="empty">Keine Organisationen gefunden.</td>
</tr>
}
</tbody>
</table>
</div>
<div class="pagination">
<button
mat-button
type="button"
[disabled]="!canPageBack"
(click)="loadOrganizations(page - 1)">
<mat-icon>chevron_left</mat-icon>
Zurück
</button>
<span>Seite {{ page + 1 }}</span>
<button
mat-button
type="button"
[disabled]="!canPageForward"
(click)="loadOrganizations(page + 1)">
Weiter
<mat-icon>chevron_right</mat-icon>
</button>
</div>
</section>
</section>
@@ -0,0 +1,130 @@
.organizations-page {
display: flex;
flex-direction: column;
gap: 20px;
padding: 24px;
}
.page-header,
.table-header,
.pagination,
.row-actions {
display: flex;
align-items: center;
}
.page-header {
justify-content: space-between;
gap: 16px;
}
h1,
p {
margin: 0;
}
.page-header p,
.table-header span {
color: #64748b;
}
.page-header p {
margin-top: 6px;
}
.table-panel {
overflow: hidden;
border: 1px solid #d7dde6;
border-radius: 8px;
background: #fff;
}
.table-header {
justify-content: space-between;
padding: 16px;
border-bottom: 1px solid #e5e7eb;
}
.table-wrap {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
padding: 12px 16px;
text-align: left;
border-bottom: 1px solid #edf1f7;
white-space: nowrap;
}
th {
color: #475569;
font-weight: 700;
background: #f8fafc;
}
tr.deleted {
color: #94a3b8;
}
.identifier {
font-family: monospace;
font-size: 12px;
}
.link-button {
border: 0;
background: transparent;
color: #1d4ed8;
padding: 0;
font: inherit;
cursor: pointer;
}
.status {
display: inline-flex;
align-items: center;
min-height: 24px;
border-radius: 999px;
padding: 2px 10px;
background: #dcfce7;
color: #166534;
font-size: 12px;
font-weight: 700;
}
.status--deleted {
background: #fee2e2;
color: #991b1b;
}
.row-actions {
gap: 4px;
}
.empty {
color: #64748b;
text-align: center;
}
.pagination {
justify-content: flex-end;
gap: 8px;
padding: 12px 16px;
}
@media (max-width: 640px) {
.organizations-page {
padding: 16px;
}
.page-header {
align-items: flex-start;
flex-direction: column;
}
}
@@ -0,0 +1,158 @@
import { CommonModule } from '@angular/common';
import { Component, OnInit, inject } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
import { finalize } from 'rxjs';
import {
OrganizationManagementService,
OrganizationProfile,
} from '../../shared/services/organization-management.service';
import type {
OrganizationDialogComponent,
OrganizationDialogData,
OrganizationDialogResult,
} from './organization-dialog/organization-dialog.component';
@Component({
selector: 'app-organizations',
imports: [
CommonModule,
MatButtonModule,
MatDialogModule,
MatIconModule,
MatSnackBarModule,
],
templateUrl: './organizations.component.html',
styleUrl: './organizations.component.scss',
standalone: true,
})
export class OrganizationsComponent implements OnInit {
private readonly organizationService = inject(OrganizationManagementService);
private readonly dialog = inject(MatDialog);
private readonly snackBar = inject(MatSnackBar);
protected organizations: OrganizationProfile[] = [];
protected total = 0;
protected page = 0;
protected readonly pageSize = 10;
protected isLoading = false;
ngOnInit(): void {
this.loadOrganizations();
}
protected loadOrganizations(page = this.page): void {
this.page = page;
this.isLoading = true;
this.organizationService
.getOrganizations(page, this.pageSize)
.pipe(finalize(() => (this.isLoading = false)))
.subscribe({
next: (result) => {
this.organizations = result.items;
this.total = result.total;
},
error: () => this.showError('Organisationen konnten nicht geladen werden.'),
});
}
protected startCreate(): void {
this.openDialog({ mode: 'create' });
}
protected startEdit(organization: OrganizationProfile): void {
this.openDialog({ mode: 'edit', organization });
}
protected deleteOrganization(organization: OrganizationProfile): void {
if (organization.deleted) return;
import('../../shared/ui/confirmation-dialog/confirmation-dialog.component').then(
({ ConfirmationDialogComponent }) => {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
data: {
title: 'Organisation deaktivieren',
message: `Möchtest Du die Organisation „${organization.name}“ wirklich deaktivieren?`,
confirmText: 'Deaktivieren',
cancelText: 'Abbrechen',
},
});
dialogRef.componentInstance.confirmDelete.subscribe(() => {
this.softDeleteOrganization(organization);
});
},
);
}
private softDeleteOrganization(organization: OrganizationProfile): void {
this.organizationService.deleteOrganization(organization.id).subscribe({
next: () => {
this.snackBar.open('Organisation wurde deaktiviert.', 'OK', {
duration: 3000,
});
this.loadOrganizations();
},
error: () => this.showError('Organisation konnte nicht deaktiviert werden.'),
});
}
protected get canPageBack(): boolean {
return this.page > 0;
}
protected get canPageForward(): boolean {
return (this.page + 1) * this.pageSize < this.total;
}
private openDialog(data: OrganizationDialogData): void {
import('./organization-dialog/organization-dialog.component').then(
({ OrganizationDialogComponent }) => {
const dialogRef = this.dialog.open<
OrganizationDialogComponent,
OrganizationDialogData,
OrganizationDialogResult | undefined
>(OrganizationDialogComponent, {
width: '620px',
maxWidth: 'calc(100vw - 32px)',
data,
});
dialogRef.afterClosed().subscribe((result) => {
if (result) this.save(result);
});
},
);
}
private save(result: OrganizationDialogResult): void {
const request =
result.mode === 'create'
? this.organizationService.createOrganization(result.payload)
: this.organizationService.updateOrganization(
result.organizationId,
result.payload,
);
request.subscribe({
next: () => {
this.snackBar.open('Organisation wurde gespeichert.', 'OK', {
duration: 3000,
});
this.loadOrganizations(0);
},
error: (error) =>
this.showError(
error.status === 409
? 'Eine Organisation mit diesem Namen existiert bereits.'
: 'Organisation konnte nicht gespeichert werden.',
),
});
}
private showError(message: string): void {
this.snackBar.open(message, 'OK', { duration: 5000 });
}
}