From 827ffc2d79a1c2655561971c21df7a72a91a2544 Mon Sep 17 00:00:00 2001 From: lotte Date: Fri, 9 Aug 2019 12:54:01 +0200 Subject: [PATCH] fixed relationship service finished --- .../publication/publication.component.ts | 19 +-- .../shared/item-relationships-utils.ts | 43 ------- .../item-types/shared/item.component.ts | 32 +---- src/app/core/data/relationship.service.ts | 109 +++++++++++------- .../journal-issue/journal-issue.component.ts | 13 +-- .../journal-volume.component.ts | 13 +-- .../item-pages/journal/journal.component.ts | 9 +- .../item-pages/orgunit/orgunit.component.ts | 22 +--- .../item-pages/person/person.component.ts | 30 ++--- .../item-pages/project/project.component.ts | 21 +--- ...dynamic-lookup-relation-modal.component.ts | 2 +- 11 files changed, 97 insertions(+), 216 deletions(-) diff --git a/src/app/+item-page/simple/item-types/publication/publication.component.ts b/src/app/+item-page/simple/item-types/publication/publication.component.ts index 1f855b59b2..11d1f7a836 100644 --- a/src/app/+item-page/simple/item-types/publication/publication.component.ts +++ b/src/app/+item-page/simple/item-types/publication/publication.component.ts @@ -7,7 +7,6 @@ import { } from '../../../../shared/items/item-type-decorator'; import { ItemComponent } from '../shared/item.component'; import { MetadataRepresentation } from '../../../../core/shared/metadata-representation/metadata-representation.model'; -import { getRelatedItemsByTypeLabel } from '../shared/item-relationships-utils'; @rendersItemType('Publication', ItemViewMode.Detail) @rendersItemType(DEFAULT_ITEM_TYPE, ItemViewMode.Detail) @@ -41,22 +40,12 @@ export class PublicationComponent extends ItemComponent implements OnInit { ngOnInit(): void { super.ngOnInit(); - if (this.resolvedRelsAndTypes$) { + this.authors$ = this.buildRepresentations('Person', 'dc.contributor.author'); - this.authors$ = this.buildRepresentations('Person', 'dc.contributor.author'); + this.projects$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isProjectOfPublication'); - this.projects$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isProjectOfPublication') - ); + this.orgUnits$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isOrgUnitOfPublication'); - this.orgUnits$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isOrgUnitOfPublication') - ); - - this.journalIssues$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isJournalIssueOfPublication') - ); - - } + this.journalIssues$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isJournalIssueOfPublication'); } } diff --git a/src/app/+item-page/simple/item-types/shared/item-relationships-utils.ts b/src/app/+item-page/simple/item-types/shared/item-relationships-utils.ts index 3ec41085f5..0f054f89ec 100644 --- a/src/app/+item-page/simple/item-types/shared/item-relationships-utils.ts +++ b/src/app/+item-page/simple/item-types/shared/item-relationships-utils.ts @@ -46,36 +46,6 @@ export const compareArraysUsing = (mapFn: (t: T) => any) => export const compareArraysUsingIds = () => compareArraysUsing((t: T) => hasValue(t) ? t.id : undefined); -/** - * Fetch the relationships which match the type label given - * @param {string} label Type label - * @param thisId The item's id of which the relations belong to - * @returns {(source: Observable<[Relationship[] , RelationshipType[]]>) => Observable} - */ -export const filterRelationsByTypeLabel = (label: string, thisId?: string) => - (source: Observable<[Relationship[], RelationshipType[]]>): Observable => - source.pipe( - switchMap(([relsCurrentPage, relTypesCurrentPage]) => { - const relatedItems$ = observableZip(...relsCurrentPage.map((rel: Relationship) => - observableCombineLatest( - rel.leftItem.pipe(getSucceededRemoteData(), getRemoteDataPayload()), - rel.rightItem.pipe(getSucceededRemoteData(), getRemoteDataPayload())) - ) - ); - return relatedItems$.pipe( - map((arr) => relsCurrentPage.filter((rel: Relationship, idx: number) => - hasValue(relTypesCurrentPage[idx]) && ( - (hasNoValue(thisId) && (relTypesCurrentPage[idx].leftLabel === label || - relTypesCurrentPage[idx].rightLabel === label)) || - (thisId === arr[idx][0].id && relTypesCurrentPage[idx].leftLabel === label) || - (thisId === arr[idx][1].id && relTypesCurrentPage[idx].rightLabel === label) - ) - )) - ); - }), - distinctUntilChanged(compareArraysUsingIds()) - ); - /** * Operator for turning a list of relationships into a list of the relevant items * @param {string} thisId The item's id of which the relations belong to @@ -104,19 +74,6 @@ export const relationsToItems = (thisId: string) => distinctUntilChanged(compareArraysUsingIds()), ); -/** - * Operator for turning a list of relationships and their relationship-types into a list of relevant items by relationship label - * @param thisId The item's id of which the relations belong to - * @param label The label of the relationship-type to filter on - * @param side Filter only on one side of the relationship (for example: child-parent relationships) - */ -export const getRelatedItemsByTypeLabel = (thisId: string, label: string) => - (source: Observable<[Relationship[], RelationshipType[]]>): Observable => - source.pipe( - filterRelationsByTypeLabel(label, thisId), - relationsToItems(thisId) - ); - /** * Operator for turning a list of relationships into a list of metadatarepresentations given the original metadata * @param parentId The id of the parent item diff --git a/src/app/+item-page/simple/item-types/shared/item.component.ts b/src/app/+item-page/simple/item-types/shared/item.component.ts index 556496fe49..5184b30359 100644 --- a/src/app/+item-page/simple/item-types/shared/item.component.ts +++ b/src/app/+item-page/simple/item-types/shared/item.component.ts @@ -15,6 +15,7 @@ import { MetadatumRepresentation } from '../../../../core/shared/metadata-repres import { of } from 'rxjs/internal/observable/of'; import { MetadataValue } from '../../../../core/shared/metadata.models'; import { compareArraysUsingIds } from './item-relationships-utils'; +import { RelationshipService } from '../../../../core/data/relationship.service'; /** * Operator for turning a list of relationships into a list of metadatarepresentations given the original metadata @@ -62,39 +63,12 @@ export const relationsToRepresentations = (thisId: string, itemType: string, met * A generic component for displaying metadata and relations of an item */ export class ItemComponent implements OnInit { - /** - * Resolved relationships and types together in one observable - */ - resolvedRelsAndTypes$: Observable<[Relationship[], RelationshipType[]]>; - constructor( - @Inject(ITEM) public item: Item + @Inject(ITEM) public item: Item, + protected relationshipService: RelationshipService ) {} ngOnInit(): void { - const relationships$ = this.item.relationships; - if (relationships$) { - const relsCurrentPage$ = relationships$.pipe( - filter((rd: RemoteData>) => rd.hasSucceeded), - getRemoteDataPayload(), - map((pl: PaginatedList) => pl.page), - distinctUntilChanged(compareArraysUsingIds()) - ); - - const relTypesCurrentPage$ = relsCurrentPage$.pipe( - flatMap((rels: Relationship[]) => - observableZip(...rels.map((rel: Relationship) => rel.relationshipType)).pipe( - map(([...arr]: Array>) => arr.map((d: RemoteData) => d.payload)) - ) - ), - distinctUntilChanged(compareArraysUsingIds()) - ); - - this.resolvedRelsAndTypes$ = observableCombineLatest( - relsCurrentPage$, - relTypesCurrentPage$ - ); - } } /** diff --git a/src/app/core/data/relationship.service.ts b/src/app/core/data/relationship.service.ts index 95f6ae4097..ad3927db90 100644 --- a/src/app/core/data/relationship.service.ts +++ b/src/app/core/data/relationship.service.ts @@ -3,7 +3,7 @@ import { RequestService } from './request.service'; import { HALEndpointService } from '../shared/hal-endpoint.service'; import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service'; import { hasValue, hasValueOperator, isNotEmptyOperator } from '../../shared/empty.util'; -import { distinctUntilChanged, filter, flatMap, map, startWith, switchMap, tap } from 'rxjs/operators'; +import { distinctUntilChanged, filter, flatMap, map, startWith, switchAll, switchMap, tap } from 'rxjs/operators'; import { configureRequest, getRemoteDataPayload, getResponseFromEntry, getSucceededRemoteData } from '../shared/operators'; import { DeleteRequest, GetRequest, PostRequest, RestRequest } from './request.models'; import { Observable } from 'rxjs/internal/Observable'; @@ -18,7 +18,6 @@ import { ItemDataService } from './item-data.service'; import { compareArraysUsingIds, relationsToItems } from '../../+item-page/simple/item-types/shared/item-relationships-utils'; import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service'; import { HttpHeaders } from '@angular/common/http'; -import { RequestEntry } from './request.reducer'; /** * The service handling all relationship requests @@ -88,36 +87,36 @@ export class RelationshipService { ); } - /** - * Get an item its relationships in the form of an array - * @param item - */ - getItemRelationships(item: Item): Observable>> { - return this.halService.getEndpoint('items/' + item.uuid + '/relationships') - .pipe( - map((endpointURL: string) => new GetRequest(this.requestService.generateRequestId(), endpointURL)), - configureRequest(this.requestService), - switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)), - filter((entry: RequestEntry) => hasValue(entry) && hasValue(entry.response)), - switchMap((entry: RequestEntry) => this.rdbService.buildList(entry.request.href)), - ) as any; - } - - /** - * Get an item its relationships in the form of an array - * @param item - */ - getItemRelationshipsByType(item: Item, relationshipTypeLabel: string): Observable>> { - return this.halService.getEndpoint(this.linkPath + '/search/byLabel') - .pipe( - map((endpointURL: string) => `${endpointURL}?label=${relationshipTypeLabel}&dso=${item.uuid}`), - map((endpointURL: string) => new GetRequest(this.requestService.generateRequestId(), endpointURL)), - configureRequest(this.requestService), - switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)), - filter((entry: RequestEntry) => hasValue(entry) && hasValue(entry.response)), - switchMap((entry: RequestEntry) => this.rdbService.buildList(entry.request.href)) - ); - } + // /** + // * Get an item its relationships in the form of an array + // * @param item + // */ + // getItemRelationships(item: Item): Observable>> { + // return this.halService.getEndpoint('items/' + item.uuid + '/relationships') + // .pipe( + // map((endpointURL: string) => new GetRequest(this.requestService.generateRequestId(), endpointURL)), + // configureRequest(this.requestService), + // switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)), + // filter((entry: RequestEntry) => hasValue(entry) && hasValue(entry.response)), + // switchMap((entry: RequestEntry) => this.rdbService.buildList(entry.request.href)), + // ) as any; + // } + // + // /** + // * Get an item its relationships in the form of an array + // * @param item + // */ + // getItemRelationshipsByType(item: Item, relationshipTypeLabel: string): Observable>> { + // return this.halService.getEndpoint(this.linkPath + '/search/byLabel') + // .pipe( + // map((endpointURL: string) => `${endpointURL}?label=${relationshipTypeLabel}&dso=${item.uuid}`), + // map((endpointURL: string) => new GetRequest(this.requestService.generateRequestId(), endpointURL)), + // configureRequest(this.requestService), + // switchMap((restRequest: RestRequest) => this.requestService.getByUUID(restRequest.uuid)), + // filter((entry: RequestEntry) => hasValue(entry) && hasValue(entry.response)), + // switchMap((entry: RequestEntry) => this.rdbService.buildList(entry.request.href)) + // ); + // } /** @@ -142,9 +141,7 @@ export class RelationshipService { * @param item */ getRelationshipTypeLabelsByItem(item: Item): Observable { - return this.getItemRelationships(item).pipe( - getSucceededRemoteData(), - map((relationshipsListRD: RemoteData>) => relationshipsListRD.payload.page), + return this.getItemRelationshipsArray(item).pipe( switchMap((relationships: Relationship[]) => observableCombineLatest(relationships.map((relationship: Relationship) => this.getRelationshipTypeLabelByRelationshipAndItem(relationship, item)))), map((labels: string[]) => Array.from(new Set(labels))) ); @@ -184,12 +181,39 @@ export class RelationshipService { * @param item * @param label */ - //TODO THIS THING IS CAUSING ISSUES (the getbytype thingie) getRelatedItemsByLabel(item: Item, label: string): Observable { - return this.getItemRelationshipsByType(item, label).pipe( - getSucceededRemoteData(), - map((relationshipsListRD: RemoteData>) => relationshipsListRD.payload.page), - relationsToItems(item.uuid) + return this.getItemRelationshipsByLabel(item, label).pipe(relationsToItems(item.uuid)); + } + + + /** + * Resolve a given item's relationships into related items, filtered by a relationship label + * and return the items as an array + * @param item + * @param label + */ + getItemRelationshipsByLabel(item: Item, label: string): Observable { + return this.getItemRelationshipsArray(item).pipe( + switchMap((relationships: Relationship[]) => { + return observableCombineLatest( + ...relationships.map((relationship: Relationship) => { + return relationship.relationshipType.pipe( + getSucceededRemoteData(), + getRemoteDataPayload(), + map((relationshipType: RelationshipType) => { + if (label === relationshipType.rightLabel || label === relationshipType.leftLabel) { + return relationship; + } else { + return undefined; + } + }), + ) + }) + ) + }), + map((relationships: Relationship[]) => + relationships.filter((relationship: Relationship) => hasValue(relationship)) + ), ); } @@ -213,10 +237,7 @@ export class RelationshipService { ); })) }), - map((relationships: Relationship[]) => { - const test = relationships.filter((relationship => hasValue(relationship))); console.log(test); return test; - }), - tap((ids) => console.log(ids)) + map((relationships: Relationship[]) => relationships.filter((relationship => hasValue(relationship)))), ) } diff --git a/src/app/entity-groups/journal-entities/item-pages/journal-issue/journal-issue.component.ts b/src/app/entity-groups/journal-entities/item-pages/journal-issue/journal-issue.component.ts index 188e7c30f7..0df34c2fbf 100644 --- a/src/app/entity-groups/journal-entities/item-pages/journal-issue/journal-issue.component.ts +++ b/src/app/entity-groups/journal-entities/item-pages/journal-issue/journal-issue.component.ts @@ -2,9 +2,7 @@ import { Component } from '@angular/core'; import { Observable } from 'rxjs'; import { Item } from '../../../../core/shared/item.model'; import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator'; -import { isNotEmpty } from '../../../../shared/empty.util'; import { ItemComponent } from '../../../../+item-page/simple/item-types/shared/item.component'; -import { getRelatedItemsByTypeLabel } from '../../../../+item-page/simple/item-types/shared/item-relationships-utils'; @rendersItemType('JournalIssue', ItemViewMode.Detail) @Component({ @@ -28,14 +26,7 @@ export class JournalIssueComponent extends ItemComponent { ngOnInit(): void { super.ngOnInit(); - - if (isNotEmpty(this.resolvedRelsAndTypes$)) { - this.volumes$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isJournalVolumeOfIssue') - ); - this.publications$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isPublicationOfJournalIssue') - ); - } + this.volumes$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isJournalVolumeOfIssue'); + this.publications$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isPublicationOfJournalIssue'); } } diff --git a/src/app/entity-groups/journal-entities/item-pages/journal-volume/journal-volume.component.ts b/src/app/entity-groups/journal-entities/item-pages/journal-volume/journal-volume.component.ts index 6c4b60de4c..9584e25160 100644 --- a/src/app/entity-groups/journal-entities/item-pages/journal-volume/journal-volume.component.ts +++ b/src/app/entity-groups/journal-entities/item-pages/journal-volume/journal-volume.component.ts @@ -2,9 +2,7 @@ import { Component } from '@angular/core'; import { Observable } from 'rxjs'; import { Item } from '../../../../core/shared/item.model'; import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator'; -import { isNotEmpty } from '../../../../shared/empty.util'; import { ItemComponent } from '../../../../+item-page/simple/item-types/shared/item.component'; -import { getRelatedItemsByTypeLabel } from '../../../../+item-page/simple/item-types/shared/item-relationships-utils'; @rendersItemType('JournalVolume', ItemViewMode.Detail) @Component({ @@ -28,14 +26,7 @@ export class JournalVolumeComponent extends ItemComponent { ngOnInit(): void { super.ngOnInit(); - - if (isNotEmpty(this.resolvedRelsAndTypes$)) { - this.journals$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isJournalOfVolume') - ); - this.issues$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isIssueOfJournalVolume') - ); - } + this.journals$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isJournalOfVolume'); + this.issues$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isIssueOfJournalVolume'); } } diff --git a/src/app/entity-groups/journal-entities/item-pages/journal/journal.component.ts b/src/app/entity-groups/journal-entities/item-pages/journal/journal.component.ts index 9004f2da2f..7ce97f923f 100644 --- a/src/app/entity-groups/journal-entities/item-pages/journal/journal.component.ts +++ b/src/app/entity-groups/journal-entities/item-pages/journal/journal.component.ts @@ -2,9 +2,7 @@ import { Component } from '@angular/core'; import { Observable } from 'rxjs'; import { Item } from '../../../../core/shared/item.model'; import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator'; -import { isNotEmpty } from '../../../../shared/empty.util'; import { ItemComponent } from '../../../../+item-page/simple/item-types/shared/item.component'; -import { getRelatedItemsByTypeLabel } from '../../../../+item-page/simple/item-types/shared/item-relationships-utils'; @rendersItemType('Journal', ItemViewMode.Detail) @Component({ @@ -23,11 +21,6 @@ export class JournalComponent extends ItemComponent { ngOnInit(): void { super.ngOnInit(); - - if (isNotEmpty(this.resolvedRelsAndTypes$)) { - this.volumes$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isVolumeOfJournal') - ); - } + this.volumes$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isVolumeOfJournal'); } } diff --git a/src/app/entity-groups/research-entities/item-pages/orgunit/orgunit.component.ts b/src/app/entity-groups/research-entities/item-pages/orgunit/orgunit.component.ts index f7c62abcc3..605673dcf1 100644 --- a/src/app/entity-groups/research-entities/item-pages/orgunit/orgunit.component.ts +++ b/src/app/entity-groups/research-entities/item-pages/orgunit/orgunit.component.ts @@ -2,9 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { Observable } from 'rxjs'; import { Item } from '../../../../core/shared/item.model'; import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator'; -import { isNotEmpty } from '../../../../shared/empty.util'; import { ItemComponent } from '../../../../+item-page/simple/item-types/shared/item.component'; -import { getRelatedItemsByTypeLabel } from '../../../../+item-page/simple/item-types/shared/item-relationships-utils'; @rendersItemType('OrgUnit', ItemViewMode.Detail) @Component({ @@ -33,18 +31,8 @@ export class OrgunitComponent extends ItemComponent implements OnInit { ngOnInit(): void { super.ngOnInit(); - - if (isNotEmpty(this.resolvedRelsAndTypes$)) { - this.people$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isPersonOfOrgUnit') - ); - - this.projects$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isProjectOfOrgUnit') - ); - - this.publications$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isPublicationOfOrgUnit') - ); - } - }} + this.people$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isPersonOfOrgUnit'); + this.projects$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isProjectOfOrgUnit'); + this.publications$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isPublicationOfOrgUnit'); + } +} diff --git a/src/app/entity-groups/research-entities/item-pages/person/person.component.ts b/src/app/entity-groups/research-entities/item-pages/person/person.component.ts index 186f3b5a84..d6b33b43e1 100644 --- a/src/app/entity-groups/research-entities/item-pages/person/person.component.ts +++ b/src/app/entity-groups/research-entities/item-pages/person/person.component.ts @@ -3,10 +3,9 @@ import { Observable, of as observableOf } from 'rxjs'; import { Item } from '../../../../core/shared/item.model'; import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator'; import { ITEM } from '../../../../shared/items/switcher/item-type-switcher.component'; -import { isNotEmpty } from '../../../../shared/empty.util'; import { ItemComponent } from '../../../../+item-page/simple/item-types/shared/item.component'; -import { getRelatedItemsByTypeLabel } from '../../../../+item-page/simple/item-types/shared/item-relationships-utils'; import { getQueryByRelations } from '../../../../shared/utils/relation-query.utils'; +import { RelationshipService } from '../../../../core/data/relationship.service'; @rendersItemType('Person', ItemViewMode.Detail) @Component({ @@ -44,28 +43,19 @@ export class PersonComponent extends ItemComponent { fixedFilterQuery: string; constructor( - @Inject(ITEM) public item: Item + @Inject(ITEM) public item: Item, + protected relationshipService: RelationshipService ) { - super(item); + super(item, relationshipService); } + ngOnInit(): void { super.ngOnInit(); + this.publications$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isPublicationOfAuthor'); + this.projects$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isProjectOfPerson'); + this.orgUnits$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isOrgUnitOfPerson'); - if (isNotEmpty(this.resolvedRelsAndTypes$)) { - this.publications$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isPublicationOfAuthor') - ); - - this.projects$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isProjectOfPerson') - ); - - this.orgUnits$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isOrgUnitOfPerson') - ); - - this.fixedFilterQuery = getQueryByRelations('isAuthorOfPublication', this.item.id); - this.fixedFilter$ = observableOf('publication'); - } + this.fixedFilterQuery = getQueryByRelations('isAuthorOfPublication', this.item.id); + this.fixedFilter$ = observableOf('publication'); } } diff --git a/src/app/entity-groups/research-entities/item-pages/project/project.component.ts b/src/app/entity-groups/research-entities/item-pages/project/project.component.ts index 1cc0e623cd..a1a2604775 100644 --- a/src/app/entity-groups/research-entities/item-pages/project/project.component.ts +++ b/src/app/entity-groups/research-entities/item-pages/project/project.component.ts @@ -3,9 +3,7 @@ import { Observable } from 'rxjs'; import { Item } from '../../../../core/shared/item.model'; import { MetadataRepresentation } from '../../../../core/shared/metadata-representation/metadata-representation.model'; import { ItemViewMode, rendersItemType } from '../../../../shared/items/item-type-decorator'; -import { isNotEmpty } from '../../../../shared/empty.util'; import { ItemComponent } from '../../../../+item-page/simple/item-types/shared/item.component'; -import { getRelatedItemsByTypeLabel } from '../../../../+item-page/simple/item-types/shared/item-relationships-utils'; @rendersItemType('Project', ItemViewMode.Detail) @Component({ @@ -39,21 +37,10 @@ export class ProjectComponent extends ItemComponent implements OnInit { ngOnInit(): void { super.ngOnInit(); + this.contributors$ = this.buildRepresentations('OrgUnit', 'project.contributor.other'); - if (isNotEmpty(this.resolvedRelsAndTypes$)) { - this.contributors$ = this.buildRepresentations('OrgUnit', 'project.contributor.other'); - - this.people$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isPersonOfProject') - ); - - this.publications$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isPublicationOfProject') - ); - - this.orgUnits$ = this.resolvedRelsAndTypes$.pipe( - getRelatedItemsByTypeLabel(this.item.id, 'isOrgUnitOfProject') - ); - } + this.people$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isPersonOfProject'); + this.publications$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isPublicationOfProject'); + this.orgUnits$ = this.relationshipService.getRelatedItemsByLabel(this.item, 'isOrgUnitOfProject'); } } diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts index dbd3bfd477..b923332e8f 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/dynamic-lookup-relation-modal.component.ts @@ -175,7 +175,7 @@ export class DsDynamicLookupRelationModalComponent implements OnInit, OnDestroy deselect(selectableObject: SearchResult) { this.itemRD$.pipe( getSucceededRemoteData(), - switchMap((itemRD: RemoteData) => this.relationshipService.getItemRelationshipsByType(itemRD.payload, this.relationship.relationshipType)), + switchMap((itemRD: RemoteData) => this.relationshipService.getItemRelationshipsByLabel(itemRD.payload, this.relationship.relationshipType)), // map((items: Item[]) => items.find((item: Item) => )) ).subscribe();