diff --git a/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-issue/journal-issue-sidebar-search-list-element.component.spec.ts b/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-issue/journal-issue-sidebar-search-list-element.component.spec.ts index 5cf06fdeade..dc692644bda 100644 --- a/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-issue/journal-issue-sidebar-search-list-element.component.spec.ts +++ b/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-issue/journal-issue-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,12 @@ +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; + import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../../../shared/object-collection/shared/item-search-result.model'; @@ -37,6 +46,52 @@ const parent = Object.assign(new Collection(), { }, }); -describe('JournalIssueSidebarSearchListElementComponent', - createSidebarSearchListElementTests(JournalIssueSidebarSearchListElementComponent, object, parent, 'parent title', 'title', '5 - 7'), -); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Collection = parentObj; + + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); + } + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('JournalIssueSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests( + JournalIssueSidebarSearchListElementComponent, + object, + parent, + hierarchicalTitle, + 'title', + '1234, 5678', + ); + }); + }); +} diff --git a/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-volume/journal-volume-sidebar-search-list-element.component.spec.ts b/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-volume/journal-volume-sidebar-search-list-element.component.spec.ts index 16f13945337..aa4e3a6d2be 100644 --- a/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-volume/journal-volume-sidebar-search-list-element.component.spec.ts +++ b/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-volume/journal-volume-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,12 @@ +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; + import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../../../shared/object-collection/shared/item-search-result.model'; @@ -40,6 +49,45 @@ const parent = Object.assign(new Collection(), { }, }); -describe('JournalVolumeSidebarSearchListElementComponent', - createSidebarSearchListElementTests(JournalVolumeSidebarSearchListElementComponent, object, parent, 'parent title', 'title', 'journal title (1) (2)'), -); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Collection = parentObj; + + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); + } + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('JournalVolumeSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(JournalVolumeSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', 'journal title (1) (2)'); + }); + }); +} diff --git a/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal/journal-sidebar-search-list-element.component.spec.ts b/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal/journal-sidebar-search-list-element.component.spec.ts index a7c2af3806f..8b73d728b34 100644 --- a/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal/journal-sidebar-search-list-element.component.spec.ts +++ b/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal/journal-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,13 @@ +import { + catchError, + map, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; + import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../../../shared/object-collection/shared/item-search-result.model'; @@ -35,6 +45,48 @@ const parent = Object.assign(new Collection(), { }, }); -describe('JournalSidebarSearchListElementComponent', - createSidebarSearchListElementTests(JournalSidebarSearchListElementComponent, object, parent, 'parent title', 'title', '1234, 5678'), -); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Collection = parentObj; + + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + if (remoteData.payload) { + return fetchParentTitles(remoteData.payload); + } + } + return of([]); + }), + catchError(() => of([])), + map(() => titles), + ); + } + }; + + if (fetchParentTitles(currentParent)) { + return fetchParentTitles(currentParent).pipe( + map(() => titles.join(' > ')), + ); + } +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('JournalSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(JournalSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', '1234, 5678'); + }); + }); +} diff --git a/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/org-unit/org-unit-sidebar-search-list-element.component.spec.ts b/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/org-unit/org-unit-sidebar-search-list-element.component.spec.ts index 4d3f27f6ef4..352687de2d5 100644 --- a/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/org-unit/org-unit-sidebar-search-list-element.component.spec.ts +++ b/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/org-unit/org-unit-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,12 @@ +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; + import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../../../shared/object-collection/shared/item-search-result.model'; @@ -37,6 +46,45 @@ const parent = Object.assign(new Collection(), { }, }); -describe('OrgUnitSidebarSearchListElementComponent', - createSidebarSearchListElementTests(OrgUnitSidebarSearchListElementComponent, object, parent, 'parent title', 'title', 'description'), -); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Collection = parentObj; + + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); + } + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('OrgUnitSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(OrgUnitSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', 'description'); + }); + }); +} diff --git a/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/person/person-sidebar-search-list-element.component.spec.ts b/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/person/person-sidebar-search-list-element.component.spec.ts index 6e614c58114..9ba619637bd 100644 --- a/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/person/person-sidebar-search-list-element.component.spec.ts +++ b/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/person/person-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,12 @@ +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; + import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../../../shared/object-collection/shared/item-search-result.model'; @@ -42,7 +51,45 @@ const parent = Object.assign(new Collection(), { }, }); -describe('PersonSidebarSearchListElementComponent', - createSidebarSearchListElementTests(PersonSidebarSearchListElementComponent, object, parent, 'parent title', 'family name, given name', 'job title', [ - ]), -); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Collection = parentObj; + + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); + } + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('PersonSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(PersonSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'family name,given name', 'job title', []); + }); + }); +} diff --git a/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/project/project-sidebar-search-list-element.component.spec.ts b/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/project/project-sidebar-search-list-element.component.spec.ts index a7be69965fc..becb8842a41 100644 --- a/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/project/project-sidebar-search-list-element.component.spec.ts +++ b/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/project/project-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,12 @@ +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; + import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../../../shared/object-collection/shared/item-search-result.model'; @@ -27,6 +36,45 @@ const parent = Object.assign(new Collection(), { }, }); -describe('ProjectSidebarSearchListElementComponent', - createSidebarSearchListElementTests(ProjectSidebarSearchListElementComponent, object, parent, 'parent title', 'title', undefined), -); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Collection = parentObj; + + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); + } + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('ProjectSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(ProjectSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', undefined); + }); + }); +} diff --git a/src/app/shared/object-list/sidebar-search-list-element/collection/collection-sidebar-search-list-element.component.spec.ts b/src/app/shared/object-list/sidebar-search-list-element/collection/collection-sidebar-search-list-element.component.spec.ts index 5b0e07ba232..1109b32621e 100644 --- a/src/app/shared/object-list/sidebar-search-list-element/collection/collection-sidebar-search-list-element.component.spec.ts +++ b/src/app/shared/object-list/sidebar-search-list-element/collection/collection-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,11 @@ +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; + import { Collection } from '../../../../core/shared/collection.model'; import { Community } from '../../../../core/shared/community.model'; import { CollectionSearchResult } from '../../../object-collection/shared/collection-search-result.model'; @@ -32,6 +40,45 @@ const parent = Object.assign(new Community(), { }, }); -describe('CollectionSidebarSearchListElementComponent', - createSidebarSearchListElementTests(CollectionSidebarSearchListElementComponent, object, parent, 'parent title', 'title', 'description'), -); +function getExpectedHierarchicalTitle(parentObj: Community, obj: CollectionSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Community = parentObj; + + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); + } + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('CollectionSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(CollectionSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', 'description'); + }); + }); +} diff --git a/src/app/shared/object-list/sidebar-search-list-element/community/community-sidebar-search-list-element.component.spec.ts b/src/app/shared/object-list/sidebar-search-list-element/community/community-sidebar-search-list-element.component.spec.ts index f3114feda4e..626081ca7f6 100644 --- a/src/app/shared/object-list/sidebar-search-list-element/community/community-sidebar-search-list-element.component.spec.ts +++ b/src/app/shared/object-list/sidebar-search-list-element/community/community-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,11 @@ +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; + import { Community } from '../../../../core/shared/community.model'; import { CommunitySearchResult } from '../../../object-collection/shared/community-search-result.model'; import { createSidebarSearchListElementTests } from '../sidebar-search-list-element.component.spec'; @@ -31,6 +39,45 @@ const parent = Object.assign(new Community(), { }, }); -describe('CommunitySidebarSearchListElementComponent', - createSidebarSearchListElementTests(CommunitySidebarSearchListElementComponent, object, parent, 'parent title', 'title', 'description'), -); +function getExpectedHierarchicalTitle(parentObj: Community, obj: CommunitySearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Community = parentObj; + + const fetchParentTitles = (currParent: Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); + } + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('CommunitySidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(CommunitySidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', 'description'); + }); + }); +} diff --git a/src/app/shared/object-list/sidebar-search-list-element/item-types/publication/publication-sidebar-search-list-element.component.spec.ts b/src/app/shared/object-list/sidebar-search-list-element/item-types/publication/publication-sidebar-search-list-element.component.spec.ts index d078d8e1c5b..d7f9e38dec4 100644 --- a/src/app/shared/object-list/sidebar-search-list-element/item-types/publication/publication-sidebar-search-list-element.component.spec.ts +++ b/src/app/shared/object-list/sidebar-search-list-element/item-types/publication/publication-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,12 @@ +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; + import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../../object-collection/shared/item-search-result.model'; @@ -42,6 +51,45 @@ const parent = Object.assign(new Collection(), { }, }); -describe('PublicationSidebarSearchListElementComponent', - createSidebarSearchListElementTests(PublicationSidebarSearchListElementComponent, object, parent, 'parent title', 'title', '(publisher, date) author'), -); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Collection = parentObj; + + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); + } + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('PublicationSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(PublicationSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', '(publisher, date) author'); + }); + }); +} diff --git a/src/app/shared/object-list/sidebar-search-list-element/sidebar-search-list-element.component.html b/src/app/shared/object-list/sidebar-search-list-element/sidebar-search-list-element.component.html index 040f528768d..a8f7cfb5dc5 100644 --- a/src/app/shared/object-list/sidebar-search-list-element/sidebar-search-list-element.component.html +++ b/src/app/shared/object-list/sidebar-search-list-element/sidebar-search-list-element.component.html @@ -1,6 +1,6 @@ - +
+ [innerHTML]="(hierarchicalTitle$ && hierarchicalTitle$ | async) ? (hierarchicalTitle$ | async) : ('home.breadcrumbs' | translate)">
, parent: DSpaceObject, - expectedParentTitle: string, + expectedHierarchicalTitle: string, expectedTitle: string, expectedDescription: string, extraProviders: any[] = [], @@ -59,9 +59,9 @@ export function createSidebarSearchListElementTests( fixture.detectChanges(); }); - it('should contain the correct parent title', (done) => { - component.parentTitle$.subscribe((title) => { - expect(title).toEqual(expectedParentTitle); + it('should contain the correct hierarchical title', (done) => { + component.hierarchicalTitle$.subscribe((title) => { + expect(title).toEqual(expectedHierarchicalTitle); done(); }); }); diff --git a/src/app/shared/object-list/sidebar-search-list-element/sidebar-search-list-element.component.ts b/src/app/shared/object-list/sidebar-search-list-element/sidebar-search-list-element.component.ts index e65883cd3ec..54f3fe419f9 100644 --- a/src/app/shared/object-list/sidebar-search-list-element/sidebar-search-list-element.component.ts +++ b/src/app/shared/object-list/sidebar-search-list-element/sidebar-search-list-element.component.ts @@ -13,8 +13,10 @@ import { of as observableOf, } from 'rxjs'; import { + catchError, find, map, + switchMap, } from 'rxjs/operators'; import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; @@ -46,9 +48,9 @@ import { SearchResultListElementComponent } from '../search-result-list-element/ */ export class SidebarSearchListElementComponent, K extends DSpaceObject> extends SearchResultListElementComponent implements OnInit { /** - * Observable for the title of the parent object (displayed above the object's title) + * Observable for the hierarchical title i.e community > subcommunity > collection */ - parentTitle$: Observable; + hierarchicalTitle$: Observable; /** * A description to display below the title @@ -68,7 +70,7 @@ export class SidebarSearchListElementComponent, K exte ngOnInit(): void { super.ngOnInit(); if (hasValue(this.dso)) { - this.parentTitle$ = this.getParentTitle(); + this.hierarchicalTitle$ = this.getHierarchicalName(); this.description = this.getDescription(); } } @@ -82,16 +84,36 @@ export class SidebarSearchListElementComponent, K exte /** * Get the title of the object's parent - * Retrieve the parent by using the object's parent link and retrieving its 'dc.title' metadata + * keep on Retrieving recursively the parent by using the object's parent link and retrieving its 'dc.title' metadata + * and build a heirarchical name by concating the parent's names */ - getParentTitle(): Observable { + getHierarchicalName(): Observable { return this.getParent().pipe( - map((parentRD: RemoteData) => { - return hasValue(parentRD) && hasValue(parentRD.payload) ? this.dsoNameService.getName(parentRD.payload) : undefined; + switchMap((parentRD: RemoteData) => { + if (hasValue(parentRD) && hasValue(parentRD.payload)) { + const parentName$: string = this.dsoNameService.getName(parentRD.payload); + if (parentName$) { + return this.createInstanceFromDSpaceObject(parentRD.payload).getHierarchicalName().pipe( + map((ancestorName: string) => ancestorName ? `${ancestorName} > ${parentName$}` : parentName$), + ); + } + return observableOf(''); + } + return observableOf(''); }), + catchError(() => observableOf('')), ); } + /** + * Utility method to create an instance of the current class from a DSpaceObject + */ + private createInstanceFromDSpaceObject(dso: DSpaceObject): this { + const instance = Object.create(this); + instance.dso = dso; + return instance; + } + /** * Get the parent of the object */ diff --git a/src/app/shared/truncatable/truncatable-part/truncatable-part.component.scss b/src/app/shared/truncatable/truncatable-part/truncatable-part.component.scss index e045b197d28..a3656fc389e 100644 --- a/src/app/shared/truncatable/truncatable-part/truncatable-part.component.scss +++ b/src/app/shared/truncatable/truncatable-part/truncatable-part.component.scss @@ -9,3 +9,8 @@ .removeFaded.content::after { display: none; } + +.content { + white-space: normal; + overflow: visible; +} \ No newline at end of file