mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-14 05:23:06 +00:00
[CST-7604] added hithighlight for person and orgunit
This commit is contained in:
@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
|
||||
import { hasValue, isEmpty } from '../../shared/empty.util';
|
||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { Metadata } from '../shared/metadata.utils';
|
||||
|
||||
/**
|
||||
* Returns a name for a {@link DSpaceObject} based
|
||||
@@ -67,4 +68,45 @@ export class DSONameService {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Hit highlight
|
||||
*
|
||||
* @param object
|
||||
* @param dso
|
||||
*
|
||||
* @returns {string} html embedded hit highlight.
|
||||
*/
|
||||
getHitHighlights(object: any, dso: DSpaceObject): string {
|
||||
const types = dso.getRenderTypes();
|
||||
const entityType = types
|
||||
.filter((type) => typeof type === 'string')
|
||||
.find((type: string) => (['Person', 'OrgUnit']).includes(type)) as string;
|
||||
if (entityType === 'Person') {
|
||||
const familyName = this.firstMetadataValue(object, dso, 'person.familyName');
|
||||
const givenName = this.firstMetadataValue(object, dso, 'person.givenName');
|
||||
if (isEmpty(familyName) && isEmpty(givenName)) {
|
||||
return this.firstMetadataValue(object, dso, 'dc.title') || dso.name;
|
||||
} else if (isEmpty(familyName) || isEmpty(givenName)) {
|
||||
return familyName || givenName;
|
||||
}
|
||||
return `${familyName}, ${givenName}`;
|
||||
} else if (entityType === 'OrgUnit') {
|
||||
return this.firstMetadataValue(object, dso, 'organization.legalName');
|
||||
}
|
||||
return this.firstMetadataValue(object, dso, 'dc.title') || dso.name || this.translateService.instant('dso.name.untitled');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first matching metadata string value from hitHighlights or dso metadata, preferring hitHighlights.
|
||||
*
|
||||
* @param object
|
||||
* @param dso
|
||||
* @param {string|string[]} keyOrKeys The metadata key(s) in scope. Wildcards are supported; see [[Metadata]].
|
||||
*
|
||||
* @returns {string} the first matching string value, or `undefined`.
|
||||
*/
|
||||
firstMetadataValue(object: any, dso: DSpaceObject, keyOrKeys: string | string[]): string {
|
||||
return Metadata.firstValue([object.hitHighlights, dso.metadata], keyOrKeys);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -6,4 +6,15 @@ export class DSONameServiceMock {
|
||||
public getName(dso: DSpaceObject) {
|
||||
return UNDEFINED_NAME;
|
||||
}
|
||||
|
||||
public getHitHighlights(object: any, dso: DSpaceObject) {
|
||||
if (object.hitHighlights && object.hitHighlights['dc.title']) {
|
||||
return object.hitHighlights['dc.title'][0];
|
||||
} else if (object.hitHighlights && object.hitHighlights['organization.legalName']) {
|
||||
return object.hitHighlights['organization.legalName'][0];
|
||||
} else if (object.hitHighlights && (object.hitHighlights['person.familyName'] || object.hitHighlights['person.givenName'])) {
|
||||
return `${object.hitHighlights['person.familyName'][0] || ''}, ${object.hitHighlights['person.givenName'][0] || ''}`;
|
||||
}
|
||||
return UNDEFINED_NAME;
|
||||
}
|
||||
}
|
||||
|
@@ -30,6 +30,9 @@ const mockItemWithMetadata: ItemSearchResult = new ItemSearchResult();
|
||||
mockItemWithMetadata.hitHighlights = {};
|
||||
const dcTitle = 'This is just another <em>title</em>';
|
||||
mockItemWithMetadata.indexableObject = Object.assign(new Item(), {
|
||||
hitHighlights: {
|
||||
'dc.title': [dcTitle],
|
||||
},
|
||||
bundles: createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [])),
|
||||
metadata: {
|
||||
'dc.title': [
|
||||
|
@@ -42,7 +42,6 @@ export class ItemSearchResultGridElementComponent extends SearchResultGridElemen
|
||||
ngOnInit(): void {
|
||||
super.ngOnInit();
|
||||
this.itemPageRoute = getItemPageRoute(this.dso);
|
||||
this.dsoTitle = this.firstMetadataValue('dc.title') ??
|
||||
(this.dso ? this.dsoNameService.getName(this.dso) : undefined);
|
||||
this.dsoTitle = this.dsoNameService.getHitHighlights(this.object, this.dso);
|
||||
}
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ export class ItemListPreviewComponent implements OnInit {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.showThumbnails = this.appConfig.browseBy.showThumbnails;
|
||||
this.dsoTitle = this.dsoNameService.getName(this.item);
|
||||
this.dsoTitle = this.dsoNameService.getHitHighlights(this.object, this.item);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -15,6 +15,9 @@ let publicationListElementComponent: ItemSearchResultListElementComponent;
|
||||
let fixture: ComponentFixture<ItemSearchResultListElementComponent>;
|
||||
const dcTitle = 'This is just another <em>title</em>';
|
||||
const mockItemWithMetadata: ItemSearchResult = Object.assign(new ItemSearchResult(), {
|
||||
hitHighlights: {
|
||||
'dc.title': [dcTitle],
|
||||
},
|
||||
indexableObject:
|
||||
Object.assign(new Item(), {
|
||||
bundles: observableOf({}),
|
||||
@@ -22,7 +25,7 @@ const mockItemWithMetadata: ItemSearchResult = Object.assign(new ItemSearchResul
|
||||
'dc.title': [
|
||||
{
|
||||
language: 'en_US',
|
||||
value: dcTitle
|
||||
value: 'This is just another title'
|
||||
}
|
||||
],
|
||||
'dc.contributor.author': [
|
||||
|
@@ -33,7 +33,7 @@ export class SearchResultListElementComponent<T extends SearchResult<K>, K exten
|
||||
ngOnInit(): void {
|
||||
if (hasValue(this.object)) {
|
||||
this.dso = this.object.indexableObject;
|
||||
this.dsoTitle = this.firstMetadataValue('dc.title') ?? this.dsoNameService.getName(this.dso);
|
||||
this.dsoTitle = this.dsoNameService.getHitHighlights(this.object, this.dso);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user