Skip to content

Commit

Permalink
fix: use correct class and translate the label (DEV-4373) (#1922)
Browse files Browse the repository at this point in the history
Co-authored-by: Irmantas Kaukas <[email protected]>
Co-authored-by: Marcin Procyk <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent d3369da commit b1ae8b0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
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

0 comments on commit b1ae8b0

Please sign in to comment.