UI changed: Super Admin only sees the suggestions, Admin can make them in the editor
This commit is contained in:
@@ -13,5 +13,6 @@ export interface HierarchyResponse {
|
||||
hierarchy: Array<HierarchyNode>;
|
||||
can_edit?: boolean;
|
||||
can_suggest?: boolean;
|
||||
can_review?: boolean;
|
||||
number_of_suggestion_slots?: number;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ export interface HierarchySuggestion {
|
||||
created_at: string;
|
||||
status: HierarchySuggestion.StatusEnum;
|
||||
active: boolean;
|
||||
institution: string;
|
||||
suggested_by: string;
|
||||
hierarchy: Array<HierarchyNode>;
|
||||
}
|
||||
export namespace HierarchySuggestion {
|
||||
|
||||
@@ -33,27 +33,13 @@
|
||||
can_edit() ? 1 : number_of_suggestion_slots()
|
||||
"
|
||||
[isManager]="can_edit()"
|
||||
[editorStatus]="
|
||||
pendingSuggestion()?.status === 'new' ? 'in-progress' : null
|
||||
"
|
||||
(saved)="onHierarchySaved($event)">
|
||||
</app-hierarchy-edit-dialog>
|
||||
}
|
||||
@if (can_edit()) {
|
||||
<button
|
||||
mat-stroked-button
|
||||
color="primary"
|
||||
(click)="reviewSuggestions()">
|
||||
Vorschläge prüfen
|
||||
@if (suggestionCount() > 0) {
|
||||
({{ suggestionCount() }})
|
||||
}
|
||||
</button>
|
||||
} @else if (can_suggest()) {
|
||||
<button
|
||||
mat-stroked-button
|
||||
color="primary"
|
||||
(click)="viewMySuggestions()">
|
||||
Meine Vorschläge
|
||||
</button>
|
||||
}
|
||||
<!-- -->
|
||||
<button
|
||||
mat-icon-button
|
||||
(click)="toggleLanguage()"
|
||||
|
||||
@@ -21,18 +21,11 @@ import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatChipsModule } from '@angular/material/chips';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import { MatDialog, MatDialogModule } from '@angular/material/dialog';
|
||||
import type { EChartsOption } from 'echarts';
|
||||
import { CredentialService } from '../../../shared/services/credential.service';
|
||||
import { ChartThemeService } from '../../../shared/services/chart-theme.service';
|
||||
import { HierarchyEditDialogComponent } from './hierarchy-edit-dialog/hierarchy-edit-dialog.component';
|
||||
import { HierarchyEditorDialogData } from './hierarchy-edit-dialog/hierarchy-edit-dialog.component';
|
||||
import { HierarchyTreeEditorComponent } from './hierarchy-tree-editor/hierarchy-tree-editor.component';
|
||||
import {
|
||||
HierarchySuggestionsDialogComponent,
|
||||
HierarchySuggestionDecision,
|
||||
} from './hierarchy-suggestions-dialog/hierarchy-suggestions-dialog.component';
|
||||
import { HierarchyEditorResult } from './hierarchy-tree-editor/hierarchy-tree-editor.component';
|
||||
import { OrgminerService } from '../../../api/api/orgminer.service';
|
||||
import { HierarchyResponse } from '../../../api/model/hierarchyResponse';
|
||||
import { SaveHierarchyResponse } from '../../../api/model/saveHierarchyResponse';
|
||||
@@ -79,7 +72,6 @@ const MIN_TREE_HEIGHT = 200;
|
||||
MatIconModule,
|
||||
MatChipsModule,
|
||||
MatTooltipModule,
|
||||
MatDialogModule,
|
||||
HierarchyEditDialogComponent,
|
||||
],
|
||||
templateUrl: './hierarchy-chart.component.html',
|
||||
@@ -99,7 +91,6 @@ export class HierarchyChartComponent implements OnInit {
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private readonly credentialService = inject(CredentialService);
|
||||
private readonly orgminerService = inject(OrgminerService);
|
||||
private readonly dialog = inject(MatDialog);
|
||||
private readonly chartTheme = inject(ChartThemeService);
|
||||
readonly loading = signal<boolean>(true);
|
||||
readonly lang = signal<'de' | 'en'>('de');
|
||||
@@ -118,15 +109,16 @@ export class HierarchyChartComponent implements OnInit {
|
||||
|
||||
private isOwnNavigation = false;
|
||||
hierarchyData = input.required<HierarchyResponse>();
|
||||
pendingSuggestion = input<HierarchySuggestion | null>(null);
|
||||
can_edit = computed(() => this.hierarchyData().can_edit ?? false);
|
||||
can_suggest = computed(() => this.hierarchyData().can_suggest ?? true);
|
||||
readonly suggestionCount = signal(0);
|
||||
can_suggest = computed(() => this.hierarchyData().can_suggest ?? false);
|
||||
number_of_suggestion_slots = signal(0);
|
||||
university_name = computed(
|
||||
() => this.credentialService.organizationName() ?? 'Universität',
|
||||
);
|
||||
hierarchySaved = signal<boolean | null>(null);
|
||||
@Output() analyzeOrgEvent = new EventEmitter<{ name: string; url: string }>();
|
||||
@Output() suggestionSaved = new EventEmitter<void>();
|
||||
|
||||
private initialized = false;
|
||||
|
||||
@@ -152,6 +144,10 @@ export class HierarchyChartComponent implements OnInit {
|
||||
);
|
||||
});
|
||||
});
|
||||
effect(() => {
|
||||
const suggestion = this.pendingSuggestion();
|
||||
untracked(() => this.loadPendingSuggestionIntoEditor(suggestion));
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -159,9 +155,6 @@ export class HierarchyChartComponent implements OnInit {
|
||||
this.hierarchyData().number_of_suggestion_slots ?? 0,
|
||||
);
|
||||
this.loadData();
|
||||
if (this.can_edit()) {
|
||||
this.loadSuggestionCount();
|
||||
}
|
||||
this.route.queryParamMap
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
.subscribe((params) => {
|
||||
@@ -191,6 +184,29 @@ export class HierarchyChartComponent implements OnInit {
|
||||
this.loading.set(false);
|
||||
}
|
||||
|
||||
private loadPendingSuggestionIntoEditor(
|
||||
suggestion: HierarchySuggestion | null,
|
||||
): void {
|
||||
if (!suggestion) {
|
||||
if (this.universityRoot) {
|
||||
this.editorTree.set(structuredClone(this.universityRoot));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const children = structuredClone(suggestion.hierarchy) as RawNode[];
|
||||
this.assignIds(children, 'pending-suggestion-root', false);
|
||||
this.editorTree.set({
|
||||
id: 'pending-suggestion-root',
|
||||
name_de: this.university_name(),
|
||||
name_en: this.university_name(),
|
||||
link_de: '',
|
||||
link_en: '',
|
||||
type: 'university',
|
||||
children,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Single place that (re)builds the internal state from a list of top-level nodes.
|
||||
* Works on a deep copy, so neither the API response nor the editor's data is mutated.
|
||||
@@ -266,17 +282,21 @@ export class HierarchyChartComponent implements OnInit {
|
||||
.map((l) => l.id)
|
||||
.join(',');
|
||||
|
||||
const urlTree = this.router.createUrlTree([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: {
|
||||
[QUERY_PARAM_PATH]: path,
|
||||
[QUERY_PARAM_LANG]: this.lang(),
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
});
|
||||
if (this.router.serializeUrl(urlTree) === this.router.url) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isOwnNavigation = true;
|
||||
this.router
|
||||
.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: {
|
||||
[QUERY_PARAM_PATH]: path,
|
||||
[QUERY_PARAM_LANG]: this.lang(),
|
||||
},
|
||||
queryParamsHandling: 'merge',
|
||||
replaceUrl: true,
|
||||
})
|
||||
.navigateByUrl(urlTree, { replaceUrl: true })
|
||||
.then((navigated) => {
|
||||
if (!navigated) this.isOwnNavigation = false;
|
||||
});
|
||||
@@ -284,171 +304,6 @@ export class HierarchyChartComponent implements OnInit {
|
||||
|
||||
/* ------------------------------- UI actions ------------------------------ */
|
||||
|
||||
reviewSuggestions(): void {
|
||||
this.orgminerService.getHierarchySuggestions().subscribe({
|
||||
next: (suggestions: HierarchySuggestion[]) => {
|
||||
this.suggestionCount.set(this.countNewSuggestions(suggestions));
|
||||
const dialogRef = this.dialog.open(
|
||||
HierarchySuggestionsDialogComponent,
|
||||
{
|
||||
data: { suggestions, canReview: true },
|
||||
width: '65%',
|
||||
maxWidth: '95vw',
|
||||
maxHeight: '90vh',
|
||||
},
|
||||
);
|
||||
dialogRef
|
||||
.afterClosed()
|
||||
.subscribe((decision: HierarchySuggestionDecision | undefined) => {
|
||||
if (!decision) return;
|
||||
if (decision.action === 'review') {
|
||||
this.openSuggestionEditor(decision.suggestion);
|
||||
} else {
|
||||
this.rejectSuggestion(decision.suggestion);
|
||||
}
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error(
|
||||
'[HierarchyChart] error loading hierarchy suggestions:',
|
||||
error,
|
||||
);
|
||||
this.snackBar.open('Error loading hierarchy suggestions', 'Close', {
|
||||
duration: 3000,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
viewMySuggestions(): void {
|
||||
this.orgminerService.getMyHierarchySuggestions().subscribe({
|
||||
next: (suggestions) => {
|
||||
this.dialog.open(HierarchySuggestionsDialogComponent, {
|
||||
data: { suggestions, canReview: false },
|
||||
width: '65%',
|
||||
maxWidth: '95vw',
|
||||
maxHeight: '90vh',
|
||||
});
|
||||
},
|
||||
error: (error) => {
|
||||
console.error(
|
||||
'[HierarchyChart] error loading own hierarchy suggestions:',
|
||||
error,
|
||||
);
|
||||
this.snackBar.open('Error loading your suggestions', 'Close', {
|
||||
duration: 3000,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private acceptSuggestion(
|
||||
suggestion: HierarchySuggestion,
|
||||
hierarchy: RawNode[],
|
||||
): void {
|
||||
this.orgminerService
|
||||
.acceptHierarchySuggestion(
|
||||
suggestion.id,
|
||||
|
||||
hierarchy,
|
||||
)
|
||||
.subscribe({
|
||||
next: () => {
|
||||
this.snackBar.open('Hierarchy suggestion accepted', 'Close', {
|
||||
duration: 3000,
|
||||
});
|
||||
this.suggestionCount.update((count) => Math.max(0, count - 1));
|
||||
this.refreshHierarchy(hierarchy);
|
||||
},
|
||||
error: (error) => {
|
||||
console.error(
|
||||
'[HierarchyChart] error accepting hierarchy suggestion:',
|
||||
error,
|
||||
);
|
||||
this.snackBar.open('Error accepting hierarchy suggestion', 'Close', {
|
||||
duration: 3000,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private openSuggestionEditor(suggestion: HierarchySuggestion): void {
|
||||
const tree: RawNode = {
|
||||
id: 'suggestion-root',
|
||||
name_de: 'Universität',
|
||||
name_en: 'University',
|
||||
type: 'university',
|
||||
children: suggestion.hierarchy as RawNode[],
|
||||
};
|
||||
this.assignIds(tree.children ?? [], 'suggestion-root', false);
|
||||
|
||||
const dialogRef = this.dialog.open<
|
||||
HierarchyTreeEditorComponent,
|
||||
HierarchyEditorDialogData,
|
||||
RawNode | HierarchyEditorResult
|
||||
>(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 (!('children' in result)) {
|
||||
if (suggestion.status === HierarchySuggestion.StatusEnum.New) {
|
||||
this.rejectSuggestion(suggestion);
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.acceptSuggestion(suggestion, result.children ?? []);
|
||||
});
|
||||
}
|
||||
|
||||
private rejectSuggestion(suggestion: HierarchySuggestion): void {
|
||||
this.orgminerService.rejectHierarchySuggestion(suggestion.id).subscribe({
|
||||
next: () => {
|
||||
this.snackBar.open('Hierarchy suggestion rejected', 'Close', {
|
||||
duration: 3000,
|
||||
});
|
||||
this.suggestionCount.update((count) => Math.max(0, count - 1));
|
||||
},
|
||||
error: (error) => {
|
||||
console.error(
|
||||
'[HierarchyChart] error rejecting hierarchy suggestion:',
|
||||
error,
|
||||
);
|
||||
this.snackBar.open('Error rejecting hierarchy suggestion', 'Close', {
|
||||
duration: 3000,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
private loadSuggestionCount(): void {
|
||||
this.orgminerService.getHierarchySuggestions().subscribe({
|
||||
next: (suggestions) =>
|
||||
this.suggestionCount.set(this.countNewSuggestions(suggestions)),
|
||||
error: (error) =>
|
||||
console.error(
|
||||
'[HierarchyChart] error loading suggestion count:',
|
||||
error,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
private countNewSuggestions(suggestions: HierarchySuggestion[]): number {
|
||||
return suggestions.filter(
|
||||
(suggestion) => suggestion.status === HierarchySuggestion.StatusEnum.New,
|
||||
).length;
|
||||
}
|
||||
|
||||
toggleLanguage(): void {
|
||||
this.lang.set(this.lang() === 'de' ? 'en' : 'de');
|
||||
// rebuild every currently opened level with the new language, keep the path
|
||||
@@ -713,6 +568,8 @@ export class HierarchyChartComponent implements OnInit {
|
||||
|
||||
if (this.can_edit()) {
|
||||
this.refreshHierarchy(children);
|
||||
} else {
|
||||
this.suggestionSaved.emit();
|
||||
}
|
||||
},
|
||||
error: (error) => {
|
||||
|
||||
+6
@@ -13,6 +13,8 @@ export interface HierarchyEditorDialogData {
|
||||
isManager: boolean;
|
||||
isSuggestion?: boolean;
|
||||
suggestionStatus?: 'new' | 'accepted' | 'rejected';
|
||||
readOnly?: boolean;
|
||||
editorStatus?: 'in-progress' | null;
|
||||
}
|
||||
|
||||
/** Opens the tree editor for live-hierarchy edits and forwards saved trees. */
|
||||
@@ -26,6 +28,8 @@ export class HierarchyEditDialogComponent {
|
||||
private readonly dialog = inject(MatDialog);
|
||||
numberOfSuggestions = input<number>(0);
|
||||
isManager = input(false);
|
||||
readOnly = input(false);
|
||||
editorStatus = input<'in-progress' | null>(null);
|
||||
data = input.required<RawNode | null>();
|
||||
|
||||
@Output() saved = new EventEmitter<RawNode>();
|
||||
@@ -41,6 +45,8 @@ export class HierarchyEditDialogComponent {
|
||||
numberOfSuggestions: this.numberOfSuggestions(),
|
||||
isManager: this.isManager(),
|
||||
isSuggestion: false,
|
||||
readOnly: this.readOnly(),
|
||||
editorStatus: this.editorStatus(),
|
||||
},
|
||||
width: '65%',
|
||||
maxWidth: '95vw',
|
||||
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
<h2 mat-dialog-title>Hierarchy suggestions</h2>
|
||||
<mat-dialog-content>
|
||||
@if (data.suggestions.length === 0) {
|
||||
<p>Keine Hierarchie-Vorschläge vorhanden.</p>
|
||||
} @else {
|
||||
@for (suggestion of data.suggestions; track suggestion.id) {
|
||||
<div
|
||||
class="suggestion"
|
||||
[class.suggestion-history]="suggestion.status !== 'new'">
|
||||
<div class="suggestion-details">
|
||||
<span
|
||||
>Vorschlag vom {{ suggestion.created_at | date: 'medium' }}</span
|
||||
>
|
||||
<span [class]="'suggestion-status status-' + suggestion.status">
|
||||
{{ statusLabel(suggestion.status) }}
|
||||
</span>
|
||||
@if (suggestion.active) {
|
||||
<span class="suggestion-active">Aktiv</span>
|
||||
}
|
||||
</div>
|
||||
@if (data.canReview) {
|
||||
<button mat-stroked-button (click)="review(suggestion)">
|
||||
Vorschlag ansehen
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</mat-dialog-content>
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button (click)="close()">Close</button>
|
||||
</mat-dialog-actions>
|
||||
-46
@@ -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;
|
||||
}
|
||||
-65
@@ -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';
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
<app-data-table
|
||||
[data]="suggestions()"
|
||||
[columns]="columns"
|
||||
[stickyHeader]="true">
|
||||
</app-data-table>
|
||||
|
||||
<ng-template #actionTemplate let-suggestion>
|
||||
<button
|
||||
mat-stroked-button
|
||||
type="button"
|
||||
(click)="review(suggestion); $event.stopPropagation()">
|
||||
Prüfen
|
||||
</button>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #statusTemplate let-suggestion>
|
||||
<span class="status">{{ statusLabel(suggestion.status) }}</span>
|
||||
</ng-template>
|
||||
+166
@@ -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<HierarchySuggestion[]>();
|
||||
readonly reload = output<void>();
|
||||
|
||||
readonly actionTemplate =
|
||||
viewChild.required<TemplateRef<unknown>>('actionTemplate');
|
||||
readonly statusTemplate =
|
||||
viewChild.required<TemplateRef<unknown>>('statusTemplate');
|
||||
readonly columns: GenericColumn<HierarchySuggestion>[] = [
|
||||
{
|
||||
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,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,19 @@
|
||||
<div class="content">
|
||||
<h6>Organizationsstruktur</h6>
|
||||
@if (suggestionsOnly()) {
|
||||
<h6>Hierarchie-Vorschläge</h6>
|
||||
} @else {
|
||||
<h6>Organizationsstruktur</h6>
|
||||
}
|
||||
@if (!hierarchyData()) {
|
||||
<div class="error">
|
||||
<span>Keine Hierarchie-Daten verfügbar.</span>
|
||||
</div>
|
||||
} @else {
|
||||
@if (suggestionsOnly()) {
|
||||
<app-hierarchy-suggestions
|
||||
[suggestions]="suggestions()"
|
||||
(reload)="reloadSuggestions()" />
|
||||
} @else {
|
||||
<mat-accordion multi>
|
||||
<mat-expansion-panel
|
||||
[expanded]="hierarchyExpanded()"
|
||||
@@ -15,7 +24,11 @@
|
||||
</mat-expansion-panel-header>
|
||||
<app-hierarchy-chart
|
||||
[hierarchyData]="hierarchyData()"
|
||||
(analyzeOrgEvent)="analyzeOrg($event)" />
|
||||
[pendingSuggestion]="
|
||||
suggestions().find((suggestion) => suggestion.status === 'new') ?? null
|
||||
"
|
||||
(analyzeOrgEvent)="analyzeOrg($event)"
|
||||
(suggestionSaved)="reloadSuggestions()" />
|
||||
</mat-expansion-panel>
|
||||
@if (orgUrl()) {
|
||||
<mat-expansion-panel
|
||||
@@ -47,5 +60,6 @@
|
||||
</div>
|
||||
}
|
||||
</mat-accordion>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -37,3 +37,7 @@ mat-panel-description {
|
||||
app-hierarchy-chart {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.suggestions-only-chart {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@@ -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<HierarchyResponse>();
|
||||
suggestions = input<HierarchySuggestion[] | []>([]);
|
||||
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 });
|
||||
|
||||
@@ -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<HierarchyResponse> = () => {
|
||||
return inject(OrgminerService).getHierarchy();
|
||||
};
|
||||
|
||||
export const suggestionResolver: ResolveFn<HierarchySuggestion[]> = () => {
|
||||
const credentialService = inject(CredentialService);
|
||||
if (credentialService.isEffectiveSuperAdmin()) {
|
||||
return inject(OrgminerService).getHierarchySuggestions();
|
||||
} else if (credentialService.isEffectiveAdmin()) {
|
||||
return inject(OrgminerService).getMyHierarchySuggestions();
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user