fix(frontend/organizations): unfucked everything (again)
This commit is contained in:
@@ -20,7 +20,8 @@ import { publicationResolver } from './resolvers/publication-resolver';
|
||||
import { accountResolver } from './resolvers/account.resolver';
|
||||
import { accountViewerGuard } from './shared/guards/account-viewer.guard';
|
||||
import { accountsPageResolver } from './resolvers/accounts-page.resolver';
|
||||
import { organizationsResolver } from './resolvers/organizations.resolver';
|
||||
import { accountsOrganizationResolver } from './resolvers/accounts-organizations.resolver';
|
||||
import { organizationsOrganizationsResolver } from './resolvers/organizations-organizations.resolver';
|
||||
|
||||
export const routes: Routes = [
|
||||
{
|
||||
@@ -117,7 +118,7 @@ export const routes: Routes = [
|
||||
),
|
||||
resolve: {
|
||||
accountPage: accountsPageResolver,
|
||||
organizations: organizationsResolver,
|
||||
organizations: accountsOrganizationResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always',
|
||||
},
|
||||
@@ -128,7 +129,12 @@ export const routes: Routes = [
|
||||
import('./modules/organizations/organizations.component').then(
|
||||
(mod) => mod.OrganizationsComponent,
|
||||
),
|
||||
resolve: {
|
||||
organizationPage: organizationsOrganizationsResolver,
|
||||
},
|
||||
runGuardsAndResolvers: 'always',
|
||||
},
|
||||
|
||||
{
|
||||
path: 'news/:id',
|
||||
canActivate: [userGuard],
|
||||
|
||||
+17
-11
@@ -16,15 +16,22 @@ import {
|
||||
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';
|
||||
import { InseOrganizationManagementModelOrganizationProfile } from '../../../api';
|
||||
|
||||
export interface CreateOrganizationPayload {
|
||||
name: string;
|
||||
other_inst_id?: string | null;
|
||||
}
|
||||
|
||||
export interface UpdateOrganizationPayload {
|
||||
name?: string;
|
||||
other_inst_id?: string | null;
|
||||
deleted?: boolean;
|
||||
}
|
||||
|
||||
export interface OrganizationDialogData {
|
||||
mode: 'create' | 'edit';
|
||||
organization?: OrganizationProfile;
|
||||
organization?: InseOrganizationManagementModelOrganizationProfile;
|
||||
}
|
||||
|
||||
export type OrganizationDialogResult =
|
||||
@@ -66,10 +73,9 @@ export class OrganizationDialogComponent {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
otherInstId: new FormControl(
|
||||
this.data.organization?.other_inst_id ?? '',
|
||||
{ nonNullable: true },
|
||||
),
|
||||
otherInstId: new FormControl(this.data.organization?.other_inst_id ?? '', {
|
||||
nonNullable: true,
|
||||
}),
|
||||
deleted: new FormControl(this.data.organization?.deleted ?? false, {
|
||||
nonNullable: true,
|
||||
}),
|
||||
@@ -100,6 +106,6 @@ export class OrganizationDialogComponent {
|
||||
}
|
||||
|
||||
protected close(): void {
|
||||
this.dialogRef.close(undefined);
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<div>
|
||||
<h1>Organisationen</h1>
|
||||
<p>Mandanten, externe Institutions-IDs und Status verwalten.</p>
|
||||
<!-- Was meinte die KI mit Mandanten? -->
|
||||
</div>
|
||||
<button
|
||||
mat-flat-button
|
||||
@@ -14,92 +15,38 @@
|
||||
</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>
|
||||
<mat-card appearance="outlined">
|
||||
<mat-card-content>
|
||||
<app-data-table
|
||||
[columns]="organizationColumns"
|
||||
[data]="organizationPage().items" />
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
<app-query-param-paginator [total]="organizationPage().total" />
|
||||
</section>
|
||||
|
||||
<ng-template #organizationStatusTmp let-row>
|
||||
<span class="status" [class.status--deleted]="row.deleted">
|
||||
{{ (row.deleted ? 'inactive' : 'active') | status }}
|
||||
</span>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #organizationActionsTmp let-row>
|
||||
<div class="row-actions">
|
||||
<button
|
||||
mat-icon-button
|
||||
type="button"
|
||||
aria-label="Bearbeiten"
|
||||
(click)="startEdit(row)">
|
||||
<mat-icon>edit</mat-icon>
|
||||
</button>
|
||||
<button
|
||||
mat-icon-button
|
||||
type="button"
|
||||
aria-label="Deaktivieren"
|
||||
[disabled]="row.deleted"
|
||||
(click)="deleteOrganization(row)">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</ng-template>
|
||||
|
||||
@@ -5,15 +5,9 @@
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.page-header,
|
||||
.table-header,
|
||||
.pagination,
|
||||
.row-actions {
|
||||
.page-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
}
|
||||
@@ -32,60 +26,6 @@ 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;
|
||||
@@ -103,21 +43,6 @@ tr.deleted {
|
||||
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;
|
||||
@@ -128,3 +53,8 @@ tr.deleted {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
mat-card,
|
||||
mat-paginator {
|
||||
background-color: var(--sg-background);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,34 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { Component, OnInit, inject } from '@angular/core';
|
||||
import {
|
||||
Component,
|
||||
inject,
|
||||
input,
|
||||
OnInit,
|
||||
TemplateRef,
|
||||
viewChild,
|
||||
} 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';
|
||||
import {
|
||||
InseOrganizationManagementModelOrganizationProfile,
|
||||
OrganizationPage,
|
||||
OrganizationService,
|
||||
} from '../../api';
|
||||
import {
|
||||
GenericColumn,
|
||||
DataTableComponent,
|
||||
} from '../../shared/ui/data-table/data-table.component';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { StatusPipe } from '../../shared/pipes/status.pipe';
|
||||
import { QueryParamPaginatorComponent } from '../../shared/ui/query-param-paginator/query-param-paginator.component';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-organizations',
|
||||
@@ -23,50 +38,81 @@ import type {
|
||||
MatDialogModule,
|
||||
MatIconModule,
|
||||
MatSnackBarModule,
|
||||
DataTableComponent,
|
||||
MatCardModule,
|
||||
StatusPipe,
|
||||
QueryParamPaginatorComponent,
|
||||
],
|
||||
templateUrl: './organizations.component.html',
|
||||
styleUrl: './organizations.component.scss',
|
||||
standalone: true,
|
||||
})
|
||||
export class OrganizationsComponent implements OnInit {
|
||||
private readonly organizationService = inject(OrganizationManagementService);
|
||||
private readonly router = inject(Router);
|
||||
private readonly dialog = inject(MatDialog);
|
||||
private readonly snackBar = inject(MatSnackBar);
|
||||
private readonly organizationService = inject(OrganizationService);
|
||||
|
||||
protected organizations: OrganizationProfile[] = [];
|
||||
protected total = 0;
|
||||
protected page = 0;
|
||||
protected readonly pageSize = 10;
|
||||
protected isLoading = false;
|
||||
organizationPage = input.required<OrganizationPage>();
|
||||
organizationColumns: GenericColumn<InseOrganizationManagementModelOrganizationProfile>[] =
|
||||
[];
|
||||
|
||||
organizationStatusTmp = viewChild.required<TemplateRef<any>>(
|
||||
'organizationStatusTmp',
|
||||
);
|
||||
organizationActionsTmp = viewChild.required<TemplateRef<any>>(
|
||||
'organizationActionsTmp',
|
||||
);
|
||||
|
||||
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.'),
|
||||
});
|
||||
this.organizationColumns = [
|
||||
{
|
||||
id: 'name',
|
||||
header: 'Name',
|
||||
type: 'accessor',
|
||||
accessorKey: 'name',
|
||||
},
|
||||
{
|
||||
id: 'other_inst_id',
|
||||
header: 'Externe ID',
|
||||
type: 'accessor',
|
||||
accessorKey: 'other_inst_id',
|
||||
},
|
||||
{
|
||||
id: 'member_count',
|
||||
header: 'Mitglieder',
|
||||
type: 'accessor',
|
||||
accessorKey: 'member_count',
|
||||
},
|
||||
{
|
||||
id: 'deleted',
|
||||
header: 'Status',
|
||||
type: 'accessor',
|
||||
accessorKey: 'deleted',
|
||||
cellTemplate: this.organizationStatusTmp(),
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: 'Aktionen',
|
||||
type: 'display',
|
||||
cellTemplate: this.organizationActionsTmp(),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
protected startCreate(): void {
|
||||
this.openDialog({ mode: 'create' });
|
||||
}
|
||||
|
||||
protected startEdit(organization: OrganizationProfile): void {
|
||||
protected startEdit(
|
||||
organization: InseOrganizationManagementModelOrganizationProfile,
|
||||
): void {
|
||||
this.openDialog({ mode: 'edit', organization });
|
||||
}
|
||||
|
||||
protected deleteOrganization(organization: OrganizationProfile): void {
|
||||
protected deleteOrganization(
|
||||
organization: InseOrganizationManagementModelOrganizationProfile,
|
||||
): void {
|
||||
if (organization.deleted) return;
|
||||
|
||||
import('../../shared/ui/confirmation-dialog/confirmation-dialog.component').then(
|
||||
@@ -87,26 +133,24 @@ export class OrganizationsComponent implements OnInit {
|
||||
);
|
||||
}
|
||||
|
||||
private softDeleteOrganization(organization: OrganizationProfile): void {
|
||||
this.organizationService.deleteOrganization(organization.id).subscribe({
|
||||
private softDeleteOrganization(
|
||||
organization: InseOrganizationManagementModelOrganizationProfile,
|
||||
): void {
|
||||
this.organizationService.deleteOrganisation(organization.id).subscribe({
|
||||
next: () => {
|
||||
this.snackBar.open('Organisation wurde deaktiviert.', 'OK', {
|
||||
duration: 3000,
|
||||
});
|
||||
this.loadOrganizations();
|
||||
this.router.navigate([], {
|
||||
queryParams: { page: 0 },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
},
|
||||
error: () => this.showError('Organisation konnte nicht deaktiviert werden.'),
|
||||
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 }) => {
|
||||
@@ -130,8 +174,8 @@ export class OrganizationsComponent implements OnInit {
|
||||
private save(result: OrganizationDialogResult): void {
|
||||
const request =
|
||||
result.mode === 'create'
|
||||
? this.organizationService.createOrganization(result.payload)
|
||||
: this.organizationService.updateOrganization(
|
||||
? this.organizationService.createOrganisation(result.payload)
|
||||
: this.organizationService.updateOrganisation(
|
||||
result.organizationId,
|
||||
result.payload,
|
||||
);
|
||||
@@ -141,7 +185,10 @@ export class OrganizationsComponent implements OnInit {
|
||||
this.snackBar.open('Organisation wurde gespeichert.', 'OK', {
|
||||
duration: 3000,
|
||||
});
|
||||
this.loadOrganizations(0);
|
||||
this.router.navigate([], {
|
||||
queryParams: { page: 0 },
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
},
|
||||
error: (error) =>
|
||||
this.showError(
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
||||
InseAccountManagementModelOrganizationProfile,
|
||||
} from '../api';
|
||||
|
||||
export const organizationsResolver: ResolveFn<
|
||||
export const accountsOrganizationResolver: ResolveFn<
|
||||
InseAccountManagementModelOrganizationProfile[]
|
||||
> = (route, state) => {
|
||||
return inject(AuthService).listAccountOrganizations();
|
||||
@@ -0,0 +1,12 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { ResolveFn } from '@angular/router';
|
||||
import { OrganizationPage, OrganizationService } from '../api';
|
||||
|
||||
export const organizationsOrganizationsResolver: ResolveFn<
|
||||
OrganizationPage
|
||||
> = (route, state) => {
|
||||
const page = Number(route.queryParamMap.get('page') ?? '0');
|
||||
const size = Number(route.queryParamMap.get('size') ?? '10');
|
||||
|
||||
return inject(OrganizationService).getOrganisations(page, size);
|
||||
};
|
||||
@@ -1,75 +0,0 @@
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Configuration } from '../../api';
|
||||
|
||||
export interface OrganizationProfile {
|
||||
id: string;
|
||||
name: string;
|
||||
other_inst_id?: string | null;
|
||||
deleted: boolean;
|
||||
member_count: number;
|
||||
}
|
||||
|
||||
export interface OrganizationPage {
|
||||
items: OrganizationProfile[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
}
|
||||
|
||||
export interface CreateOrganizationPayload {
|
||||
name: string;
|
||||
other_inst_id?: string | null;
|
||||
}
|
||||
|
||||
export interface UpdateOrganizationPayload {
|
||||
name?: string;
|
||||
other_inst_id?: string | null;
|
||||
deleted?: boolean;
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class OrganizationManagementService {
|
||||
private readonly httpClient = inject(HttpClient);
|
||||
private readonly apiConfiguration = inject(Configuration, { optional: true });
|
||||
|
||||
getOrganizations(page: number, pageSize: number): Observable<OrganizationPage> {
|
||||
const params = new HttpParams()
|
||||
.set('page', page)
|
||||
.set('page_size', pageSize);
|
||||
return this.httpClient.get<OrganizationPage>(
|
||||
`${this.apiBasePath}/api/organizations`,
|
||||
{ params },
|
||||
);
|
||||
}
|
||||
|
||||
createOrganization(
|
||||
payload: CreateOrganizationPayload,
|
||||
): Observable<OrganizationProfile> {
|
||||
return this.httpClient.post<OrganizationProfile>(
|
||||
`${this.apiBasePath}/api/organizations`,
|
||||
payload,
|
||||
);
|
||||
}
|
||||
|
||||
updateOrganization(
|
||||
organizationId: string,
|
||||
payload: UpdateOrganizationPayload,
|
||||
): Observable<OrganizationProfile> {
|
||||
return this.httpClient.put<OrganizationProfile>(
|
||||
`${this.apiBasePath}/api/organizations/${organizationId}`,
|
||||
payload,
|
||||
);
|
||||
}
|
||||
|
||||
deleteOrganization(organizationId: string): Observable<void> {
|
||||
return this.httpClient.delete<void>(
|
||||
`${this.apiBasePath}/api/organizations/${organizationId}`,
|
||||
);
|
||||
}
|
||||
|
||||
private get apiBasePath(): string {
|
||||
return this.apiConfiguration?.basePath ?? '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user