Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use correct class and translate the label (DEV-4373) #1922

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions libs/vre/shared/app-ontology/src/lib/ontology.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class OntologyComponent extends ProjectBase implements OnInit, OnDestroy
private ngUnsubscribe = new Subject<void>();

// all resource classes in the current ontology
ontoClasses: ClassDefinition[];
ontoClasses: ResourceClassDefinitionWithAllLanguages[];
// expand the resource class cards
expandClasses = true;

Expand Down Expand Up @@ -278,7 +278,7 @@ export class OntologyComponent extends ProjectBase implements OnInit, OnDestroy
}
}

private initOntoClasses(allOntoClasses: ClassDefinition[]) {
private initOntoClasses(allOntoClasses: ResourceClassDefinitionWithAllLanguages[]) {
// reset the ontology classes
this.ontoClasses = [];

Expand Down Expand Up @@ -358,7 +358,11 @@ export class OntologyComponent extends ProjectBase implements OnInit, OnDestroy
this.initView(ontology);
this._dspApiConnection.v2.ontologyCache.reloadCachedItem(ontology.id);
// grab the onto class information to display
this.initOntoClasses(getAllEntityDefinitionsAsArray(ontology.classes));
this.initOntoClasses(
ontology.getClassDefinitionsByType<ResourceClassDefinitionWithAllLanguages>(
ResourceClassDefinitionWithAllLanguages
)
);
// grab the onto properties information to display
this.initOntoProperties(ontology, getAllEntityDefinitionsAsArray(ontology.properties));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- class card header -->
<mat-card-header class="resource-class-header" cdkDragHandle>
<mat-card-title [matTooltip]="resourceClass.comment" matTooltipPosition="above">
{{ resourceClass.label | appTruncate: 24 }}
{{ classLabel | appTruncate: 24 }}
</mat-card-title>
<mat-card-subtitle>
<span [matTooltip]="'id: ' + resourceClass.id" matTooltipPosition="above" matTooltipClass="wide-tooltip">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import {
} from '@angular/core';
import {
CanDoResponse,
ClassDefinition,
Constants,
KnoraApiConnection,
PropertyDefinition,
ReadOntology,
ResourceClassDefinitionWithAllLanguages,
ResourcePropertyDefinitionWithAllLanguages,
} from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken, RouteConstants } from '@dasch-swiss/vre/shared/app-config';
import { DefaultClass, DefaultResourceClasses } from '@dasch-swiss/vre/shared/app-helper-services';
import { DefaultClass, DefaultResourceClasses, LocalizationService } from '@dasch-swiss/vre/shared/app-helper-services';
import { NotificationService } from '@dasch-swiss/vre/shared/app-notification';
import {
OntologiesSelectors,
Expand All @@ -44,7 +44,7 @@ export class ResourceClassInfoComponent implements OnInit, OnDestroy {
// open / close res class card
@Input() expanded = false;

@Input() resourceClass: ClassDefinition;
@Input() resourceClass: ResourceClassDefinitionWithAllLanguages;

@Input() projectUuid: string;

Expand Down Expand Up @@ -73,6 +73,8 @@ export class ResourceClassInfoComponent implements OnInit, OnDestroy {

classCanBeDeleted: boolean;

classLabel: string;

subClassOfLabel = '';

readonly defaultClasses: DefaultClass[] = DefaultResourceClasses.data;
Expand All @@ -88,6 +90,7 @@ export class ResourceClassInfoComponent implements OnInit, OnDestroy {
constructor(
@Inject(DspApiConnectionToken)
private _dspApiConnection: KnoraApiConnection,
private _localizationService: LocalizationService,
private _notification: NotificationService,
private _store: Store,
private _actions$: Actions
Expand All @@ -99,6 +102,7 @@ export class ResourceClassInfoComponent implements OnInit, OnDestroy {
this.translateSubClassOfIri(this.resourceClass.subClassOf);
// check if the class can be deleted
this.canBeDeleted();
this.getOntologiesLabelsInPreferredLanguage();
}

ngOnDestroy() {
Expand Down Expand Up @@ -149,6 +153,12 @@ export class ResourceClassInfoComponent implements OnInit, OnDestroy {
return propsToDisplay;
}

getOntologiesLabelsInPreferredLanguage(): void {
const preferredLanguage = this._localizationService.getCurrentLanguage();
const preferedLabelLiteral = this.resourceClass.labels.find(l => l.language === preferredLanguage);
this.classLabel = preferedLabelLiteral ? preferedLabelLiteral.value : this.resourceClass.label || '';
}

/**
* translates iris from "subclass of" array
* - display label from default resource classes (as part of DSP System Project)
Expand Down
Loading