diff --git a/webapp/src/app/api/model/hierarchyResponse.ts b/webapp/src/app/api/model/hierarchyResponse.ts index f92a3d60..8926ca31 100644 --- a/webapp/src/app/api/model/hierarchyResponse.ts +++ b/webapp/src/app/api/model/hierarchyResponse.ts @@ -13,5 +13,6 @@ export interface HierarchyResponse { hierarchy: Array; can_edit?: boolean; can_suggest?: boolean; + can_review?: boolean; number_of_suggestion_slots?: number; } diff --git a/webapp/src/app/api/model/hierarchySuggestion.ts b/webapp/src/app/api/model/hierarchySuggestion.ts index b430d33c..efa87a5c 100644 --- a/webapp/src/app/api/model/hierarchySuggestion.ts +++ b/webapp/src/app/api/model/hierarchySuggestion.ts @@ -14,6 +14,8 @@ export interface HierarchySuggestion { created_at: string; status: HierarchySuggestion.StatusEnum; active: boolean; + institution: string; + suggested_by: string; hierarchy: Array; } export namespace HierarchySuggestion { diff --git a/webapp/src/app/modules/hierarchy/hierarchy-chart/hierarchy-chart.component.html b/webapp/src/app/modules/hierarchy/hierarchy-chart/hierarchy-chart.component.html index dafd0e09..cebd0d75 100644 --- a/webapp/src/app/modules/hierarchy/hierarchy-chart/hierarchy-chart.component.html +++ b/webapp/src/app/modules/hierarchy/hierarchy-chart/hierarchy-chart.component.html @@ -33,27 +33,13 @@ can_edit() ? 1 : number_of_suggestion_slots() " [isManager]="can_edit()" + [editorStatus]=" + pendingSuggestion()?.status === 'new' ? 'in-progress' : null + " (saved)="onHierarchySaved($event)"> } - @if (can_edit()) { - - } @else if (can_suggest()) { - - } + - } - - } - } - - - - diff --git a/webapp/src/app/modules/hierarchy/hierarchy-chart/hierarchy-suggestions-dialog/hierarchy-suggestions-dialog.component.scss b/webapp/src/app/modules/hierarchy/hierarchy-chart/hierarchy-suggestions-dialog/hierarchy-suggestions-dialog.component.scss deleted file mode 100644 index 161b7aab..00000000 --- a/webapp/src/app/modules/hierarchy/hierarchy-chart/hierarchy-suggestions-dialog/hierarchy-suggestions-dialog.component.scss +++ /dev/null @@ -1,46 +0,0 @@ -.suggestion { - display: flex; - align-items: center; - justify-content: space-between; - margin: 0 0 12px; - width: 100%; - text-align: left; -} - -.suggestion-details { - display: flex; - align-items: center; - gap: 12px; -} - -.suggestion-history { - opacity: 0.75; -} - -.suggestion-status { - border-radius: 12px; - padding: 2px 10px; - font-size: 0.85rem; - font-weight: 500; -} - -.suggestion-active { - color: #2e7d32; - font-size: 0.85rem; - font-weight: 600; -} - -.status-new { - background: #e3f2fd; - color: #1565c0; -} - -.status-accepted { - background: #e8f5e9; - color: #2e7d32; -} - -.status-rejected { - background: #ffebee; - color: #c62828; -} diff --git a/webapp/src/app/modules/hierarchy/hierarchy-chart/hierarchy-suggestions-dialog/hierarchy-suggestions-dialog.component.ts b/webapp/src/app/modules/hierarchy/hierarchy-chart/hierarchy-suggestions-dialog/hierarchy-suggestions-dialog.component.ts deleted file mode 100644 index cc7b6003..00000000 --- a/webapp/src/app/modules/hierarchy/hierarchy-chart/hierarchy-suggestions-dialog/hierarchy-suggestions-dialog.component.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { Component, Inject } from '@angular/core'; -import { CommonModule, DatePipe } from '@angular/common'; -import { - MAT_DIALOG_DATA, - MatDialogModule, - MatDialogRef, -} from '@angular/material/dialog'; -import { MatButtonModule } from '@angular/material/button'; -import { HierarchySuggestion } from '../../../../api/model/hierarchySuggestion'; - -export interface HierarchySuggestionsDialogData { - suggestions: HierarchySuggestion[]; - canReview?: boolean; -} - -export interface HierarchySuggestionDecision { - suggestion: HierarchySuggestion; - action: 'review' | 'reject'; -} - -/** Displays suggestion history, read-only for users and actionable for managers. */ -@Component({ - standalone: true, - imports: [CommonModule, DatePipe, MatDialogModule, MatButtonModule], - templateUrl: './hierarchy-suggestions-dialog.component.html', - styleUrls: ['./hierarchy-suggestions-dialog.component.scss'], -}) -export class HierarchySuggestionsDialogComponent { - constructor( - private readonly dialogRef: MatDialogRef< - HierarchySuggestionsDialogComponent, - HierarchySuggestionDecision | undefined - >, - @Inject(MAT_DIALOG_DATA) - readonly data: HierarchySuggestionsDialogData, - ) {} - - review(suggestion: HierarchySuggestion): void { - if (!this.data.canReview) return; - this.dialogRef.close({ - suggestion, - action: 'review', - }); - } - - reject(suggestion: HierarchySuggestion): void { - if (!this.data.canReview) return; - this.dialogRef.close({ suggestion, action: 'reject' }); - } - - close(): void { - this.dialogRef.close(); - } - - statusLabel(status: HierarchySuggestion.StatusEnum): string { - switch (status) { - case HierarchySuggestion.StatusEnum.New: - return 'Neu'; - case HierarchySuggestion.StatusEnum.Accepted: - return 'Angenommen'; - case HierarchySuggestion.StatusEnum.Rejected: - return 'Abgelehnt'; - } - } -} diff --git a/webapp/src/app/modules/hierarchy/hierarchy-suggestions/hierarchy-suggestions.component.html b/webapp/src/app/modules/hierarchy/hierarchy-suggestions/hierarchy-suggestions.component.html new file mode 100644 index 00000000..9d8c1eb5 --- /dev/null +++ b/webapp/src/app/modules/hierarchy/hierarchy-suggestions/hierarchy-suggestions.component.html @@ -0,0 +1,18 @@ + + + + + + + + + {{ statusLabel(suggestion.status) }} + diff --git a/webapp/src/app/modules/hierarchy/hierarchy-suggestions/hierarchy-suggestions.component.ts b/webapp/src/app/modules/hierarchy/hierarchy-suggestions/hierarchy-suggestions.component.ts new file mode 100644 index 00000000..fe732b1b --- /dev/null +++ b/webapp/src/app/modules/hierarchy/hierarchy-suggestions/hierarchy-suggestions.component.ts @@ -0,0 +1,166 @@ +import { + Component, + AfterViewInit, + TemplateRef, + inject, + input, + output, + viewChild, +} from '@angular/core'; +import { MatButtonModule } from '@angular/material/button'; +import { MatDialog } from '@angular/material/dialog'; +import { MatSnackBar } from '@angular/material/snack-bar'; +import { + DataTableComponent, + GenericColumn, +} from '../../../shared/ui/data-table/data-table.component'; +import { HierarchySuggestion } from '../../../api/model/hierarchySuggestion'; +import { OrgminerService } from '../../../api/api/orgminer.service'; +import { HierarchyTreeEditorComponent } from '../hierarchy-chart/hierarchy-tree-editor/hierarchy-tree-editor.component'; +import type { RawNode } from '../hierarchy-chart/hierarchy-chart.component'; +import type { HierarchyEditorDialogData } from '../hierarchy-chart/hierarchy-edit-dialog/hierarchy-edit-dialog.component'; + +@Component({ + selector: 'app-hierarchy-suggestions', + standalone: true, + imports: [MatButtonModule, DataTableComponent], + templateUrl: './hierarchy-suggestions.component.html', +}) +export class HierarchySuggestionsComponent implements AfterViewInit { + readonly suggestions = input.required(); + readonly reload = output(); + + readonly actionTemplate = + viewChild.required>('actionTemplate'); + readonly statusTemplate = + viewChild.required>('statusTemplate'); + readonly columns: GenericColumn[] = [ + { + id: 'created_at', + header: 'Datum', + type: 'accessor', + accessorKey: 'created_at', + }, + { + id: 'institution', + header: 'Institution', + type: 'accessor', + accessorKey: 'institution', + }, + { + id: 'suggested_by', + header: 'Vorgeschlagen von', + type: 'accessor', + accessorKey: 'suggested_by', + }, + { id: 'status', header: 'Status', type: 'display' }, + { id: 'actions', header: 'Aktionen', type: 'display' }, + ]; + + private readonly dialog = inject(MatDialog); + private readonly orgminerService = inject(OrgminerService); + private readonly snackBar = inject(MatSnackBar); + + ngAfterViewInit(): void { + const statusColumn = this.columns.find((column) => column.id === 'status'); + const actionColumn = this.columns.find((column) => column.id === 'actions'); + if (statusColumn) statusColumn.cellTemplate = this.statusTemplate(); + if (actionColumn) actionColumn.cellTemplate = this.actionTemplate(); + } + + statusLabel(status: HierarchySuggestion.StatusEnum): string { + return status === HierarchySuggestion.StatusEnum.New + ? 'In Bearbeitung' + : status === HierarchySuggestion.StatusEnum.Accepted + ? 'Angenommen' + : 'Abgelehnt'; + } + + review(suggestion: HierarchySuggestion): void { + const children = suggestion.hierarchy as RawNode[]; + const tree: RawNode = { + id: 'suggestion-root', + name_de: 'Universität', + name_en: 'University', + type: 'university', + children, + }; + this.assignIds(children, 'suggestion-root'); + + const dialogRef = this.dialog.open< + HierarchyTreeEditorComponent, + HierarchyEditorDialogData, + RawNode | { action: 'reject' } + >(HierarchyTreeEditorComponent, { + data: { + tree, + numberOfSuggestions: 1, + isManager: true, + isSuggestion: true, + suggestionStatus: suggestion.status, + }, + width: '65%', + maxWidth: '95vw', + maxHeight: '90vh', + panelClass: 'hierarchy-edit-dialog-panel', + }); + + dialogRef.afterClosed().subscribe((result) => { + if (!result) return; + if ('action' in result) { + this.reject(suggestion); + } else { + this.accept(suggestion, result.children ?? []); + } + }); + } + + private assignIds(nodes: RawNode[], parentId: string): void { + nodes.forEach((node, index) => { + node.id = `${parentId}-${index}`; + if (node.children) this.assignIds(node.children, node.id); + }); + } + + private accept(suggestion: HierarchySuggestion, hierarchy: RawNode[]): void { + this.orgminerService + .acceptHierarchySuggestion(suggestion.id, hierarchy) + .subscribe({ + next: () => { + this.snackBar.open('Vorschlag angenommen.', 'OK', { duration: 3000 }); + this.reload.emit(); + }, + error: (error) => { + console.error( + '[HierarchySuggestions] error accepting suggestion:', + error, + ); + this.snackBar.open( + 'Vorschlag konnte nicht angenommen werden.', + 'OK', + { + duration: 3000, + }, + ); + }, + }); + } + + private reject(suggestion: HierarchySuggestion): void { + this.orgminerService.rejectHierarchySuggestion(suggestion.id).subscribe({ + next: () => { + this.snackBar.open('Vorschlag abgelehnt.', 'OK', { duration: 3000 }); + this.reload.emit(); + }, + error: (error) => { + console.error( + '[HierarchySuggestions] error rejecting suggestion:', + error, + ); + this.snackBar.open('Vorschlag konnte nicht abgelehnt werden.', 'OK', { + duration: 3000, + }); + }, + }); + } +} diff --git a/webapp/src/app/modules/hierarchy/hierarchy.component.html b/webapp/src/app/modules/hierarchy/hierarchy.component.html index db11faab..fd478628 100644 --- a/webapp/src/app/modules/hierarchy/hierarchy.component.html +++ b/webapp/src/app/modules/hierarchy/hierarchy.component.html @@ -1,10 +1,19 @@
-
Organizationsstruktur
+ @if (suggestionsOnly()) { +
Hierarchie-Vorschläge
+ } @else { +
Organizationsstruktur
+ } @if (!hierarchyData()) {
Keine Hierarchie-Daten verfügbar.
} @else { + @if (suggestionsOnly()) { + + } @else { + [pendingSuggestion]=" + suggestions().find((suggestion) => suggestion.status === 'new') ?? null + " + (analyzeOrgEvent)="analyzeOrg($event)" + (suggestionSaved)="reloadSuggestions()" /> @if (orgUrl()) { } + } }
diff --git a/webapp/src/app/modules/hierarchy/hierarchy.component.scss b/webapp/src/app/modules/hierarchy/hierarchy.component.scss index ba323d42..5c656d1d 100644 --- a/webapp/src/app/modules/hierarchy/hierarchy.component.scss +++ b/webapp/src/app/modules/hierarchy/hierarchy.component.scss @@ -37,3 +37,7 @@ mat-panel-description { app-hierarchy-chart { height: 100%; } + +.suggestions-only-chart { + display: none; +} diff --git a/webapp/src/app/modules/hierarchy/hierarchy.component.ts b/webapp/src/app/modules/hierarchy/hierarchy.component.ts index 32c704e3..f13daeb1 100644 --- a/webapp/src/app/modules/hierarchy/hierarchy.component.ts +++ b/webapp/src/app/modules/hierarchy/hierarchy.component.ts @@ -5,6 +5,7 @@ import { input, OnInit, signal, + computed, } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { ActivatedRoute, Router } from '@angular/router'; @@ -14,6 +15,9 @@ import { ClassifiedPagesComponent } from './classified-pages/classified-pages.co import { MatExpansionModule } from '@angular/material/expansion'; import { MatIconModule } from '@angular/material/icon'; import { HierarchyResponse } from '../../api/model/hierarchyResponse'; +import { CredentialService } from '../../shared/services/credential.service'; +import { HierarchySuggestionsComponent } from './hierarchy-suggestions/hierarchy-suggestions.component'; +import { HierarchySuggestion } from '../../api/model/hierarchySuggestion'; const ORGANIZATION_URL_PARAM = 'orgUrl'; const ORGANIZATION_NAME_PARAM = 'orgName'; const ORGMINER_EXPANDED_PARAM = 'orgExpanded'; @@ -33,12 +37,14 @@ const CLASSIFIED_PAGES_PANEL_PARAM = 'classifiedPagesExpanded'; ClassifiedPagesComponent, MatExpansionModule, MatIconModule, + HierarchySuggestionsComponent, ], templateUrl: './hierarchy.component.html', styleUrl: './hierarchy.component.scss', }) export class HierarchyComponent implements OnInit { hierarchyData = input.required(); + suggestions = input([]); hierarchyExpanded = signal(true); organizationExpanded = signal(true); classifiedPagesExpanded = signal(false); @@ -47,6 +53,10 @@ export class HierarchyComponent implements OnInit { private readonly router = inject(Router); private readonly route = inject(ActivatedRoute); private readonly destroyRef = inject(DestroyRef); + readonly credentialService = inject(CredentialService); + readonly suggestionsOnly = computed(() => + this.credentialService.isEffectiveSuperAdmin(), + ); ngOnInit(): void { this.route.queryParamMap .pipe(takeUntilDestroyed(this.destroyRef)) @@ -73,6 +83,10 @@ export class HierarchyComponent implements OnInit { }); } + reloadSuggestions(): void { + void this.router.navigateByUrl(this.router.url); + } + onHierarchyExpandedChange(expanded: boolean): void { this.hierarchyExpanded.set(expanded); this.syncPanelState({ [HIERARCHY_PANEL_PARAM]: expanded }); diff --git a/webapp/src/app/resolvers/hierarchy.resolver.ts b/webapp/src/app/resolvers/hierarchy.resolver.ts index 0fbb7f14..bc609eff 100644 --- a/webapp/src/app/resolvers/hierarchy.resolver.ts +++ b/webapp/src/app/resolvers/hierarchy.resolver.ts @@ -2,7 +2,18 @@ import { ResolveFn } from '@angular/router'; import { inject } from '@angular/core'; import { OrgminerService } from '../api'; import { HierarchyResponse } from '../api/model/hierarchyResponse'; - +import { HierarchySuggestion } from '../api/model/hierarchySuggestion'; +import { CredentialService } from '../shared/services/credential.service'; export const hierarchyResolver: ResolveFn = () => { return inject(OrgminerService).getHierarchy(); }; + +export const suggestionResolver: ResolveFn = () => { + const credentialService = inject(CredentialService); + if (credentialService.isEffectiveSuperAdmin()) { + return inject(OrgminerService).getHierarchySuggestions(); + } else if (credentialService.isEffectiveAdmin()) { + return inject(OrgminerService).getMyHierarchySuggestions(); + } + return []; +};