updated hierarchy chart to enable hierarchy editing
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
<span class="uh-loader-text">Lade Daten...</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (!loading()) {
|
||||
<div class="uh-spacer">
|
||||
<mat-chip-set
|
||||
@@ -21,6 +20,19 @@
|
||||
}
|
||||
</mat-chip-set>
|
||||
<div>
|
||||
<!-- @if (hierarchySaved() !== null) {
|
||||
<app-interaction-feedback
|
||||
[success]="hierarchySaved() ?? false"
|
||||
[status]="200" />
|
||||
} -->
|
||||
|
||||
@if (can_edit()) {
|
||||
<app-hierarchy-edit-dialog
|
||||
[data]="universityRoot"
|
||||
[numberOfSuggestions]="number_of_suggestion_slots()"
|
||||
(saved)="onHierarchySaved($event)">
|
||||
</app-hierarchy-edit-dialog>
|
||||
}
|
||||
<button
|
||||
mat-icon-button
|
||||
(click)="toggleLanguage()"
|
||||
|
||||
@@ -24,16 +24,17 @@ import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
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 { OrgminerService } from '../../../api/api/orgminer.service';
|
||||
import { HierarchyResponse } from '../../../api/model/hierarchyResponse';
|
||||
import { SaveHierarchyResponse } from '../../../api/model/saveHierarchyResponse';
|
||||
import { HierarchyNode } from '../../../api/model/hierarchyNode';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
export type modifiedOption = 'created' | 'updated' | 'deleted' | '';
|
||||
|
||||
interface RawNode {
|
||||
id?: string;
|
||||
name_de: string;
|
||||
name_en?: string;
|
||||
link_de?: string;
|
||||
link_en?: string;
|
||||
type?: string; // 'faculty' | 'institutes' | 'chairs' | 'leaf' | 'university'
|
||||
color?: string;
|
||||
value?: number;
|
||||
export interface RawNode extends HierarchyNode {
|
||||
id: string;
|
||||
modified?: modifiedOption;
|
||||
children?: RawNode[];
|
||||
[key: string]: any; // faculty_de, institutes_aggregator, chairs_aggregator, ...
|
||||
}
|
||||
@@ -63,6 +64,7 @@ const MIN_TREE_HEIGHT = 200;
|
||||
MatIconModule,
|
||||
MatChipsModule,
|
||||
MatTooltipModule,
|
||||
HierarchyEditDialogComponent,
|
||||
],
|
||||
templateUrl: './hierarchy-chart.component.html',
|
||||
styleUrls: ['./hierarchy-chart.component.scss'],
|
||||
@@ -72,18 +74,23 @@ export class HierarchyChartComponent implements OnInit {
|
||||
private readonly route = inject(ActivatedRoute);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private readonly credentialService = inject(CredentialService);
|
||||
private readonly orgminerService = inject(OrgminerService);
|
||||
private readonly chartTheme = inject(ChartThemeService);
|
||||
readonly loading = signal<boolean>(true);
|
||||
readonly lang = signal<'de' | 'en'>('de');
|
||||
readonly levels = signal<TreeLevel[]>([]);
|
||||
|
||||
private readonly _snackBar = inject(MatSnackBar);
|
||||
private idMap = new Map<string, RawNode>();
|
||||
private universityRoot: RawNode | null = null;
|
||||
public universityRoot: RawNode | null = null;
|
||||
private isOwnNavigation = false;
|
||||
hierarchyData = input.required<any>();
|
||||
hierarchyData = input.required<HierarchyResponse>();
|
||||
can_edit = computed(() => this.hierarchyData().can_edit);
|
||||
number_of_suggestion_slots = signal(0);
|
||||
university_name = computed(
|
||||
() => this.credentialService.organizationName() ?? 'Universität',
|
||||
);
|
||||
hierarchySaved = signal<boolean | null>(null); // null = no feedback, true = success, false = failure
|
||||
@Output() analyzeOrgEvent = new EventEmitter<{ name: string; url: string }>();
|
||||
|
||||
constructor() {
|
||||
@@ -102,6 +109,9 @@ export class HierarchyChartComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.number_of_suggestion_slots.set(
|
||||
this.hierarchyData().number_of_suggestion_slots ?? 0,
|
||||
);
|
||||
this.loadData();
|
||||
this.route.queryParamMap
|
||||
.pipe(takeUntilDestroyed(this.destroyRef))
|
||||
@@ -118,9 +128,9 @@ export class HierarchyChartComponent implements OnInit {
|
||||
|
||||
private loadData(): void {
|
||||
this.loading.set(true);
|
||||
if (!this.hierarchyData() || !Array.isArray(this.hierarchyData())) {
|
||||
if (!this.hierarchyData()) {
|
||||
console.error(
|
||||
'[HierarchyChart] hierarchyData is not an array:',
|
||||
'[HierarchyChart] hierarchyData is not available:',
|
||||
this.hierarchyData(),
|
||||
);
|
||||
this.loading.set(false);
|
||||
@@ -128,13 +138,15 @@ export class HierarchyChartComponent implements OnInit {
|
||||
}
|
||||
|
||||
// assign unique IDs to every node in the hierarchy, so we can restore the path from the URL later
|
||||
this.assignIds(this.hierarchyData(), 'root');
|
||||
this.assignIds(this.hierarchyData().hierarchy as RawNode[], 'root');
|
||||
this.universityRoot = {
|
||||
id: 'root',
|
||||
name_de: this.university_name(),
|
||||
name_en: this.university_name(),
|
||||
link_de: '',
|
||||
link_en: '',
|
||||
type: 'university',
|
||||
children: this.hierarchyData(),
|
||||
children: this.hierarchyData().hierarchy as RawNode[],
|
||||
};
|
||||
this.idMap.set('root', this.universityRoot);
|
||||
|
||||
@@ -269,7 +281,7 @@ export class HierarchyChartComponent implements OnInit {
|
||||
|
||||
/* ------------------------------ tree building ----------------------------- */
|
||||
|
||||
private getLink(raw: RawNode): string | undefined {
|
||||
private getLink(raw: RawNode): string | null | undefined {
|
||||
return this.lang() === 'en'
|
||||
? (raw.link_en ?? raw.link_de)
|
||||
: (raw.link_de ?? raw.link_en);
|
||||
@@ -281,15 +293,6 @@ export class HierarchyChartComponent implements OnInit {
|
||||
: (raw.name_de ?? raw.name_en ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts one raw node into an ECharts tree node.
|
||||
* `expandGroup` controls whether an `institutes`/`chairs` GROUP node is
|
||||
* allowed to reveal its direct items in this pass (used once per drill step).
|
||||
* `parentType` is the *group's* raw type ('institutes' | 'chairs'); it lets a
|
||||
* generic 'leaf' item (an individual institute/chair entry, which usually has
|
||||
* no more specific type of its own) inherit an icon from the group it came
|
||||
* from, instead of falling back to a generic dot.
|
||||
*/
|
||||
private toChartNode(
|
||||
raw: RawNode,
|
||||
expandGroup: boolean,
|
||||
@@ -308,7 +311,7 @@ export class HierarchyChartComponent implements OnInit {
|
||||
link: this.getLink(raw),
|
||||
itemStyle: {
|
||||
color:
|
||||
raw.color ||
|
||||
raw['color'] ||
|
||||
(isGroup
|
||||
? this.chartTheme.colors().blueHighlight
|
||||
: this.chartTheme.colors().success),
|
||||
@@ -342,7 +345,8 @@ export class HierarchyChartComponent implements OnInit {
|
||||
name: this.displayName(raw),
|
||||
nodeType: raw.type,
|
||||
hasChildren: true,
|
||||
itemStyle: { color: raw.color || this.chartTheme.colors().primary },
|
||||
link: this.getLink(raw),
|
||||
itemStyle: { color: raw['color'] || this.chartTheme.colors().primary },
|
||||
children,
|
||||
};
|
||||
|
||||
@@ -357,15 +361,6 @@ export class HierarchyChartComponent implements OnInit {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Symbol per node category. `nodeType` here is the *effective* type from
|
||||
* `toChartNode` — for institute/chair leaves this is already resolved to
|
||||
* 'institutes' / 'chairs' via inheritance, so they get the same icon as
|
||||
* their group header. Anything that doesn't map to a known category (a
|
||||
* genuinely untyped leaf) falls back to a plain circle, which is a valid
|
||||
* ECharts built-in symbol — unlike an arbitrary string, which ECharts
|
||||
* would silently fail to render.
|
||||
*/
|
||||
private getNodeIcon(nodeType: string | undefined): string {
|
||||
switch (nodeType) {
|
||||
case 'faculty':
|
||||
@@ -455,4 +450,32 @@ export class HierarchyChartComponent implements OnInit {
|
||||
],
|
||||
};
|
||||
}
|
||||
//save new hierarchy data from the editor dialog
|
||||
onHierarchySaved(newData: RawNode): void {
|
||||
this.orgminerService.saveHierarchy(newData.children as any).subscribe({
|
||||
next: (response) => {
|
||||
this._snackBar.open('Hierarchy saved successfully', 'Close', {
|
||||
duration: 3000,
|
||||
});
|
||||
console.log('[HierarchyChart] hierarchy saved successfully:', response);
|
||||
const saveResponse = response as SaveHierarchyResponse;
|
||||
if (typeof saveResponse.remaining_today !== 'number') {
|
||||
console.error(
|
||||
'[HierarchyChart] save response did not include the remaining suggestion count:',
|
||||
response,
|
||||
);
|
||||
} else {
|
||||
this.number_of_suggestion_slots.set(saveResponse.remaining_today);
|
||||
}
|
||||
this.hierarchySaved.set(true);
|
||||
},
|
||||
error: (error) => {
|
||||
this._snackBar.open('Error saving hierarchy', 'Close', {
|
||||
duration: 3000,
|
||||
});
|
||||
console.error('[HierarchyChart] error saving hierarchy:', error);
|
||||
this.hierarchySaved.set(false);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { OrgminerContentComponent } from './orgminer-content/orgminer-content.co
|
||||
import { ClassifiedPagesComponent } from './classified-pages/classified-pages.component';
|
||||
import { MatExpansionModule } from '@angular/material/expansion';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { HierarchyResponse } from '../../api/model/hierarchyResponse';
|
||||
const ORGANIZATION_URL_PARAM = 'orgUrl';
|
||||
const ORGANIZATION_NAME_PARAM = 'orgName';
|
||||
const ORGMINER_EXPANDED_PARAM = 'orgExpanded';
|
||||
@@ -37,7 +38,7 @@ const CLASSIFIED_PAGES_PANEL_PARAM = 'classifiedPagesExpanded';
|
||||
styleUrl: './hierarchy.component.scss',
|
||||
})
|
||||
export class HierarchyComponent implements OnInit {
|
||||
hierarchyData = input.required();
|
||||
hierarchyData = input.required<HierarchyResponse>();
|
||||
hierarchyExpanded = signal(true);
|
||||
organizationExpanded = signal(true);
|
||||
classifiedPagesExpanded = signal(false);
|
||||
|
||||
Reference in New Issue
Block a user